From 80d520fcf2f71148db1df4377757258f7f7b7f3a Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Tue, 25 Nov 2014 17:28:49 -0600 Subject: [PATCH 1/3] Don't use the same llvmdeps.rs for every host. --- mk/docs.mk | 3 ++- mk/llvm.mk | 24 +++++++++++++++++------- mk/target.mk | 5 ++--- src/librustc_llvm/lib.rs | 4 +++- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/mk/docs.mk b/mk/docs.mk index 48eb9e81c20..0b5240d51d5 100644 --- a/mk/docs.mk +++ b/mk/docs.mk @@ -299,7 +299,8 @@ $(2) += doc/$(1)/index.html doc/$(1)/index.html: CFG_COMPILER_HOST_TRIPLE = $(CFG_TARGET) doc/$(1)/index.html: $$(LIB_DOC_DEP_$(1)) doc/$(1)/ @$$(call E, rustdoc: $$@) - $$(Q)$$(RUSTDOC) --cfg dox --cfg stage2 $$< + $$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(CFG_BUILD)) \ + $$(RUSTDOC) --cfg dox --cfg stage2 $$< endef $(foreach crate,$(DOC_CRATES),$(eval $(call DEF_LIB_DOC,$(crate),DOC_TARGETS))) diff --git a/mk/llvm.mk b/mk/llvm.mk index bce43902056..ba2e0738039 100644 --- a/mk/llvm.mk +++ b/mk/llvm.mk @@ -49,6 +49,12 @@ else LLVM_STDCPP_LOCATION_$(1) = endif + +# LLVM linkage: +LLVM_LINKAGE_PATH_$(1):=$$(abspath $$(RT_OUTPUT_DIR_$(1))/llvmdeps.rs) +$$(LLVM_LINKAGE_PATH_$(1)): $(S)src/etc/mklldeps.py $$(LLVM_CONFIG_$(1)) + $(Q)$(CFG_PYTHON) "$$<" "$$@" "$$(LLVM_COMPONENTS)" "$$(CFG_ENABLE_LLVM_STATIC_STDCPP)" \ + $$(LLVM_CONFIG_$(1)) endef $(foreach host,$(CFG_HOST), \ @@ -57,10 +63,14 @@ $(foreach host,$(CFG_HOST), \ $(foreach host,$(CFG_HOST), \ $(eval LLVM_CONFIGS := $(LLVM_CONFIGS) $(LLVM_CONFIG_$(host)))) -$(S)src/librustc_llvm/llvmdeps.rs: \ - $(LLVM_CONFIGS) \ - $(S)src/etc/mklldeps.py \ - $(MKFILE_DEPS) - $(Q)$(CFG_PYTHON) $(S)src/etc/mklldeps.py \ - "$@" "$(LLVM_COMPONENTS)" "$(CFG_ENABLE_LLVM_STATIC_STDCPP)" \ - $(LLVM_CONFIGS) +# This can't be done in target.mk because it's included before this file. +define LLVM_LINKAGE_DEPS +$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc_llvm: $$(LLVM_LINKAGE_PATH_$(3)) +endef + +$(foreach source,$(CFG_HOST), \ + $(foreach target,$(CFG_TARGET), \ + $(eval $(call LLVM_LINKAGE_DEPS,0,$(target),$(source))) \ + $(eval $(call LLVM_LINKAGE_DEPS,1,$(target),$(source))) \ + $(eval $(call LLVM_LINKAGE_DEPS,2,$(target),$(source))) \ + $(eval $(call LLVM_LINKAGE_DEPS,3,$(target),$(source))))) diff --git a/mk/target.mk b/mk/target.mk index acdf780f105..5b0de64574c 100644 --- a/mk/target.mk +++ b/mk/target.mk @@ -79,7 +79,8 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \ $$(dir $$@)$$(call CFG_LIB_GLOB_$(2),$(4))) $$(call REMOVE_ALL_OLD_GLOB_MATCHES, \ $$(dir $$@)$$(call CFG_RLIB_GLOB,$(4))) - $$(STAGE$(1)_T_$(2)_H_$(3)) \ + $(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(2)) \ + $$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) \ $$(RUST_LIB_FLAGS_ST$(1)) \ -L "$$(RT_OUTPUT_DIR_$(2))" \ -L "$$(LLVM_LIBDIR_$(2))" \ @@ -134,8 +135,6 @@ SNAPSHOT_RUSTC_POST_CLEANUP=$(HBIN0_H_$(CFG_BUILD))/rustc$(X_$(CFG_BUILD)) define TARGET_HOST_RULES -$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc_llvm: $(S)src/librustc_llvm/llvmdeps.rs - $$(TBIN$(1)_T_$(2)_H_$(3))/: mkdir -p $$@ diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index d67d0fa59ae..8c12ccb9c8b 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -2214,4 +2214,6 @@ pub unsafe fn static_link_hack_this_sucks() { // parts of LLVM that rustllvm depends on aren't thrown away by the linker. // Works to the above fix for #15460 to ensure LLVM dependencies that // are only used by rustllvm don't get stripped by the linker. -mod llvmdeps; +mod llvmdeps { + include!(env!("CFG_LLVM_LINKAGE_FILE")) +} From f17faf49be668dfc22e9cae97ed644e3881fd64e Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Tue, 25 Nov 2014 17:53:05 -0600 Subject: [PATCH 2/3] Never generate multiple extern {} blocks in mklldeps.py. --- src/etc/mklldeps.py | 91 +++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 56 deletions(-) diff --git a/src/etc/mklldeps.py b/src/etc/mklldeps.py index 0003de117a8..834ba074c62 100644 --- a/src/etc/mklldeps.py +++ b/src/etc/mklldeps.py @@ -19,6 +19,7 @@ f = open(sys.argv[1], 'wb') components = sys.argv[2].split(' ') components = [i for i in components if i] # ignore extra whitespaces enable_static = sys.argv[3] +llconfig = sys.argv[4] f.write("""// Copyright 2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at @@ -44,69 +45,47 @@ def run(args): sys.exit(1) return out -for llconfig in sys.argv[4:]: - f.write("\n") +f.write("\n") - out = run([llconfig, '--host-target']) - arch, os = out.split('-', 1) - arch = 'x86' if arch == 'i686' or arch == 'i386' else arch - if 'darwin' in os: - os = 'macos' - elif 'linux' in os: - os = 'linux' - elif 'freebsd' in os: - os = 'freebsd' - elif 'dragonfly' in os: - os = 'dragonfly' - elif 'android' in os: - os = 'android' - elif 'win' in os or 'mingw' in os: - os = 'windows' - cfg = [ - "target_arch = \"" + arch + "\"", - "target_os = \"" + os + "\"", - ] +version = run([llconfig, '--version']).strip() - f.write("#[cfg(all(" + ', '.join(cfg) + "))]\n") +# LLVM libs +if version < '3.5': + args = [llconfig, '--libs'] +else: + args = [llconfig, '--libs', '--system-libs'] - version = run([llconfig, '--version']).strip() +args.extend(components) +out = run(args) +for lib in out.strip().replace("\n", ' ').split(' '): + lib = lib.strip()[2:] # chop of the leading '-l' + f.write("#[link(name = \"" + lib + "\"") + # LLVM libraries are all static libraries + if 'LLVM' in lib: + f.write(", kind = \"static\"") + f.write(")]\n") - # LLVM libs - if version < '3.5': - args = [llconfig, '--libs'] - else: - args = [llconfig, '--libs', '--system-libs'] - args.extend(components) - out = run(args) - for lib in out.strip().replace("\n", ' ').split(' '): - lib = lib.strip()[2:] # chop of the leading '-l' - f.write("#[link(name = \"" + lib + "\"") - # LLVM libraries are all static libraries - if 'LLVM' in lib: - f.write(", kind = \"static\"") - f.write(")]\n") - - # llvm-config before 3.5 didn't have a system-libs flag - if version < '3.5': - if os == 'win32': +# llvm-config before 3.5 didn't have a system-libs flag +if version < '3.5': + if os == 'win32': f.write("#[link(name = \"imagehlp\")]") - # LLVM ldflags - out = run([llconfig, '--ldflags']) - for lib in out.strip().split(' '): - if lib[:2] == "-l": - f.write("#[link(name = \"" + lib[2:] + "\")]\n") +# LLVM ldflags +out = run([llconfig, '--ldflags']) +for lib in out.strip().split(' '): + if lib[:2] == "-l": + f.write("#[link(name = \"" + lib[2:] + "\")]\n") - # C++ runtime library - out = run([llconfig, '--cxxflags']) - if enable_static == '1': - assert('stdlib=libc++' not in out) - f.write("#[link(name = \"stdc++\", kind = \"static\")]\n") - else: - if 'stdlib=libc++' in out: +# C++ runtime library +out = run([llconfig, '--cxxflags']) +if enable_static == '1': + assert('stdlib=libc++' not in out) + f.write("#[link(name = \"stdc++\", kind = \"static\")]\n") +else: + if 'stdlib=libc++' in out: f.write("#[link(name = \"c++\")]\n") - else: + else: f.write("#[link(name = \"stdc++\")]\n") - # Attach everything to an extern block - f.write("extern {}\n") +# Attach everything to an extern block +f.write("extern {}\n") From ce507c6c2217f88394f8c3fc10f7c36af6867fb2 Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Tue, 25 Nov 2014 19:03:03 -0600 Subject: [PATCH 3/3] Don't forget the tests. --- mk/tests.mk | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mk/tests.mk b/mk/tests.mk index 63a34e0f010..0ec0c81f288 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -412,7 +412,8 @@ $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): \ $$(CRATEFILE_$(4)) \ $$(TESTDEP_$(1)_$(2)_$(3)_$(4)) @$$(call E, rustc: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test \ + $(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(2)) \ + $$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) -o $$@ $$< --test \ -L "$$(RT_OUTPUT_DIR_$(2))" \ -L "$$(LLVM_LIBDIR_$(2))" \ $$(RUSTFLAGS_$(4)) @@ -890,7 +891,8 @@ endif ifeq ($(2),$$(CFG_BUILD)) $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4)) @$$(call E, run doc-crate-$(4) [$(2)]) - $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test --cfg dox \ + $$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(2)) \ + $$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test --cfg dox \ $$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && touch $$@ else $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)):