77
88jobs :
99 build-rust :
10- name : Build Rust (${{ matrix.os }}-${{ matrix.arch }})
11- runs-on : ${{ matrix.os }}
10+ name : Build Rust (${{ matrix.target }})
11+ runs-on :
12+ group : databricks-protected-runner-group
13+ labels : ${{ matrix.os-label }}
1214 strategy :
1315 fail-fast : false
1416 matrix :
1517 include :
16- - os : ubuntu-latest
18+ - os-label : linux- ubuntu-latest
1719 arch : amd64
1820 target : x86_64-unknown-linux-gnu
19- - os : ubuntu-latest
21+ use-zig : false
22+ - os-label : linux-ubuntu-latest
2023 arch : arm64
2124 target : aarch64-unknown-linux-gnu
22- - os : macos-latest
25+ use-zig : false
26+ - os-label : linux-ubuntu-latest
2327 arch : amd64
2428 target : x86_64-apple-darwin
25- - os : macos-latest
29+ use-zig : true
30+ - os-label : linux-ubuntu-latest
2631 arch : arm64
2732 target : aarch64-apple-darwin
28- - os : windows-latest
33+ use-zig : true
34+ - os-label : windows-server-latest
2935 arch : amd64
3036 target : x86_64-pc-windows-gnu
37+ use-zig : false
3138
3239 steps :
3340 - uses : actions/checkout@v4
@@ -43,34 +50,91 @@ jobs:
4350 sudo apt-get update
4451 sudo apt-get install -y gcc-aarch64-linux-gnu
4552
46- - name : Build Rust Library
53+ - name : Install Zig and cargo-zigbuild (for macOS cross-compilation)
54+ if : matrix.use-zig == true
55+ shell : bash
56+ run : |
57+ # Determine architecture
58+ ARCH=$(uname -m)
59+ case "$ARCH" in
60+ x86_64) ZIG_ARCH="x86_64" ;;
61+ aarch64) ZIG_ARCH="aarch64" ;;
62+ *) echo "Unsupported architecture: $ARCH"; exit 1 ;;
63+ esac
64+
65+ ZIG_VERSION="0.13.0"
66+ ZIG_URL="https://ziglang.org/download/${ZIG_VERSION}/zig-linux-${ZIG_ARCH}-${ZIG_VERSION}.tar.xz"
67+
68+ echo "Downloading Zig from $ZIG_URL"
69+ wget -q "$ZIG_URL"
70+ tar -xf "zig-linux-${ZIG_ARCH}-${ZIG_VERSION}.tar.xz"
71+
72+ # Install to a local directory and add to PATH
73+ mkdir -p $HOME/.local/bin
74+ rm -rf $HOME/.local/zig
75+ mv "zig-linux-${ZIG_ARCH}-${ZIG_VERSION}" $HOME/.local/zig
76+ ln -sf $HOME/.local/zig/zig $HOME/.local/bin/zig
77+ echo "$HOME/.local/bin" >> $GITHUB_PATH
78+
79+ # Install cargo-zigbuild if not present
80+ if ! command -v cargo-zigbuild &> /dev/null; then
81+ cargo install cargo-zigbuild
82+ fi
83+
84+ - name : Build Rust Library (Standard)
85+ if : matrix.use-zig == false
4786 working-directory : zerobus-ffi
4887 run : |
4988 cargo build --release --target ${{ matrix.target }}
5089 env :
5190 CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER : aarch64-linux-gnu-gcc
5291
92+ - name : Build Rust Library (Zig Cross-Compile)
93+ if : matrix.use-zig == true
94+ working-directory : zerobus-ffi
95+ run : |
96+ cargo zigbuild --release --target ${{ matrix.target }}
97+
5398 - name : Prepare Artifact
5499 shell : bash
55100 run : |
56- mkdir -p dist/${{ runner.os == 'macOS' && 'darwin' || (runner.os == 'Windows' && 'windows' || 'linux') }}_${{ matrix.arch }}
101+ # Determine OS name based on target
102+ case "${{ matrix.target }}" in
103+ *-apple-darwin)
104+ OS_NAME="darwin"
105+ ;;
106+ *-pc-windows-*)
107+ OS_NAME="windows"
108+ ;;
109+ *-linux-*)
110+ OS_NAME="linux"
111+ ;;
112+ *)
113+ OS_NAME="unknown"
114+ ;;
115+ esac
116+
117+ mkdir -p dist/${OS_NAME}_${{ matrix.arch }}
118+
57119 if [ "${{ runner.os }}" = "Windows" ]; then
58120 cp zerobus-ffi/target/${{ matrix.target }}/release/libzerobus_ffi.a dist/windows_${{ matrix.arch }}/libzerobus_ffi.a || \
59121 cp zerobus-ffi/target/${{ matrix.target }}/release/zerobus_ffi.lib dist/windows_${{ matrix.arch }}/libzerobus_ffi.a
60122 else
61- cp zerobus-ffi/target/${{ matrix.target }}/release/libzerobus_ffi.a dist/${{ runner.os == 'macOS' && 'darwin' || 'linux' } }_${{ matrix.arch }}/libzerobus_ffi.a
123+ cp zerobus-ffi/target/${{ matrix.target }}/release/libzerobus_ffi.a dist/${OS_NAME }_${{ matrix.arch }}/libzerobus_ffi.a
62124 fi
63125
64126 - name : Upload Artifact
65127 uses : actions/upload-artifact@v4
66128 with :
67- name : lib-${{ matrix.os }}-${{ matrix.arch }}
129+ name : lib-${{ matrix.target }}
68130 path : dist/
69131
70132 update-tag :
71133 name : Update Tag with Binaries
72134 needs : build-rust
73- runs-on : ubuntu-latest
135+ runs-on :
136+ group : databricks-protected-runner-group
137+ labels : linux-ubuntu-latest
74138 permissions :
75139 contents : write
76140 steps :
@@ -104,4 +168,3 @@ jobs:
104168 # Force update the tag to this new commit
105169 git tag -f ${{ github.ref_name }}
106170 git push origin ${{ github.ref_name }} --force
107-
0 commit comments