Skip to content

Commit a3d5ec6

Browse files
bnarasclaude
andcommitted
Fix macOS deployment target mismatch by detecting R actual target
The Rust cc crate defaults to the SDK version (xcrun --show-sdk-version) when MACOSX_DEPLOYMENT_TARGET is unset, which can exceed the deployment target used by R compiler and linked libraries (e.g., libgfortran), causing an ld warning. Instead of re-exporting an env var that may not exist, configure now compiles a test object with R compiler and reads the minos value via otool to determine the correct deployment target. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e01b04c commit a3d5ec6

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

configure

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,22 @@ fi
88

99
CC_ALONE=`$R_HOME/bin/R CMD config CC | awk '{print $1}'`
1010

11-
sed -e "s/@TARGET@/${TARGET}/" -e "s|@R_HOME@|${R_HOME}|" -e "s|@CC_ALONE@|${CC_ALONE}|" src/Makevars.in > src/Makevars
11+
# Detect macOS deployment target for Rust cc crate.
12+
# The cc crate defaults to the SDK version (via xcrun --show-sdk-version)
13+
# which can exceed the target used by R's compiler, causing an ld warning.
14+
# We compile a test object with R's compiler to determine the actual target.
15+
MACOSX_DT=""
16+
if [ "$(uname)" = "Darwin" ]; then
17+
if [ -n "$MACOSX_DEPLOYMENT_TARGET" ]; then
18+
MACOSX_DT="$MACOSX_DEPLOYMENT_TARGET"
19+
else
20+
R_CC=`"${R_HOME}/bin/R" CMD config CC`
21+
R_CFLAGS=`"${R_HOME}/bin/R" CMD config CFLAGS`
22+
echo "int x;" > conftest_dt.c
23+
$R_CC $R_CFLAGS -c conftest_dt.c -o conftest_dt.o 2>/dev/null
24+
MACOSX_DT=`otool -l conftest_dt.o 2>/dev/null | awk '/LC_BUILD_VERSION/{found=1} found && /minos/{print $2; exit}'`
25+
rm -f conftest_dt.c conftest_dt.o
26+
fi
27+
fi
28+
29+
sed -e "s/@TARGET@/${TARGET}/" -e "s|@R_HOME@|${R_HOME}|" -e "s|@CC_ALONE@|${CC_ALONE}|" -e "s|@MACOSX_DT@|${MACOSX_DT}|" src/Makevars.in > src/Makevars

src/Makevars.in

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
TARGET = @TARGET@
22
R_HOME = @R_HOME@
33
CC_ALONE = @CC_ALONE@
4+
MACOSX_DT = @MACOSX_DT@
45
VENDORING = yes
56
VENDOR_SRC = ./rust/vendor.tar.xz
67
VENDOR_DIR = ./rust/vendor
@@ -17,6 +18,16 @@ CARGOTMP = $(CURDIR)/rust/.cargo
1718
CARGO_BUILD_ARGS = -j 2 --lib --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR)
1819
RUST_BACKTRACE=1
1920

21+
# Ensure the Rust cc crate uses the correct macOS deployment target.
22+
# Without this, cc falls back to xcrun --show-sdk-version which may
23+
# return a newer version than the R link target, causing an ld warning.
24+
ifneq ($(MACOSX_DT),)
25+
MACOSX_DEPLOYMENT_TARGET = $(MACOSX_DT)
26+
endif
27+
ifdef MACOSX_DEPLOYMENT_TARGET
28+
export MACOSX_DEPLOYMENT_TARGET
29+
endif
30+
2031
all: $(SHLIB) clean_intermediate
2132

2233
$(SHLIB): $(STATLIB)
@@ -37,7 +48,6 @@ $(STATLIB):
3748
export R_HOME=$(R_HOME); \
3849
export PATH="$(PATH):$(HOME)/.cargo/bin"; \
3950
export RUSTFLAGS="-C linker=${CC_ALONE}"; \
40-
export MACOSX_DEPLOYMENT_TARGET; \
4151
cargo build $(CARGO_BUILD_ARGS) --release --offline; \
4252
else \
4353
cargo build $(CARGO_BUILD_ARGS); \

0 commit comments

Comments
 (0)