diff --git a/Makefile.in b/Makefile.in index aab1e2ff556ae..3380356ee3c50 100644 --- a/Makefile.in +++ b/Makefile.in @@ -124,6 +124,12 @@ endif ifdef TRACE CFG_RUSTC_FLAGS += -Z trace endif +ifdef DISABLE_RPATH +# NOTE: make this CFG_RUSTC_FLAGS after stage0 snapshot +RUSTFLAGS_STAGE1 += --no-rpath +RUSTFLAGS_STAGE2 += --no-rpath +RUSTFLAGS_STAGE3 += --no-rpath +endif # The executables crated during this compilation process have no need to include # static copies of libstd and libextra. We also generate dynamic versions of all @@ -541,8 +547,21 @@ CFGFLAG$(1)_T_$(2)_H_$(3) = stage1 endif endif +ifdef CFG_DISABLE_RPATH +ifeq ($$(OSTYPE_$(3)),apple-darwin) + RPATH_VAR$(1)_T_$(2)_H_$(3) := \ + DYLD_LIBRARY_PATH="$$$$DYLD_LIBRARY_PATH:$$(HLIB$(1)_H_$(3))" +else + RPATH_VAR$(1)_T_$(2)_H_$(3) := \ + LD_LIBRARY_PATH="$$$$LD_LIBRARY_PATH:$$(HLIB$(1)_H_$(3))" +endif +else + RPATH_VAR$(1)_T_$(2)_H_$(3) := +endif + STAGE$(1)_T_$(2)_H_$(3) := \ - $$(Q)$$(call CFG_RUN_TARG_$(3),$(1), \ + $$(Q)$$(RPATH_VAR$(1)_T_$(2)_H_$(3)) \ + $$(call CFG_RUN_TARG_$(3),$(1), \ $$(CFG_VALGRIND_COMPILE$(1)) \ $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \ --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3)) \ diff --git a/configure b/configure index f758d75fe7600..8a9daabaf6177 100755 --- a/configure +++ b/configure @@ -382,6 +382,7 @@ opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds" 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" 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" diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 63c4d9f4a2976..a57f1296969f1 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -1089,8 +1089,10 @@ fn link_args(sess: Session, args.push(~"-dynamiclib"); args.push(~"-Wl,-dylib"); // FIXME (#9639): This needs to handle non-utf8 paths - args.push(~"-Wl,-install_name,@rpath/" + - out_filename.filename_str().unwrap()); + if !sess.opts.no_rpath { + args.push(~"-Wl,-install_name,@rpath/" + + out_filename.filename_str().unwrap()); + } } else { args.push(~"-shared") } @@ -1108,7 +1110,9 @@ fn link_args(sess: Session, // FIXME (#2397): At some point we want to rpath our guesses as to // where extern libraries might live, based on the // addl_lib_search_paths - args.push_all(rpath::get_rpath_flags(sess, out_filename)); + if !sess.opts.no_rpath { + args.push_all(rpath::get_rpath_flags(sess, out_filename)); + } // Finally add all the linker arguments provided on the command line along // with any #[link_args] attributes found inside the crate diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 301a49d8aec66..a2a0660d57510 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -734,6 +734,7 @@ pub fn build_session_options(binary: ~str, let parse_only = matches.opt_present("parse-only"); let no_trans = matches.opt_present("no-trans"); let no_analysis = matches.opt_present("no-analysis"); + let no_rpath = matches.opt_present("no-rpath"); let lint_levels = [lint::allow, lint::warn, lint::deny, lint::forbid]; @@ -888,6 +889,7 @@ pub fn build_session_options(binary: ~str, parse_only: parse_only, no_trans: no_trans, no_analysis: no_analysis, + no_rpath: no_rpath, debugging_opts: debugging_opts, android_cross_path: android_cross_path, write_dependency_info: write_dependency_info, @@ -995,6 +997,7 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] { \"list\" will list all of the available passes", "NAMES"), optopt("", "llvm-args", "A list of arguments to pass to llvm, comma \ separated", "ARGS"), + optflag("", "no-rpath", "Disables setting the rpath in libs/exes"), optopt( "", "out-dir", "Write output to compiler-chosen filename in