From e715cdba31ae2bfee603cfe0c56260390ec36f1c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 22 Jan 2014 21:39:03 -0800 Subject: [PATCH] Allow opting-out of rpath usage By default, the compiler and libraries are all still built with rpaths, but this can be opted out of with --disable-rpath to ./configure or --no-rpath to rustc. cc #5219 --- Makefile.in | 21 ++++++++++++++++++++- configure | 1 + src/librustc/back/link.rs | 10 +++++++--- src/librustc/driver/driver.rs | 3 +++ src/librustc/driver/session.rs | 2 ++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Makefile.in b/Makefile.in index 7f1a6945d8a..95bc635e579 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 f758d75fe76..8a9daabaf61 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 63c4d9f4a29..a57f1296969 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 9cc12caa478..8c3d7e4215d 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 ", "DIR"), diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 75094bc8084..5b3b94cf7fc 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -170,6 +170,7 @@ pub struct Options { parse_only: bool, no_trans: bool, no_analysis: bool, + no_rpath: bool, debugging_opts: u64, android_cross_path: Option<~str>, /// Whether to write dependency files. It's (enabled, optional filename). @@ -388,6 +389,7 @@ pub fn basic_options() -> @Options { parse_only: false, no_trans: false, no_analysis: false, + no_rpath: false, debugging_opts: 0, android_cross_path: None, write_dependency_info: (false, None),