diff --git a/Makefile.in b/Makefile.in index 04ff606d0b939..660aeae621713 100644 --- a/Makefile.in +++ b/Makefile.in @@ -232,19 +232,20 @@ ifneq ($(strip $(findstring prepare,$(MAKECMDGOALS)) \ include $(CFG_SRC_DIR)mk/prepare.mk endif -# (Unix) Installation from the build directory -ifneq ($(findstring install,$(MAKECMDGOALS)),) - CFG_INFO := $(info cfg: including install rules) - include $(CFG_SRC_DIR)mk/install.mk -endif - # Source and binary distribution artifacts ifneq ($(strip $(findstring dist,$(MAKECMDGOALS)) \ + $(findstring install,$(MAKECMDGOALS)) \ $(findstring clean,$(MAKECMDGOALS))),) CFG_INFO := $(info cfg: including dist rules) include $(CFG_SRC_DIR)mk/dist.mk endif +# (Unix) Installation from the build directory +ifneq ($(findstring install,$(MAKECMDGOALS)),) + CFG_INFO := $(info cfg: including install rules) + include $(CFG_SRC_DIR)mk/install.mk +endif + # Cleaning ifneq ($(findstring clean,$(MAKECMDGOALS)),) CFG_INFO := $(info cfg: including clean rules) diff --git a/configure b/configure index 45b4405132f69..b2b861a019aa6 100755 --- a/configure +++ b/configure @@ -383,6 +383,7 @@ opt local-rust 0 "use an installed rustc rather than downloading a snapshot" opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-patched kernels)" opt inject-std-version 1 "inject the current compiler version of libstd into programs" opt rpath 1 "build rpaths into rustc itself" +opt nightly 0 "build nightly packages" valopt prefix "/usr/local" "set installation prefix" valopt local-rust-root "/usr/local" "set prefix for local rust binary" valopt llvm-root "" "set LLVM root" @@ -401,7 +402,8 @@ valopt infodir "${CFG_PREFIX}/share/info" "install additional info" valopt mandir "${CFG_PREFIX}/share/man" "install man pages in PATH" # On windows we just store the libraries in the bin directory because -# there's no rpath +# there's no rpath. This is where the build system itself puts libraries; +# --libdir is used to configure the installation directory. # FIXME: Thise needs to parameterized over target triples. Do it in platform.mk CFG_LIBDIR_RELATIVE=lib if [ "$CFG_OSTYPE" = "pc-mingw32" ] @@ -410,7 +412,6 @@ then fi valopt libdir "${CFG_PREFIX}/${CFG_LIBDIR_RELATIVE}" "install libraries" -valopt rustlibdir "rustlib" "subdirectory name for rustc's libraries" if [ $HELP -eq 1 ] then @@ -777,10 +778,10 @@ do make_dir $h/stage$i/test # target bin dir - make_dir $h/stage$i/$CFG_LIBDIR_RELATIVE/$CFG_RUSTLIBDIR/$t/bin + make_dir $h/stage$i/$CFG_LIBDIR_RELATIVE/rustlib/$t/bin # target lib dir - make_dir $h/stage$i/$CFG_LIBDIR_RELATIVE/$CFG_RUSTLIBDIR/$t/lib + make_dir $h/stage$i/$CFG_LIBDIR_RELATIVE/rustlib/$t/lib done done @@ -1039,7 +1040,6 @@ putvar CFG_HOST putvar CFG_TARGET putvar CFG_C_COMPILER putvar CFG_LIBDIR -putvar CFG_RUSTLIBDIR putvar CFG_LIBDIR_RELATIVE putvar CFG_DISABLE_MANAGE_SUBMODULES putvar CFG_ANDROID_CROSS_PATH diff --git a/mk/dist.mk b/mk/dist.mk index 4990ae12f5e97..cd6aedc6e8992 100644 --- a/mk/dist.mk +++ b/mk/dist.mk @@ -22,7 +22,7 @@ # * dist-tar-bins - Ad-hoc Unix binary installers # * dist-docs - Stage docs for upload -PKG_NAME = $(CFG_PACKAGE_NAME) +PKG_NAME := $(CFG_PACKAGE_NAME) # License suitable for displaying in a popup LICENSE.txt: $(S)COPYRIGHT $(S)LICENSE-APACHE $(S)LICENSE-MIT @@ -199,8 +199,10 @@ dist-install-dir-$(1): PREPARE_LIB_CMD=$(DEFAULT_PREPARE_LIB_CMD) dist-install-dir-$(1): PREPARE_MAN_CMD=$(DEFAULT_PREPARE_MAN_CMD) dist-install-dir-$(1): PREPARE_CLEAN=true dist-install-dir-$(1): prepare-base-dir-$(1) - $$(Q)(cd $$(PREPARE_DEST_DIR)/ && find -type f) \ - > $$(PREPARE_DEST_DIR)/$$(CFG_LIBDIR_RELATIVE)/$$(CFG_RUSTLIBDIR)/manifest + $$(Q)(cd $$(PREPARE_DEST_DIR)/ && find . -type f | sed 's/^\.\///') \ + > tmp/dist/manifest-$(1).in + $$(Q)mv tmp/dist/manifest-$(1).in $$(PREPARE_DEST_DIR)/$$(CFG_LIBDIR_RELATIVE)/rustlib/manifest.in +# Add remaining non-installed files $$(Q)$$(PREPARE_MAN_CMD) $$(S)COPYRIGHT $$(PREPARE_DEST_DIR) $$(Q)$$(PREPARE_MAN_CMD) $$(S)LICENSE-APACHE $$(PREPARE_DEST_DIR) $$(Q)$$(PREPARE_MAN_CMD) $$(S)LICENSE-MIT $$(PREPARE_DEST_DIR) diff --git a/mk/install.mk b/mk/install.mk index 57f4db269542f..e360afe291b7c 100644 --- a/mk/install.mk +++ b/mk/install.mk @@ -8,70 +8,19 @@ # option. This file may not be copied, modified, or distributed # except according to those terms. -# FIXME: Docs are currently not installed from the stageN dirs. -# For consistency it might be desirable for stageN to be an exact -# mirror of the installation directory structure. -# The stage we install from -ISTAGE = $(PREPARE_STAGE) +install: dist-install-dir-$(CFG_BUILD) + $(Q)sh tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --prefix="$(CFG_PREFIX)" --libdir="$(CFG_LIBDIR)" --mandir="$(CFG_MANDIR)" +# Remove tmp files while we can because they may have been created under sudo + $(Q)rm -R tmp/dist/$(PKG_NAME)-$(CFG_BUILD/ -$(eval $(call DEF_PREPARE,mkfile-install)) +uninstall: dist-install-dir-$(CFG_BUILD) + $(Q)sh tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --uninstall --prefix="$(CFG_PREFIX)" --libdir="$(CFG_LIBDIR)" --mandir="$(CFG_MANDIR)" -install: PREPARE_HOST=$(CFG_BUILD) -install: PREPARE_TARGETS=$(CFG_TARGET) -install: PREPARE_DIR_CMD=$(DEFAULT_PREPARE_DIR_CMD) -install: PREPARE_BIN_CMD=$(DEFAULT_PREPARE_BIN_CMD) -install: PREPARE_LIB_CMD=$(DEFAULT_PREPARE_LIB_CMD) -install: PREPARE_MAN_CMD=$(DEFAULT_PREPARE_MAN_CMD) -install: PREPARE_SOURCE_DIR=$(PREPARE_HOST)/stage$(PREPARE_STAGE) -install: PREPARE_SOURCE_BIN_DIR=$(PREPARE_SOURCE_DIR)/bin -install: PREPARE_SOURCE_LIB_DIR=$(PREPARE_SOURCE_DIR)/$(CFG_LIBDIR_RELATIVE) -install: PREPARE_SOURCE_MAN_DIR=$(S)/man -install: PREPARE_DEST_BIN_DIR=$(DESTDIR)$(CFG_PREFIX)/bin -install: PREPARE_DEST_LIB_DIR=$(DESTDIR)$(CFG_LIBDIR) -install: PREPARE_DEST_MAN_DIR=$(DESTDIR)$(CFG_MANDIR)/man1 -install: prepare-everything-mkfile-install - - -# Uninstall code - -PREFIX_ROOT = $(CFG_PREFIX) -PREFIX_BIN = $(PREFIX_ROOT)/bin -PREFIX_LIB = $(CFG_LIBDIR) - -INSTALL_TOOLS := $(PREPARE_TOOLS) - -# Shorthand for build/stageN/bin -HB = $(HBIN$(ISTAGE)_H_$(CFG_BUILD)) -HB2 = $(HBIN2_H_$(CFG_BUILD)) -# Shorthand for build/stageN/lib -HL = $(HLIB$(ISTAGE)_H_$(CFG_BUILD)) -# Shorthand for the prefix bin directory -PHB = $(PREFIX_BIN) -# Shorthand for the prefix bin directory -PHL = $(PREFIX_LIB) - -HOST_LIB_FROM_HL_GLOB = \ - $(patsubst $(HL)/%,$(PHL)/%,$(wildcard $(HL)/$(1))) - -uninstall: $(foreach tool,$(INSTALL_TOOLS),uninstall-tool-$(tool)) - $(Q)rm -Rf $(PHL)/$(CFG_RUSTLIBDIR) - -define UNINSTALL_TOOL -uninstall-tool-$(1): $$(foreach dep,$$(TOOL_DEPS_$(1)),uninstall-lib-$$(dep)) - $$(Q)rm -f $$(PHB)/$(1)$$(X_$$(CFG_BUILD)) - $$(Q)rm -f $$(CFG_MANDIR)/man1/$(1).1 -endef - -$(foreach tool,$(INSTALL_TOOLS),$(eval $(call UNINSTALL_TOOL,$(tool)))) - -define UNINSTALL_LIB -uninstall-lib-$(1): $$(foreach dep,$$(RUST_DEPS_$(1)),uninstall-lib-$$(dep)) - $$(Q)rm -f $$(call HOST_LIB_FROM_HL_GLOB,$$(call CFG_LIB_GLOB_$$(CFG_BUILD),$(1))) -endef - -$(foreach lib,$(CRATES),$(eval $(call UNINSTALL_LIB,$(lib)))) +###################################################################### +# Android remote installation +###################################################################### # Android runtime setup # FIXME: This probably belongs somewhere else diff --git a/mk/main.mk b/mk/main.mk index ccbdf30a1ffe4..f59a553d783ba 100644 --- a/mk/main.mk +++ b/mk/main.mk @@ -16,7 +16,7 @@ CFG_RELEASE_NUM=0.10 CFG_RELEASE_LABEL=-pre -ifndef CFG_NIGHTLY +ifndef CFG_ENABLE_NIGHTLY # This is the normal version string CFG_RELEASE=$(CFG_RELEASE_NUM)$(CFG_RELEASE_LABEL) CFG_PACKAGE_VERS=$(CFG_RELEASE) @@ -281,7 +281,6 @@ export CFG_LLVM_ROOT export CFG_ENABLE_MINGW_CROSS export CFG_PREFIX export CFG_LIBDIR -export CFG_RUSTLIBDIR export CFG_LIBDIR_RELATIVE export CFG_DISABLE_INJECT_STD_VERSION @@ -302,7 +301,7 @@ HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR_RELATIVE) # Destinations of artifacts for target architectures -TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/$$(CFG_RUSTLIBDIR)/$(2) +TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustlib/$(2) TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/lib diff --git a/mk/prepare.mk b/mk/prepare.mk index bf626b2101e41..d850aba27cd33 100644 --- a/mk/prepare.mk +++ b/mk/prepare.mk @@ -86,6 +86,7 @@ PREPARE_TOOLS = $(filter-out compiletest, $(TOOLS)) define DEF_PREPARE_HOST_TOOL prepare-host-tool-$(1)-$(2)-$(3)-$(4): prepare-maybe-clean-$(4) \ $$(foreach dep,$$(TOOL_DEPS_$(1)),prepare-host-lib-$$(dep)-$(2)-$(3)-$(4)) \ + $$(HBIN$(2)_H_$(3))/$(1)$$(X_$(3)) \ prepare-host-dirs-$(4) $$(if $$(findstring $(2), $$(PREPARE_STAGE)),\ $$(if $$(findstring $(3), $$(PREPARE_HOST)),\ @@ -121,8 +122,8 @@ endef # $(4) tag define DEF_PREPARE_TARGET_N # Rebind PREPARE_*_LIB_DIR to point to rustlib, then install the libs for the targets -prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_WORKING_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_LIB_DIR)/$$(CFG_RUSTLIBDIR)/$(2)/lib -prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)/$$(CFG_RUSTLIBDIR)/$(2)/lib +prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_WORKING_SOURCE_LIB_DIR=$$(PREPARE_SOURCE_LIB_DIR)/rustlib/$(2)/lib +prepare-target-$(2)-host-$(3)-$(1)-$(4): PREPARE_WORKING_DEST_LIB_DIR=$$(PREPARE_DEST_LIB_DIR)/rustlib/$(2)/lib prepare-target-$(2)-host-$(3)-$(1)-$(4): prepare-maybe-clean-$(4) \ $$(foreach crate,$$(TARGET_CRATES), \ $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)) \ diff --git a/mk/stage0.mk b/mk/stage0.mk index 5582e50b7c42f..080e733724d46 100644 --- a/mk/stage0.mk +++ b/mk/stage0.mk @@ -15,7 +15,7 @@ $(SNAPSHOT_RUSTC_POST_CLEANUP): \ # Note: the variable "SNAPSHOT_FILE" is generally not set, and so # we generally only pass one argument to this script. ifdef CFG_ENABLE_LOCAL_RUST - $(Q)$(S)src/etc/local_stage0.sh $(CFG_BUILD) $(CFG_LOCAL_RUST_ROOT) $(CFG_RUSTLIBDIR) + $(Q)$(S)src/etc/local_stage0.sh $(CFG_BUILD) $(CFG_LOCAL_RUST_ROOT) rustlib else $(Q)$(CFG_PYTHON) $(S)src/etc/get-snapshot.py $(CFG_BUILD) $(SNAPSHOT_FILE) ifdef CFG_ENABLE_PAX_FLAGS diff --git a/mk/target.mk b/mk/target.mk index 03569cb8b67c8..11c57ac070f39 100644 --- a/mk/target.mk +++ b/mk/target.mk @@ -11,7 +11,7 @@ # This is the compile-time target-triple for the compiler. For the compiler at # runtime, this should be considered the host-triple. More explanation for why # this exists can be found on issue #2400 -export CFG_COMPILER +export CFG_COMPILER_HOST_TRIPLE # The standard libraries should be held up to a higher standard than any old # code, make sure that these common warnings are denied by default. These can @@ -68,7 +68,7 @@ $(foreach host,$(CFG_HOST), \ # $(4) is the crate name define RUST_TARGET_STAGE_N -$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): CFG_COMPILER = $(2) +$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): CFG_COMPILER_HOST_TRIPLE = $(2) $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \ $$(CRATEFILE_$(4)) \ $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4)) \ diff --git a/mk/tests.mk b/mk/tests.mk index 22d686b1b0e24..7fd6d148f3863 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -104,7 +104,7 @@ ifdef CFG_WINDOWSY_$(1) stage2/$$(CFG_LIBDIR_RELATIVE), \ $$(if $$(findstring stage3,$$(1)), \ stage3/$$(CFG_LIBDIR_RELATIVE), \ - )))))/$$(CFG_RUSTLIBDIR)/$$(CFG_BUILD)/lib + )))))/rustlib/$$(CFG_BUILD)/lib CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),$$(call CFG_TESTLIB_$(1),$$(1),$$(3)),$$(1)) endif @@ -350,7 +350,7 @@ else TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4)) endif -$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): CFG_COMPILER = $(2) +$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): CFG_COMPILER_HOST_TRIPLE = $(2) $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): \ $$(CRATEFILE_$(4)) \ $$(TESTDEP_$(1)_$(2)_$(3)_$(4)) diff --git a/src/etc/install.sh b/src/etc/install.sh index 8dfc1903094e7..3a1ba91d01f23 100644 --- a/src/etc/install.sh +++ b/src/etc/install.sh @@ -213,6 +213,10 @@ VAL_OPTIONS="" flag uninstall "only uninstall from the installation prefix" valopt prefix "/usr/local" "set installation prefix" +# NB This isn't quite the same definition as in `configure`. +# just using 'lib' instead of CFG_LIBDIR_RELATIVE +valopt libdir "${CFG_PREFIX}/lib" "install libraries" +valopt mandir "${CFG_PREFIX}/share/man" "install man pages in PATH" if [ $HELP -eq 1 ] then @@ -223,49 +227,63 @@ fi step_msg "validating $CFG_SELF args" validate_opt + +# OK, let's get installing ... + # Sanity check: can we can write to the destination? -umask 022 && mkdir -p "${CFG_PREFIX}/lib" -need_ok "directory creation failed" -touch "${CFG_PREFIX}/lib/rust-install-probe" 2> /dev/null +umask 022 && mkdir -p "${CFG_LIBDIR}" +need_ok "can't write to destination. consider 'sudo'." +touch "${CFG_LIBDIR}/rust-install-probe" 2> /dev/null if [ $? -ne 0 ] then - err "can't write to destination. try again with 'sudo'." + err "can't write to destination. consider 'sudo'." fi -rm "${CFG_PREFIX}/lib/rust-install-probe" +rm "${CFG_LIBDIR}/rust-install-probe" need_ok "failed to remove install probe" +# Sanity check: don't install to the directory containing the installer. +# That would surely cause chaos. +INSTALLER_DIR="$(cd $(dirname $0) && pwd)" +PREFIX_DIR="$(cd ${CFG_PREFIX} && pwd)" +if [ "${INSTALLER_DIR}" = "${PREFIX_DIR}" ] +then + err "can't install to same directory as installer" +fi + +# The file name of the manifest we're going to create during install +INSTALLED_MANIFEST="${CFG_LIBDIR}/rustlib/manifest" # First, uninstall from the installation prefix. # Errors are warnings - try to rm everything in the manifest even if some fail. -# FIXME: Hardcoded 'rustlib' ignores CFG_RUSTLIBDIR -if [ -f "${CFG_PREFIX}/lib/rustlib/manifest" ] +if [ -f "${INSTALLED_MANIFEST}" ] then # Iterate through installed manifest and remove files while read p; do - msg "removing ${CFG_PREFIX}/$p" - if [ -f "${CFG_PREFIX}/$p" ] + # The installed manifest contains absolute paths + msg "removing $p" + if [ -f "$p" ] then - rm "${CFG_PREFIX}/$p" + rm "$p" if [ $? -ne 0 ] then - warn "failed to remove ${CFG_PREFIX}/$p" + warn "failed to remove $p" fi else - warn "supposedly installed file ${CFG_PREFIX}/$p does not exist!" + warn "supposedly installed file $p does not exist!" fi - done < "${CFG_PREFIX}/lib/rustlib/manifest" + done < "${INSTALLED_MANIFEST}" # Remove 'rustlib' directory - msg "removing ${CFG_PREFIX}/lib/rustlib" - rm -r "${CFG_PREFIX}/lib/rustlib" + rm -r "${CFG_LIBDIR}/rustlib" if [ $? -ne 0 ] then warn "failed to remove rustlib" fi else + # There's no manifest. If we were asked to uninstall, then that's a problem. if [ -n "${CFG_UNINSTALL}" ] then - err "unable to find installation manifest at ${CFG_PREFIX}/lib/rustlib" + err "unable to find installation manifest at ${CFG_LIBDIR}/rustlib" fi fi @@ -278,24 +296,55 @@ then exit 0 fi +# Create the installed manifest, which we will fill in with absolute file paths +mkdir -p "${CFG_LIBDIR}/rustlib" +touch "${INSTALLED_MANIFEST}" # Now install, iterate through the new manifest and copy files while read p; do - umask 022 && mkdir -p "${CFG_PREFIX}/$(dirname $p)" + # Decide the destination of the file + FILE_INSTALL_PATH="${CFG_PREFIX}/$p" + + if echo "$p" | grep "^lib/" > /dev/null + then + pp=`echo $p | sed 's/^lib\///'` + FILE_INSTALL_PATH="${CFG_LIBDIR}/$pp" + fi + + if echo "$p" | grep "^share/man/" > /dev/null + then + pp=`echo $p | sed 's/^share\/man\///'` + FILE_INSTALL_PATH="${CFG_MANDIR}/$pp" + fi + + # Make sure there's a directory for it + umask 022 && mkdir -p "$(dirname ${FILE_INSTALL_PATH})" need_ok "directory creation failed" - msg "${CFG_PREFIX}/$p" - if echo "$p" | grep "/bin/" > /dev/null + # Make the path absolute so we can uninstall it later without + # starting from the installation cwd + FILE_INSTALL_PATH_DIRNAME="$(dirname ${FILE_INSTALL_PATH})" + FILE_INSTALL_PATH_BASENAME="$(basename ${FILE_INSTALL_PATH})" + FILE_INSTALL_ABS_PATH="$(cd ${FILE_INSTALL_PATH_DIRNAME} && pwd)" + FILE_INSTALL_PATH="${FILE_INSTALL_ABS_PATH}/${FILE_INSTALL_PATH_BASENAME}" + + # Install the file + msg "${FILE_INSTALL_PATH}" + if echo "$p" | grep "^bin/" > /dev/null then - install -m755 "${CFG_SRC_DIR}/$p" "${CFG_PREFIX}/$p" + install -m755 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}" else - install -m644 "${CFG_SRC_DIR}/$p" "${CFG_PREFIX}/$p" + install -m644 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}" fi need_ok "file creation failed" + # Update the manifest + echo "${FILE_INSTALL_PATH}" >> "${INSTALLED_MANIFEST}" + need_ok "failed to update manifest" + # The manifest lists all files to install -done < "${CFG_SRC_DIR}/lib/rustlib/manifest" +done < "${CFG_SRC_DIR}/lib/rustlib/manifest.in" echo echo " Rust is ready to roll." diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index 08e96ec9215ed..c47f9893cd2ef 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -54,8 +54,9 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> { } fn get_sysroot_absolute_rt_lib(sess: &Session) -> Path { - let r = filesearch::relative_target_lib_path(sess.opts.target_triple); - let mut p = sess.filesearch().sysroot.join(&r); + let sysroot = sess.filesearch().sysroot; + let r = filesearch::relative_target_lib_path(sysroot, sess.opts.target_triple); + let mut p = sysroot.join(&r); p.push(os::dll_filename("rustrt")); p } @@ -91,7 +92,7 @@ fn get_rpaths(os: abi::Os, let abs_rpaths = get_absolute_rpaths(libs); // And a final backup rpath to the global library location. - let fallback_rpaths = vec!(get_install_prefix_rpath(target_triple)); + let fallback_rpaths = vec!(get_install_prefix_rpath(sysroot, target_triple)); fn log_rpaths(desc: &str, rpaths: &[~str]) { debug!("{} rpaths:", desc); @@ -156,10 +157,10 @@ pub fn get_absolute_rpath(lib: &Path) -> ~str { p.as_str().expect("non-utf8 component in rpath").to_owned() } -pub fn get_install_prefix_rpath(target_triple: &str) -> ~str { +pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &str) -> ~str { let install_prefix = env!("CFG_PREFIX"); - let tlib = filesearch::relative_target_lib_path(target_triple); + let tlib = filesearch::relative_target_lib_path(sysroot, target_triple); let mut path = Path::new(install_prefix); path.push(&tlib); let path = os::make_absolute(&path); @@ -195,7 +196,8 @@ mod test { #[test] fn test_prefix_rpath() { - let res = get_install_prefix_rpath("triple"); + let sysroot = filesearch::get_or_default_sysroot(); + let res = get_install_prefix_rpath(&sysroot, "triple"); let mut d = Path::new(env!("CFG_PREFIX")); d.push("lib"); d.push(filesearch::rustlibdir()); @@ -208,7 +210,8 @@ mod test { #[test] fn test_prefix_rpath_abs() { - let res = get_install_prefix_rpath("triple"); + let sysroot = filesearch::get_or_default_sysroot(); + let res = get_install_prefix_rpath(&sysroot, "triple"); assert!(Path::new(res).is_absolute()); } diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index fb0de95948988..9ee0bb4a107cd 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -800,7 +800,7 @@ pub fn host_triple() -> ~str { // Instead of grabbing the host triple (for the current host), we grab (at // compile time) the target triple that this rustc is built with and // calling that (at runtime) the host triple. - (env!("CFG_COMPILER")).to_owned() + (env!("CFG_COMPILER_HOST_TRIPLE")).to_owned() } pub fn build_session_options(matches: &getopts::Matches) -> session::Options { diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index fa794c883450a..7aed0e5b7f409 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -60,7 +60,8 @@ impl<'a> FileSearch<'a> { if !found { let rustpath = rust_path(); for path in rustpath.iter() { - let tlib_path = make_rustpkg_target_lib_path(path, self.target_triple); + let tlib_path = make_rustpkg_target_lib_path( + self.sysroot, path, self.target_triple); debug!("is {} in visited_dirs? {:?}", tlib_path.display(), visited_dirs.contains_equiv(&tlib_path.as_vec().to_owned())); @@ -136,8 +137,8 @@ impl<'a> FileSearch<'a> { } } -pub fn relative_target_lib_path(target_triple: &str) -> Path { - let mut p = Path::new(libdir()); +pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> Path { + let mut p = Path::new(find_libdir(sysroot)); assert!(p.is_relative()); p.push(rustlibdir()); p.push(target_triple); @@ -147,12 +148,13 @@ pub fn relative_target_lib_path(target_triple: &str) -> Path { fn make_target_lib_path(sysroot: &Path, target_triple: &str) -> Path { - sysroot.join(&relative_target_lib_path(target_triple)) + sysroot.join(&relative_target_lib_path(sysroot, target_triple)) } -fn make_rustpkg_target_lib_path(dir: &Path, - target_triple: &str) -> Path { - let mut p = dir.join(libdir()); +fn make_rustpkg_target_lib_path(sysroot: &Path, + dir: &Path, + target_triple: &str) -> Path { + let mut p = dir.join(find_libdir(sysroot)); p.push(target_triple); p } @@ -235,12 +237,36 @@ pub fn rust_path() -> Vec { // The name of the directory rustc expects libraries to be located. // On Unix should be "lib", on windows "bin" -pub fn libdir() -> ~str { - (env!("CFG_LIBDIR_RELATIVE")).to_owned() +#[cfg(unix)] +fn find_libdir(sysroot: &Path) -> ~str { + // 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 sysroot.join(primary_libdir_name()).join(rustlibdir()).exists() { + return primary_libdir_name(); + } else { + return secondary_libdir_name(); + } + + #[cfg(target_word_size = "64")] + fn primary_libdir_name() -> ~str { ~"lib64" } + + #[cfg(target_word_size = "32")] + fn primary_libdir_name() -> ~str { ~"lib32" } + + fn secondary_libdir_name() -> ~str { ~"lib" } +} + +#[cfg(windows)] +fn find_libdir(_sysroot: &Path) -> ~str { + ~"bin" } // The name of rustc's own place to organize libraries. // Used to be "rustc", now the default is "rustlib" pub fn rustlibdir() -> ~str { - (env!("CFG_RUSTLIBDIR")).to_owned() + ~"rustlib" }