This better matches where upstream puts compilers and development utilities.
363 lines
13 KiB
Diff
363 lines
13 KiB
Diff
From 64dcf50a8a0f3aaf37ec6e4fe6143d0832592c05 Mon Sep 17 00:00:00 2001
|
|
From: Cody P Schafer <dev@codyps.com>
|
|
Date: Mon, 24 Nov 2014 13:10:15 -0500
|
|
Subject: [PATCH 5/8] configure: support --bindir, and extend libdir to
|
|
non-blessed dirs
|
|
|
|
Adds --bindir, and:
|
|
|
|
Allows --bindir and --libdir to have multiple elements in their paths
|
|
relative to sysroot, and allows libdir to end in an arbitrary directory
|
|
(previously it was limited to lib, lib32, and lib64).
|
|
|
|
Note that this assumes absolute paths start with '/', which may break
|
|
windows platforms
|
|
---
|
|
configure | 49 ++++++++++++++++------
|
|
mk/host.mk | 6 ++-
|
|
mk/main.mk | 11 +++++
|
|
mk/perf.mk | 4 +-
|
|
mk/prepare.mk | 4 +-
|
|
src/librustc/metadata/filesearch.rs | 84 ++++++++++++++-----------------------
|
|
src/librustc_trans/back/link.rs | 3 +-
|
|
7 files changed, 90 insertions(+), 71 deletions(-)
|
|
|
|
diff --git a/configure b/configure
|
|
index 891f524..441793c 100755
|
|
--- a/configure
|
|
+++ b/configure
|
|
@@ -323,6 +323,31 @@ envopt() {
|
|
fi
|
|
}
|
|
|
|
+abspath () {
|
|
+ case "$1" in
|
|
+ /*) echo "$1" ;;
|
|
+ *) echo "$PWD/$1" ;;
|
|
+ esac
|
|
+}
|
|
+
|
|
+relpath () {
|
|
+ local src=$(abspath "$1")
|
|
+ local dst=$(abspath "$2")
|
|
+ local common=$src
|
|
+ local result=
|
|
+
|
|
+ # Start by checking if the whole src is common, then strip off pack
|
|
+ # components until we find the common element.
|
|
+ while [ "${dst#"$common"}" = "$dst" ]; do
|
|
+ common=$(dirname "$common")
|
|
+ result="../$result"
|
|
+ done
|
|
+
|
|
+ local down="${dst#"$common"}"
|
|
+ result="${result}${down#/}"
|
|
+ echo "$result"
|
|
+}
|
|
+
|
|
to_llvm_triple() {
|
|
case $1 in
|
|
i686-w64-mingw32) echo i686-pc-windows-gnu ;;
|
|
@@ -609,6 +634,8 @@ putvar CFG_BUILD # Yes, this creates a duplicate entry, but the last one wins.
|
|
CFG_HOST=$(to_llvm_triple $CFG_HOST)
|
|
CFG_TARGET=$(to_llvm_triple $CFG_TARGET)
|
|
|
|
+CFG_LIBDIR_RELATIVE=lib
|
|
+
|
|
# On windows we just store the libraries in the bin directory because
|
|
# there's no rpath. This is where the build system itself puts libraries;
|
|
# --libdir is used to configure the installation directory.
|
|
@@ -616,24 +643,21 @@ CFG_TARGET=$(to_llvm_triple $CFG_TARGET)
|
|
if [ "$CFG_OSTYPE" = "pc-windows-gnu" ] || [ "$CFG_OSTYPE" = "pc-windows-msvc" ]
|
|
then
|
|
CFG_LIBDIR_RELATIVE=bin
|
|
-else
|
|
- CFG_LIBDIR_RELATIVE=lib
|
|
fi
|
|
|
|
-valopt libdir "${CFG_PREFIX}/${CFG_LIBDIR_RELATIVE}" "install libraries (do not set it on windows platform)"
|
|
+valopt libdir "${CFG_PREFIX}/${CFG_LIBDIR_RELATIVE}" "install libraries"
|
|
|
|
-case "$CFG_LIBDIR" in
|
|
- "$CFG_PREFIX"/*) CAT_INC=2;;
|
|
- "$CFG_PREFIX"*) CAT_INC=1;;
|
|
- *)
|
|
- err "libdir must begin with the prefix. Use --prefix to set it accordingly.";;
|
|
-esac
|
|
+CFG_BINDIR_RELATIVE=bin
|
|
+valopt bindir "${CFG_PREFIX}/${CFG_BINDIR_RELATIVE}" "install binaries"
|
|
|
|
-CFG_LIBDIR_RELATIVE=`echo ${CFG_LIBDIR} | cut -c$((${#CFG_PREFIX}+${CAT_INC}))-`
|
|
+# Determine libdir and bindir relative to prefix
|
|
+step_msg "calculating relative paths to prefix = ${CFG_PREFIX}"
|
|
+CFG_BINDIR_RELATIVE=$(relpath "${CFG_PREFIX}" "${CFG_BINDIR}")
|
|
+CFG_LIBDIR_RELATIVE=$(relpath "${CFG_PREFIX}" "${CFG_LIBDIR}")
|
|
|
|
if ( [ "$CFG_OSTYPE" = "pc-windows-gnu" ] || [ "$CFG_OSTYPE" = "pc-windows-msvc" ] ) \
|
|
- && [ "$CFG_LIBDIR_RELATIVE" != "bin" ]; then
|
|
- err "libdir on windows should be set to 'bin'"
|
|
+ && [ "$CFG_LIBDIR_RELATIVE" != "$CFG_BINDIR_RELATIVE" ]; then
|
|
+ err "Windows builds currently require that LIBDIR == BINDIR (we have libdir{$CFG_LIBDIR_RELATIVE} != bindir{$CFG_BINDIR_RELATIVE} )"
|
|
fi
|
|
|
|
if [ $HELP -eq 1 ]
|
|
@@ -1588,6 +1612,7 @@ putvar CFG_PREFIX
|
|
putvar CFG_HOST
|
|
putvar CFG_TARGET
|
|
putvar CFG_LIBDIR_RELATIVE
|
|
+putvar CFG_BINDIR_RELATIVE
|
|
putvar CFG_DISABLE_MANAGE_SUBMODULES
|
|
putvar CFG_ANDROID_CROSS_PATH
|
|
putvar CFG_MANDIR
|
|
diff --git a/mk/host.mk b/mk/host.mk
|
|
index 59a0095..b8e8345 100644
|
|
--- a/mk/host.mk
|
|
+++ b/mk/host.mk
|
|
@@ -59,9 +59,13 @@ endef
|
|
# $(4) - the host triple (same as $(3))
|
|
define CP_HOST_STAGE_N
|
|
|
|
-ifneq ($(CFG_LIBDIR_RELATIVE),bin)
|
|
$$(HLIB$(2)_H_$(4))/:
|
|
@mkdir -p $$@
|
|
+
|
|
+# Avoid redefinition warnings if libdir==bindir
|
|
+ifneq ($(HBIN$(2)_H_$(4)),$(HLIB$(2)_H_$(4)))
|
|
+$$(HBIN$(2)_H_$(4))/:
|
|
+ @mkdir -p $$@
|
|
endif
|
|
|
|
endef
|
|
diff --git a/mk/main.mk b/mk/main.mk
|
|
index 165afc3..33f9545 100644
|
|
--- a/mk/main.mk
|
|
+++ b/mk/main.mk
|
|
@@ -339,7 +339,9 @@ export CFG_RELEASE_CHANNEL
|
|
export CFG_LLVM_ROOT
|
|
export CFG_PREFIX
|
|
export CFG_LIBDIR
|
|
+export CFG_BINDIR
|
|
export CFG_LIBDIR_RELATIVE
|
|
+export CFG_BINDIR_RELATIVE
|
|
export CFG_DISABLE_INJECT_STD_VERSION
|
|
ifdef CFG_DISABLE_UNSTABLE_FEATURES
|
|
CFG_INFO := $(info cfg: disabling unstable features (CFG_DISABLE_UNSTABLE_FEATURES))
|
|
@@ -369,7 +371,16 @@ define SREQ
|
|
|
|
# Destinations of artifacts for the host compiler
|
|
HROOT$(1)_H_$(3) = $(3)/stage$(1)
|
|
+
|
|
+ifeq ($(1)-$(3),0-$$(CFG_BUILD))
|
|
+# stage0 relative paths are fixed so we can bootstrap from snapshots
|
|
+# (downloaded snapshots drop their rustc in HROOT/bin)
|
|
+# libdir discrepancy is worked around with RUSTFLAGS below.
|
|
HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
|
|
+else
|
|
+HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_BINDIR_RELATIVE)
|
|
+endif
|
|
+
|
|
HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR_RELATIVE)
|
|
|
|
# Destinations of artifacts for target architectures
|
|
diff --git a/mk/perf.mk b/mk/perf.mk
|
|
index 16cbaab..f8a354c 100644
|
|
--- a/mk/perf.mk
|
|
+++ b/mk/perf.mk
|
|
@@ -10,13 +10,13 @@
|
|
|
|
|
|
ifdef CFG_PERF_TOOL
|
|
-rustc-perf$(X): $(CFG_BUILD)/stage2/bin/rustc$(X_$(CFG_BUILD))
|
|
+rustc-perf$(X): $(CFG_BUILD)/stage2/$(CFG_BINDIR_RELATIVE)/rustc$(X_$(CFG_BUILD))
|
|
@$(call E, perf compile: $@)
|
|
$(PERF_STAGE2_T_$(CFG_BUILD)_H_$(CFG_BUILD)) \
|
|
-o $@ $(COMPILER_CRATE) >rustc-perf.err 2>&1
|
|
$(Q)rm -f $(LIBRUSTC_GLOB)
|
|
else
|
|
-rustc-perf$(X): $(CFG_BUILD)/stage2/bin/rustc$(X_$(CFG_BUILD))
|
|
+rustc-perf$(X): $(CFG_BUILD)/stage2/$(CFG_BINDIR_RELATIVE)/rustc$(X_$(CFG_BUILD))
|
|
$(Q)touch $@
|
|
endif
|
|
|
|
diff --git a/mk/prepare.mk b/mk/prepare.mk
|
|
index fe619cc..b8aa0cb 100644
|
|
--- a/mk/prepare.mk
|
|
+++ b/mk/prepare.mk
|
|
@@ -186,10 +186,10 @@ INSTALL_DEBUGGER_SCRIPT_COMMANDS=$(if $(findstring windows,$(1)),\
|
|
define DEF_PREPARE
|
|
|
|
prepare-base-$(1): PREPARE_SOURCE_DIR=$$(PREPARE_HOST)/stage$$(PREPARE_STAGE)
|
|
-prepare-base-$(1): PREPARE_SOURCE_BIN_DIR=$$(PREPARE_SOURCE_DIR)/bin
|
|
+prepare-base-$(1): PREPARE_SOURCE_BIN_DIR=$$(PREPARE_SOURCE_DIR)/$$(CFG_BINDIR_RELATIVE)
|
|
prepare-base-$(1): PREPARE_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_DIR)/$$(CFG_LIBDIR_RELATIVE)
|
|
prepare-base-$(1): PREPARE_SOURCE_MAN_DIR=$$(S)/man
|
|
-prepare-base-$(1): PREPARE_DEST_BIN_DIR=$$(PREPARE_DEST_DIR)/bin
|
|
+prepare-base-$(1): PREPARE_DEST_BIN_DIR=$$(PREPARE_DEST_DIR)/$$(CFG_BINDIR_RELATIVE)
|
|
prepare-base-$(1): PREPARE_DEST_LIB_DIR=$$(PREPARE_DEST_DIR)/$$(CFG_LIBDIR_RELATIVE)
|
|
prepare-base-$(1): PREPARE_DEST_MAN_DIR=$$(PREPARE_DEST_DIR)/share/man/man1
|
|
prepare-base-$(1): prepare-everything-$(1)
|
|
diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs
|
|
index 311ab1c..1b03b1a 100644
|
|
--- a/src/librustc/metadata/filesearch.rs
|
|
+++ b/src/librustc/metadata/filesearch.rs
|
|
@@ -68,8 +68,7 @@ impl<'a> FileSearch<'a> {
|
|
if !found {
|
|
let rustpath = rust_path();
|
|
for path in &rustpath {
|
|
- let tlib_path = make_rustpkg_lib_path(
|
|
- self.sysroot, path, self.triple);
|
|
+ let tlib_path = make_rustpkg_lib_path(path, self.triple);
|
|
debug!("is {} in visited_dirs? {}", tlib_path.display(),
|
|
visited_dirs.contains(&tlib_path));
|
|
|
|
@@ -96,7 +95,7 @@ impl<'a> FileSearch<'a> {
|
|
where F: FnMut(&Path, PathKind) -> FileMatch
|
|
{
|
|
self.for_each_lib_search_path(|lib_search_path, kind| {
|
|
- debug!("searching {}", lib_search_path.display());
|
|
+ info!("searching {}", lib_search_path.display());
|
|
match fs::read_dir(lib_search_path) {
|
|
Ok(files) => {
|
|
let files = files.filter_map(|p| p.ok().map(|s| s.path()))
|
|
@@ -157,7 +156,7 @@ impl<'a> FileSearch<'a> {
|
|
// Returns a list of directories where target-specific tool binaries are located.
|
|
pub fn get_tools_search_paths(&self) -> Vec<PathBuf> {
|
|
let mut p = PathBuf::from(self.sysroot);
|
|
- p.push(&find_libdir(self.sysroot));
|
|
+ p.push(libdir_str());
|
|
p.push(&rustlibdir());
|
|
p.push(&self.triple);
|
|
p.push("bin");
|
|
@@ -165,8 +164,8 @@ impl<'a> FileSearch<'a> {
|
|
}
|
|
}
|
|
|
|
-pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf {
|
|
- let mut p = PathBuf::from(&find_libdir(sysroot));
|
|
+pub fn relative_target_lib_path(target_triple: &str) -> PathBuf {
|
|
+ let mut p = PathBuf::from(&libdir_str());
|
|
assert!(p.is_relative());
|
|
p.push(&rustlibdir());
|
|
p.push(target_triple);
|
|
@@ -176,17 +175,28 @@ pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf
|
|
|
|
fn make_target_lib_path(sysroot: &Path,
|
|
target_triple: &str) -> PathBuf {
|
|
- sysroot.join(&relative_target_lib_path(sysroot, target_triple))
|
|
+ sysroot.join(&relative_target_lib_path(target_triple))
|
|
}
|
|
|
|
-fn make_rustpkg_lib_path(sysroot: &Path,
|
|
- dir: &Path,
|
|
+fn make_rustpkg_lib_path(dir: &Path,
|
|
triple: &str) -> PathBuf {
|
|
- let mut p = dir.join(&find_libdir(sysroot));
|
|
+ let mut p = dir.join(libdir_str());
|
|
p.push(triple);
|
|
p
|
|
}
|
|
|
|
+pub fn bindir_relative_str() -> &'static str {
|
|
+ env!("CFG_BINDIR_RELATIVE")
|
|
+}
|
|
+
|
|
+pub fn bindir_relative_path() -> PathBuf {
|
|
+ PathBuf::from(bindir_relative_str())
|
|
+}
|
|
+
|
|
+pub fn libdir_str() -> &'static str {
|
|
+ env!("CFG_LIBDIR_RELATIVE")
|
|
+}
|
|
+
|
|
pub fn get_or_default_sysroot() -> PathBuf {
|
|
// Follow symlinks. If the resolved path is relative, make it absolute.
|
|
fn canonicalize(path: Option<PathBuf>) -> Option<PathBuf> {
|
|
@@ -202,7 +212,18 @@ pub fn get_or_default_sysroot() -> PathBuf {
|
|
}
|
|
|
|
match canonicalize(env::current_exe().ok()) {
|
|
- Some(mut p) => { p.pop(); p.pop(); p }
|
|
+ Some(mut p) => {
|
|
+ // Remove the exe name
|
|
+ p.pop();
|
|
+ let mut rel = bindir_relative_path();
|
|
+
|
|
+ // Remove a number of elements equal to the number of elements in the bindir relative
|
|
+ // path
|
|
+ while rel.pop() {
|
|
+ p.pop();
|
|
+ }
|
|
+ p
|
|
+ }
|
|
None => panic!("can't determine value for sysroot")
|
|
}
|
|
}
|
|
@@ -257,47 +278,6 @@ pub fn rust_path() -> Vec<PathBuf> {
|
|
env_rust_path
|
|
}
|
|
|
|
-// The name of the directory rustc expects libraries to be located.
|
|
-// On Unix should be "lib", on windows "bin"
|
|
-#[cfg(unix)]
|
|
-fn find_libdir(sysroot: &Path) -> String {
|
|
- // FIXME: This is a quick hack to make the rustc binary able to locate
|
|
- // Rust libraries in Linux environments where libraries might be installed
|
|
- // to lib64/lib32. This would be more foolproof by basing the sysroot off
|
|
- // of the directory where librustc is located, rather than where the rustc
|
|
- // binary is.
|
|
- //If --libdir is set during configuration to the value other than
|
|
- // "lib" (i.e. non-default), this value is used (see issue #16552).
|
|
-
|
|
- match option_env!("CFG_LIBDIR_RELATIVE") {
|
|
- Some(libdir) if libdir != "lib" => return libdir.to_string(),
|
|
- _ => if sysroot.join(&primary_libdir_name()).join(&rustlibdir()).exists() {
|
|
- return primary_libdir_name();
|
|
- } else {
|
|
- return secondary_libdir_name();
|
|
- }
|
|
- }
|
|
-
|
|
- #[cfg(target_pointer_width = "64")]
|
|
- fn primary_libdir_name() -> String {
|
|
- "lib64".to_string()
|
|
- }
|
|
-
|
|
- #[cfg(target_pointer_width = "32")]
|
|
- fn primary_libdir_name() -> String {
|
|
- "lib32".to_string()
|
|
- }
|
|
-
|
|
- fn secondary_libdir_name() -> String {
|
|
- "lib".to_string()
|
|
- }
|
|
-}
|
|
-
|
|
-#[cfg(windows)]
|
|
-fn find_libdir(_sysroot: &Path) -> String {
|
|
- "bin".to_string()
|
|
-}
|
|
-
|
|
// The name of rustc's own place to organize libraries.
|
|
// Used to be "rustc", now the default is "rustlib"
|
|
pub fn rustlibdir() -> String {
|
|
diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs
|
|
index 6b8b59d..6e03f3c 100644
|
|
--- a/src/librustc_trans/back/link.rs
|
|
+++ b/src/librustc_trans/back/link.rs
|
|
@@ -997,11 +997,10 @@ fn link_args(cmd: &mut Linker,
|
|
// where extern libraries might live, based on the
|
|
// addl_lib_search_paths
|
|
if sess.opts.cg.rpath {
|
|
- let sysroot = sess.sysroot();
|
|
let target_triple = &sess.opts.target_triple;
|
|
let mut get_install_prefix_lib_path = || {
|
|
let install_prefix = option_env!("CFG_PREFIX").expect("CFG_PREFIX");
|
|
- let tlib = filesearch::relative_target_lib_path(sysroot, target_triple);
|
|
+ let tlib = filesearch::relative_target_lib_path(target_triple);
|
|
let mut path = PathBuf::from(install_prefix);
|
|
path.push(&tlib);
|
|
|
|
--
|
|
2.4.3
|
|
|