@@ -14,29 +14,43 @@ export type BuildMode = "release" | "debug";
14
14
15
15
export type ConfigFlags = string | string [ ] ;
16
16
17
- export interface XcodeConfig {
18
- destinations ?: string [ ]
17
+ export interface SwiftPMBuilder {
18
+ type ?: "swiftpm"
19
+ // flags passed directly to `swift build`
20
+ settings ?: ConfigFlags
21
+ // --triple flag
22
+ // warning: cross-compilation triples break macros as of Swift 5.9
23
+ triple ?: string
24
+ }
25
+
26
+ export interface XcodeBuilder {
27
+ type : "xcode"
28
+ // flags passed directly to `xcodebuild`
19
29
settings ?: ConfigFlags
30
+ // -destination parameters
31
+ destinations ?: string [ ]
20
32
}
21
33
34
+ export type Builder = SwiftPMBuilder | XcodeBuilder ;
35
+
22
36
export interface Config {
23
37
buildPath ?: string
24
38
packagePath ?: string
25
39
product ?: string
26
40
27
- triple ?: string
28
41
napi ?: number | "experimental"
29
42
30
43
static ?: boolean
31
44
32
- spmFlags ?: ConfigFlags
33
45
cFlags ?: ConfigFlags
34
46
swiftFlags ?: ConfigFlags
35
47
cxxFlags ?: ConfigFlags
36
48
linkerFlags ?: ConfigFlags
37
49
38
- // if truthy, build using xcodebuild instead of swift-build
39
- xcode ?: boolean | XcodeConfig
50
+ // flags passed to `swift package dump-package`
51
+ dumpFlags ?: ConfigFlags
52
+
53
+ builder ?: Builder | Builder [ "type" ]
40
54
}
41
55
42
56
export async function clean ( config : Config = { } ) {
@@ -74,7 +88,7 @@ function getFlags<C>(config: C, name: keyof C & string): string[] {
74
88
}
75
89
76
90
export async function build ( mode : BuildMode , config : Config = { } ) : Promise < string > {
77
- let spmFlags = getFlags ( config , "spmFlags " ) ;
91
+ let dumpFlags = getFlags ( config , "dumpFlags " ) ;
78
92
let cFlags = getFlags ( config , "cFlags" ) ;
79
93
let swiftFlags = getFlags ( config , "swiftFlags" ) ;
80
94
let cxxFlags = getFlags ( config , "cxxFlags" ) ;
@@ -102,12 +116,6 @@ export async function build(mode: BuildMode, config: Config = {}): Promise<strin
102
116
103
117
let napi = config . napi ;
104
118
105
- if ( typeof config . triple === "string" ) {
106
- spmFlags . push ( "--triple" , config . triple ) ;
107
- } else if ( typeof config . triple !== "undefined" ) {
108
- throw new Error ( "Invalid value for triple option." ) ;
109
- }
110
-
111
119
if ( typeof napi === "number" ) {
112
120
cFlags . push ( `-DNAPI_VERSION=${ napi } ` ) ;
113
121
swiftFlags . push ( "-DNAPI_VERSIONED" ) ;
@@ -136,7 +144,7 @@ export async function build(mode: BuildMode, config: Config = {}): Promise<strin
136
144
"package" ,
137
145
"dump-package" ,
138
146
"--package-path" , packagePath ,
139
- ...spmFlags . filter ( f => f !== "-v" ) ,
147
+ ...dumpFlags ,
140
148
...nonSPMFlags ,
141
149
] ,
142
150
{ stdio : [ "inherit" , "pipe" , "inherit" ] }
@@ -217,8 +225,8 @@ export async function build(mode: BuildMode, config: Config = {}): Promise<strin
217
225
218
226
const realBinaryPath = path . join ( buildDir , mode , `${ product } .node` ) ;
219
227
const binaryPath = path . join ( buildDir , `${ product } .node` ) ;
220
- if ( config . xcode ) {
221
- const xcode = typeof config . xcode === "object" ? config . xcode : { } ;
228
+ if ( config . builder === " xcode" || ( typeof config . builder === "object" && config . builder . type === "xcode" ) ) {
229
+ const xcode = typeof config . builder === "object" ? config . builder : ( { type : "xcode" } as XcodeBuilder ) ;
222
230
const settings = getFlags ( xcode , "settings" ) ;
223
231
const destinations = xcode . destinations || [ "generic/platform=macOS" ] ;
224
232
const derivedDataPath = path . join ( buildDir , "DerivedData" ) ;
@@ -258,6 +266,11 @@ export async function build(mode: BuildMode, config: Config = {}): Promise<strin
258
266
{ recursive : true , force : true }
259
267
) ;
260
268
} else {
269
+ const swiftPM = typeof config . builder === "object" ? config . builder : { } ;
270
+ const swiftPMFlags = getFlags ( swiftPM , "settings" ) ;
271
+ if ( typeof swiftPM . triple === "string" ) {
272
+ swiftPMFlags . push ( "--triple" , swiftPM . triple ) ;
273
+ }
261
274
const result = spawnSync (
262
275
"swift" ,
263
276
[
@@ -267,7 +280,7 @@ export async function build(mode: BuildMode, config: Config = {}): Promise<strin
267
280
"--build-path" , buildDir ,
268
281
"--package-path" , packagePath ,
269
282
...ldflags ,
270
- ...spmFlags ,
283
+ ...swiftPMFlags ,
271
284
...nonSPMFlags ,
272
285
] ,
273
286
{
0 commit comments