Skip to content

Commit 09edb7d

Browse files
committed
build CI
1 parent 0c82c6e commit 09edb7d

File tree

2 files changed

+104
-9
lines changed

2 files changed

+104
-9
lines changed

.github/workflows/ci.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,75 @@
11
name: CI
22

3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
8+
jobs:
9+
linux:
10+
name: Linux (x86_64)
11+
runs-on: ubuntu-22.04
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Zig
17+
uses: goto-bus-stop/setup-zig@v2
18+
with:
19+
version: 0.14.1
20+
21+
- name: Install dependencies
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install -y clang lld cmake ninja-build libc++-dev libc++abi-dev libboost-dev
25+
echo "CC=clang" >> "$GITHUB_ENV"
26+
echo "CXX=clang++" >> "$GITHUB_ENV"
27+
28+
- name: Build (ReleaseFast)
29+
run: zig build -Doptimize=ReleaseFast
30+
31+
macos-arm64:
32+
name: macOS (arm64)
33+
runs-on: macos-14
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
38+
- name: Setup Zig
39+
uses: goto-bus-stop/setup-zig@v2
40+
with:
41+
version: 0.14.1
42+
43+
- name: Install dependencies
44+
run: |
45+
brew update
46+
brew install cmake ninja boost
47+
48+
- name: Build (ReleaseFast, native arm64)
49+
run: zig build -Doptimize=ReleaseFast
50+
51+
macos-x86_64:
52+
name: macOS (x86_64)
53+
runs-on: macos-13
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v4
57+
58+
- name: Setup Zig
59+
uses: goto-bus-stop/setup-zig@v2
60+
with:
61+
version: 0.14.1
62+
63+
- name: Install dependencies
64+
run: |
65+
brew update
66+
brew install cmake ninja boost
67+
68+
- name: Build (ReleaseFast, native x86_64)
69+
run: zig build -Doptimize=ReleaseFast
70+
71+
name: CI
72+
373
on:
474
push:
575
branches: [ main, develop ]

build.zig

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)