Skip to content

Commit

Permalink
[mono] Exclude unused bundle files in AppleAppBuilder (#86316)
Browse files Browse the repository at this point in the history
* Exclude .cs dedup file

* Use excludes list and use a wildcard for icudt_*

* Use variable for ExcludeFromAppDir
  • Loading branch information
kotlarmilos authored May 26, 2023
1 parent 2678b34 commit b09e864
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/mono/sample/iOS/Program.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
<PropertyGroup Condition="'$(iOSLikeDedup)' == 'true'">
<_iOSLikeDedupAssembly>$(MSBuildThisFileDirectory)$(PublishDir)\aot-instances.dll</_iOSLikeDedupAssembly>
</PropertyGroup>
<WriteLinesToFile Condition="'$(iOSLikeDedup)' == 'true'" File="$(MSBuildThisFileDirectory)$(PublishDir)/aot-instances.cs" Overwrite="true" Lines="" WriteOnlyWhenDifferent="true" />
<WriteLinesToFile Condition="'$(iOSLikeDedup)' == 'true'" File="$(IntermediateOutputPath)/aot-instances.cs" Overwrite="true" Lines="" WriteOnlyWhenDifferent="true" />
<Csc Condition="'$(iOSLikeDedup)' == 'true'"
Sources="$(MSBuildThisFileDirectory)$(PublishDir)\aot-instances.cs"
Sources="$(IntermediateOutputPath)\aot-instances.cs"
OutputAssembly="$(_iOSLikeDedupAssembly)"
TargetType="library"
Deterministic="true"
Expand All @@ -62,6 +62,7 @@
<AotArguments>@(MonoAOTCompilerDefaultAotArguments, ';')</AotArguments>
<ProcessArguments>@(MonoAOTCompilerDefaultProcessArguments, ';')</ProcessArguments>
</AotInputAssemblies>
<_ExcludeFromAppDir Include="$(_iOSLikeDedupAssembly)" />
</ItemGroup>

<PropertyGroup>
Expand Down Expand Up @@ -109,6 +110,7 @@
EnableAppSandbox="$(EnableAppSandbox)"
DiagnosticPorts="$(DiagnosticPorts)"
StripSymbolTable="$(StripDebugSymbols)"
ExcludeFromAppDir="@(_ExcludeFromAppDir)"
AppDir="$(MSBuildThisFileDirectory)$(PublishDir)">
<Output TaskParameter="AppBundlePath" PropertyName="AppBundlePath" />
<Output TaskParameter="XcodeProjectPath" PropertyName="XcodeProjectPath" />
Expand Down
4 changes: 2 additions & 2 deletions src/tasks/AppleAppBuilder/AppleAppBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public override bool Execute()

if (GenerateXcodeProject)
{
XcodeProjectPath = generator.GenerateXCode(ProjectName, MainLibraryFileName, assemblerFiles, assemblerDataFiles, assemblerFilesToLink, extraLinkerArgs,
XcodeProjectPath = generator.GenerateXCode(ProjectName, MainLibraryFileName, assemblerFiles, assemblerDataFiles, assemblerFilesToLink, extraLinkerArgs, excludes,
AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, HybridGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource, UseNativeAOTRuntime);

if (BuildAppBundle)
Expand All @@ -348,7 +348,7 @@ public override bool Execute()
}
else if (GenerateCMakeProject)
{
generator.GenerateCMake(ProjectName, MainLibraryFileName, assemblerFiles, assemblerDataFiles, assemblerFilesToLink, extraLinkerArgs,
generator.GenerateCMake(ProjectName, MainLibraryFileName, assemblerFiles, assemblerDataFiles, assemblerFilesToLink, extraLinkerArgs, excludes,
AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, HybridGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource, UseNativeAOTRuntime);
}

Expand Down
13 changes: 8 additions & 5 deletions src/tasks/AppleAppBuilder/Xcode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public string GenerateXCode(
IEnumerable<string> asmDataFiles,
IEnumerable<string> asmLinkFiles,
IEnumerable<string> extraLinkerArgs,
IEnumerable<string> excludes,
string workspace,
string binDir,
string monoInclude,
Expand All @@ -191,7 +192,7 @@ public string GenerateXCode(
string? nativeMainSource = null,
bool useNativeAOTRuntime = false)
{
var cmakeDirectoryPath = GenerateCMake(projectName, entryPointLib, asmFiles, asmDataFiles, asmLinkFiles, extraLinkerArgs, workspace, binDir, monoInclude, preferDylibs, useConsoleUiTemplate, forceAOT, forceInterpreter, invariantGlobalization, hybridGlobalization, optimized, enableRuntimeLogging, enableAppSandbox, diagnosticPorts, runtimeComponents, nativeMainSource, useNativeAOTRuntime);
var cmakeDirectoryPath = GenerateCMake(projectName, entryPointLib, asmFiles, asmDataFiles, asmLinkFiles, extraLinkerArgs, excludes, workspace, binDir, monoInclude, preferDylibs, useConsoleUiTemplate, forceAOT, forceInterpreter, invariantGlobalization, hybridGlobalization, optimized, enableRuntimeLogging, enableAppSandbox, diagnosticPorts, runtimeComponents, nativeMainSource, useNativeAOTRuntime);
CreateXcodeProject(projectName, cmakeDirectoryPath);
return Path.Combine(binDir, projectName, projectName + ".xcodeproj");
}
Expand Down Expand Up @@ -236,6 +237,7 @@ public string GenerateCMake(
IEnumerable<string> asmDataFiles,
IEnumerable<string> asmLinkFiles,
IEnumerable<string> extraLinkerArgs,
IEnumerable<string> excludes,
string workspace,
string binDir,
string monoInclude,
Expand All @@ -254,18 +256,19 @@ public string GenerateCMake(
bool useNativeAOTRuntime = false)
{
// bundle everything as resources excluding native files
var excludes = new List<string> { ".dll.o", ".dll.s", ".dwarf", ".m", ".h", ".a", ".bc", "libmonosgen-2.0.dylib", "libcoreclr.dylib" };
var predefinedExcludes = new List<string> { ".dll.o", ".dll.s", ".dwarf", ".m", ".h", ".a", ".bc", "libmonosgen-2.0.dylib", "libcoreclr.dylib", "icudt_*" };
predefinedExcludes = predefinedExcludes.Concat(excludes).ToList();
if (!preferDylibs)
{
excludes.Add(".dylib");
predefinedExcludes.Add(".dylib");
}
if (optimized)
{
excludes.Add(".pdb");
predefinedExcludes.Add(".pdb");
}

string[] resources = Directory.GetFileSystemEntries(workspace, "", SearchOption.TopDirectoryOnly)
.Where(f => !excludes.Any(e => f.EndsWith(e, StringComparison.InvariantCultureIgnoreCase)))
.Where(f => !predefinedExcludes.Any(e => (!e.EndsWith('*') && f.EndsWith(e, StringComparison.InvariantCultureIgnoreCase)) || (e.EndsWith('*') && Path.GetFileName(f).StartsWith(e.TrimEnd('*'), StringComparison.InvariantCultureIgnoreCase))))
.ToArray();

if (string.IsNullOrEmpty(nativeMainSource))
Expand Down

0 comments on commit b09e864

Please sign in to comment.