Skip to content

Commit 55a0ef5

Browse files
committed
(#571) Build: pack compiler as runtime-dependent for nuget
1 parent 11c8d45 commit 55a0ef5

File tree

6 files changed

+92
-86
lines changed

6 files changed

+92
-86
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636

3737
- name: 📦 Pack Everything 📦
3838
shell: bash
39-
run: dotnet nuke PackCompilerBundle PackSdk PackTemplates
39+
run: dotnet nuke PackAllCompilerRuntimeSpecificBundles PackCompilerNuPkg PackSdk PackTemplates
4040

4141
- name: ✅ Upload Artifacts ✅
4242
# TODO

.github/workflows/run-build-and-unit-tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ jobs:
3838
shell: bash
3939
run: dotnet nuke CompileAll
4040

41-
- name: 🚚 Publish Compiler Bundle 🚚
41+
- name: 🚚 Pack Compiler Runtime-Specific Bundles 🚚
4242
shell: bash
43-
run: dotnet nuke PublishCompilerBundle
43+
run: dotnet nuke PackAllCompilerRuntimeSpecificBundles
4444

45-
- name: 📦 Pack Compiler Bundle 📦
45+
- name: 📦 Pack Compiler NuPkg 📦
4646
shell: bash
47-
run: dotnet nuke PackCompilerBundle
47+
run: dotnet nuke PackCompilerNuPkg
4848

4949
- name: ✅ Run Unit Tests ✅
5050
shell: bash

Cesium.Compiler/Cesium.Compiler.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ SPDX-License-Identifier: MIT
1010
<OutputType>Exe</OutputType>
1111
<TargetFramework>net9.0</TargetFramework>
1212
<ImplicitUsings>enable</ImplicitUsings>
13-
<PublishSingleFile>true</PublishSingleFile>
1413
<PublishTrimmed>true</PublishTrimmed>
1514
<RollForward>Major</RollForward>
16-
<RuntimeIdentifiers>win-x64;win-x86;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
1715
</PropertyGroup>
1816

1917
<ItemGroup>

Cesium.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<s:Boolean x:Key="/Default/UserDictionary/Words/=MSBUILDENSURESTDOUTFORTASKPROCESSES/@EntryIndexedValue">True</s:Boolean>
1717
<s:Boolean x:Key="/Default/UserDictionary/Words/=nint/@EntryIndexedValue">True</s:Boolean>
1818
<s:Boolean x:Key="/Default/UserDictionary/Words/=nuint/@EntryIndexedValue">True</s:Boolean>
19+
<s:Boolean x:Key="/Default/UserDictionary/Words/=nupkg/@EntryIndexedValue">True</s:Boolean>
1920
<s:Boolean x:Key="/Default/UserDictionary/Words/=offsetof/@EntryIndexedValue">True</s:Boolean>
2021
<s:Boolean x:Key="/Default/UserDictionary/Words/=runtimeconfig/@EntryIndexedValue">True</s:Boolean>
2122
<s:Boolean x:Key="/Default/UserDictionary/Words/=Subscriptable/@EntryIndexedValue">True</s:Boolean>

build/Build.Sdk.cs

Lines changed: 84 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
//
33
// SPDX-License-Identifier: MIT
44

5-
using System.Collections.Generic;
65
using System.IO;
7-
using NuGet.Packaging;
8-
using NuGet.Versioning;
96
using Nuke.Common;
7+
using Nuke.Common.IO;
108
using Nuke.Common.ProjectModel;
119
using Nuke.Common.Tools.DotNet;
1210
using Serilog;
@@ -15,49 +13,52 @@
1513

1614
public partial class Build
1715
{
18-
const string _compilerBundlePackagePrefix = "Cesium.Compiler.Bundle";
19-
20-
Target PublishAllCompilerBundles => _ => _
16+
private const string _compilerBundlePackageName = "Cesium.Compiler.Bundle";
17+
18+
private static readonly string[] _compilerRuntimeSpecificRuntimeIds = [
19+
"win-x64",
20+
"win-x86",
21+
"win-arm64",
22+
"linux-x64",
23+
"linux-arm64",
24+
"osx-x64",
25+
"osx-arm64"
26+
];
27+
28+
Target PublishAllCompilerRuntimeSpecificBundles => _ => _
2129
.DependsOn(CompileAll)
2230
.Executes(() =>
2331
{
24-
var compilerProject = Solution.Cesium_Compiler.GetMSBuildProject();
25-
26-
var runtimeIds = compilerProject.GetEvaluatedProperty("RuntimeIdentifiers").Split(";");
32+
var runtimeIds = _compilerRuntimeSpecificRuntimeIds;
2733
Log.Information(
2834
$"Runtime identifiers defined in {Solution.Cesium_Compiler.Name}: {string.Join(", ", runtimeIds)}");
2935

3036
foreach (var runtimeId in runtimeIds)
3137
PublishCompiler(runtimeId);
3238
});
3339

34-
Target PublishCompilerBundle => _ => _
40+
Target PublishCompilerFrameworkDependentBundle => _ => _
3541
.DependsOn(CompileAll)
3642
.Executes(() =>
3743
{
38-
PublishCompiler(EffectiveRuntimeId);
44+
PublishCompiler(null);
3945
});
4046

41-
Target PackAllCompilerBundles => _ => _
42-
.DependsOn(PublishAllCompilerBundles)
47+
Target PackAllCompilerRuntimeSpecificBundles => _ => _
48+
.DependsOn(PublishAllCompilerRuntimeSpecificBundles)
4349
.Executes(() =>
4450
{
45-
var compilerProject = Solution.Cesium_Compiler.GetMSBuildProject();
46-
47-
var runtimeIds = compilerProject.GetRuntimeIds();
51+
var runtimeIds = _compilerRuntimeSpecificRuntimeIds;
4852
Log.Information(
4953
$"Runtime identifiers defined in {Solution.Cesium_Compiler.Name}: {string.Join(", ", runtimeIds)}");
5054

5155
foreach (var runtimeId in runtimeIds)
52-
PackCompiler(runtimeId);
56+
GenerateCompilerRuntimeSpecificBundle(runtimeId);
5357
});
5458

55-
Target PackCompilerBundle => _ => _
56-
.DependsOn(PublishCompilerBundle)
57-
.Executes(() =>
58-
{
59-
PackCompiler(EffectiveRuntimeId);
60-
});
59+
Target PackCompilerNuPkg => _ => _
60+
.DependsOn(PublishCompilerFrameworkDependentBundle)
61+
.Executes(GenerateCompilerNuPkg);
6162

6263
Target PackSdk => _ => _
6364
.DependsOn(CompileAll)
@@ -76,49 +77,6 @@ public partial class Build
7677
.SetProject(Solution.Cesium_Sdk.Path));
7778
});
7879

