From a0546ded103e4f00f0036becd6055a887fa53b80 Mon Sep 17 00:00:00 2001
From: Alex Crichton <alex@alexcrichton.com>
Date: Wed, 11 Jun 2014 14:52:38 -0700
Subject: [PATCH] rustc: Disable rpath settings by default

This commit disables rustc's emission of rpath attributes into dynamic libraries
and executables by default. The functionality is still preserved, but it must
now be manually enabled via a `-C rpath` flag.

This involved a few changes to the local build system:

* --disable-rpath is now the default configure option
* Makefiles now prefer our own LD_LIBRARY_PATH over the user's LD_LIBRARY_PATH
  in order to support building rust with rust already installed.
* The compiletest program was taught to correctly pass through the aux dir as a
  component of LD_LIBRARY_PATH in more situations.

The major impact of this change is that neither rustdoc nor rustc will work
out-of-the-box in all situations because they are dynamically linked. It must be
arranged to ensure that the libraries of a rust installation are part of the
LD_LIBRARY_PATH. The default installation paths for all platforms ensure this,
but if an installation is in a nonstandard location, then configuration may be
necessary.

Additionally, for all developers of rustc, it will no longer be possible to run
$target/stageN/bin/rustc out-of-the-box. The old behavior can be regained
through the `--enable-rpath` option to the configure script.

This change brings linux/mac installations in line with windows installations
where rpath is not possible.

Closes #11747
[breaking-change]
---
 configure                     | 2 +-
 man/rustc.1                   | 4 ++--
 mk/main.mk                    | 4 ++--
 src/librustc/back/link.rs     | 4 ++--
 src/librustc/driver/config.rs | 4 ++--
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/configure b/configure
index bdcfecd8ce903..5839b19c2d9c2 100755
--- a/configure
+++ b/configure
@@ -418,7 +418,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 inject-std-version 1 "inject the current compiler version of libstd into programs"
 opt llvm-static-stdcpp 0 "statically link to libstdc++ for LLVM"
-opt rpath 1 "build rpaths into rustc itself"
+opt rpath 0 "build rpaths into rustc itself"
 opt nightly 0 "build nightly packages"
 opt verify-install 1 "verify installed binaries work"
 opt jemalloc 1 "build liballoc with jemalloc"
diff --git a/man/rustc.1 b/man/rustc.1
index a71547893ad0b..b9737bca10457 100644
--- a/man/rustc.1
+++ b/man/rustc.1
@@ -138,8 +138,8 @@ A space-separated list of arguments to pass through to LLVM.
 If specified, the compiler will save more files (.bc, .o, .no-opt.bc) generated
 throughout compilation in the output directory.
 .TP
-\fBno-rpath\fR
-If specified, then the rpath value for dynamic libraries will not be set in
+\fBrpath\fR
+If specified, then the rpath value for dynamic libraries will be set in
 either dynamic library or executable outputs.
 .TP
 \fBno-prepopulate-passes\fR
diff --git a/mk/main.mk b/mk/main.mk
index b56f4d7a25f20..e43c8c6b984be 100644
--- a/mk/main.mk
+++ b/mk/main.mk
@@ -120,8 +120,8 @@ endif
 ifdef TRACE
   CFG_RUSTC_FLAGS += -Z trace
 endif
-ifdef CFG_DISABLE_RPATH
-CFG_RUSTC_FLAGS += -C no-rpath
+ifdef CFG_ENABLE_RPATH
+CFG_RUSTC_FLAGS += -C rpath
 endif
 
 # The executables crated during this compilation process have no need to include
diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs
index d644a0cc35330..aad6b72edf3fd 100644
--- a/src/librustc/back/link.rs
+++ b/src/librustc/back/link.rs
@@ -1327,7 +1327,7 @@ fn link_args(cmd: &mut Command,
         if sess.targ_cfg.os == abi::OsMacos {
             cmd.args(["-dynamiclib", "-Wl,-dylib"]);
 
-            if !sess.opts.cg.no_rpath {
+            if sess.opts.cg.rpath {
                 let mut v = Vec::from_slice("-Wl,-install_name,@rpath/".as_bytes());
                 v.push_all(out_filename.filename().unwrap());
                 cmd.arg(v.as_slice());
@@ -1346,7 +1346,7 @@ fn link_args(cmd: &mut Command,
     // 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
-    if !sess.opts.cg.no_rpath {
+    if sess.opts.cg.rpath {
         cmd.args(rpath::get_rpath_flags(sess, out_filename).as_slice());
     }
 
diff --git a/src/librustc/driver/config.rs b/src/librustc/driver/config.rs
index db96330d656fe..575373419f0da 100644
--- a/src/librustc/driver/config.rs
+++ b/src/librustc/driver/config.rs
@@ -300,8 +300,8 @@ cgoptions!(
         "a list of arguments to pass to llvm (space separated)"),
     save_temps: bool = (false, parse_bool,
         "save all temporary output files during compilation"),
-    no_rpath: bool = (false, parse_bool,
-        "disables setting the rpath in libs/exes"),
+    rpath: bool = (false, parse_bool,
+        "set rpath values in libs/exes"),
     no_prepopulate_passes: bool = (false, parse_bool,
         "don't pre-populate the pass manager with a list of passes"),
     no_vectorize_loops: bool = (false, parse_bool,