Skip to content

Commit

Permalink
Build for the current OS when doing a CoreRT build
Browse files Browse the repository at this point in the history
Thealexbarney committed Nov 28, 2019
1 parent 62d2b79 commit f304f66
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
@@ -31,6 +32,9 @@ partial class Build : NukeBuild
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
public readonly string Configuration = IsLocalBuild ? "Debug" : "Release";

[Parameter("Don't enable any size-reducing settings on native builds.")]
public readonly bool Untrimmed;

[Solution("LibHac.sln")] readonly Solution _solution;
[GitRepository] readonly GitRepository _gitRepository;
[GitVersion] readonly GitVersion _gitVersion;
@@ -48,18 +52,40 @@ partial class Build : NukeBuild
AbsolutePath NugetConfig => RootDirectory / "nuget.config";

AbsolutePath CliMergedExe => ArtifactsDirectory / "hactoolnet.exe";
AbsolutePath CliNativeExe => ArtifactsDirectory / "hactoolnet_native.exe";
AbsolutePath CliNativeExe => ArtifactsDirectory / NativeProgramFilename;

Project LibHacProject => _solution.GetProject("LibHac").NotNull();
Project LibHacTestProject => _solution.GetProject("LibHac.Tests").NotNull();
Project HactoolnetProject => _solution.GetProject("hactoolnet").NotNull();

private string NativeRuntime { get; set; }
private string NativeProgramFilename { get; set; }

string AppVeyorVersion { get; set; }
Dictionary<string, object> VersionProps { get; set; } = new Dictionary<string, object>();

private const string DotNetFeedSource = "https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json";
const string CertFileName = "cert.pfx";

public Build()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
NativeRuntime = "win-x64";
NativeProgramFilename = "hactoolnet_native.exe";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
NativeRuntime = "linux-x64";
NativeProgramFilename = "hactoolnet_native";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
NativeRuntime = "osx-x64";
NativeProgramFilename = "hactoolnet_native";
}
}

private bool IsMasterBranch => _gitVersion?.BranchName.Equals("master") ?? false;

Target SetVersion => _ => _
@@ -305,16 +331,26 @@ partial class Build : NukeBuild
DotNet($"add {nativeProject} package Microsoft.DotNet.ILCompiler --version 1.0.0-alpha-*");

DotNetPublishSettings publishSettings = new DotNetPublishSettings()
.SetConfiguration(Configuration);

DotNetPublish(s => publishSettings
.SetConfiguration(Configuration)
.SetProject(nativeProject)
.SetFramework("netcoreapp3.0")
.SetRuntime("win-x64")
.SetRuntime(NativeRuntime)
.SetOutput(CliNativeDir)
.SetProperties(VersionProps));
.SetProperties(VersionProps);

if (!Untrimmed)
{
publishSettings = publishSettings
.AddProperty("RootAllApplicationAssemblies", false)
.AddProperty("IlcGenerateCompleteTypeMetadata", false)
.AddProperty("IlcGenerateStackTraceData", false)
.AddProperty("IlcFoldIdenticalMethodBodies", true)
;
}

DotNetPublish(publishSettings);

AbsolutePath tempExe = CliNativeDir / "hactoolnet_native.exe";
AbsolutePath tempExe = CliNativeDir / NativeProgramFilename;

File.Copy(tempExe, CliNativeExe, true);

0 comments on commit f304f66

Please sign in to comment.