Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 6a7cccb

Browse files
committed
Bug 1747298 - Use CXX for Cargo linking when necessary. r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D135219
1 parent 891a4b8 commit 6a7cccb

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

build/cargo-linker

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@
1717
# and not quoting it ensures that each of those arguments is passed
1818
# as a separate argument to the actual LD.
1919
#
20+
# * In rare cases, we also need MOZ_CARGO_WRAP_LD_CXX, which is the
21+
# equivalent of CXX, when linking C++ code. Usually, this should
22+
# simply work by the use of CC and -lstdc++ (added by cc-rs).
23+
# However, in the case of sanitizer runtimes, there is a separate
24+
# runtime for C and C++ and linking C++ code with the C runtime can
25+
# fail if the requested feature is in the C++ runtime only (bug 1747298).
26+
#
2027
# $@ is doubly quoted for the eval. See bug 1418598.
2128

22-
eval ${MOZ_CARGO_WRAP_LD} ${MOZ_CARGO_WRAP_LDFLAGS} '"$@"'
29+
WRAP_LD=${MOZ_CARGO_WRAP_LD}
30+
for opt; do
31+
case "$opt" in
32+
-lc++|-lstdc++)
33+
WRAP_LD=${MOZ_CARGO_WRAP_LD_CXX};
34+
break;
35+
;;
36+
esac
37+
done
38+
eval ${WRAP_LD} ${MOZ_CARGO_WRAP_LDFLAGS} '"$@"'

config/makefiles/rust.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,10 @@ cargo_linker_env_var := CARGO_TARGET_$(call varize,$(RUST_TARGET))_LINKER
318318

319319
export MOZ_CARGO_WRAP_LDFLAGS
320320
export MOZ_CARGO_WRAP_LD
321+
export MOZ_CARGO_WRAP_LD_CXX
321322
export MOZ_CARGO_WRAP_HOST_LDFLAGS
322323
export MOZ_CARGO_WRAP_HOST_LD
324+
export MOZ_CARGO_WRAP_HOST_LD_CXX
323325
# Exporting from make always exports a value. Setting a value per-recipe
324326
# would export an empty value for the host recipes. When not doing a
325327
# cross-compile, the --target for those is the same, and cargo will use
@@ -382,16 +384,22 @@ $(TARGET_RECIPES) $(HOST_RECIPES): MOZ_CARGO_WRAP_HOST_LDFLAGS:=$(HOST_LDFLAGS)
382384

383385
ifeq (,$(filter clang-cl,$(CC_TYPE)))
384386
$(TARGET_RECIPES): MOZ_CARGO_WRAP_LD:=$(CC)
387+
$(TARGET_RECIPES): MOZ_CARGO_WRAP_LD_CXX:=$(CXX)
385388
else
386389
$(TARGET_RECIPES): MOZ_CARGO_WRAP_LD:=$(LINKER)
390+
$(TARGET_RECIPES): MOZ_CARGO_WRAP_LD_CXX:=$(LINKER)
387391
endif
388392

389393
ifeq (,$(filter clang-cl,$(HOST_CC_TYPE)))
390394
$(HOST_RECIPES): MOZ_CARGO_WRAP_LD:=$(HOST_CC)
395+
$(HOST_RECIPES): MOZ_CARGO_WRAP_LD_CXX:=$(HOST_CXX)
391396
$(TARGET_RECIPES) $(HOST_RECIPES): MOZ_CARGO_WRAP_HOST_LD:=$(HOST_CC)
397+
$(TARGET_RECIPES) $(HOST_RECIPES): MOZ_CARGO_WRAP_HOST_LD_CXX:=$(HOST_CXX)
392398
else
393399
$(HOST_RECIPES): MOZ_CARGO_WRAP_LD:=$(HOST_LINKER)
400+
$(HOST_RECIPES): MOZ_CARGO_WRAP_LD_CXX:=$(HOST_LINKER)
394401
$(TARGET_RECIPES) $(HOST_RECIPES): MOZ_CARGO_WRAP_HOST_LD:=$(HOST_LINKER)
402+
$(TARGET_RECIPES) $(HOST_RECIPES): MOZ_CARGO_WRAP_HOST_LD_CXX:=$(HOST_LINKER)
395403
endif
396404

397405
ifdef RUST_LIBRARY_FILE

taskcluster/scripts/misc/wr-macos-cross-build-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@ export AR="${CLANGDIR}/bin/llvm-ar"
5555
# the right arguments to the linker when invoked by cargo is nigh impossible
5656
# without this.
5757
export MOZ_CARGO_WRAP_LD="${CC}"
58+
export MOZ_CARGO_WRAP_LD_CXX="${CXX}"
5859
export MOZ_CARGO_WRAP_LDFLAGS="${TARGET_CFLAGS}"
5960
export CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER="${GECKO_PATH}/build/cargo-linker"

0 commit comments

Comments
 (0)