Skip to content

Commit 4c5b966

Browse files
committed
rollup merge of rust-lang#19322: DiamondLovesYou/multi-llvmdeps
2 parents 99338cf + ce507c6 commit 4c5b966

File tree

6 files changed

+68
-75
lines changed

6 files changed

+68
-75
lines changed

mk/docs.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ $(2) += doc/$(1)/index.html
279279
doc/$(1)/index.html: CFG_COMPILER_HOST_TRIPLE = $(CFG_TARGET)
280280
doc/$(1)/index.html: $$(LIB_DOC_DEP_$(1)) doc/$(1)/
281281
@$$(call E, rustdoc: $$@)
282-
$$(Q)$$(RUSTDOC) --cfg dox --cfg stage2 $$<
282+
$$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(CFG_BUILD)) \
283+
$$(RUSTDOC) --cfg dox --cfg stage2 $$<
283284
endef
284285

285286
$(foreach crate,$(DOC_CRATES),$(eval $(call DEF_LIB_DOC,$(crate),DOC_TARGETS)))

mk/llvm.mk

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ else
4949
LLVM_STDCPP_LOCATION_$(1) =
5050
endif
5151

52+
53+
# LLVM linkage:
54+
LLVM_LINKAGE_PATH_$(1):=$$(abspath $$(RT_OUTPUT_DIR_$(1))/llvmdeps.rs)
55+
$$(LLVM_LINKAGE_PATH_$(1)): $(S)src/etc/mklldeps.py $$(LLVM_CONFIG_$(1))
56+
$(Q)$(CFG_PYTHON) "$$<" "$$@" "$$(LLVM_COMPONENTS)" "$$(CFG_ENABLE_LLVM_STATIC_STDCPP)" \
57+
$$(LLVM_CONFIG_$(1))
5258
endef
5359

5460
$(foreach host,$(CFG_HOST), \
@@ -57,10 +63,14 @@ $(foreach host,$(CFG_HOST), \
5763
$(foreach host,$(CFG_HOST), \
5864
$(eval LLVM_CONFIGS := $(LLVM_CONFIGS) $(LLVM_CONFIG_$(host))))
5965

60-
$(S)src/librustc_llvm/llvmdeps.rs: \
61-
$(LLVM_CONFIGS) \
62-
$(S)src/etc/mklldeps.py \
63-
$(MKFILE_DEPS)
64-
$(Q)$(CFG_PYTHON) $(S)src/etc/mklldeps.py \
65-
"$@" "$(LLVM_COMPONENTS)" "$(CFG_ENABLE_LLVM_STATIC_STDCPP)" \
66-
$(LLVM_CONFIGS)
66+
# This can't be done in target.mk because it's included before this file.
67+
define LLVM_LINKAGE_DEPS
68+
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc_llvm: $$(LLVM_LINKAGE_PATH_$(3))
69+
endef
70+
71+
$(foreach source,$(CFG_HOST), \
72+
$(foreach target,$(CFG_TARGET), \
73+
$(eval $(call LLVM_LINKAGE_DEPS,0,$(target),$(source))) \
74+
$(eval $(call LLVM_LINKAGE_DEPS,1,$(target),$(source))) \
75+
$(eval $(call LLVM_LINKAGE_DEPS,2,$(target),$(source))) \
76+
$(eval $(call LLVM_LINKAGE_DEPS,3,$(target),$(source)))))

mk/target.mk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
7979
$$(dir $$@)$$(call CFG_LIB_GLOB_$(2),$(4)))
8080
$$(call REMOVE_ALL_OLD_GLOB_MATCHES, \
8181
$$(dir $$@)$$(call CFG_RLIB_GLOB,$(4)))
82-
$$(STAGE$(1)_T_$(2)_H_$(3)) \
82+
$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(2)) \
83+
$$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) \
8384
$$(RUST_LIB_FLAGS_ST$(1)) \
8485
-L "$$(RT_OUTPUT_DIR_$(2))" \
8586
-L "$$(LLVM_LIBDIR_$(2))" \
@@ -134,8 +135,6 @@ SNAPSHOT_RUSTC_POST_CLEANUP=$(HBIN0_H_$(CFG_BUILD))/rustc$(X_$(CFG_BUILD))
134135

135136
define TARGET_HOST_RULES
136137

137-
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc_llvm: $(S)src/librustc_llvm/llvmdeps.rs
138-
139138
$$(TBIN$(1)_T_$(2)_H_$(3))/:
140139
mkdir -p $$@
141140

mk/tests.mk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): \
412412
$$(CRATEFILE_$(4)) \
413413
$$(TESTDEP_$(1)_$(2)_$(3)_$(4))
414414
@$$(call E, rustc: $$@)
415-
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test \
415+
$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(2)) \
416+
$$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) -o $$@ $$< --test \
416417
-L "$$(RT_OUTPUT_DIR_$(2))" \
417418
-L "$$(LLVM_LIBDIR_$(2))" \
418419
$$(RUSTFLAGS_$(4))
@@ -890,7 +891,8 @@ endif
890891
ifeq ($(2),$$(CFG_BUILD))
891892
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4))
892893
@$$(call E, run doc-crate-$(4) [$(2)])
893-
$$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test --cfg dox \
894+
$$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(2)) \
895+
$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test --cfg dox \
894896
$$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && touch $$@
895897
else
896898
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)):