79-
void EmitCompilerBundle(string runtimeId, Project compilerProject)
80-
{
81-
var version = compilerProject.GetVersion();
82-
var runtimePackageId = GetRuntimeBundleId(runtimeId);
83-
var packageFile = GetRuntimeBundleFileName(version, runtimeId);
84-
var publishDirectory = GetCompilerRuntimePublishFolder(compilerProject, runtimeId);
85-
Directory.CreateDirectory(publishDirectory);
86-
var publishedFiles = Directory.GetFiles(publishDirectory, "*.*", SearchOption.AllDirectories);
87-
var packageOutputPath = compilerProject.GetPackageOutputPath();
88-
89-
Log.Debug($"Source publish directory: {publishDirectory}");
90-
Log.Debug($"Target package ID: {runtimePackageId}");
91-
Log.Debug($"Target package output directory: {packageOutputPath}");
92-
93-
var builder = new PackageBuilder
94-
{
95-
Id = runtimePackageId,
96-
Version = NuGetVersion.Parse(compilerProject.GetVersion()),
97-
Description = $"Cesium compiler native executable pack for {runtimeId} platform.",
98-
Authors = { "Cesium Team" }
99-
};
100-
builder.Files.AddRange(GetPhysicalFiles(publishDirectory, publishedFiles));
101-
102-
var packageFileName = Path.Combine(packageOutputPath, packageFile);
103-
Log.Information($"Package is ready, saving to {packageFileName}...");
104-
Directory.CreateDirectory(packageOutputPath);
105-
using var outputStream = new FileStream(packageFileName, FileMode.Create);
106-
builder.Save(outputStream);
107-
return;
108-
109-
IEnumerable<IPackageFile> GetPhysicalFiles(string publishDirectory, IEnumerable<string> filePaths)
110-
{
111-
foreach (var filePath in filePaths)
112-
{
113-
yield return new PhysicalPackageFile
114-
{
115-
SourcePath = filePath,
116-
TargetPath = $"tools/{Path.GetRelativePath(publishDirectory, filePath)}"
117-
};
118-
}
119-
}
120-
}
121-
12280
void PublishCompiler(string runtimeId)
12381
{
12482
var compilerProject = Solution.Cesium_Compiler.GetMSBuildProject();
@@ -141,35 +99,74 @@ void PublishCompiler(string runtimeId)
14199
.SetOutput(GetCompilerRuntimePublishFolder(compilerProject, runtimeId)));
142100
}
143101

