Skip to content

Commit deec438

Browse files
fix: use linker wrapper script for cross-compilation flags
The cargo linker config only accepts a single executable path, but cross-compilation requires flags like --target and -isysroot. Create a wrapper script that invokes the full CC command (minus ccache) with all cross-compilation flags. This ensures rustc/cargo passes the correct target and sysroot when linking for macOS from Linux. Before: linker = "/usr/bin/clang" (missing flags, -arch fails) After: linker = "wrapper.sh" -> exec /usr/bin/clang --target=... -isysroot... "$@" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 3ec6e79 commit deec438

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/Makefile.grovedb.include

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ endif
4848
# The cc crate (used by lz4-sys, zstd-sys, etc.) looks for CC_<target> and CFLAGS_<target>
4949
# We pass the cross-compiler from the depends/ build system via these variables
5050
if HAVE_RUST_TARGET
51-
# Generate cargo config for linker and set CC/CFLAGS for the cc crate
52-
# Note: CC may include ccache (e.g., "/usr/bin/ccache gcc -m64" or "ccache gcc").
53-
# The cc crate handles this fine, but cargo's linker config needs just the compiler path.
54-
# We use awk to extract the actual compiler: if first word contains "ccache", use second word.
55-
GROVEDB_CARGO_CONFIG_SETUP = mkdir -p $(GROVEDB_DIST_DIR)/.cargo && linker=$$(echo "$(CC)" | awk '{if ($$1 ~ /ccache/) print $$2; else print $$1}') && printf '[target.%s]\nlinker = "%s"\n' "$(RUST_TARGET)" "$$linker" > $(GROVEDB_DIST_DIR)/.cargo/config.toml
51+
# For the linker, we need the full CC command (with --target, -isysroot, etc.), not just
52+
# the compiler path. Create a wrapper script that invokes CC with all its flags.
53+
# Strip ccache if present since it's not needed for linking.
54+
GROVEDB_CC_WITHOUT_CCACHE = $(shell echo "$(CC)" | awk '{if ($$1 ~ /ccache/) {for(i=2;i<=NF;i++) printf "%s ", $$i} else {print}}')
55+
56+
# Create wrapper script and cargo config
57+
GROVEDB_CARGO_CONFIG_SETUP = mkdir -p $(GROVEDB_DIST_DIR)/.cargo && \
58+
wrapper=$(GROVEDB_DIST_DIR)/.cargo/linker-wrapper.sh && \
59+
printf '%s\n' '#!/bin/sh' 'exec $(GROVEDB_CC_WITHOUT_CCACHE) "$$@"' > $$wrapper && \
60+
chmod +x $$wrapper && \
61+
printf '[target.%s]\nlinker = "%s"\n' "$(RUST_TARGET)" "$$wrapper" > $(GROVEDB_DIST_DIR)/.cargo/config.toml
5662

5763
# Base environment for cc crate
5864
GROVEDB_CARGO_ENV = CC_$(RUST_TARGET_UNDERSCORED)="$(CC)" CXX_$(RUST_TARGET_UNDERSCORED)="$(CXX)" AR_$(RUST_TARGET_UNDERSCORED)="$(AR)" CFLAGS_$(RUST_TARGET_UNDERSCORED)="$(CFLAGS)" CXXFLAGS_$(RUST_TARGET_UNDERSCORED)="$(CXXFLAGS)"

0 commit comments

Comments
 (0)