Skip to content

Commit

Permalink
Reduce app size for iOS (dotnet#36902)
Browse files Browse the repository at this point in the history
We did the same mistake for Android - `libmonosgen-2.0.dylib` shouldn't be copied to bundle (we already have a mono runtime there)
  • Loading branch information
EgorBo authored May 27, 2020
1 parent 8b92b46 commit d422b0f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
]
},
"microsoft.dotnet.xharness.cli": {
"version": "1.0.0-prerelease.20265.8",
"version": "1.0.0-prerelease.20271.3",
"commands": [
"xharness"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public override bool Execute()
if (GenerateXcodeProject)
{
XcodeProjectPath = Xcode.GenerateXCode(ProjectName, MainLibraryFileName, assemblerFiles,
AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, UseAotForSimulator, NativeMainSource);
AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, UseAotForSimulator, Optimized, NativeMainSource);

if (BuildAppBundle)
{
Expand Down
18 changes: 16 additions & 2 deletions tools-local/tasks/mobile.tasks/AppleAppBuilder/Xcode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ public static string GenerateXCode(
bool preferDylibs,
bool useConsoleUiTemplate,
bool useAotForSimulator,
bool stripDebugSymbols,
string? nativeMainSource = null)
{
// bundle everything as resources excluding native files
string[] excludes = {".dll.o", ".dll.s", ".dwarf", ".m", ".h", ".a", ".bc"};
var excludes = new List<string> { ".dll.o", ".dll.s", ".dwarf", ".m", ".h", ".a", ".bc", "libmonosgen-2.0.dylib" };
if (stripDebugSymbols)
{
excludes.Add(".pdb");
}

string[] resources = Directory.GetFiles(workspace)
.Where(f => !excludes.Any(e => f.EndsWith(e, StringComparison.InvariantCultureIgnoreCase)))
Expand Down Expand Up @@ -150,7 +155,16 @@ public static string BuildAppBundle(
args.Append(" -configuration ").Append(config);

Utils.RunProcess("xcodebuild", args.ToString(), workingDir: Path.GetDirectoryName(xcodePrjPath));
return Path.Combine(Path.GetDirectoryName(xcodePrjPath)!, config + "-" + sdk,

string appPath = Path.Combine(Path.GetDirectoryName(xcodePrjPath)!, config + "-" + sdk,
Path.GetFileNameWithoutExtension(xcodePrjPath) + ".app");

long appSize = new DirectoryInfo(appPath)
.EnumerateFiles("*", SearchOption.AllDirectories)
.Sum(file => file.Length);

Utils.LogInfo($"\nAPP size: {(appSize / 1000_000.0):0.#} Mb.\n");

return appPath;
}
}

0 comments on commit d422b0f

Please sign in to comment.