Skip to content

Commit dbf7512

Browse files
committed
fix cargo zig link error
1 parent 8dfa343 commit dbf7512

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

.github/actions/configure-cmake/action.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,24 @@ runs:
4444
wrapper_dir="${RUNNER_TEMP}/zig-linkers/${{ inputs.target }}"
4545
mkdir -p "$wrapper_dir"
4646
47-
printf '%s\n' '#!/usr/bin/env bash' \
48-
"exec zig cc -target \"$zig_target\" \"\$@\"" >"$wrapper_dir/cc"
49-
printf '%s\n' '#!/usr/bin/env bash' \
50-
"exec zig c++ -target \"$zig_target\" \"\$@\"" >"$wrapper_dir/cxx"
51-
chmod +x "$wrapper_dir/cc" "$wrapper_dir/cxx"
47+
# Single wrapper: used by rustc as linker only (via CARGO_TARGET_*_RUSTFLAGS).
48+
# We do NOT set it as CMAKE_C_COMPILER — Corrosion propagates CMAKE_C_COMPILER
49+
# as CC_<target> to all cargo C build scripts (aws-lc-sys, sha2-asm, etc.),
50+
# and zig cc cannot handle LLVM-style flags those scripts pass (e.g.
51+
# --target=x86_64-unknown-linux-gnu, -march=armv8-a+crypto).
52+
printf '#!/usr/bin/env bash\nexec zig cc -target "%s" "$@"\n' "$zig_target" > "$wrapper_dir/cc"
53+
chmod +x "$wrapper_dir/cc"
5254
53-
echo "Resolved linker wrapper: $wrapper_dir/cc"
54-
echo "Resolved C++ wrapper: $wrapper_dir/cxx"
55+
triple_upper=$(echo "${{ inputs.target }}" | tr '[:lower:]-' '[:upper:]_')
5556
56-
CMAKE_FLAGS+=(
57-
"-DCMAKE_C_COMPILER=$wrapper_dir/cc"
58-
"-DCMAKE_CXX_COMPILER=$wrapper_dir/cxx"
59-
)
57+
{
58+
# Tell rustc to use zig cc as linker only (not as CC for build scripts).
59+
# Cargo C build deps (aws-lc-sys, sha2-asm, etc.) will use the system
60+
# clang via CC/CXX set at the job level, avoiding zig's CPU/flag
61+
# parsing issues (e.g. -march=armv8-a+crypto, --target= LLVM triples).
62+
# linker-flavor=gcc means rustc will NOT pass --target to the linker.
63+
echo "CARGO_TARGET_${triple_upper}_RUSTFLAGS=-C linker=$wrapper_dir/cc -C linker-flavor=gcc"
64+
} >> "$GITHUB_ENV"
6065
fi
6166
6267
cmake -S . -B "$build_dir" "${CMAKE_FLAGS[@]}"

0 commit comments

Comments
 (0)