@@ -117,7 +117,6 @@ pub fn build(b: *std.Build) !void {
117
117
const boost = boostLibraries (b , .{
118
118
.target = target ,
119
119
.optimize = optimize ,
120
- .headers_only = b .option (bool , "headers-only" , "Use headers-only libraries (default: true)" ) orelse true ,
121
120
.module = .{
122
121
.cobalt = b .option (bool , "cobalt" , "Build cobalt library (default: false)" ) orelse false ,
123
122
.context = b .option (bool , "context" , "Build context library (default: false)" ) orelse false ,
@@ -160,73 +159,34 @@ pub fn boostLibraries(b: *std.Build, config: Config) *std.Build.Step.Compile {
160
159
lib .addIncludePath (boostLib );
161
160
}
162
161
163
- if (config .headers_only ) {
164
- // zig-pkg bypass (artifact need source file)
165
- const empty = b .addWriteFile ("empty.cc" ,
166
- \\ #include <boost/config.hpp>
167
- );
168
- lib .step .dependOn (& empty .step );
169
- lib .addCSourceFiles (.{
170
- .root = empty .getDirectory (),
171
- .files = &.{"empty.cc" },
172
- .flags = cxxFlags ,
173
- });
174
- } else {
175
- if (config .module ) | module | {
176
- if (module .cobalt ) {
177
- const boostCobalt = buildCobalt (b , .{
178
- .headers_only = config .headers_only ,
179
- .target = config .target ,
180
- .optimize = config .optimize ,
181
- .include_dirs = lib .root_module .include_dirs ,
182
- });
183
- lib .addObject (boostCobalt );
184
- }
185
- if (module .container ) {
186
- const boostContainer = buildContainer (b , .{
187
- .headers_only = config .headers_only ,
188
- .target = config .target ,
189
- .optimize = config .optimize ,
190
- .include_dirs = lib .root_module .include_dirs ,
191
- });
192
- lib .addObject (boostContainer );
193
- }
194
- if (module .context ) {
195
- const boostContext = buildContext (b , .{
196
- .headers_only = config .headers_only ,
197
- .target = config .target ,
198
- .optimize = config .optimize ,
199
- .include_dirs = lib .root_module .include_dirs ,
200
- });
201
- lib .addObject (boostContext );
202
- }
203
- if (module .json ) {
204
- const boostJson = buildJson (b , .{
205
- .headers_only = config .headers_only ,
206
- .target = config .target ,
207
- .optimize = config .optimize ,
208
- .include_dirs = lib .root_module .include_dirs ,
209
- });
210
- lib .addObject (boostJson );
211
- }
212
- if (module .filesystem ) {
213
- const boostFileSystem = buildFileSystem (b , .{
214
- .headers_only = config .headers_only ,
215
- .target = config .target ,
216
- .optimize = config .optimize ,
217
- .include_dirs = lib .root_module .include_dirs ,
218
- });
219
- lib .addObject (boostFileSystem );
220
- }
221
- if (module .system ) {
222
- const boostSystem = buildSystem (b , .{
223
- .headers_only = config .headers_only ,
224
- .target = config .target ,
225
- .optimize = config .optimize ,
226
- .include_dirs = lib .root_module .include_dirs ,
227
- });
228
- lib .addObject (boostSystem );
229
- }
162
+ // zig-pkg bypass (artifact need source file to generate object file)
163
+ const empty = b .addWriteFile ("empty.cc" ,
164
+ \\ #include <boost/config.hpp>
165
+ );
166
+ lib .step .dependOn (& empty .step );
167
+ lib .addCSourceFiles (.{
168
+ .root = empty .getDirectory (),
169
+ .files = &.{"empty.cc" },
170
+ .flags = cxxFlags ,
171
+ });
172
+ if (config .module ) | module | {
173
+ if (module .cobalt ) {
174
+ buildCobalt (b , lib );
175
+ }
176
+ if (module .container ) {
177
+ buildContainer (b , lib );
178
+ }
179
+ if (module .context ) {
180
+ buildContext (b , lib );
181
+ }
182
+ if (module .json ) {
183
+ buildJson (b , lib );
184
+ }
185
+ if (module .filesystem ) {
186
+ buildFileSystem (b , lib );
187
+ }
188
+ if (module .system ) {
189
+ buildSystem (b , lib );
230
190
}
231
191
}
232
192
if (lib .rootModuleTarget ().abi == .msvc )
@@ -239,11 +199,9 @@ pub fn boostLibraries(b: *std.Build, config: Config) *std.Build.Step.Compile {
239
199
}
240
200
241
201
pub const Config = struct {
242
- headers_only : bool = false ,
243
202
target : std.Build.ResolvedTarget ,
244
203
optimize : std.builtin.OptimizeMode ,
245
204
module : ? boostLibrariesModules = null ,
246
- include_dirs : ? std .ArrayListUnmanaged (std .Build .Module .IncludeDir ) = null ,
247
205
};
248
206
249
207
// No header-only libraries
@@ -257,21 +215,10 @@ const boostLibrariesModules = struct {
257
215
system : bool = false ,
258
216
};
259
217
260
- fn buildCobalt (b : * std.Build , config : Config ) * std.Build.Step.Compile {
218
+ fn buildCobalt (b : * std.Build , obj : * std.Build.Step.Compile ) void {
261
219
const cobaltPath = b .dependency ("cobalt" , .{}).path ("src" );
262
- const obj = b .addObject (.{
263
- .name = "cobalt" ,
264
- .target = config .target ,
265
- .optimize = config .optimize ,
266
- });
267
-
268
- if (config .include_dirs ) | include_dirs | {
269
- for (include_dirs .items ) | include | {
270
- obj .root_module .include_dirs .append (b .allocator , include ) catch unreachable ;
271
- }
272
- }
273
220
obj .defineCMacro ("BOOST_COBALT_SOURCE" , null );
274
- obj .defineCMacro ("BOOST_COBALT_USE_BOOST_CONTAINER_PMR" , null );
221
+ // obj.defineCMacro("BOOST_COBALT_USE_BOOST_CONTAINER_PMR", null);
275
222
obj .addCSourceFiles (.{
276
223
.root = cobaltPath ,
277
224
.files = &.{
@@ -285,29 +232,10 @@ fn buildCobalt(b: *std.Build, config: Config) *std.Build.Step.Compile {
285
232
},
286
233
.flags = cxxFlags ++ &[_ ][]const u8 {"-std=c++20" },
287
234
});
288
- if (obj .rootModuleTarget ().abi == .msvc )
289
- obj .linkLibC ()
290
- else {
291
- obj .defineCMacro ("_GNU_SOURCE" , null );
292
- obj .linkLibCpp ();
293
- }
294
-
295
- return obj ;
296
235
}
297
236
298
- fn buildContainer (b : * std.Build , config : Config ) * std.Build.Step.Compile {
237
+ fn buildContainer (b : * std.Build , obj : * std.Build.Step.Compile ) void {
299
238
const containerPath = b .dependency ("container" , .{}).path ("src" );
300
- const obj = b .addObject (.{
301
- .name = "container" ,
302
- .target = config .target ,
303
- .optimize = config .optimize ,
304
- });
305
-
306
- if (config .include_dirs ) | include_dirs | {
307
- for (include_dirs .items ) | include | {
308
- obj .root_module .include_dirs .append (b .allocator , include ) catch unreachable ;
309
- }
310
- }
311
239
obj .addCSourceFiles (.{
312
240
.root = containerPath ,
313
241
.files = &.{
@@ -319,89 +247,35 @@ fn buildContainer(b: *std.Build, config: Config) *std.Build.Step.Compile {
319
247
},
320
248
.flags = cxxFlags ,
321
249
});
322
- if (obj .rootModuleTarget ().abi == .msvc )
323
- obj .linkLibC ()
324
- else {
325
- obj .defineCMacro ("_GNU_SOURCE" , null );
326
- obj .linkLibCpp ();
327
- }
328
-
329
- return obj ;
330
250
}
331
251
332
- fn buildJson (b : * std.Build , config : Config ) * std.Build.Step.Compile {
252
+ fn buildJson (b : * std.Build , obj : * std.Build.Step.Compile ) void {
333
253
const jsonPath = b .dependency ("json" , .{}).path ("src" );
334
- const obj = b .addObject (.{
335
- .name = "json" ,
336
- .target = config .target ,
337
- .optimize = config .optimize ,
338
- });
339
254
340
- if (config .include_dirs ) | include_dirs | {
341
- for (include_dirs .items ) | include | {
342
- obj .root_module .include_dirs .append (b .allocator , include ) catch unreachable ;
343
- }
344
- }
345
255
obj .addCSourceFiles (.{
346
256
.root = jsonPath ,
347
257
.files = &.{
348
258
"src.cpp" ,
349
259
},
350
260
.flags = cxxFlags ,
351
261
});
352
- if (obj .rootModuleTarget ().abi == .msvc )
353
- obj .linkLibC ()
354
- else {
355
- obj .defineCMacro ("_GNU_SOURCE" , null );
356
- obj .linkLibCpp ();
357
- }
358
-
359
- return obj ;
360
262
}
361
263
362
- fn buildSystem (b : * std.Build , config : Config ) * std.Build.Step.Compile {
264
+ fn buildSystem (b : * std.Build , obj : * std.Build.Step.Compile ) void {
363
265
const systemPath = b .dependency ("system" , .{}).path ("src" );
364
- const obj = b .addObject (.{
365
- .name = "system" ,
366
- .target = config .target ,
367
- .optimize = config .optimize ,
368
- });
369
266
370
- if (config .include_dirs ) | include_dirs | {
371
- for (include_dirs .items ) | include | {
372
- obj .root_module .include_dirs .append (b .allocator , include ) catch unreachable ;
373
- }
374
- }
375
267
obj .addCSourceFiles (.{
376
268
.root = systemPath ,
377
269
.files = &.{
378
270
"error_code.cpp" ,
379
271
},
380
272
.flags = cxxFlags ,
381
273
});
382
- if (obj .rootModuleTarget ().abi == .msvc )
383
- obj .linkLibC ()
384
- else {
385
- obj .defineCMacro ("_GNU_SOURCE" , null );
386
- obj .linkLibCpp ();
387
- }
388
-
389
- return obj ;
390
274
}
391
275
392
- fn buildFileSystem (b : * std.Build , config : Config ) * std.Build.Step.Compile {
276
+ fn buildFileSystem (b : * std.Build , obj : * std.Build.Step.Compile ) void {
393
277
const fsPath = b .dependency ("filesystem" , .{}).path ("src" );
394
- const obj = b .addObject (.{
395
- .name = "filesystem" ,
396
- .target = config .target ,
397
- .optimize = config .optimize ,
398
- });
399
278
400
- if (config .include_dirs ) | include_dirs | {
401
- for (include_dirs .items ) | include | {
402
- obj .root_module .include_dirs .append (b .allocator , include ) catch unreachable ;
403
- }
404
- }
405
279
if (obj .rootModuleTarget ().os .tag == .windows ) {
406
280
obj .addCSourceFiles (.{
407
281
.root = fsPath ,
@@ -429,32 +303,15 @@ fn buildFileSystem(b: *std.Build, config: Config) *std.Build.Step.Compile {
429
303
.flags = cxxFlags ,
430
304
});
431
305
if (obj .rootModuleTarget ().abi == .msvc ) {
432
- obj .linkLibC ();
433
306
obj .defineCMacro ("_SCL_SECURE_NO_WARNINGS" , null );
434
307
obj .defineCMacro ("_SCL_SECURE_NO_DEPRECATE" , null );
435
308
obj .defineCMacro ("_CRT_SECURE_NO_WARNINGS" , null );
436
309
obj .defineCMacro ("_CRT_SECURE_NO_DEPRECATE" , null );
437
- } else {
438
- obj .defineCMacro ("_GNU_SOURCE" , null );
439
- obj .linkLibCpp ();
440
310
}
441
-
442
- return obj ;
443
311
}
444
312
445
- fn buildContext (b : * std.Build , config : Config ) * std.Build.Step.Compile {
313
+ fn buildContext (b : * std.Build , obj : * std.Build.Step.Compile ) void {
446
314
const contextPath = b .dependency ("context" , .{}).path ("src" );
447
- const obj = b .addObject (.{
448
- .name = "context" ,
449
- .target = config .target ,
450
- .optimize = config .optimize ,
451
- });
452
-
453
- if (config .include_dirs ) | include_dirs | {
454
- for (include_dirs .items ) | include | {
455
- obj .root_module .include_dirs .append (b .allocator , include ) catch unreachable ;
456
- }
457
- }
458
315
const ctxPath = contextPath .getPath (b );
459
316
obj .addIncludePath (.{
460
317
.cwd_relative = b .pathJoin (&.{ ctxPath , "asm" }),
@@ -609,13 +466,4 @@ fn buildContext(b: *std.Build, config: Config) *std.Build.Step.Compile {
609
466
},
610
467
else = > @panic ("Invalid arch" ),
611
468
}
612
-
613
- if (obj .rootModuleTarget ().abi == .msvc )
614
- obj .linkLibC ()
615
- else {
616
- obj .defineCMacro ("_GNU_SOURCE" , null );
617
- obj .linkLibCpp ();
618
- }
619
-
620
- return obj ;
621
469
}
0 commit comments