@@ -451,12 +451,24 @@ fn buildSolidityLibrariesImpl(step: *std.Build.Step, options: std.Build.Step.Mak
451451 std .log .info ("Adding Boost paths for Linux" , .{});
452452 // Force libc++ usage on Linux to match macOS ABI
453453 try cmake_args .append ("-DCMAKE_CXX_FLAGS=-stdlib=libc++ -lc++abi" );
454+ // Ensure the linker uses libc++ and c++abi as well
455+ try cmake_args .append ("-DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ -lc++abi" );
456+ try cmake_args .append ("-DCMAKE_SHARED_LINKER_FLAGS=-stdlib=libc++ -lc++abi" );
457+ try cmake_args .append ("-DCMAKE_MODULE_LINKER_FLAGS=-stdlib=libc++ -lc++abi" );
454458 try cmake_args .append ("-DCMAKE_CXX_COMPILER=clang++" );
455459 try cmake_args .append ("-DCMAKE_C_COMPILER=clang" );
456460 } else if (builtin .os .tag == .macos ) {
457461 std .log .info ("Adding Boost paths for Apple Silicon Mac" , .{});
458462 // macOS already uses libc++ by default, but be explicit
459463 try cmake_args .append ("-DCMAKE_CXX_FLAGS=-stdlib=libc++" );
464+
465+ // Allow forcing CMake arch when cross-compiling on macOS via env var
466+ if (std .process .getEnvVarOwned (allocator , "ORA_CMAKE_OSX_ARCH" ) catch null ) | arch | {
467+ defer allocator .free (arch );
468+ const flag = b .fmt ("-DCMAKE_OSX_ARCHITECTURES={s}" , .{arch });
469+ try cmake_args .append (flag );
470+ std .log .info ("Using CMAKE_OSX_ARCHITECTURES={s}" , .{arch });
471+ }
460472 } else if (builtin .os .tag == .windows ) {
461473 std .log .info ("Adding Boost paths for Windows" , .{});
462474 // Windows: Use MSVC and configure Boost paths
@@ -497,6 +509,7 @@ fn buildSolidityLibrariesImpl(step: *std.Build.Step, options: std.Build.Step.Mak
497509 "cmake" ,
498510 "--build" ,
499511 build_dir ,
512+ "--parallel" ,
500513 "--target" ,
501514 "solutil" ,
502515 "--target" ,
@@ -538,13 +551,23 @@ fn buildYulWrapper(b: *std.Build, target: std.Build.ResolvedTarget, optimize: st
538551 yul_wrapper .step .dependOn (cmake_step );
539552
540553 // Add the C++ source file
554+ // Configure C++ flags and ensure libc++ on Linux to match CMake configuration
555+ var cpp_flags = std .ArrayList ([]const u8 ).init (b .allocator );
556+ defer cpp_flags .deinit ();
557+ cpp_flags .appendSlice (&[_ ][]const u8 {
558+ "-std=c++20" ,
559+ "-fPIC" ,
560+ "-Wno-deprecated" ,
561+ }) catch @panic ("OOM" );
562+
563+ if (target .result .os .tag == .linux ) {
564+ // Use libc++ headers on Linux to align with CMake's -stdlib=libc++
565+ cpp_flags .append ("-stdlib=libc++" ) catch @panic ("OOM" );
566+ }
567+
541568 yul_wrapper .addCSourceFile (.{
542569 .file = b .path ("src/yul_wrapper.cpp" ),
543- .flags = &[_ ][]const u8 {
544- "-std=c++20" ,
545- "-fPIC" ,
546- "-Wno-deprecated" ,
547- },
570+ .flags = cpp_flags .items ,
548571 });
549572
550573 // Add include directories
@@ -566,8 +589,9 @@ fn buildYulWrapper(b: *std.Build, target: std.Build.ResolvedTarget, optimize: st
566589 // Use the appropriate C++ stdlib based on the target
567590 switch (target .result .os .tag ) {
568591 .linux = > {
569- // On Linux, use libstdc++ for better compatibility
570- yul_wrapper .linkSystemLibrary ("stdc++" );
592+ // On Linux, use libc++ and c++abi to match CMake build
593+ yul_wrapper .linkLibCpp ();
594+ yul_wrapper .linkSystemLibrary ("c++abi" );
571595 },
572596 .macos = > {
573597 // On macOS, use libc++
@@ -605,8 +629,9 @@ fn linkSolidityLibraries(b: *std.Build, exe: *std.Build.Step.Compile, cmake_step
605629 // Use the appropriate C++ stdlib based on the target
606630 switch (target .result .os .tag ) {
607631 .linux = > {
608- // On Linux, use libstdc++ for better compatibility
609- exe .linkSystemLibrary ("stdc++" );
632+ // On Linux, use libc++ and c++abi to match CMake build
633+ exe .linkLibCpp ();
634+ exe .linkSystemLibrary ("c++abi" );
610635 },
611636 .macos = > {
612637 // On macOS, use libc++
0 commit comments