144-
void PackCompiler(string runtimeId)
102+
void GenerateCompilerRuntimeSpecificBundle(string runtimeId)
145103
{
146104
var compilerProject = Solution.Cesium_Compiler.GetMSBuildProject();
147105

148-
if (!SkipCaches && !NeedPackageCompilerBundle(compilerProject, runtimeId))
106+
if (!SkipCaches && !NeedPackageCompilerRuntimeSpecificBundle(compilerProject, runtimeId))
149107
{
150108
Log.Information($"Skipping {runtimeId} because it was already packed. Use '--skip-caches true' to re-pack.");
151109
return;
152110
}
153111

154-
Log.Information($"Packing compiler for {runtimeId}...");
155-
EmitCompilerBundle(runtimeId, compilerProject);
112+
Log.Information($"Generating compiler runtime specific bundle {runtimeId}...");
113+
114+
var version = compilerProject.GetVersion();
115+
var runtimePackageId = GetRuntimeBundleId(runtimeId);
116+
var packageFile = GetCompilerRuntimeSpecificBundleFileName(version, runtimeId);
117+
var publishDirectory = GetCompilerRuntimePublishFolder(compilerProject, runtimeId);
118+
Directory.CreateDirectory(publishDirectory);
119+
120+
var packageOutputPath = compilerProject.GetPackageOutputPath();
121+
122+
Log.Debug($"Source publish directory: {publishDirectory}");
123+
Log.Debug($"Target package ID: {runtimePackageId}");
124+
Log.Debug($"Target package output directory: {packageOutputPath}");
125+
126+
var packageFileName = Path.Combine(packageOutputPath, packageFile);
127+
Log.Information($"Package is ready, saving to {packageFileName}...");
128+
Directory.CreateDirectory(packageOutputPath);
129+
publishDirectory.ZipTo(
130+
packageFileName,
131+
fileMode: FileMode.CreateNew
132+
);
156133
}
157134

