Skip to content

Commit

Permalink
Allow opting-out of rpath usage
Browse files Browse the repository at this point in the history
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 rust-lang#5219
  • Loading branch information
alexcrichton authored and nathanielherman committed Jan 30, 2014
1 parent 8fc0a3b commit fe266e1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
21 changes: 20 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) \
Expand Down
1 change: 1 addition & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 7 additions & 3 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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>", "DIR"),
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -391,6 +392,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),
Expand Down

0 comments on commit fe266e1

Please sign in to comment.