@@ -24,7 +24,7 @@ const boost_libs = [_][]const u8{
24
24
"utility" ,
25
25
"endian" ,
26
26
"regex" ,
27
- "asio" ,
27
+ "asio" , // stackless coroutine (stl) and stackful coroutine (need boost.context)
28
28
"align" ,
29
29
"system" ,
30
30
"intrusive" ,
@@ -81,7 +81,7 @@ const boost_libs = [_][]const u8{
81
81
"function" ,
82
82
"spirit" ,
83
83
"function_types" ,
84
- "cobalt" , // need boost.context & boost. asio (no header-only)
84
+ "cobalt" , // need boost.asio (no header-only)
85
85
"phoenix" ,
86
86
"nowide" ,
87
87
"locale" ,
@@ -181,6 +181,15 @@ pub fn boostLibraries(b: *std.Build, config: Config) *std.Build.Step.Compile {
181
181
});
182
182
lib .addObject (boostContainer );
183
183
}
184
+ if (module .context ) {
185
+ const boostContext = buildContext (b , .{
186
+ .header_only = config .header_only ,
187
+ .target = config .target ,
188
+ .optimize = config .optimize ,
189
+ .include_dirs = lib .root_module .include_dirs ,
190
+ });
191
+ lib .addObject (boostContext );
192
+ }
184
193
if (module .json ) {
185
194
const boostJson = buildJson (b , .{
186
195
.header_only = config .header_only ,
@@ -202,7 +211,7 @@ pub fn boostLibraries(b: *std.Build, config: Config) *std.Build.Step.Compile {
202
211
}
203
212
204
213
pub const Config = struct {
205
- header_only : bool ,
214
+ header_only : bool = false ,
206
215
target : std.Build.ResolvedTarget ,
207
216
optimize : std.builtin.OptimizeMode ,
208
217
module : ? boostLibrariesModules = null ,
@@ -320,3 +329,181 @@ fn buildJson(b: *std.Build, config: Config) *std.Build.Step.Compile {
320
329
321
330
return obj ;
322
331
}
332
+
333
+ fn buildContext (b : * std.Build , config : Config ) * std.Build.Step.Compile {
334
+ const contextPath = b .dependency ("context" , .{}).path ("" );
335
+ const obj = b .addObject (.{
336
+ .name = "context" ,
337
+ .target = config .target ,
338
+ .optimize = config .optimize ,
339
+ });
340
+
341
+ if (config .include_dirs ) | include_dirs | {
342
+ for (include_dirs .items ) | include | {
343
+ obj .root_module .include_dirs .append (b .allocator , include ) catch unreachable ;
344
+ }
345
+ }
346
+ const ctxPath = contextPath .getPath (b );
347
+ obj .addIncludePath (.{
348
+ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm" }),
349
+ }); // common.h
350
+ obj .addCSourceFiles (.{
351
+ .root = contextPath ,
352
+ .files = &.{
353
+ "src/continuation.cpp" ,
354
+ "src/fiber.cpp" ,
355
+ },
356
+ .flags = cxxFlags ,
357
+ });
358
+
359
+ obj .addCSourceFile (.{
360
+ .file = switch (obj .rootModuleTarget ().os .tag ) {
361
+ .windows = > .{
362
+ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/windows/stack_traits.cpp" }),
363
+ },
364
+ else = > .{
365
+ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/posix/stack_traits.cpp" }),
366
+ },
367
+ },
368
+ .flags = cxxFlags ,
369
+ });
370
+ if (obj .rootModuleTarget ().os .tag == .windows ) {
371
+ obj .defineCMacro ("BOOST_USE_WINFIB" , null );
372
+ obj .want_lto = false ;
373
+ } else {
374
+ obj .defineCMacro ("BOOST_USE_UCONTEXT" , null );
375
+ }
376
+ switch (obj .rootModuleTarget ().cpu .arch ) {
377
+ .arm = > switch (obj .rootModuleTarget ().os .tag ) {
378
+ .windows = > {
379
+ if (obj .rootModuleTarget ().abi == .msvc ) {
380
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_arm_aapcs_pe_armasm.asm" }) });
381
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_arm_aapcs_pe_armasm.asm" }) });
382
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_arm_aapcs_pe_armasm.asm" }) });
383
+ }
384
+ },
385
+ .macos = > {
386
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_arm_aapcs_macho_gas.S" }) });
387
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_arm_aapcs_macho_gas.S" }) });
388
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_arm_aapcs_macho_gas.S" }) });
389
+ },
390
+ else = > {
391
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_arm_aapcs_elf_gas.S" }) });
392
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_arm_aapcs_elf_gas.S" }) });
393
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_arm_aapcs_elf_gas.S" }) });
394
+ },
395
+ },
396
+ .aarch64 = > switch (obj .rootModuleTarget ().os .tag ) {
397
+ .windows = > {
398
+ if (obj .rootModuleTarget ().abi == .msvc ) {
399
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_arm64_aapcs_pe_armasm.asm" }) });
400
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_arm64_aapcs_pe_armasm.asm" }) });
401
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_arm64_aapcs_pe_armasm.asm" }) });
402
+ }
403
+ },
404
+ .macos = > {
405
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_arm64_aapcs_macho_gas.S" }) });
406
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_arm64_aapcs_macho_gas.S" }) });
407
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_arm64_aapcs_macho_gas.S" }) });
408
+ },
409
+ else = > {
410
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_arm64_aapcs_elf_gas.S" }) });
411
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_arm64_aapcs_elf_gas.S" }) });
412
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_arm64_aapcs_elf_gas.S" }) });
413
+ },
414
+ },
415
+ .riscv64 = > {
416
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_riscv64_sysv_elf_gas.S" }) });
417
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_riscv64_sysv_elf_gas.S" }) });
418
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_riscv64_sysv_elf_gas.S" }) });
419
+ },
420
+ .x86 = > switch (obj .rootModuleTarget ().os .tag ) {
421
+ .windows = > {
422
+ // @panic("undefined symbol:{j/m/o}-fcontext");
423
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_i386_ms_pe_clang_gas.S" }) });
424
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_i386_ms_pe_clang_gas.S" }) });
425
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_i386_ms_pe_clang_gas.S" }) });
426
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_i386_ms_pe_gas.S" }) });
427
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_i386_ms_pe_gas.S" }) });
428
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_i386_ms_pe_gas.S" }) });
429
+ },
430
+ .macos = > {
431
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_i386_x86_64_sysv_macho_gas.S" }) });
432
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_i386_sysv_macho_gas.S" }) });
433
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_i386_x86_64_sysv_macho_gas.S" }) });
434
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_i386_sysv_macho_gas.S" }) });
435
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_i386_sysv_macho_gas.S" }) });
436
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_i386_x86_64_sysv_macho_gas.S" }) });
437
+ },
438
+ else = > {
439
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_i386_sysv_elf_gas.S" }) });
440
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_i386_sysv_elf_gas.S" }) });
441
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_i386_sysv_elf_gas.S" }) });
442
+ },
443
+ },
444
+ .x86_64 = > switch (obj .rootModuleTarget ().os .tag ) {
445
+ .windows = > {
446
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_x86_64_ms_pe_clang_gas.S" }) });
447
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_x86_64_ms_pe_clang_gas.S" }) });
448
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_x86_64_ms_pe_clang_gas.S" }) });
449
+ },
450
+ .macos = > {
451
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_i386_x86_64_sysv_macho_gas.S" }) });
452
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_x86_64_sysv_macho_gas.S" }) });
453
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_i386_x86_64_sysv_macho_gas.S" }) });
454
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_x86_64_sysv_macho_gas.S" }) });
455
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_x86_64_sysv_macho_gas.S" }) });
456
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_i386_x86_64_sysv_macho_gas.S" }) });
457
+ },
458
+ else = > {
459
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_x86_64_sysv_elf_gas.S" }) });
460
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_x86_64_sysv_elf_gas.S" }) });
461
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_x86_64_sysv_elf_gas.S" }) });
462
+ },
463
+ },
464
+ .s390x = > {
465
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_s390x_sysv_elf_gas.S" }) });
466
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_s390x_sysv_elf_gas.S" }) });
467
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_s390x_sysv_elf_gas.S" }) });
468
+ },
469
+ .mips , .mipsel = > {
470
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_mips32_o32_elf_gas.S" }) });
471
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_mips32_o32_elf_gas.S" }) });
472
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_mips32_o32_elf_gas.S" }) });
473
+ },
474
+ .mips64 , .mips64el = > {
475
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_mips64_n64_elf_gas.S" }) });
476
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_mips64_n64_elf_gas.S" }) });
477
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_mips64_n64_elf_gas.S" }) });
478
+ },
479
+ .loongarch64 = > {
480
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_loongarch64_sysv_elf_gas.S" }) });
481
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_loongarch64_sysv_elf_gas.S" }) });
482
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_loongarch64_sysv_elf_gas.S" }) });
483
+ },
484
+ .powerpc = > {
485
+ obj .addCSourceFile (.{
486
+ .file = .{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/tail_ontop_ppc32_sysv.cpp" }) },
487
+ .flags = cxxFlags ,
488
+ });
489
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_ppc32_sysv_elf_gas.S" }) });
490
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_ppc32_sysv_elf_gas.S" }) });
491
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_ppc32_sysv_elf_gas.S" }) });
492
+ },
493
+ .powerpc64 = > {
494
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/jump_ppc64_sysv_elf_gas.S" }) });
495
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/make_ppc64_sysv_elf_gas.S" }) });
496
+ obj .addAssemblyFile (.{ .cwd_relative = b .pathJoin (&.{ ctxPath , "src/asm/ontop_ppc64_sysv_elf_gas.S" }) });
497
+ },
498
+ else = > @panic ("Invalid arch" ),
499
+ }
500
+
501
+ if (obj .rootModuleTarget ().abi == .msvc )
502
+ obj .linkLibC ()
503
+ else {
504
+ obj .defineCMacro ("_GNU_SOURCE" , null );
505
+ obj .linkLibCpp ();
506
+ }
507
+
508
+ return obj ;
509
+ }
0 commit comments