about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-11-26 09:47:01 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-11-26 16:50:12 -0800
commit4c5b9669e802ca851b47d934c9fd236e5b7a4b2a (patch)
treecc8e9aaf2882c07d42083e20dcb906f9c8cc606a
parent99338cf8f6c9b611b18df2f0cdd165522489ca5a (diff)
parentce507c6c2217f88394f8c3fc10f7c36af6867fb2 (diff)
rollup merge of #19322: DiamondLovesYou/multi-llvmdeps
-rw-r--r--mk/docs.mk3
-rw-r--r--mk/llvm.mk24
-rw-r--r--mk/target.mk5
-rw-r--r--mk/tests.mk6
-rw-r--r--src/etc/mklldeps.py101
-rw-r--r--src/librustc_llvm/lib.rs4
6 files changed, 68 insertions, 75 deletions
diff --git a/mk/docs.mk b/mk/docs.mk
index 59b17ff16de..898e4eb8c75 100644
--- a/mk/docs.mk
+++ b/mk/docs.mk
@@ -279,7 +279,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/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)):
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")
-
-    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 + "\"",
-    ]
-
-    f.write("#[cfg(all(" + ', '.join(cfg) + "))]\n")
-
-    version = run([llconfig, '--version']).strip()
-
-    # 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':
+f.write("\n")
+
+version = run([llconfig, '--version']).strip()
+
+# 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':
         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")
-
-    # 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:
+# 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:
         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")
diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs
index 8752a14d610..eef0ecaae6a 100644
--- a/src/librustc_llvm/lib.rs
+++ b/src/librustc_llvm/lib.rs
@@ -2211,4 +2211,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"))
+}