mirror of
https://github.com/Ellpeck/GameBundle.git
synced 2024-12-22 19:59:23 +01:00
added the option to create ARM builds
This commit is contained in:
parent
1373859a13
commit
6474fa037c
3 changed files with 61 additions and 31 deletions
|
@ -24,9 +24,22 @@ namespace GameBundle {
|
|||
public string LinuxRid { get; set; }
|
||||
[Option("mac-rid", Default = "osx-x64", HelpText = "The RID to use for mac builds")]
|
||||
public string MacRid { get; set; }
|
||||
|
||||
[Option('W', "win-arm", HelpText = "Bundle for windows arm")]
|
||||
public bool BuildWindowsArm { get; set; }
|
||||
[Option('L', "linux-arm", HelpText = "Bundle for linux arm")]
|
||||
public bool BuildLinuxArm { get; set; }
|
||||
[Option('M', "mac-arm", HelpText = "Bundle for mac arm")]
|
||||
public bool BuildMacArm { get; set; }
|
||||
[Option("win-arm-rid", Default = "win-arm64", HelpText = "The RID to use for windows arm builds")]
|
||||
public string WindowsArmRid { get; set; }
|
||||
[Option("linux-arm-rid", Default = "linux-arm64", HelpText = "The RID to use for linux arm builds")]
|
||||
public string LinuxArmRid { get; set; }
|
||||
[Option("mac-arm-rid", Default = "osx-arm64", HelpText = "The RID to use for mac arm builds")]
|
||||
public string MacArmRid { get; set; }
|
||||
|
||||
[Option('z', "zip", HelpText = "Store the build results in zip files instead of folders")]
|
||||
public bool Zip { get; set; }
|
||||
|
||||
[Option('b', "mac-bundle", HelpText = "Create an app bundle for mac")]
|
||||
public bool MacBundle { get; set; }
|
||||
[Option("mac-bundle-resources", Default = new[] {"Content", "*.icns"}, HelpText = "When creating an app bundle for mac, things that should go into the Resources folder rather than the MacOS folder")]
|
||||
|
|
|
@ -32,43 +32,40 @@ namespace GameBundle {
|
|||
Console.WriteLine($"Bundling project {proj.FullName}");
|
||||
|
||||
var builtAnything = false;
|
||||
if (options.BuildWindows) {
|
||||
Console.WriteLine("Bundling for windows");
|
||||
var res = Publish(options, proj, GetBuildDir(options, "win"), options.WindowsRid);
|
||||
if (res != 0)
|
||||
return res;
|
||||
builtAnything = true;
|
||||
var toBuild = new List<BuildConfig> {
|
||||
// regular builds
|
||||
new("windows", "win", options.WindowsRid, options.BuildWindows),
|
||||
new("linux", "linux", options.LinuxRid, options.BuildLinux),
|
||||
new("mac", "mac", options.MacRid, options.BuildMac, false, d => options.MacBundle ? CreateMacBundle(options, d) : 0),
|
||||
// arm builds
|
||||
new("windows arm", "win-arm", options.WindowsArmRid, options.BuildWindowsArm, true),
|
||||
new("linux arm", "linux-arm", options.LinuxArmRid, options.BuildLinuxArm, true),
|
||||
new("mac arm", "mac-arm", options.MacArmRid, options.BuildMacArm, true, d => options.MacBundle ? CreateMacBundle(options, d) : 0)
|
||||
};
|
||||
foreach (var config in toBuild) {
|
||||
if (config.ShouldBuild) {
|
||||
Console.WriteLine($"Bundling for {config.DisplayName}");
|
||||
var res = Publish(options, proj, config);
|
||||
if (res != 0)
|
||||
return res;
|
||||
builtAnything = true;
|
||||
}
|
||||
}
|
||||
if (options.BuildLinux) {
|
||||
Console.WriteLine("Bundling for linux");
|
||||
var res = Publish(options, proj, GetBuildDir(options, "linux"), options.LinuxRid);
|
||||
if (res != 0)
|
||||
return res;
|
||||
builtAnything = true;
|
||||
}
|
||||
if (options.BuildMac) {
|
||||
Console.WriteLine("Bundling for mac");
|
||||
var dir = GetBuildDir(options, "mac");
|
||||
var res = Publish(options, proj, dir, options.MacRid,
|
||||
() => options.MacBundle ? CreateMacBundle(options, dir, proj) : 0);
|
||||
if (res != 0)
|
||||
return res;
|
||||
builtAnything = true;
|
||||
}
|
||||
|
||||
if (!builtAnything)
|
||||
Console.WriteLine("No build took place. Supply -w, -l or -m arguments or see available arguments using --help.");
|
||||
|
||||
Console.WriteLine("Done");
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int Publish(Options options, FileInfo proj, DirectoryInfo buildDir, string rid, Func<int> additionalAction = null) {
|
||||
var publishResult = RunProcess(options, "dotnet", $"publish \"{proj.FullName}\" -o \"{buildDir.FullName}\" -r {rid} -c {options.BuildConfig} /p:PublishTrimmed={options.Trim} {options.BuildArgs}");
|
||||
private static int Publish(Options options, FileInfo proj, BuildConfig config) {
|
||||
var buildDir = GetBuildDir(options, config.DirectoryName);
|
||||
var publishResult = RunProcess(options, "dotnet", $"publish \"{proj.FullName}\" -o \"{buildDir.FullName}\" -r {config.Rid} -c {options.BuildConfig} /p:PublishTrimmed={options.Trim} {options.BuildArgs}");
|
||||
if (publishResult != 0)
|
||||
return publishResult;
|
||||
|
||||
// Run beauty
|
||||
if (!options.SkipLib) {
|
||||
if (!options.SkipLib && !config.SkipLib) {
|
||||
var excludes = $"\"{string.Join(";", options.ExcludedFiles)}\"";
|
||||
var log = options.Verbose ? "Detail" : "Error";
|
||||
var beautyResult = RunProcess(options, "dotnet", $"ncbeauty --loglevel={log} --force=True --noflag=True \"{buildDir.FullName}\" \"{options.LibFolder}\" {excludes}", AppDomain.CurrentDomain.BaseDirectory);
|
||||
|
@ -92,8 +89,8 @@ namespace GameBundle {
|
|||
}
|
||||
|
||||
// Run any additional actions like creating the mac bundle
|
||||
if (additionalAction != null) {
|
||||
var result = additionalAction();
|
||||
if (config.AdditionalAction != null) {
|
||||
var result = config.AdditionalAction.Invoke(buildDir);
|
||||
if (result != 0)
|
||||
return result;
|
||||
}
|
||||
|
@ -135,7 +132,7 @@ namespace GameBundle {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static int CreateMacBundle(Options options, DirectoryInfo buildDir, FileInfo proj) {
|
||||
private static int CreateMacBundle(Options options, DirectoryInfo buildDir) {
|
||||
var buildName = GetBuildName(options, buildDir);
|
||||
var app = buildDir.CreateSubdirectory($"{buildName}.app");
|
||||
var contents = app.CreateSubdirectory("Contents");
|
||||
|
@ -196,5 +193,25 @@ namespace GameBundle {
|
|||
return null;
|
||||
}
|
||||
|
||||
private readonly struct BuildConfig {
|
||||
|
||||
public readonly string DisplayName;
|
||||
public readonly string DirectoryName;
|
||||
public readonly string Rid;
|
||||
public readonly bool ShouldBuild;
|
||||
public readonly bool SkipLib;
|
||||
public readonly Func<DirectoryInfo, int> AdditionalAction;
|
||||
|
||||
public BuildConfig(string displayName, string directoryName, string rid, bool shouldBuild, bool skipLib = false, Func<DirectoryInfo, int> additionalAction = null) {
|
||||
this.DisplayName = displayName;
|
||||
this.DirectoryName = directoryName;
|
||||
this.Rid = rid;
|
||||
this.ShouldBuild = shouldBuild;
|
||||
this.SkipLib = skipLib;
|
||||
this.AdditionalAction = additionalAction;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1 +1 @@
|
|||
"../GameBundle/bin/Debug/net5.0/GameBundle.exe" -wlm -bzn -s Test.csproj -o bin/Bundled -v --mac-bundle-ignore macmain.txt
|
||||
"../GameBundle/bin/Debug/net5.0/GameBundle.exe" -wlmWL -bzn -s Test.csproj -o bin/Bundled -v --mac-bundle-ignore macmain.txt
|
Loading…
Reference in a new issue