22//
33// SPDX-License-Identifier: MIT
44
5- using System . Collections . Generic ;
65using System . IO ;
7- using NuGet . Packaging ;
8- using NuGet . Versioning ;
96using Nuke . Common ;
7+ using Nuke . Common . IO ;
108using Nuke . Common . ProjectModel ;
119using Nuke . Common . Tools . DotNet ;
1210using Serilog ;
1513
1614public 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 }
0 commit comments