src/etc/mklldeps.py

Lines changed: 40 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
components = sys.argv[2].split(' ')
2020
components = [i for i in components if i] # ignore extra whitespaces
2121
enable_static = sys.argv[3]
22+
llconfig = sys.argv[4]
2223

2324
f.write("""// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2425
// file at the top-level directory of this distribution and at
@@ -44,69 +45,47 @@ def run(args):
4445
sys.exit(1)
4546
return out
4647

47-
for llconfig in sys.argv[4:]:
48-
f.write("\n")
49-
50-
out = run([llconfig, '--host-target'])
51-
arch, os = out.split('-', 1)
52-
arch = 'x86' if arch == 'i686' or arch == 'i386' else arch
53-
if 'darwin' in os:
54-
os = 'macos'
55-
elif 'linux' in os:
56-
os = 'linux'
57-
elif 'freebsd' in os:
58-
os = 'freebsd'
59-
elif 'dragonfly' in os:
60-
os = 'dragonfly'
61-
elif 'android' in os:
62-
os = 'android'
63-
elif 'win' in os or 'mingw' in os:
64-
os = 'windows'
65-
cfg = [
66-
"target_arch = \"" + arch + "\"",
67-
"target_os = \"" + os + "\"",
68-
]
69-
70-
f.write("#[cfg(all(" + ', '.join(cfg) + "))]\n")
71-
72-
version = run([llconfig, '--version']).strip()
73-
74-
# LLVM libs
75-
if version < '3.5':
76-
args = [llconfig, '--libs']
77-
else:
78-
args = [llconfig, '--libs', '--system-libs']
79-
args.extend(components)
80-
out = run(args)
81-
for lib in out.strip().replace("\n", ' ').split(' '):
82-
lib = lib.strip()[2:] # chop of the leading '-l'
83-
f.write("#[link(name = \"" + lib + "\"")
84-
# LLVM libraries are all static libraries
85-
if 'LLVM' in lib:
86-
f.write(", kind = \"static\"")
87-
f.write(")]\n")
88-
89-
# llvm-config before 3.5 didn't have a system-libs flag
90-
if version < '3.5':
91-
if os == 'win32':
48+
f.write("\n")
49+
50+
version = run([llconfig, '--version']).strip()
51+
52+
# LLVM libs
53+
if version < '3.5':
54+
args = [llconfig, '--libs']
55+
else:
56+
args = [llconfig, '--libs', '--system-libs']
57+
58+
args.extend(components)
59+
out = run(args)
60+
for lib in out.strip().replace("\n", ' ').split(' '):
61+
lib = lib.strip()[2:] # chop of the leading '-l'
62+
f.write("#[link(name = \"" + lib + "\"")
63+
# LLVM libraries are all static libraries
64+
if 'LLVM' in lib:
65+
f.write(", kind = \"static\"")
66+
f.write(")]\n")
67+
68+
# llvm-config before 3.5 didn't have a system-libs flag
69+
if version < '3.5':
70+
if os == 'win32':
9271
f.write("#[link(name = \"imagehlp\")]")
9372

94-
# LLVM ldflags
95-
out = run([llconfig, '--ldflags'])
96-
for lib in out.strip().split(' '):
97-
if lib[:2] == "-l":
98-
f.write("#[link(name = \"" + lib[2:] + "\")]\n")
99-
100-
# C++ runtime library
101-
out = run([llconfig, '--cxxflags'])
102-
if enable_static == '1':
103-
assert('stdlib=libc++' not in out)
104-
f.write("#[link(name = \"stdc++\", kind = \"static\")]\n")
105-
else:
106-
if 'stdlib=libc++' in out:
73+
# LLVM ldflags
74+
out = run([llconfig, '--ldflags'])
75+
for lib in out.strip().split(' '):
76+
if lib[:2] == "-l":
77+
f.write("#[link(name = \"" + lib[2:] + "\")]\n")
78+
79+
# C++ runtime library
80+
out = run([llconfig, '--cxxflags'])
81+
if enable_static == '1':
82+
assert('stdlib=libc++' not in out)
83+
f.write("#[link(name = \"stdc++\", kind = \"static\")]\n")
84+
else:
85+
if 'stdlib=libc++' in out:
10786
f.write("#[link(name = \"c++\")]\n")
108-
else:
87+
else:
10988
f.write("#[link(name = \"stdc++\")]\n")
11089

111-
# Attach everything to an extern block
112-
f.write("extern {}\n")
90+
# Attach everything to an extern block
91+
f.write("extern {}\n")

src/librustc_llvm/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,4 +2211,6 @@ pub unsafe fn static_link_hack_this_sucks() {
22112211
// parts of LLVM that rustllvm depends on aren't thrown away by the linker.
22122212
// Works to the above fix for #15460 to ensure LLVM dependencies that
22132213
// are only used by rustllvm don't get stripped by the linker.
2214-
mod llvmdeps;
2214+
mod llvmdeps {
2215+
include!(env!("CFG_LLVM_LINKAGE_FILE"))
2216+
}

0 commit comments

Comments
 (0)