commit:     34f463773e4a99b2a07959070be3598036ac6b68
Author:     Aric Belsito <lluixhi <AT> gmail <DOT> com>
AuthorDate: Wed Dec 13 18:29:58 2017 +0000
Commit:     Aric Belsito <lluixhi <AT> gmail <DOT> com>
CommitDate: Wed Dec 13 18:29:58 2017 +0000
URL:        https://gitweb.gentoo.org/proj/musl.git/commit/?id=34f46377

dev-lang/rust: new package

adjust from @smaeul's overlay.

 dev-lang/rust/Manifest                             |   9 +
 ...Explicitly-run-perl-for-OpenSSL-Configure.patch |  30 ++
 ...bs-for-dependent-crates-when-linking-stat.patch | 121 ++++++
 ...ndency-resolution-errors-to-be-more-consi.patch |  68 ++++
 ...tic-native-libraries-when-linking-static-.patch |  44 +++
 ...-nostdlib-and-musl_root-from-musl-targets.patch | 416 +++++++++++++++++++++
 ...-Prefer-libgcc_eh-over-libunwind-for-musl.patch |  24 ++
 dev-lang/rust/files/0007-Fix-LLVM-build.patch      |  26 ++
 ...dd-openssl-configuration-for-musl-targets.patch |  40 ++
 dev-lang/rust/files/0009-liblibc.patch             |  16 +
 .../rust/files/0010-static-linking-default.patch   |  13 +
 dev-lang/rust/files/llvm-musl-fixes.patch          |  33 ++
 dev-lang/rust/metadata.xml                         |  13 +
 dev-lang/rust/rust-1.21.0.ebuild                   | 234 ++++++++++++
 14 files changed, 1087 insertions(+)

diff --git a/dev-lang/rust/Manifest b/dev-lang/rust/Manifest
new file mode 100644
index 0000000..ef6f419
--- /dev/null
+++ b/dev-lang/rust/Manifest
@@ -0,0 +1,9 @@
+DIST rust-1.20.0-arm-unknown-linux-gnueabi.tar.xz 62038900 BLAKE2B 
b044754d736a2c795305fbd113abb196b105ae49b5130bace40fe2fa2f5e76614ab14ab48ece3edc535ea1551ae8ef5eee23263f25eafefe5447ea62af6cd689
 SHA512 
99156745cb8f21404db5f91ef615e1bcc129de86fa41e2c0188eb2b2845a2e7e7e2d9457f2f84a03e5e9e1f91d3424d30e8e6566c3ddd3963c97c5148228011a
+DIST rust-1.20.0-arm-unknown-linux-musleabi.tar.xz 55867948 BLAKE2B 
8d084553ae4f7060c3196cd8b6f6a56043d1a6464b334ed8c565f572a07b639b279205101f80e27545573539755f8516577576877fba4e72cab344e8b02c0bd8
 SHA512 
0a4387d1751590d3e90060ea985f786639866782315b12c4919347c5975894485807eaf7c7f45328c40a966fd3ad599406edb7e305fff39fc5b726118fe3bd28
+DIST rust-1.20.0-armv7-unknown-linux-gnueabihf.tar.xz 62395492 BLAKE2B 
7f701a02cbbb0445a41c616176dac7bb51ec94952e18c8a5afe2a74d217da805f7ffe59de6d99eca926ed083c67668f2a1aefeb9fe6da437f425e3892279af29
 SHA512 
ca041644fd78d399e81a8dad9b5d5b401a2d8426eaf1e4ed02a2c5415b0a1caefadbc9716fefd6fd01aedde4fae15fc0357375d43a803714a88d65643b8ab5d1
+DIST rust-1.20.0-armv7-unknown-linux-musleabihf.tar.xz 56067408 BLAKE2B 
bbb0c0e9a01005ac9341af67b77108de1eb33a3fefa3e3191d5f7f895098a3891f26869c30da7cce034feb70b419cd39fa29b00f77e7c8fe203c82759a87c5b3
 SHA512 
fe616c9fd1da2a89bf8e78ffbf41adfdfd32582ed2bfd9f7e13f18afa8866c65403e377a5ed65dfd927d5bb2e7b2d41ed98f62399e0e897bc0f78844a3f72832
+DIST rust-1.20.0-i686-unknown-linux-gnu.tar.xz 64411000 BLAKE2B 
bc5aaece728f2d589605a9ee1d27f81dd76e66e3a68891cb50718850e6c3e9a90cab004d16cc414f62c3a8bac54ec86dfd2915f2b90b90fd3ffef52b796f75de
 SHA512 
fdd3e039589feba8a1f3ab2aa0d92bfe87a05d0e1697c5ea981577628e89715d3790a747408cb0d52fc48605c3faf6b59548e6237bdfc0505f8090b23a63a89b
+DIST rust-1.20.0-i686-unknown-linux-musl.tar.xz 59060784 BLAKE2B 
5633d0e86e7d47ebdd7fb6e324193221fc33320480e310102faa8d6b113fcbd0f2b21f7e071bd8f320cc4678fcd3c09bf64315f746dbb5775480d65b021c4c87
 SHA512 
602fc7c656e9c44c8a2b591a276bb68624862d6b1e48746ad4e04d11d33198b7c07b3266b1a0c551c2ae03137cb185593ed077126f57ff3a1c6059ec0dae5c2f
+DIST rust-1.20.0-x86_64-unknown-linux-gnu.tar.xz 68410500 BLAKE2B 
777bf0c248f86da0eb75bd38f1069652b1637692ed4d96921b8c3d62a2711cae60586f23ba4f0c48f5a42678fd77629b8dc3a27c7141d5fe8653ad3891943e8b
 SHA512 
5e397b1d3f7ef2ef7f11a7d48ad309f17220751246d5bf3e7301cca1c1a81864be49a7b78e122bb3bc66938971b73c8db443ba9e969880544e61af4061a5d96e
+DIST rust-1.20.0-x86_64-unknown-linux-musl.tar.xz 56417968 BLAKE2B 
12b5b32226f944672e3ce535cb046e627e7781840f8680193b1aa10746f03e8e1efe43bd3ca2abfc65daabeac93eef10b3b9107cbaa4e04eb2824cbc26eeaefa
 SHA512 
32f9e36b84606879a91b802a8f73502fbc4f3079177b13d3c0fbe4a784745526e0eab2ba93ae2f0c38042c8fe434370774080223c7fa3d839cb4666c3f26c0b1
+DIST rustc-1.21.0-src.tar.xz 34212448 BLAKE2B 
608fa85f4391f3f15db2d1b6f88df8f6811ba460d727c2ed366972f884dd3856711ed50ab0320d939885004d72a8d604be0aa8a65e6d61bd2e1ce33b5aee01be
 SHA512 
63b5c247ef7028c59bb246b96cb9917476d6d13cf68b37956e290248a1e53de3e4dbfad1dcae3c5c2cacc73c9dd212c50e45902c7d913fadeaac81db630bc951

