@@ -770,16 +770,16 @@ fn buildStacktrace(b: *std.Build, obj: *std.Build.Step.Compile) void {
770770 .flags = cxxFlags ,
771771 });
772772 // TODO: fix https://github.com/ziglang/zig/issues/21308
773- // if (obj.dependsOnSystemLibrary( "backtrace")) {
774- // obj.addCSourceFiles(.{
775- // .root = stackPath,
776- // .files = &.{
777- // "backtrace.cpp",
778- // },
779- // .flags = cxxFlags,
780- // });
781- // obj.linkSystemLibrary("backtrace");
782- // }
773+ if (checkSystemLibrary ( obj , "backtrace" )) {
774+ obj .addCSourceFiles (.{
775+ .root = stackPath ,
776+ .files = &.{
777+ "backtrace.cpp" ,
778+ },
779+ .flags = cxxFlags ,
780+ });
781+ obj .linkSystemLibrary ("backtrace" );
782+ }
783783
784784 if (obj .rootModuleTarget ().abi == .msvc ) {
785785 obj .addCSourceFiles (.{
@@ -1023,19 +1023,21 @@ fn buildPython(b: *std.Build, obj: *std.Build.Step.Compile) void {
10231023 .flags = cxxFlags ,
10241024 });
10251025
1026- // obj.linkSystemLibrary("npymath");
1027- // obj.addCSourceFiles(.{
1028- // .root = pyPath,
1029- // .files = &.{
1030- // "numpy/dtype.cpp",
1031- // "numpy/matrix.cpp",
1032- // "numpy/ndarray.cpp",
1033- // "numpy/numpy.cpp",
1034- // "numpy/scalars.cpp",
1035- // "numpy/ufunc.cpp",
1036- // },
1037- // .flags = cxxFlags,
1038- // });
1026+ if (checkSystemLibrary (obj , "npymath" )) {
1027+ obj .linkSystemLibrary ("npymath" );
1028+ obj .addCSourceFiles (.{
1029+ .root = pyPath ,
1030+ .files = &.{
1031+ "numpy/dtype.cpp" ,
1032+ "numpy/matrix.cpp" ,
1033+ "numpy/ndarray.cpp" ,
1034+ "numpy/numpy.cpp" ,
1035+ "numpy/scalars.cpp" ,
1036+ "numpy/ufunc.cpp" ,
1037+ },
1038+ .flags = cxxFlags ,
1039+ });
1040+ }
10391041}
10401042
10411043fn buildWave (b : * std.Build , obj : * std.Build.Step.Compile ) void {
@@ -1060,3 +1062,33 @@ fn buildWave(b: *std.Build, obj: *std.Build.Step.Compile) void {
10601062 .flags = cxxFlags ,
10611063 });
10621064}
1065+
1066+ // temporary workaround for https://github.com/ziglang/zig/issues/21308
1067+ fn checkSystemLibrary (compile : * std.Build.Step.Compile , name : []const u8 ) bool {
1068+ var is_linking_libc = false ;
1069+ var is_linking_libcpp = false ;
1070+
1071+ var dep_it = compile .root_module .iterateDependencies (compile , true );
1072+ while (dep_it .next ()) | dep | {
1073+ for (dep .module .link_objects .items ) | link_object | {
1074+ switch (link_object ) {
1075+ .system_lib = > | lib | if (std .mem .eql (u8 , lib .name , name )) return true ,
1076+ else = > continue ,
1077+ }
1078+ }
1079+ if (dep .module .link_libc ) | link_libc |
1080+ is_linking_libc = is_linking_libc or link_libc ;
1081+ if (dep .module .link_libcpp ) | link_libcpp |
1082+ is_linking_libcpp = is_linking_libcpp or (link_libcpp == true );
1083+ }
1084+
1085+ if (compile .rootModuleTarget ().is_libc_lib_name (name )) {
1086+ return is_linking_libc ;
1087+ }
1088+
1089+ if (compile .rootModuleTarget ().is_libcpp_lib_name (name )) {
1090+ return is_linking_libcpp ;
1091+ }
1092+
1093+ return false ;
1094+ }
0 commit comments