diff --git a/pkgs/development/compilers/rust/default.nix b/pkgs/development/compilers/rust/default.nix index 02c402094bd..a93bf4af613 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 00000000000..1500446cea9 --- /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. + +