diff --git 
a/dev-lang/rust/files/0001-Explicitly-run-perl-for-OpenSSL-Configure.patch 
b/dev-lang/rust/files/0001-Explicitly-run-perl-for-OpenSSL-Configure.patch
new file mode 100644
index 0000000..b0267d7
--- /dev/null
+++ b/dev-lang/rust/files/0001-Explicitly-run-perl-for-OpenSSL-Configure.patch
@@ -0,0 +1,30 @@
+From 56da47a7e21b90dbd9fec0f935d4519d072b6a92 Mon Sep 17 00:00:00 2001
+From: Samuel Holland <sam...@sholland.org>
+Date: Mon, 28 Aug 2017 11:22:11 -0500
+Subject: [PATCH 1/8] Explicitly run perl for OpenSSL Configure
+
+OpenSSL's Configure script is missing a shebang. On some platforms,
+execve falls back to execution with the shell. Some other platforms,
+like musl, will fail with an exec format error. Avoid this by calling
+perl explicitly (since it's a perl script).
+---
+ src/bootstrap/native.rs | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs
+index 8429b64513..58148c7c8b 100644
+--- a/src/bootstrap/native.rs
++++ b/src/bootstrap/native.rs
+@@ -388,7 +388,8 @@ impl Step for Openssl {
+         drop(fs::remove_dir_all(&dst));
+         
build.run(Command::new("tar").arg("xf").arg(&tarball).current_dir(&out));
+ 
+-        let mut configure = Command::new(obj.join("Configure"));
++        let mut configure = Command::new("perl");
++        configure.arg(obj.join("Configure"));
+         configure.arg(format!("--prefix={}", dst.display()));
+         configure.arg("no-dso");
+         configure.arg("no-ssl2");
+-- 
+2.13.6
+

diff --git 
a/dev-lang/rust/files/0002-Require-rlibs-for-dependent-crates-when-linking-stat.patch
 
b/dev-lang/rust/files/0002-Require-rlibs-for-dependent-crates-when-linking-stat.patch
new file mode 100644
index 0000000..672e864
--- /dev/null
+++ 
b/dev-lang/rust/files/0002-Require-rlibs-for-dependent-crates-when-linking-stat.patch
@@ -0,0 +1,121 @@
+From 1f9f168d318a0c87847b33afa9f13463c22a83ff Mon Sep 17 00:00:00 2001
+From: Samuel Holland <sam...@sholland.org>
+Date: Sat, 2 Sep 2017 18:15:57 -0500
+Subject: [PATCH 2/8] Require rlibs for dependent crates when linking static
+ executables
+
+This handles the case for `CrateTypeExecutable` and `+crt_static`. I
+reworked the match block to avoid duplicating the `attempt_static` and
+error checking code again (this case would have been a copy of the
+`CrateTypeCdylib`/`CrateTypeStaticlib` case).
+
+On `linux-musl` targets where `std` was built with `crt_static = false`
+in `config.toml`, this change brings the test suite from entirely
+failing to mostly passing.
+
+This change should not affect behavior for other crate types, or for
+targets which do not respect `+crt_static`.
+---
+ src/librustc/middle/dependency_format.rs | 76 ++++++++++++++++++--------------
+ 1 file changed, 42 insertions(+), 34 deletions(-)
+
+diff --git a/src/librustc/middle/dependency_format.rs 
b/src/librustc/middle/dependency_format.rs
+index 837ab4fd4a..8d9a72723f 100644
+--- a/src/librustc/middle/dependency_format.rs
++++ b/src/librustc/middle/dependency_format.rs
+@@ -112,26 +112,51 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
+         return Vec::new();
+     }
+ 
+-    match ty {
+-        // If the global prefer_dynamic switch is turned off, first attempt
+-        // static linkage (this can fail).
+-        config::CrateTypeExecutable if !sess.opts.cg.prefer_dynamic => {
+-            if let Some(v) = attempt_static(tcx) {
+-                return v;
+-            }
+-        }
++    let preferred_linkage = match ty {
++        // cdylibs must have all static dependencies.
++        config::CrateTypeCdylib => Linkage::Static,
++
++        // Generating a dylib without `-C prefer-dynamic` means that we're 
going
++        // to try to eagerly statically link all dependencies. This is 
normally
++        // done for end-product dylibs, not intermediate products.
++        config::CrateTypeDylib if !sess.opts.cg.prefer_dynamic => 
Linkage::Static,
++        config::CrateTypeDylib => Linkage::Dynamic,
++
++        // If the global prefer_dynamic switch is turned off, or the final
++        // executable will be statically linked, prefer static crate linkage.
++        config::CrateTypeExecutable if !sess.opts.cg.prefer_dynamic ||
++            sess.crt_static() => Linkage::Static,
++        config::CrateTypeExecutable => Linkage::Dynamic,
++
++        // proc-macro crates are required to be dylibs, and they're currently
++        // required to link to libsyntax as well.
++        config::CrateTypeProcMacro => Linkage::Dynamic,
+ 
+         // No linkage happens with rlibs, we just needed the metadata (which 
we
+         // got long ago), so don't bother with anything.
+-        config::CrateTypeRlib => return Vec::new(),
+-
+-        // Staticlibs and cdylibs must have all static dependencies. If any 
fail
+-        // to be found, we generate some nice pretty errors.
+-        config::CrateTypeStaticlib |
+-        config::CrateTypeCdylib => {
+-            if let Some(v) = attempt_static(tcx) {
+-                return v;
+-            }
++        config::CrateTypeRlib => Linkage::NotLinked,
++
++        // staticlibs must have all static dependencies.
++        config::CrateTypeStaticlib => Linkage::Static,
++    };
++
++    if preferred_linkage == Linkage::NotLinked {
++        // If the crate is not linked, there are no link-time dependencies.
++        return Vec::new();
++    }
++
++    if preferred_linkage == Linkage::Static {
++        // Attempt static linkage first. For dylibs and executables, we may be
++        // able to retry below with dynamic linkage.
++        if let Some(v) = attempt_static(tcx) {
++            return v;
++        }
++
++        // Staticlibs, cdylibs, and static executables must have all static
++        // dependencies. If any are not found, generate some nice pretty 
errors.
++        if ty == config::CrateTypeCdylib || ty == config::CrateTypeStaticlib 
||
++                (ty == config::CrateTypeExecutable && sess.crt_static() &&
++                !sess.target.target.options.crt_static_allows_dylibs) {
+             for cnum in sess.cstore.crates() {
+                 if sess.cstore.dep_kind(cnum).macros_only() { continue }
+                 let src = sess.cstore.used_crate_source(cnum);
+@@ -141,23 +166,6 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
+             }
+             return Vec::new();
+         }
+-
+-        // Generating a dylib without `-C prefer-dynamic` means that we're 
going
+-        // to try to eagerly statically link all dependencies. This is 
normally
+-        // done for end-product dylibs, not intermediate products.
+-        config::CrateTypeDylib if !sess.opts.cg.prefer_dynamic => {
+-            if let Some(v) = attempt_static(tcx) {
+-                return v;
+-            }
+-        }
+-
+-        // Everything else falls through below. This will happen either with 
the
+-        // `-C prefer-dynamic` or because we're a proc-macro crate. Note that
+-        // proc-macro crates are required to be dylibs, and they're currently
+-        // required to link to libsyntax as well.
+-        config::CrateTypeExecutable |
+-        config::CrateTypeDylib |
+-        config::CrateTypeProcMacro => {},
+     }
+ 
+     let mut formats = FxHashMap();
+-- 
+2.13.6
+

diff --git 
a/dev-lang/rust/files/0003-Adjust-dependency-resolution-errors-to-be-more-consi.patch
 
b/dev-lang/rust/files/0003-Adjust-dependency-resolution-errors-to-be-more-consi.patch
new file mode 100644
index 0000000..f92683d
--- /dev/null
+++ 
b/dev-lang/rust/files/0003-Adjust-dependency-resolution-errors-to-be-more-consi.patch
@@ -0,0 +1,68 @@
+From 02ef7616b6f5d192032c250982362c0ae0f06b45 Mon Sep 17 00:00:00 2001
+From: Samuel Holland <sam...@sholland.org>
+Date: Thu, 14 Sep 2017 23:42:21 -0500
+Subject: [PATCH 3/8] Adjust dependency-resolution errors to be more consistent
+
+---
+ src/librustc/middle/dependency_format.rs            | 10 +++++-----
+ src/test/compile-fail/cdylib-deps-must-be-static.rs |  2 +-
+ src/test/compile-fail/rmeta_lib.rs                  |  2 +-
+ 3 files changed, 7 insertions(+), 7 deletions(-)
+
+diff --git a/src/librustc/middle/dependency_format.rs 
b/src/librustc/middle/dependency_format.rs
+index 8d9a72723f..c8da696c37 100644
+--- a/src/librustc/middle/dependency_format.rs
++++ b/src/librustc/middle/dependency_format.rs
+@@ -161,7 +161,8 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
+                 if sess.cstore.dep_kind(cnum).macros_only() { continue }
+                 let src = sess.cstore.used_crate_source(cnum);
+                 if src.rlib.is_some() { continue }
+-                sess.err(&format!("dependency `{}` not found in rlib format",
++                sess.err(&format!("crate `{}` required to be available in 
rlib format, \
++                                  but was not found in this form",
+                                   sess.cstore.crate_name(cnum)));
+             }
+             return Vec::new();
+@@ -245,10 +246,9 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
+                     Linkage::Static => "rlib",
+                     _ => "dylib",
+                 };
+-                let name = sess.cstore.crate_name(cnum);
+-                sess.err(&format!("crate `{}` required to be available in {}, 
\
+-                                  but it was not available in this form",
+-                                  name, kind));
++                sess.err(&format!("crate `{}` required to be available in {} 
format, \
++                                  but was not found in this form",
++                                  sess.cstore.crate_name(cnum), kind));
+             }
+         }
+     }
+diff --git a/src/test/compile-fail/cdylib-deps-must-be-static.rs 
b/src/test/compile-fail/cdylib-deps-must-be-static.rs
+index 853507cbc6..bf7189c21f 100644
+--- a/src/test/compile-fail/cdylib-deps-must-be-static.rs
++++ b/src/test/compile-fail/cdylib-deps-must-be-static.rs
+@@ -8,7 +8,7 @@
+ // option. This file may not be copied, modified, or distributed
+ // except according to those terms.
+ 
+-// error-pattern: dependency `cdylib_dep` not found in rlib format
++// error-pattern: crate `cdylib_dep` required to be available in rlib format, 
but was not found
+ // aux-build:cdylib-dep.rs
+ // ignore-musl
+ // ignore-emscripten
+diff --git a/src/test/compile-fail/rmeta_lib.rs 
b/src/test/compile-fail/rmeta_lib.rs
+index 3b7d1f3cc9..a61ff05e8c 100644
+--- a/src/test/compile-fail/rmeta_lib.rs
++++ b/src/test/compile-fail/rmeta_lib.rs
+@@ -10,7 +10,7 @@
+ 
+ // aux-build:rmeta_meta.rs
+ // no-prefer-dynamic
+-// error-pattern: crate `rmeta_meta` required to be available in rlib, but it 
was not available
++// error-pattern: crate `rmeta_meta` required to be available in rlib format, 
but was not found
+ 
+ // Check that building a non-metadata crate fails if a dependent crate is
+ // metadata-only.
+-- 
+2.13.6
+

