Skip to content

Commit 655b2ef

Browse files
committed
Auto merge of #28495 - semarie:stdcpp-name, r=alexcrichton
it makes rustc compatible with gcc installation that are using `--program-transform-name' configure flag (on OpenBSD for example). - detects at configure the name of stdc++ library on the system - use the detected name in llvm makefile (with enable-static-stdcpp), and pass it to mklldeps.py - generate mklldeps.rs using this detected name note that CFG_STDCPP_NAME is about stdc++ name, not about libc++. If using libc++, the default name will be `stdc++', but it won't be used when linking. r? @alexcrichton I added this support globally instead of just for OpenBSD as it isn't specially related to OpenBSD (except OpenBSD use it for gcc-4.9). And as I would had to change `llvm.mk', having just a default value in `configure' for others platforms won't be very useful.
2 parents b3afb16 + 913fe6d commit 655b2ef

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

configure

+6
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,12 @@ envopt CPP
10951095
envopt CFLAGS
10961096
envopt CXXFLAGS
10971097

1098+
# stdc++ name in use
1099+
# used to manage non-standard name (on OpenBSD for example)
1100+
program_transform_name=$($CFG_CC -v 2>&1 | sed -n "s/.*--program-transform-name='\([^']*\)'.*/\1/p")
1101+
CFG_STDCPP_NAME=$(echo "stdc++" | sed "${program_transform_name}")
1102+
putvar CFG_STDCPP_NAME
1103+
10981104
# a little post-processing of various config values
10991105
CFG_PREFIX=${CFG_PREFIX%/}
11001106
CFG_MANDIR=${CFG_MANDIR%/}

mk/llvm.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ $$(LLVM_STAMP_$(1)): $(S)src/rustllvm/llvm-auto-clean-trigger
7373

7474
ifeq ($$(CFG_ENABLE_LLVM_STATIC_STDCPP),1)
7575
LLVM_STDCPP_RUSTFLAGS_$(1) = -L "$$(dir $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \
76-
-print-file-name=libstdc++.a))"
76+
-print-file-name=lib$(CFG_STDCPP_NAME).a))"
7777
else
7878
LLVM_STDCPP_RUSTFLAGS_$(1) =
7979
endif
@@ -83,7 +83,7 @@ endif
8383
LLVM_LINKAGE_PATH_$(1):=$$(abspath $$(RT_OUTPUT_DIR_$(1))/llvmdeps.rs)
8484
$$(LLVM_LINKAGE_PATH_$(1)): $(S)src/etc/mklldeps.py $$(LLVM_CONFIG_$(1))
8585
$(Q)$(CFG_PYTHON) "$$<" "$$@" "$$(LLVM_COMPONENTS)" "$$(CFG_ENABLE_LLVM_STATIC_STDCPP)" \
86-
$$(LLVM_CONFIG_$(1))
86+
$$(LLVM_CONFIG_$(1)) "$(CFG_STDCPP_NAME)"
8787
endef
8888

8989
$(foreach host,$(CFG_HOST), \

src/etc/mklldeps.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
components = sys.argv[2].split() # splits on whitespace
1818
enable_static = sys.argv[3]
1919
llvm_config = sys.argv[4]
20+
stdcpp_name = sys.argv[5]
2021

2122
f.write("""// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2223
// file at the top-level directory of this distribution and at
@@ -77,15 +78,15 @@ def run(args):
7778
out = run([llvm_config, '--cxxflags'])
7879
if enable_static == '1':
7980
assert('stdlib=libc++' not in out)
80-
f.write("#[link(name = \"stdc++\", kind = \"static\")]\n")
81+
f.write("#[link(name = \"" + stdcpp_name + "\", kind = \"static\")]\n")
8182
else:
8283
# Note that we use `cfg_attr` here because on MSVC the C++ standard library
8384
# is not c++ or stdc++, but rather the linker takes care of linking the
8485
# right standard library.
8586
if 'stdlib=libc++' in out:
8687
f.write("#[cfg_attr(not(target_env = \"msvc\"), link(name = \"c++\"))]\n")
8788
else:
88-
f.write("#[cfg_attr(not(target_env = \"msvc\"), link(name = \"stdc++\"))]\n")
89+
f.write("#[cfg_attr(not(target_env = \"msvc\"), link(name = \"" + stdcpp_name + "\"))]\n")
8990

9091
# Attach everything to an extern block
9192
f.write("extern {}\n")

0 commit comments

Comments
 (0)