about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGeorges Dubus <georges.dubus@compiletoi.net>2014-01-20 17:05:29 +0100
committerGeorges Dubus <georges.dubus@compiletoi.net>2014-01-22 13:33:04 +0100
commit6eed023894ce51547772f6ba86ebfeae473aeede (patch)
treec9dbef88fa880a3bbd92bbdcd030f3b8e009e636
parent35aa1313718187509bf7b5b5ab34a98a10129cef (diff)
downloadnixlib-6eed023894ce51547772f6ba86ebfeae473aeede.tar
nixlib-6eed023894ce51547772f6ba86ebfeae473aeede.tar.gz
nixlib-6eed023894ce51547772f6ba86ebfeae473aeede.tar.bz2
nixlib-6eed023894ce51547772f6ba86ebfeae473aeede.tar.lz
nixlib-6eed023894ce51547772f6ba86ebfeae473aeede.tar.xz
nixlib-6eed023894ce51547772f6ba86ebfeae473aeede.tar.zst
nixlib-6eed023894ce51547772f6ba86ebfeae473aeede.zip
rust: patched the source to hardcode gcc path
to avoid using a wrapper.
-rw-r--r--pkgs/development/compilers/rust/default.nix29
-rw-r--r--pkgs/development/compilers/rust/hardcode_paths.patch44
2 files changed, 66 insertions, 7 deletions
diff --git a/pkgs/development/compilers/rust/default.nix b/pkgs/development/compilers/rust/default.nix
index 02c402094bd2..a93bf4af6132 100644
--- a/pkgs/development/compilers/rust/default.nix
+++ b/pkgs/development/compilers/rust/default.nix
@@ -1,5 +1,19 @@
 {stdenv, fetchurl, which, file, perl, curl, python27, makeWrapper}:
 
+/* Rust's build process has a few quirks :
+
+- It requires some patched in llvm that haven't landed upstream, so it
+  compiles its own llvm. This might change in the future, so at some
+  point we may be able to switch to nix's llvm.
+
+- The Rust compiler is written is Rust, so it requires a bootstrap
+  compiler, which is downloaded during the build. To make the build
+  pure, we download it ourself before and put it where it is
+  expected. Once the language is stable (1.0) , we might want to
+  switch it to use nix's packaged rust compiler.
+
+*/
+
 with if stdenv.system == "i686-linux" then {
   platform = "linux-i386";
   snapshot = "03e60be1f1b90dddd15f3597bc45ec8d9626b35d";
@@ -38,6 +52,14 @@ stdenv.mkDerivation {
     ln -s $snapshot $sourceRoot/dl/${snapshotName}
   '';
 
+  # The compiler requires cc, so we patch the source to tell it where to find it
+  patches = [ ./hardcode_paths.patch ];
+  postPatch = ''
+    substituteInPlace src/librustc/back/link.rs \
+      --subst-var-by "gccPath" ${stdenv.gcc}/bin/cc \
+      --subst-var-by "binutilsPath" ${stdenv.gcc.binutils}/bin/ar
+  '';
+
   # Modify the snapshot compiler so that is can be executed
   preBuild = if stdenv.isLinux then ''
     make ${target}/stage0/bin/rustc
@@ -46,13 +68,6 @@ stdenv.mkDerivation {
              ${target}/stage0/bin/rustc
   '' else null;
 
-  # rustc requires cc
-  postInstall = ''
-    for f in $out/bin/*; do
-      wrapProgram $f --prefix PATH : "${stdenv.gcc}/bin"
-    done
-  '';
-
   buildInputs = [ which file perl curl python27 makeWrapper ];
   enableParallelBuilding = true;
 
diff --git a/pkgs/development/compilers/rust/hardcode_paths.patch b/pkgs/development/compilers/rust/hardcode_paths.patch
new file mode 100644
index 000000000000..1500446cea93
--- /dev/null
+++ b/pkgs/development/compilers/rust/hardcode_paths.patch
@@ -0,0 +1,44 @@
+diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs
+index 101b2e3..124267f 100644
+--- a/src/librustc/back/link.rs
++++ b/src/librustc/back/link.rs
+@@ -728,7 +728,7 @@ pub fn get_cc_prog(sess: Session) -> ~str {
+         _ => {},
+     }
+ 
+-    get_system_tool(sess, "cc")
++    ~"@gccPath@"
+ }
+ 
+ pub fn get_ar_prog(sess: Session) -> ~str {
+@@ -737,27 +737,9 @@ pub fn get_ar_prog(sess: Session) -> ~str {
+         None => {}
+     }
+ 
+-    get_system_tool(sess, "ar")
++    ~"@binutilsPath@"
+ }
+ 
+-fn get_system_tool(sess: Session, tool: &str) -> ~str {
+-    match sess.targ_cfg.os {
+-        abi::OsAndroid => match sess.opts.android_cross_path {
+-            Some(ref path) => {
+-                let tool_str = match tool {
+-                    "cc" => "gcc",
+-                    _ => tool
+-                };
+-                format!("{}/bin/arm-linux-androideabi-{}", *path, tool_str)
+-            }
+-            None => {
+-                sess.fatal(format!("need Android NDK path for the '{}' tool \
+-                                    (--android-cross-path)", tool))
+-            }
+-        },
+-        _ => tool.to_owned(),
+-    }
+-}
+ 
+ /// Perform the linkage portion of the compilation phase. This will generate all
+ /// of the requested outputs for this compilation session.
+
+