diff --git 
a/dev-lang/rust/files/0004-Require-static-native-libraries-when-linking-static-.patch
 
b/dev-lang/rust/files/0004-Require-static-native-libraries-when-linking-static-.patch
new file mode 100644
index 0000000..b58c08d
--- /dev/null
+++ 
b/dev-lang/rust/files/0004-Require-static-native-libraries-when-linking-static-.patch
@@ -0,0 +1,44 @@
+From b6ace9145b6ec3540b17c7253ed3b042eb8aee5e Mon Sep 17 00:00:00 2001
+From: Samuel Holland <sam...@sholland.org>
+Date: Fri, 8 Sep 2017 00:05:18 -0500
+Subject: [PATCH 4/8] Require static native libraries when linking static
+ executables
+
+---
+ src/librustc_trans/back/link.rs | 13 ++++++++++---
+ 1 file changed, 10 insertions(+), 3 deletions(-)
+
+diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs
+index 5de48fbce9..4b4b5846af 100644
+--- a/src/librustc_trans/back/link.rs
++++ b/src/librustc_trans/back/link.rs
+@@ -1312,8 +1312,8 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
+     }
+ }
+ 
+-// Link in all of our upstream crates' native dependencies. Remember that
+-// all of these upstream native dependencies are all non-static
++// Link in all of our upstream crates' native dependencies. Remember that when
++// linking libraries, these upstream native dependencies are all non-static
+ // dependencies. We've got two cases then:
+ //
+ // 1. The upstream crate is an rlib. In this case we *must* link in the
+@@ -1350,7 +1350,14 @@ fn add_upstream_native_libraries(cmd: &mut Linker, 
sess: &Session, crate_type: c
+                 continue
+             }
+             match lib.kind {
+-                NativeLibraryKind::NativeUnknown => 
cmd.link_dylib(&lib.name.as_str()),
++                NativeLibraryKind::NativeUnknown => {
++                    // When creating executables, match library linkage to 
that of the executable.
++                    if crate_type == config::CrateTypeExecutable && 
sess.crt_static() {
++                        cmd.link_staticlib(&lib.name.as_str())
++                    } else {
++                        cmd.link_dylib(&lib.name.as_str())
++                    }
++                },
+                 NativeLibraryKind::NativeFramework => 
cmd.link_framework(&lib.name.as_str()),
+                 NativeLibraryKind::NativeStaticNobundle => {
+                     // Link "static-nobundle" native libs only if the crate 
they originate from
+-- 
+2.13.6
+

diff --git 
a/dev-lang/rust/files/0005-Remove-nostdlib-and-musl_root-from-musl-targets.patch
 
b/dev-lang/rust/files/0005-Remove-nostdlib-and-musl_root-from-musl-targets.patch
new file mode 100644
index 0000000..985d007
--- /dev/null
+++ 
b/dev-lang/rust/files/0005-Remove-nostdlib-and-musl_root-from-musl-targets.patch
@@ -0,0 +1,416 @@
+From 40709f672f29ad2c9454615d3d0741f78cec7447 Mon Sep 17 00:00:00 2001
+From: Samuel Holland <sam...@sholland.org>
+Date: Fri, 8 Sep 2017 22:11:14 -0500
+Subject: [PATCH 5/8] Remove -nostdlib and musl_root from musl targets
+
+---
+ configure                                        |  6 ----
+ src/bootstrap/bin/rustc.rs                       | 10 -------
+ src/bootstrap/cc.rs                              | 27 ++----------------
+ src/bootstrap/compile.rs                         | 31 ---------------------
+ src/bootstrap/config.rs                          | 35 ------------------------
+ src/bootstrap/lib.rs                             |  8 ------
+ src/bootstrap/sanity.rs                          | 29 --------------------
+ src/ci/docker/cross/Dockerfile                   |  5 +---
+ src/ci/docker/dist-i586-gnu-i686-musl/Dockerfile |  1 -
+ src/ci/docker/dist-x86_64-musl/Dockerfile        |  1 -
+ src/librustc_back/target/linux_musl_base.rs      | 15 ----------
+ 12 files changed, 4 insertions(+), 170 deletions(-)
+
+diff --git a/configure b/configure
+index 664b473b2c..eead8a9b7b 100755
+--- a/configure
++++ b/configure
+@@ -481,12 +481,6 @@ valopt armv7-linux-androideabi-ndk "" 
"armv7-linux-androideabi NDK standalone pa
+ valopt aarch64-linux-android-ndk "" "aarch64-linux-android NDK standalone 
path"
+ valopt x86_64-linux-android-ndk "" "x86_64-linux-android NDK standalone path"
+ valopt nacl-cross-path  "" "NaCl SDK path (Pepper Canary is recommended). 
Must be absolute!"
+-valopt musl-root "/usr/local" "MUSL root installation directory (deprecated)"
+-valopt musl-root-x86_64 "" "x86_64-unknown-linux-musl install directory"
+-valopt musl-root-i686 "" "i686-unknown-linux-musl install directory"
+-valopt musl-root-arm "" "arm-unknown-linux-musleabi install directory"
+-valopt musl-root-armhf "" "arm-unknown-linux-musleabihf install directory"
+-valopt musl-root-armv7 "" "armv7-unknown-linux-musleabihf install directory"
+ valopt extra-filename "" "Additional data that is hashed and passed to the -C 
extra-filename flag"
+ valopt qemu-armhf-rootfs "" "rootfs in qemu testing, you probably don't want 
to use this"
+ valopt qemu-aarch64-rootfs "" "rootfs in qemu testing, you probably don't 
want to use this"
+diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs
+index 0baca9e58f..7b12956f74 100644
+--- a/src/bootstrap/bin/rustc.rs
++++ b/src/bootstrap/bin/rustc.rs
+@@ -30,7 +30,6 @@
+ extern crate bootstrap;
+ 
+ use std::env;
+-use std::ffi::OsString;
+ use std::io;
+ use std::io::prelude::*;
+ use std::str::FromStr;
+@@ -113,15 +112,6 @@ fn main() {
+             cmd.arg("-Cprefer-dynamic");
+         }
+ 
+-        // Help the libc crate compile by assisting it in finding the MUSL
+-        // native libraries.
+-        if let Some(s) = env::var_os("MUSL_ROOT") {
+-            let mut root = OsString::from("native=");
+-            root.push(&s);
+-            root.push("/lib");
+-            cmd.arg("-L").arg(&root);
+-        }
+-
+         // Pass down extra flags, commonly used to configure `-Clinker` when
+         // cross compiling.
+         if let Ok(s) = env::var("RUSTC_FLAGS") {
+diff --git a/src/bootstrap/cc.rs b/src/bootstrap/cc.rs
+index 0f25da8a23..b808fd86da 100644
+--- a/src/bootstrap/cc.rs
++++ b/src/bootstrap/cc.rs
+@@ -53,7 +53,7 @@ pub fn find(build: &mut Build) {
+         if let Some(cc) = config.and_then(|c| c.cc.as_ref()) {
+             cfg.compiler(cc);
+         } else {
+-            set_compiler(&mut cfg, "gcc", target, config, build);
++            set_compiler(&mut cfg, "gcc", target, config);
+         }
+ 
+         let compiler = cfg.get_compiler();
+@@ -74,7 +74,7 @@ pub fn find(build: &mut Build) {
+         if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
+             cfg.compiler(cxx);
+         } else {
+-            set_compiler(&mut cfg, "g++", host, config, build);
++            set_compiler(&mut cfg, "g++", host, config);
+         }
+         let compiler = cfg.get_compiler();
+         build.verbose(&format!("CXX_{} = {:?}", host, compiler.path()));
+@@ -85,8 +85,7 @@ pub fn find(build: &mut Build) {
+ fn set_compiler(cfg: &mut gcc::Config,
+                 gnu_compiler: &str,
+                 target: Interned<String>,
+-                config: Option<&Target>,
+-                build: &Build) {
++                config: Option<&Target>) {
+     match &*target {
+         // When compiling for android we may have the NDK configured in the
+         // config.toml in which case we look there. Otherwise the default
+@@ -122,26 +121,6 @@ fn set_compiler(cfg: &mut gcc::Config,
+             }
+         }
+ 
+-        "mips-unknown-linux-musl" => {
+-            if cfg.get_compiler().path().to_str() == Some("gcc") {
+-                cfg.compiler("mips-linux-musl-gcc");
+-            }
+-        }
+-        "mipsel-unknown-linux-musl" => {
+-            if cfg.get_compiler().path().to_str() == Some("gcc") {
+-                cfg.compiler("mipsel-linux-musl-gcc");
+-            }
+-        }
+-
+-        t if t.contains("musl") => {
+-            if let Some(root) = build.musl_root(target) {
+-                let guess = root.join("bin/musl-gcc");
+-                if guess.exists() {
+-                    cfg.compiler(guess);
+-                }
+-            }
+-        }
+-
+         _ => {}
+     }
+ }
+diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs
+index 335e1690a2..ab3a8a66ea 100644
+--- a/src/bootstrap/compile.rs
++++ b/src/bootstrap/compile.rs
+@@ -78,13 +78,6 @@ impl Step for Std {
+             });
+             println!("Uplifting stage1 std ({} -> {})", from.host, target);
+ 
+-            // Even if we're not building std this stage, the new sysroot must
+-            // still contain the musl startup objects.
+-            if target.contains("musl") && !target.contains("mips") {
+-                let libdir = builder.sysroot_libdir(compiler, target);
+-                copy_musl_third_party_objects(build, target, &libdir);
+-            }
+-
+             builder.ensure(StdLink {
+                 compiler: from,
+                 target_compiler: compiler,
+@@ -97,11 +90,6 @@ impl Step for Std {
+         println!("Building stage{} std artifacts ({} -> {})", compiler.stage,
+                 &compiler.host, target);
+ 
+-        if target.contains("musl") && !target.contains("mips") {
+-            let libdir = builder.sysroot_libdir(compiler, target);
+-            copy_musl_third_party_objects(build, target, &libdir);
+-        }
+-
+         let out_dir = build.cargo_out(compiler, Mode::Libstd, target);
+         build.clear_if_dirty(&out_dir, &builder.rustc(compiler));
+         let mut cargo = builder.cargo(compiler, Mode::Libstd, target, 
"build");
+@@ -118,20 +106,6 @@ impl Step for Std {
+     }
+ }
+ 
+-/// Copies the crt(1,i,n).o startup objects
+-///
+-/// Since musl supports fully static linking, we can cross link for it even
+-/// with a glibc-targeting toolchain, given we have the appropriate startup
+-/// files. As those shipped with glibc won't work, copy the ones provided by
+-/// musl so we have them on linux-gnu hosts.
+-fn copy_musl_third_party_objects(build: &Build,
+-                                 target: Interned<String>,
+-                                 into: &Path) {
+-    for &obj in &["crt1.o", "crti.o", "crtn.o"] {
+-        copy(&build.musl_root(target).unwrap().join("lib").join(obj), 
&into.join(obj));
+-    }
+-}
+-
+ /// Configure cargo to compile the standard library, adding appropriate env 
vars
+ /// and such.
+ pub fn std_cargo(build: &Build,
+@@ -173,11 +147,6 @@ pub fn std_cargo(build: &Build,
+             cargo.env("JEMALLOC_OVERRIDE", jemalloc);
+         }
+     }
+-    if target.contains("musl") {
+-        if let Some(p) = build.musl_root(target) {
+-            cargo.env("MUSL_ROOT", p);
+-        }
+-    }
+ }
+ 
+ #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
+index f43035fbfe..7f9cca3905 100644
+--- a/src/bootstrap/config.rs
++++ b/src/bootstrap/config.rs
+@@ -111,8 +111,6 @@ pub struct Config {
+     pub low_priority: bool,
+     pub channel: String,
+     pub quiet_tests: bool,
+-    // Fallback musl-root for all targets
+-    pub musl_root: Option<PathBuf>,
+     pub prefix: Option<PathBuf>,
+     pub sysconfdir: Option<PathBuf>,
+     pub docdir: Option<PathBuf>,
+@@ -144,7 +142,6 @@ pub struct Target {
+     pub cxx: Option<PathBuf>,
+     pub ndk: Option<PathBuf>,
+     pub crt_static: Option<bool>,
+-    pub musl_root: Option<PathBuf>,
+     pub qemu_rootfs: Option<PathBuf>,
+ }
+ 
+@@ -259,7 +256,6 @@ struct Rust {
+     default_linker: Option<String>,
+     default_ar: Option<String>,
+     channel: Option<String>,
+-    musl_root: Option<String>,
+     rpath: Option<bool>,
+     optimize_tests: Option<bool>,
+     debuginfo_tests: Option<bool>,
+@@ -277,7 +273,6 @@ struct TomlTarget {
+     cxx: Option<String>,
+     android_ndk: Option<String>,
+     crt_static: Option<bool>,
+-    musl_root: Option<String>,
+     qemu_rootfs: Option<String>,
+ }
+ 
+@@ -424,7 +419,6 @@ impl Config {
+             set(&mut config.ignore_git, rust.ignore_git);
+             config.rustc_default_linker = rust.default_linker.clone();
+             config.rustc_default_ar = rust.default_ar.clone();
+-            config.musl_root = rust.musl_root.clone().map(PathBuf::from);
+ 
+             match rust.codegen_units {
+                 Some(0) => config.rust_codegen_units = num_cpus::get() as u32,
+@@ -449,7 +443,6 @@ impl Config {
+                 target.cxx = cfg.cxx.clone().map(PathBuf::from);
+                 target.cc = cfg.cc.clone().map(PathBuf::from);
+                 target.crt_static = cfg.crt_static.clone();
+-                target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
+                 target.qemu_rootfs = 
cfg.qemu_rootfs.clone().map(PathBuf::from);
+ 
+                 
config.target_config.insert(INTERNER.intern_string(triple.clone()), target);
+@@ -564,34 +557,6 @@ impl Config {
+                 "CFG_EXPERIMENTAL_TARGETS" if value.len() > 0 => {
+                     self.llvm_experimental_targets = Some(value.to_string());
+                 }
+-                "CFG_MUSL_ROOT" if value.len() > 0 => {
+-                    self.musl_root = Some(parse_configure_path(value));
+-                }
+-                "CFG_MUSL_ROOT_X86_64" if value.len() > 0 => {
+-                    let target = 
INTERNER.intern_str("x86_64-unknown-linux-musl");
+-                    let target = 
self.target_config.entry(target).or_insert(Target::default());
+-                    target.musl_root = Some(parse_configure_path(value));
+-                }
+-                "CFG_MUSL_ROOT_I686" if value.len() > 0 => {
+-                    let target = 
INTERNER.intern_str("i686-unknown-linux-musl");
+-                    let target = 
self.target_config.entry(target).or_insert(Target::default());
+-                    target.musl_root = Some(parse_configure_path(value));
+-                }
+-                "CFG_MUSL_ROOT_ARM" if value.len() > 0 => {
+-                    let target = 
INTERNER.intern_str("arm-unknown-linux-musleabi");
+-                    let target = 
self.target_config.entry(target).or_insert(Target::default());
+-                    target.musl_root = Some(parse_configure_path(value));
+-                }
+-                "CFG_MUSL_ROOT_ARMHF" if value.len() > 0 => {
+-                    let target = 
INTERNER.intern_str("arm-unknown-linux-musleabihf");
+-                    let target = 
self.target_config.entry(target).or_insert(Target::default());
+-                    target.musl_root = Some(parse_configure_path(value));
+-                }
+-                "CFG_MUSL_ROOT_ARMV7" if value.len() > 0 => {
+-                    let target = 
INTERNER.intern_str("armv7-unknown-linux-musleabihf");
+-                    let target = 
self.target_config.entry(target).or_insert(Target::default());
+-                    target.musl_root = Some(parse_configure_path(value));
+-                }
+                 "CFG_DEFAULT_AR" if value.len() > 0 => {
+                     self.rustc_default_ar = Some(value.to_string());
+                 }
+diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
+index 84a9e56b64..90f905163d 100644
+--- a/src/bootstrap/lib.rs
++++ b/src/bootstrap/lib.rs
+@@ -665,14 +665,6 @@ impl Build {
+         }
+     }
+ 
+-    /// Returns the "musl root" for this `target`, if defined
+-    fn musl_root(&self, target: Interned<String>) -> Option<&Path> {
+-        self.config.target_config.get(&target)
+-            .and_then(|t| t.musl_root.as_ref())
+-            .or(self.config.musl_root.as_ref())
+-            .map(|p| &**p)
+-    }
+-
+     /// Returns whether the target will be tested using the 
`remote-test-client`
+     /// and `remote-test-server` binaries.
+     fn remote_tested(&self, target: Interned<String>) -> bool {
+diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs
+index 54208d8bb5..e1ba41c165 100644
+--- a/src/bootstrap/sanity.rs
++++ b/src/bootstrap/sanity.rs
+@@ -21,7 +21,6 @@
+ use std::collections::HashMap;
+ use std::env;
+ use std::ffi::{OsString, OsStr};
+-use std::fs;
+ use std::process::Command;
+ use std::path::PathBuf;
+ 
+@@ -168,34 +167,6 @@ pub fn check(build: &mut Build) {
+             panic!("the iOS target is only supported on macOS");
+         }
+ 
+-        // Make sure musl-root is valid
+-        if target.contains("musl") && !target.contains("mips") {
+-            // If this is a native target (host is also musl) and no 
musl-root is given,
+-            // fall back to the system toolchain in /usr before giving up
+-            if build.musl_root(*target).is_none() && build.config.build == 
*target {
+-                let target = build.config.target_config.entry(target.clone())
+-                                 .or_insert(Default::default());
+-                target.musl_root = Some("/usr".into());
+-            }
+-            match build.musl_root(*target) {
+-                Some(root) => {
+-                    if fs::metadata(root.join("lib/libc.a")).is_err() {
+-                        panic!("couldn't find libc.a in musl dir: {}",
+-                               root.join("lib").display());
+-                    }
+-                    if fs::metadata(root.join("lib/libunwind.a")).is_err() {
+-                        panic!("couldn't find libunwind.a in musl dir: {}",
+-                               root.join("lib").display());
+-                    }
+-                }
+-                None => {
+-                    panic!("when targeting MUSL either the rust.musl-root \
+-                            option or the target.$TARGET.musl-root option 
must \
+-                            be specified in config.toml")
+-                }
+-            }
+-        }
+-
+         if target.contains("msvc") {
+             // There are three builds of cmake on windows: MSVC, MinGW, and
+             // Cygwin. The Cygwin build does not have generators for Visual
+diff --git a/src/ci/docker/cross/Dockerfile b/src/ci/docker/cross/Dockerfile
+index a83bbe9c60..0d931e4314 100644
+--- a/src/ci/docker/cross/Dockerfile
++++ b/src/ci/docker/cross/Dockerfile
+@@ -59,10 +59,7 @@ ENV STAGING_DIR=/tmp
+ 
+ ENV RUST_CONFIGURE_ARGS \
+       --enable-extended \
+-      --target=$TARGETS \
+-      --musl-root-arm=/usr/local/arm-linux-musleabi \
+-      --musl-root-armhf=/usr/local/arm-linux-musleabihf \
+-      --musl-root-armv7=/usr/local/armv7-linux-musleabihf
++      --target=$TARGETS
+ ENV SCRIPT python2.7 ../x.py dist --target $TARGETS
+ 
+ # sccache
+diff --git a/src/ci/docker/dist-i586-gnu-i686-musl/Dockerfile 
b/src/ci/docker/dist-i586-gnu-i686-musl/Dockerfile
+index efde3ff529..518ece660b 100644
+--- a/src/ci/docker/dist-i586-gnu-i686-musl/Dockerfile
++++ b/src/ci/docker/dist-i586-gnu-i686-musl/Dockerfile
+@@ -25,7 +25,6 @@ RUN sh /scripts/sccache.sh
+ 
+ ENV RUST_CONFIGURE_ARGS \
+       --target=i686-unknown-linux-musl,i586-unknown-linux-gnu \
+-      --musl-root-i686=/musl-i686 \
+       --enable-extended
+ 
+ # Newer binutils broke things on some vms/distros (i.e., linking against
+diff --git a/src/ci/docker/dist-x86_64-musl/Dockerfile 
b/src/ci/docker/dist-x86_64-musl/Dockerfile
+index 91ed6bfe1f..9859cfeee9 100644
+--- a/src/ci/docker/dist-x86_64-musl/Dockerfile
++++ b/src/ci/docker/dist-x86_64-musl/Dockerfile
+@@ -25,7 +25,6 @@ RUN sh /scripts/sccache.sh
+ 
+ ENV RUST_CONFIGURE_ARGS \
+       --target=x86_64-unknown-linux-musl \
+-      --musl-root-x86_64=/musl-x86_64 \
+       --enable-extended
+ 
+ # Newer binutils broke things on some vms/distros (i.e., linking against
+diff --git a/src/librustc_back/target/linux_musl_base.rs 
b/src/librustc_back/target/linux_musl_base.rs
+index 6e5e139715..d99cb55cc5 100644
+--- a/src/librustc_back/target/linux_musl_base.rs
++++ b/src/librustc_back/target/linux_musl_base.rs
+@@ -14,10 +14,6 @@ use target::TargetOptions;
+ pub fn opts() -> TargetOptions {
+     let mut base = super::linux_base::opts();
+ 
+-    // Make sure that the linker/gcc really don't pull in anything, including
+-    // default objects, libs, etc.
+-    
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-nostdlib".to_string());
+-
+     // At least when this was tested, the linker would not add the
+     // `GNU_EH_FRAME` program header to executables generated, which is 
required
+     // when unwinding to locate the unwinding information. I'm not sure why 
this
+@@ -49,17 +45,6 @@ pub fn opts() -> TargetOptions {
+     
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-Wl,-(".to_string());
+     base.post_link_args.insert(LinkerFlavor::Gcc, vec!["-Wl,-)".to_string()]);
+ 
+-    // When generating a statically linked executable there's generally some
+-    // small setup needed which is listed in these files. These are provided 
by
+-    // a musl toolchain and are linked by default by the `musl-gcc` script. 
Note
+-    // that `gcc` also does this by default, it just uses some different 
files.
+-    //
+-    // Each target directory for musl has these object files included in it so
+-    // they'll be included from there.
+-    base.pre_link_objects_exe.push("crt1.o".to_string());
+-    base.pre_link_objects_exe.push("crti.o".to_string());
+-    base.post_link_objects.push("crtn.o".to_string());
+-
+     // These targets statically link libc by default
+     base.crt_static_default = true;
+     // These targets allow the user to choose between static and dynamic 
linking.
+-- 
+2.13.6
+

diff --git 
a/dev-lang/rust/files/0006-Prefer-libgcc_eh-over-libunwind-for-musl.patch 
b/dev-lang/rust/files/0006-Prefer-libgcc_eh-over-libunwind-for-musl.patch
new file mode 100644
index 0000000..c12e6df
--- /dev/null
+++ b/dev-lang/rust/files/0006-Prefer-libgcc_eh-over-libunwind-for-musl.patch
@@ -0,0 +1,24 @@
+From cbd6ddb6036758c54a89e578b2fad183b2d50e8d Mon Sep 17 00:00:00 2001
+From: Samuel Holland <sam...@sholland.org>
+Date: Sat, 9 Sep 2017 00:14:16 -0500
+Subject: [PATCH 6/8] Prefer libgcc_eh over libunwind for musl
+
+---
+ src/libunwind/lib.rs | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/libunwind/lib.rs b/src/libunwind/lib.rs
+index 461b49aa36..aeb4686ba7 100644
+--- a/src/libunwind/lib.rs
++++ b/src/libunwind/lib.rs
+@@ -29,6 +29,6 @@ mod libunwind;
+ pub use libunwind::*;
+ 
+ #[cfg(all(target_env = "musl", not(target_arch = "mips")))]
+-#[link(name = "unwind", kind = "static", cfg(target_feature = "crt-static"))]
++#[link(name = "gcc_eh", cfg(target_feature = "crt-static"))]
+ #[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]
+ extern {}
+-- 
+2.13.6
+

diff --git a/dev-lang/rust/files/0007-Fix-LLVM-build.patch 
b/dev-lang/rust/files/0007-Fix-LLVM-build.patch
new file mode 100644
index 0000000..d435bfb
--- /dev/null
+++ b/dev-lang/rust/files/0007-Fix-LLVM-build.patch
@@ -0,0 +1,26 @@
+From ede5ae2d6278c7309601d2bb2dde55e5c91fbac2 Mon Sep 17 00:00:00 2001
+From: Samuel Holland <sam...@sholland.org>
+Date: Fri, 8 Sep 2017 00:04:29 -0500
+Subject: [PATCH 7/8] Fix LLVM build
+
+---
+ src/bootstrap/lib.rs | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
+index 90f905163d..4d7f2f9a62 100644
+--- a/src/bootstrap/lib.rs
++++ b/src/bootstrap/lib.rs
+@@ -603,7 +603,8 @@ impl Build {
+         // gcc-rs because the build scripts will determine that for 
themselves.
+         let mut base = self.cc[&target].0.args().iter()
+                            .map(|s| s.to_string_lossy().into_owned())
+-                           .filter(|s| !s.starts_with("-O") && 
!s.starts_with("/O"))
++                           .filter(|s| !s.starts_with("-O") && 
!s.starts_with("/O")
++                                   && !s.starts_with("-static"))
+                            .collect::<Vec<_>>();
+ 
+         // If we're compiling on macOS then we add a few unconditional flags
+-- 
+2.13.6
+

diff --git 
a/dev-lang/rust/files/0008-Add-openssl-configuration-for-musl-targets.patch 
b/dev-lang/rust/files/0008-Add-openssl-configuration-for-musl-targets.patch
new file mode 100644
index 0000000..691661b
--- /dev/null
+++ b/dev-lang/rust/files/0008-Add-openssl-configuration-for-musl-targets.patch
@@ -0,0 +1,40 @@
+From 6fe9d7428e87bd13d96895cc56568104fe2cc112 Mon Sep 17 00:00:00 2001
+From: Samuel Holland <sam...@sholland.org>
+Date: Mon, 11 Sep 2017 11:21:56 -0500
+Subject: [PATCH 8/8] Add openssl configuration for musl targets
+
+---
+ src/bootstrap/native.rs | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs
+index 58148c7c8b..6cd5b011a5 100644
+--- a/src/bootstrap/native.rs
++++ b/src/bootstrap/native.rs
+@@ -401,17 +401,22 @@ impl Step for Openssl {
+             "arm-linux-androideabi" => "android",
+             "arm-unknown-linux-gnueabi" => "linux-armv4",
+             "arm-unknown-linux-gnueabihf" => "linux-armv4",
+-            "armv7-linux-androideabi" => "android-armv7",
++            "arm-unknown-linux-musleabi" => "linux-armv4",
++            "arm-unknown-linux-musleabihf" => "linux-armv4",
++            "armv7-linux-androideabi" => "android-armv4",
+             "armv7-unknown-linux-gnueabihf" => "linux-armv4",
++            "armv7-unknown-linux-musleabihf" => "linux-armv4",
+             "i686-apple-darwin" => "darwin-i386-cc",
+             "i686-linux-android" => "android-x86",
+             "i686-unknown-freebsd" => "BSD-x86-elf",
+             "i686-unknown-linux-gnu" => "linux-elf",
+             "i686-unknown-linux-musl" => "linux-elf",
+             "mips-unknown-linux-gnu" => "linux-mips32",
++            "mips-unknown-linux-musl" => "linux-mips32",
+             "mips64-unknown-linux-gnuabi64" => "linux64-mips64",
+             "mips64el-unknown-linux-gnuabi64" => "linux64-mips64",
+             "mipsel-unknown-linux-gnu" => "linux-mips32",
++            "mipsel-unknown-linux-musl" => "linux-mips32",
+             "powerpc-unknown-linux-gnu" => "linux-ppc",
+             "powerpc64-unknown-linux-gnu" => "linux-ppc64",
+             "powerpc64le-unknown-linux-gnu" => "linux-ppc64le",
+-- 
+2.13.6
+

diff --git a/dev-lang/rust/files/0009-liblibc.patch 
b/dev-lang/rust/files/0009-liblibc.patch
new file mode 100644
index 0000000..d9d9c3b
--- /dev/null
+++ b/dev-lang/rust/files/0009-liblibc.patch
@@ -0,0 +1,16 @@
+diff --git a/src/liblibc/src/unix/mod.rs b/src/liblibc/src/unix/mod.rs
+index 62fc7f5e..d0a7c188 100644
+--- a/src/liblibc/src/unix/mod.rs
++++ b/src/liblibc/src/unix/mod.rs
+@@ -209,9 +209,8 @@ cfg_if! {
+     } else if #[cfg(all(not(stdbuild), feature = "use_std"))] {
+         // cargo build, don't pull in anything extra as the libstd  dep
+         // already pulls in all libs.
+-    } else if #[cfg(any(all(target_env = "musl", not(target_arch = 
"mips"))))] {
+-        #[link(name = "c", kind = "static", cfg(target_feature = 
"crt-static"))]
+-        #[link(name = "c", cfg(not(target_feature = "crt-static")))]
++    } else if #[cfg(target_env = "musl")] {
++        #[link(name = "c")]
+         extern {}
+     } else if #[cfg(target_os = "emscripten")] {
+         #[link(name = "c")]

diff --git a/dev-lang/rust/files/0010-static-linking-default.patch 
b/dev-lang/rust/files/0010-static-linking-default.patch
new file mode 100644
index 0000000..57836ad
--- /dev/null
+++ b/dev-lang/rust/files/0010-static-linking-default.patch
@@ -0,0 +1,13 @@
+diff --git a/src/librustc_back/target/linux_musl_base.rs 
b/src/librustc_back/target/linux_musl_base.rs
+index d99cb55cc5..bb786bf0f3 100644
+--- a/src/librustc_back/target/linux_musl_base.rs
++++ b/src/librustc_back/target/linux_musl_base.rs
+@@ -45,8 +45,6 @@ pub fn opts() -> TargetOptions {
+     
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-Wl,-(".to_string());
+     base.post_link_args.insert(LinkerFlavor::Gcc, vec!["-Wl,-)".to_string()]);
+ 
+-    // These targets statically link libc by default
+-    base.crt_static_default = true;
+     // These targets allow the user to choose between static and dynamic 
linking.
+     base.crt_static_respected = true;
+ 

diff --git a/dev-lang/rust/files/llvm-musl-fixes.patch 
b/dev-lang/rust/files/llvm-musl-fixes.patch
new file mode 100644
index 0000000..c683835
--- /dev/null
+++ b/dev-lang/rust/files/llvm-musl-fixes.patch
@@ -0,0 +1,33 @@
+diff --git a/src/llvm/include/llvm/Analysis/TargetLibraryInfo.def 
b/src/llvm/include/llvm/Analysis/TargetLibraryInfo.def
+index 7798e3c..ade2b96 100644
+--- a/src/llvm/include/llvm/Analysis/TargetLibraryInfo.def
++++ b/src/llvm/include/llvm/Analysis/TargetLibraryInfo.def
+@@ -27,6 +27,15 @@
+ #define TLI_DEFINE_STRING_INTERNAL(string_repr) string_repr,
+ #endif
+ 
++// avoid name conflicts with musl-libc
++#undef fopen64
++#undef fseeko64
++#undef ftello64
++#undef fstat64
++#undef lstat64
++#undef stat64
++#undef tmpfile64
++
+ /// void *new(unsigned int);
+ TLI_DEFINE_ENUM_INTERNAL(msvc_new_int)
+ TLI_DEFINE_STRING_INTERNAL("??2@YAPAXI@Z")
+diff --git a/src/llvm/lib/Support/DynamicLibrary.cpp 
b/src/llvm/lib/Support/DynamicLibrary.cpp
+index 9a7aeb5..e98ad80 100644
+--- a/src/llvm/lib/Support/DynamicLibrary.cpp
++++ b/src/llvm/lib/Support/DynamicLibrary.cpp
+@@ -143,7 +143,7 @@ void* DynamicLibrary::SearchForAddressOfSymbol(const char 
*symbolName) {
+ // On linux we have a weird situation. The stderr/out/in symbols are both
+ // macros and global variables because of standards requirements. So, we
+ // boldly use the EXPLICIT_SYMBOL macro without checking for a #define first.
+-#if defined(__linux__) and !defined(__ANDROID__)
++#if defined(__linux__) && defined(__GLIBC__)
+   {
+     EXPLICIT_SYMBOL(stderr);
+     EXPLICIT_SYMBOL(stdout);

diff --git a/dev-lang/rust/metadata.xml b/dev-lang/rust/metadata.xml
new file mode 100644
index 0000000..f170659
--- /dev/null
+++ b/dev-lang/rust/metadata.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd";>
+<pkgmetadata>
+  <maintainer type="project">
+    <email>r...@gentoo.org</email>
+    <name>Rust Project</name>
+  </maintainer>
+  <use>
+    <flag name="jemalloc">Use <pkg>dev-libs/jemalloc</pkg> for 
allocations</flag>
+    <flag name="system-llvm">Use system <pkg>sys-devel/llvm</pkg> in
+    place of the bundled one</flag>
+  </use>
+</pkgmetadata>

diff --git a/dev-lang/rust/rust-1.21.0.ebuild b/dev-lang/rust/rust-1.21.0.ebuild
new file mode 100644
index 0000000..b10900c
--- /dev/null
+++ b/dev-lang/rust/rust-1.21.0.ebuild
@@ -0,0 +1,234 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+LLVM_MAX_SLOT=4
+PYTHON_COMPAT=( python2_7 )
+
+inherit python-any-r1 versionator toolchain-funcs llvm
+
+if [[ ${PV} = *beta* ]]; then
+       betaver=${PV//*beta}
+       BETA_SNAPSHOT="${betaver:0:4}-${betaver:4:2}-${betaver:6:2}"
+       MY_P="rustc-beta"
+       SLOT="beta/${PV}"
+       SRC="${BETA_SNAPSHOT}/rustc-beta-src.tar.xz"
+       KEYWORDS=""
+else
+       ABI_VER="$(get_version_component_range 1-2)"
+       SLOT="stable/${ABI_VER}"
+       MY_P="rustc-${PV}"
+       SRC="${MY_P}-src.tar.xz"
+       KEYWORDS="~amd64 ~arm ~x86"
+fi
+
+case "${CHOST}" in
+       armv7a-hardfloat-*)
+               RUSTARCH=armv7 ;;
+       arm*)
+               RUSTARCH=arm ;;
+       *)
+               RUSTARCH=${CHOST%%-*} ;;
+esac
+case "${CHOST}" in
+       armv7a-hardfloat-*)
+               RUSTLIBC=${ELIBC/glibc/gnu}eabihf ;;
+       arm*)
+               RUSTLIBC=${ELIBC/glibc/gnu}eabi ;;
+       *)
+               RUSTLIBC=${ELIBC/glibc/gnu} ;;
+esac
+RUSTHOST=${RUSTARCH}-unknown-${KERNEL}-${RUSTLIBC}
+STAGE0_VERSION="1.$(($(get_version_component_range 2) - 1)).0"
+
+DESCRIPTION="Systems programming language from Mozilla"
+HOMEPAGE="https://www.rust-lang.org/";
+
+SRC_URI="https://static.rust-lang.org/dist/${SRC} -> rustc-${PV}-src.tar.xz
+       amd64? (
+               elibc_glibc? ( 
https://static.rust-lang.org/dist/rust-${STAGE0_VERSION}-x86_64-unknown-linux-gnu.tar.xz
 )
+               elibc_musl? ( 
https://portage.smaeul.xyz/distfiles/rust-${STAGE0_VERSION}-x86_64-unknown-linux-musl.tar.xz
 )
+       )
+       arm? (
+               elibc_glibc? (
+                       
https://static.rust-lang.org/dist/rust-${STAGE0_VERSION}-arm-unknown-linux-gnueabi.tar.xz
+                       
https://static.rust-lang.org/dist/rust-${STAGE0_VERSION}-armv7-unknown-linux-gnueabihf.tar.xz
+               )
+               elibc_musl? (
+                       
https://portage.smaeul.xyz/distfiles/rust-${STAGE0_VERSION}-arm-unknown-linux-musleabi.tar.xz
+                       
https://portage.smaeul.xyz/distfiles/rust-${STAGE0_VERSION}-armv7-unknown-linux-musleabihf.tar.xz
+               )
+       )
+       x86? (
+               elibc_glibc? ( 
https://static.rust-lang.org/dist/rust-${STAGE0_VERSION}-i686-unknown-linux-gnu.tar.xz
 )
+               elibc_musl? ( 
https://portage.smaeul.xyz/distfiles/rust-${STAGE0_VERSION}-i686-unknown-linux-musl.tar.xz
 )
+       )
+"
+
+LICENSE="|| ( MIT Apache-2.0 ) BSD-1 BSD-2 BSD-4 UoI-NCSA"
+
+IUSE="debug doc jemalloc system-llvm"
+REQUIRED_USE=""
+
+RDEPEND="
+       system-llvm? ( sys-devel/llvm:4 )
+"
+DEPEND="${RDEPEND}
+       ${PYTHON_DEPS}
+       >=sys-devel/gcc-4.7
+       !system-llvm? (
+               >=dev-util/cmake-3.4.3
+               dev-util/ninja
+       )
+"
+
+PDEPEND=">=app-eselect/eselect-rust-0.3_pre20150425
+       dev-util/cargo"
+
+PATCHES=(
+       "${FILESDIR}/0001-Explicitly-run-perl-for-OpenSSL-Configure.patch"
+       
"${FILESDIR}/0002-Require-rlibs-for-dependent-crates-when-linking-stat.patch"
+       
"${FILESDIR}/0003-Adjust-dependency-resolution-errors-to-be-more-consi.patch"
+       
"${FILESDIR}/0004-Require-static-native-libraries-when-linking-static-.patch"
+       "${FILESDIR}/0005-Remove-nostdlib-and-musl_root-from-musl-targets.patch"
+       "${FILESDIR}/0006-Prefer-libgcc_eh-over-libunwind-for-musl.patch"
+       "${FILESDIR}/0007-Fix-LLVM-build.patch"
+       "${FILESDIR}/0008-Add-openssl-configuration-for-musl-targets.patch"
+       "${FILESDIR}/0009-liblibc.patch"
+       "${FILESDIR}/0010-static-linking-default.patch"
+       "${FILESDIR}/llvm-musl-fixes.patch"
+)
+
+S="${WORKDIR}/${MY_P}-src"
+
+toml_usex() {
+       usex "$1" true false
+}
+
+pkg_setup() {
+       export RUST_BACKTRACE=1
+       if use system-llvm; then
+               llvm_pkg_setup
+               local llvm_config="$(get_llvm_prefix 
"$LLVM_MAX_SLOT")/bin/llvm-config"
+
+               export LLVM_LINK_SHARED=1
+               export RUSTFLAGS="$RUSTFLAGS -Lnative=$("$llvm_config" 
--libdir)"
+       fi
+
+       python-any-r1_pkg_setup
+}
+
+src_prepare() {
+       default
+
+       "${WORKDIR}/rust-${STAGE0_VERSION}-${RUSTHOST}/install.sh" \
+               --prefix="${WORKDIR}/stage0" \
+               --components=rust-std-${RUSTHOST},rustc,cargo \
+               --disable-ldconfig \
+               || die
+}
+
+src_configure() {
+       cat <<- EOF > "${S}"/config.toml
+       [llvm]
+       ninja = true
+       optimize = $(toml_usex !debug)
+       assertions = $(toml_usex debug)
+       [build]
+       build = "${RUSTHOST}"
+       host = ["${RUSTHOST}"]
+       target = ["${RUSTHOST}"]
+       cargo = "${WORKDIR}/stage0/bin/cargo"
+       rustc = "${WORKDIR}/stage0/bin/rustc"
+       docs = $(toml_usex doc)
+       compiler-docs = $(toml_usex doc)
+       submodules = false
+       python = "${EPYTHON}"
+       locked-deps = true
+       vendor = true
+       verbose = 2
+       [install]
+       prefix = "${EPREFIX}/usr"
+       libdir = "$(get_libdir)/${P}"
+       mandir = "share/${P}/man"
+       docdir = "share/doc/${P}"
+       [rust]
+       optimize = $(toml_usex !debug)
+       debug-assertions = $(toml_usex debug)
+       debuginfo = $(toml_usex debug)
+       use-jemalloc = $(toml_usex jemalloc)
+       channel = "${SLOT%%/*}"
+       rpath = false
+       optimize-tests = $(toml_usex !debug)
+       [dist]
+       src-tarball = false
+       [target.${RUSTHOST}]
+       cc = "$(tc-getCC)"
+       cxx = "$(tc-getCXX)"
+       crt-static = false
+       EOF
+       use system-llvm && cat <<- EOF >> "${S}"/config.toml
+       llvm-config = "$(get_llvm_prefix "$LLVM_MAX_SLOT")/bin/llvm-config"
+       EOF
+}
+
+src_compile() {
+       ./x.py build || die
+}
+
+src_install() {
+       env DESTDIR="${D}" ./x.py install || die
+
+       rm "${D}/usr/$(get_libdir)/${P}/rustlib/components" || die
+       rm "${D}/usr/$(get_libdir)/${P}/rustlib/install.log" || die
+       rm "${D}/usr/$(get_libdir)/${P}/rustlib/manifest-rust-std-${RUSTHOST}" 
|| die
+       rm "${D}/usr/$(get_libdir)/${P}/rustlib/manifest-rustc" || die
+       rm "${D}/usr/$(get_libdir)/${P}/rustlib/rust-installer-version" || die
+       rm "${D}/usr/$(get_libdir)/${P}/rustlib/uninstall.sh" || die
+
+       mv "${D}/usr/bin/rustc" "${D}/usr/bin/rustc-${PV}" || die
+       mv "${D}/usr/bin/rustdoc" "${D}/usr/bin/rustdoc-${PV}" || die
+       mv "${D}/usr/bin/rust-gdb" "${D}/usr/bin/rust-gdb-${PV}" || die
+       mv "${D}/usr/bin/rust-lldb" "${D}/usr/bin/rust-lldb-${PV}" || die
+
+       dodoc COPYRIGHT
+
+       cat <<-EOF > "${T}"/50${P}
+       LDPATH="/usr/$(get_libdir)/${P}"
+       MANPATH="/usr/share/${P}/man"
+       EOF
+       doenvd "${T}"/50${P}
+
+       cat <<-EOF > "${T}/provider-${P}"
+       /usr/bin/rustdoc
+       /usr/bin/rust-gdb
+       /usr/bin/rust-lldb
+       EOF
+       dodir /etc/env.d/rust
+       insinto /etc/env.d/rust
+       doins "${T}/provider-${P}"
+}
+
+pkg_postinst() {
+       eselect rust update --if-unset
+
+       elog "Rust installs a helper script for calling GDB now,"
+       elog "for your convenience it is installed under 
/usr/bin/rust-gdb-${PV}."
+
+       if has_version app-editors/emacs || has_version app-editors/emacs-vcs; 
then
+               elog "install app-emacs/rust-mode to get emacs support for 
rust."
+       fi
+
+       if has_version app-editors/gvim || has_version app-editors/vim; then
+               elog "install app-vim/rust-vim to get vim support for rust."
+       fi
+
+       if has_version 'app-shells/zsh'; then
+               elog "install app-shells/rust-zshcomp to get zsh completion for 
rust."
+       fi
+}
+
+pkg_postrm() {
+       eselect rust unset --if-invalid
+}

Reply via email to