158-
string GetCompilerRuntimePublishFolder(Project compilerProject, string runtimeId) =>
135+
void GenerateCompilerNuPkg()
136+
{
137+
var compilerProject = Solution.Cesium_Compiler.GetMSBuildProject();
138+
139+
if (!SkipCaches && !NeedPackageCompilerNuPkg(compilerProject))
140+
{
141+
Log.Information("Skipping .nupkg because it was already packed. Use '--skip-caches true' to re-pack.");
142+
return;
143+
}
144+
145+
Log.Information("Packing compiler .nupkg file...");
146+
DotNetPack(o => o
147+
.SetConfiguration(Configuration)
148+
.SetProject(compilerProject.ProjectFileLocation.File)
149+
.SetProperty("PublishAot", PublishAot));
150+
}
151+
152+
AbsolutePath GetCompilerRuntimePublishFolder(Project compilerProject, string? runtimeId) =>
159153
Path.Combine(
160154
compilerProject.GetProperty("ArtifactsPath").EvaluatedValue,
161155
compilerProject.GetProperty("ArtifactsPublishOutputName").EvaluatedValue,
162156
Solution.Cesium_Compiler.Name,
163157
GetRuntimeArtifactFolder(compilerProject.GetVersion(), runtimeId));
164158

165-
static string GetRuntimeArtifactFolder(string version, string runtimeId) =>
166-
$"pack_{version}_{runtimeId}";
159+
static string GetRuntimeArtifactFolder(string version, string? runtimeId) =>
160+
$"pack_{version}" + (runtimeId == null ? "" : $"_{runtimeId}");
167161

168162
static string GetRuntimeBundleId(string runtimeId) =>
169-
$"{_compilerBundlePackagePrefix}.{runtimeId}";
163+
$"{_compilerBundlePackageName}.{runtimeId}";
164+
165+
static string GetCompilerNuGetPackageFileName(string version) =>
166+
$"{_compilerBundlePackageName}.{version}.nupkg";
170167

171-
static string GetRuntimeBundleFileName(string version, string runtimeId) =>
172-
$"{_compilerBundlePackagePrefix}.{runtimeId}.{version}.nupkg";
168+
static string GetCompilerRuntimeSpecificBundleFileName(string version, string runtimeId) =>
169+
$"{_compilerBundlePackageName}.{runtimeId}.{version}.zip";
173170

174171
bool NeedPublishCompilerBundle(Project compiler, string runtimeId)
175172
{
@@ -179,11 +176,20 @@ bool NeedPublishCompilerBundle(Project compiler, string runtimeId)
179176
|| Directory.GetFiles(folder, "Cesium.Compiler*").Length == 0;
180177
}
181178

182-
bool NeedPackageCompilerBundle(Project compiler, string runtimeId)
179+
bool NeedPackageCompilerRuntimeSpecificBundle(Project compiler, string runtimeId)
180+
{
181+
var version = compiler.GetVersion();
182+
var packageDirectory = compiler.GetPackageOutputPath();
183+
var packageFileName = GetCompilerRuntimeSpecificBundleFileName(version, runtimeId);
184+
185+
return !File.Exists(Path.Combine(packageDirectory, packageFileName));
186+
}
187+
188+
bool NeedPackageCompilerNuPkg(Project compiler)
183189
{
184190
var version = compiler.GetVersion();
185191
var packageDirectory = compiler.GetPackageOutputPath();
186-
var packageFileName = GetRuntimeBundleFileName(version, runtimeId);
192+
var packageFileName = GetCompilerNuGetPackageFileName(version);
187193

188194
return !File.Exists(Path.Combine(packageDirectory, packageFileName));
189195
}

build/_build.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ SPDX-License-Identifier: MIT
1010
<OutputType>Exe</OutputType>
1111
<TargetFramework>net9.0</TargetFramework>
1212
<RootNamespace></RootNamespace>
13-
<NoWarn>CS0649;CS0169</NoWarn>
13+
<NoWarn>CS0649;CS0169;nullable</NoWarn>
1414
<NukeRootDirectory>..</NukeRootDirectory>
1515
<NukeScriptDirectory>..</NukeScriptDirectory>
1616
<NukeTelemetryVersion>1</NukeTelemetryVersion>
1717
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
18+
<Nullable>enable</Nullable>
1819
</PropertyGroup>
1920

2021
<ItemGroup>

0 commit comments

Comments
 (0)