Bug 1747298 - Use CXX for Cargo linking when necessary. r=glandium

Differential Revision: https://phabricator.services.mozilla.com/D135219
This commit is contained in:
Christian Holler 2022-01-11 11:26:39 +00:00
Родитель 891a4b8e99
Коммит 6a7cccb953
3 изменённых файлов: 26 добавлений и 1 удалений

Просмотреть файл

@ -17,6 +17,22 @@
# and not quoting it ensures that each of those arguments is passed
# as a separate argument to the actual LD.
#
# * In rare cases, we also need MOZ_CARGO_WRAP_LD_CXX, which is the
# equivalent of CXX, when linking C++ code. Usually, this should
# simply work by the use of CC and -lstdc++ (added by cc-rs).
# However, in the case of sanitizer runtimes, there is a separate
# runtime for C and C++ and linking C++ code with the C runtime can
# fail if the requested feature is in the C++ runtime only (bug 1747298).
#
# $@ is doubly quoted for the eval. See bug 1418598.
eval ${MOZ_CARGO_WRAP_LD} ${MOZ_CARGO_WRAP_LDFLAGS} '"$@"'
WRAP_LD=${MOZ_CARGO_WRAP_LD}
for opt; do
case "$opt" in
-lc++|-lstdc++)
WRAP_LD=${MOZ_CARGO_WRAP_LD_CXX};
break;
;;
esac
done
eval ${WRAP_LD} ${MOZ_CARGO_WRAP_LDFLAGS} '"$@"'

Просмотреть файл

@ -318,8 +318,10 @@ cargo_linker_env_var := CARGO_TARGET_$(call varize,$(RUST_TARGET))_LINKER
export MOZ_CARGO_WRAP_LDFLAGS
export MOZ_CARGO_WRAP_LD
export MOZ_CARGO_WRAP_LD_CXX
export MOZ_CARGO_WRAP_HOST_LDFLAGS
export MOZ_CARGO_WRAP_HOST_LD
export MOZ_CARGO_WRAP_HOST_LD_CXX
# Exporting from make always exports a value. Setting a value per-recipe
# would export an empty value for the host recipes. When not doing a
# 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)
ifeq (,$(filter clang-cl,$(CC_TYPE)))
$(TARGET_RECIPES): MOZ_CARGO_WRAP_LD:=$(CC)
$(TARGET_RECIPES): MOZ_CARGO_WRAP_LD_CXX:=$(CXX)
else
$(TARGET_RECIPES): MOZ_CARGO_WRAP_LD:=$(LINKER)
$(TARGET_RECIPES): MOZ_CARGO_WRAP_LD_CXX:=$(LINKER)
endif
ifeq (,$(filter clang-cl,$(HOST_CC_TYPE)))
$(HOST_RECIPES): MOZ_CARGO_WRAP_LD:=$(HOST_CC)
$(HOST_RECIPES): MOZ_CARGO_WRAP_LD_CXX:=$(HOST_CXX)
$(TARGET_RECIPES) $(HOST_RECIPES): MOZ_CARGO_WRAP_HOST_LD:=$(HOST_CC)
$(TARGET_RECIPES) $(HOST_RECIPES): MOZ_CARGO_WRAP_HOST_LD_CXX:=$(HOST_CXX)
else
$(HOST_RECIPES): MOZ_CARGO_WRAP_LD:=$(HOST_LINKER)
$(HOST_RECIPES): MOZ_CARGO_WRAP_LD_CXX:=$(HOST_LINKER)
$(TARGET_RECIPES) $(HOST_RECIPES): MOZ_CARGO_WRAP_HOST_LD:=$(HOST_LINKER)
$(TARGET_RECIPES) $(HOST_RECIPES): MOZ_CARGO_WRAP_HOST_LD_CXX:=$(HOST_LINKER)
endif
ifdef RUST_LIBRARY_FILE

Просмотреть файл

@ -55,5 +55,6 @@ export AR="${CLANGDIR}/bin/llvm-ar"
# the right arguments to the linker when invoked by cargo is nigh impossible
# without this.
export MOZ_CARGO_WRAP_LD="${CC}"
export MOZ_CARGO_WRAP_LD_CXX="${CXX}"
export MOZ_CARGO_WRAP_LDFLAGS="${TARGET_CFLAGS}"
export CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER="${GECKO_PATH}/build/cargo-linker"