Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Exclude unused bundle files in AppleAppBuilder #86316

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 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 Down Expand Up @@ -109,6 +109,7 @@
EnableAppSandbox="$(EnableAppSandbox)"
DiagnosticPorts="$(DiagnosticPorts)"
StripSymbolTable="$(StripDebugSymbols)"
ExcludeFromAppDir="$(_iOSLikeDedupAssembly)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This is really a nit but it would be cleaner to introduce a new local Item say:

  • _ExcludeFromAppDir Include="$(_iOSLikeDedupAssembly)" around lines 60-65 above

and then have the full list passed to the AppleAppBuilderTask:

  • ExcludeFromAppDir="@(_ExcludeFromAppDir)"

This way it would be simpler to expand the list of excluded items - if we figure out in the future something else should be excluded.

Otherwise, LGTM!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I think we could do the same thing to more properties and simplify the appbuilder.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

I think we could do the same thing to more properties and simplify the appbuilder.

I suggest we remove redundant properties and simplify the appbuilder in #86578.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

I think we could do the same thing to more properties and simplify the appbuilder.

I suggest we remove redundant properties and simplify the appbuilder in #86578.

Agreed!

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