From 68b54a5f4368ba1a66ae7d330bb95a8d6eb08c3c Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 1 Apr 2018 18:50:21 +0200 Subject: [PATCH 1/7] add a dist-thumb builder to build rust-std for the THUMB targets the rust-std component only contains the core and compiler-builtins (+c +mem) crates cc #49382 --- src/bootstrap/compile.rs | 75 +++++++++++---------- src/bootstrap/config.rs | 1 + src/bootstrap/dist.rs | 7 +- src/bootstrap/lib.rs | 6 ++ src/bootstrap/sanity.rs | 13 ++++ src/ci/docker/dist-various-3/Dockerfile | 19 ++++++ src/rustc/compiler_builtins_shim/Cargo.toml | 1 + 7 files changed, 87 insertions(+), 35 deletions(-) create mode 100644 src/ci/docker/dist-various-3/Dockerfile diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 9f33935b6e933..eaf4ab272c68e 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -140,48 +140,55 @@ pub fn std_cargo(build: &Builder, compiler: &Compiler, target: Interned, cargo: &mut Command) { - let mut features = build.std_features(); - if let Some(target) = env::var_os("MACOSX_STD_DEPLOYMENT_TARGET") { cargo.env("MACOSX_DEPLOYMENT_TARGET", target); } - // When doing a local rebuild we tell cargo that we're stage1 rather than - // stage0. This works fine if the local rust and being-built rust have the - // same view of what the default allocator is, but fails otherwise. Since - // we don't have a way to express an allocator preference yet, work - // around the issue in the case of a local rebuild with jemalloc disabled. - if compiler.stage == 0 && build.local_rebuild && !build.config.use_jemalloc { - features.push_str(" force_alloc_system"); - } + if build.no_std(target) == Some(true) { + // for no-std targets we only compile core and compiler-builtins + cargo.arg("--features").arg("c mem") + .arg("--manifest-path") + .arg(build.src.join("src/rustc/compiler_builtins_shim/Cargo.toml")); + } else { + let mut features = build.std_features(); + + // When doing a local rebuild we tell cargo that we're stage1 rather than + // stage0. This works fine if the local rust and being-built rust have the + // same view of what the default allocator is, but fails otherwise. Since + // we don't have a way to express an allocator preference yet, work + // around the issue in the case of a local rebuild with jemalloc disabled. + if compiler.stage == 0 && build.local_rebuild && !build.config.use_jemalloc { + features.push_str(" force_alloc_system"); + } - if compiler.stage != 0 && build.config.sanitizers { - // This variable is used by the sanitizer runtime crates, e.g. - // rustc_lsan, to build the sanitizer runtime from C code - // When this variable is missing, those crates won't compile the C code, - // so we don't set this variable during stage0 where llvm-config is - // missing - // We also only build the runtimes when --enable-sanitizers (or its - // config.toml equivalent) is used - let llvm_config = build.ensure(native::Llvm { - target: build.config.build, - emscripten: false, - }); - cargo.env("LLVM_CONFIG", llvm_config); - } + if compiler.stage != 0 && build.config.sanitizers { + // This variable is used by the sanitizer runtime crates, e.g. + // rustc_lsan, to build the sanitizer runtime from C code + // When this variable is missing, those crates won't compile the C code, + // so we don't set this variable during stage0 where llvm-config is + // missing + // We also only build the runtimes when --enable-sanitizers (or its + // config.toml equivalent) is used + let llvm_config = build.ensure(native::Llvm { + target: build.config.build, + emscripten: false, + }); + cargo.env("LLVM_CONFIG", llvm_config); + } - cargo.arg("--features").arg(features) - .arg("--manifest-path") - .arg(build.src.join("src/libstd/Cargo.toml")); + cargo.arg("--features").arg(features) + .arg("--manifest-path") + .arg(build.src.join("src/libstd/Cargo.toml")); - if let Some(target) = build.config.target_config.get(&target) { - if let Some(ref jemalloc) = target.jemalloc { - cargo.env("JEMALLOC_OVERRIDE", jemalloc); + if let Some(target) = build.config.target_config.get(&target) { + if let Some(ref jemalloc) = target.jemalloc { + cargo.env("JEMALLOC_OVERRIDE", jemalloc); + } } - } - if target.contains("musl") { - if let Some(p) = build.musl_root(target) { - cargo.env("MUSL_ROOT", p); + if target.contains("musl") { + if let Some(p) = build.musl_root(target) { + cargo.env("MUSL_ROOT", p); + } } } } diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 33850debd3bdb..81b60364ebba1 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -159,6 +159,7 @@ pub struct Target { pub crt_static: Option, pub musl_root: Option, pub qemu_rootfs: Option, + pub no_std: bool, } /// Structure of the `config.toml` file that configuration is read from. diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 23b7b265a94be..32257fefbf97b 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -649,7 +649,12 @@ impl Step for Std { if build.hosts.iter().any(|t| t == target) { builder.ensure(compile::Rustc { compiler, target }); } else { - builder.ensure(compile::Test { compiler, target }); + if build.no_std(target) == Some(true) { + // the `test` doesn't compile for no-std targets + builder.ensure(compile::Std { compiler, target }); + } else { + builder.ensure(compile::Test { compiler, target }); + } } let image = tmpdir(build).join(format!("{}-{}-image", name, target)); diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 833faf3618d67..d1765b3def998 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -709,6 +709,12 @@ impl Build { .map(|p| &**p) } + /// Returns true if this is a no-std `target`, if defined + fn no_std(&self, target: Interned) -> Option { + self.config.target_config.get(&target) + .map(|t| t.no_std) + } + /// Returns whether the target will be tested using the `remote-test-client` /// and `remote-test-server` binaries. fn remote_tested(&self, target: Interned) -> bool { diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index 5184cca653c4b..cd67f1eb46414 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -169,6 +169,19 @@ pub fn check(build: &mut Build) { panic!("the iOS target is only supported on macOS"); } + if target.starts_with("thumbv") { + if build.no_std(*target).is_none() { + let target = build.config.target_config.entry(target.clone()) + .or_insert(Default::default()); + + target.no_std = true; + } + + if build.no_std(*target) == Some(false) { + panic!("All the THUMB targets are no-std targets") + } + } + // Make sure musl-root is valid if target.contains("musl") { // If this is a native target (host is also musl) and no musl-root is given, diff --git a/src/ci/docker/dist-various-3/Dockerfile b/src/ci/docker/dist-various-3/Dockerfile new file mode 100644 index 0000000000000..06c80982f3cd2 --- /dev/null +++ b/src/ci/docker/dist-various-3/Dockerfile @@ -0,0 +1,19 @@ +FROM ubuntu:17.10 + +COPY scripts/cross-apt-packages.sh /scripts/ +RUN sh /scripts/cross-apt-packages.sh + +RUN apt-get build-dep -y clang llvm && apt-get install -y --no-install-recommends \ + gcc-arm-none-eabi \ + libnewlib-arm-none-eabi + +COPY scripts/sccache.sh /scripts/ +RUN sh /scripts/sccache.sh + +ENV TARGETS=thumbv6m-none-eabi +ENV TARGETS=$TARGETS,thumbv7m-none-eabi +ENV TARGETS=$TARGETS,thumbv7em-none-eabi +ENV TARGETS=$TARGETS,thumbv7em-none-eabihf + +ENV RUST_CONFIGURE_ARGS --disable-docs +ENV SCRIPT python2.7 ../x.py dist --target $TARGETS diff --git a/src/rustc/compiler_builtins_shim/Cargo.toml b/src/rustc/compiler_builtins_shim/Cargo.toml index 608e5f5f36d02..7d8423ca84eb4 100644 --- a/src/rustc/compiler_builtins_shim/Cargo.toml +++ b/src/rustc/compiler_builtins_shim/Cargo.toml @@ -35,5 +35,6 @@ cc = "1.0.1" [features] c = [] default = ["c", "rustbuild", "compiler-builtins"] +mem = [] rustbuild = [] compiler-builtins = [] From 2a99c027eb95c471daf50815ec30504c42179300 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 1 Apr 2018 18:56:13 +0200 Subject: [PATCH 2/7] add new image to .travis.yml --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 091a5abdaa216..a67c6c79bbdf8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -116,6 +116,8 @@ matrix: if: branch = auto - env: IMAGE=dist-various-2 DEPLOY=1 if: branch = auto + - env: IMAGE=dist-various-3 DEPLOY=1 + if: branch = auto - env: IMAGE=dist-aarch64-linux DEPLOY=1 if: branch = auto - env: IMAGE=dist-android DEPLOY=1 From d0693548cdb4fe9e380f7c607c53a2e16821ebc2 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 3 Apr 2018 08:26:24 +0200 Subject: [PATCH 3/7] merge dist-various-3 into dist-various-1 --- .travis.yml | 2 -- src/ci/docker/dist-various-1/Dockerfile | 8 +++++++- src/ci/docker/dist-various-3/Dockerfile | 19 ------------------- 3 files changed, 7 insertions(+), 22 deletions(-) delete mode 100644 src/ci/docker/dist-various-3/Dockerfile diff --git a/.travis.yml b/.travis.yml index a67c6c79bbdf8..091a5abdaa216 100644 --- a/.travis.yml +++ b/.travis.yml @@ -116,8 +116,6 @@ matrix: if: branch = auto - env: IMAGE=dist-various-2 DEPLOY=1 if: branch = auto - - env: IMAGE=dist-various-3 DEPLOY=1 - if: branch = auto - env: IMAGE=dist-aarch64-linux DEPLOY=1 if: branch = auto - env: IMAGE=dist-android DEPLOY=1 diff --git a/src/ci/docker/dist-various-1/Dockerfile b/src/ci/docker/dist-various-1/Dockerfile index b398e9a3c92ef..e61757ff5eea9 100644 --- a/src/ci/docker/dist-various-1/Dockerfile +++ b/src/ci/docker/dist-various-1/Dockerfile @@ -20,7 +20,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ bzip2 \ patch \ libssl-dev \ - pkg-config + pkg-config \ + gcc-arm-none-eabi \ + libnewlib-arm-none-eabi WORKDIR /build @@ -78,6 +80,10 @@ ENV TARGETS=$TARGETS,armv7-unknown-linux-musleabihf ENV TARGETS=$TARGETS,aarch64-unknown-linux-musl ENV TARGETS=$TARGETS,sparc64-unknown-linux-gnu ENV TARGETS=$TARGETS,x86_64-unknown-redox +ENV TARGETS=$TARGETS,thumbv6m-none-eabi +ENV TARGETS=$TARGETS,thumbv7m-none-eabi +ENV TARGETS=$TARGETS,thumbv7em-none-eabi +ENV TARGETS=$TARGETS,thumbv7em-none-eabihf # FIXME: remove armv5te vars after https://github.com/alexcrichton/cc-rs/issues/271 # get fixed and cc update diff --git a/src/ci/docker/dist-various-3/Dockerfile b/src/ci/docker/dist-various-3/Dockerfile deleted file mode 100644 index 06c80982f3cd2..0000000000000 --- a/src/ci/docker/dist-various-3/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM ubuntu:17.10 - -COPY scripts/cross-apt-packages.sh /scripts/ -RUN sh /scripts/cross-apt-packages.sh - -RUN apt-get build-dep -y clang llvm && apt-get install -y --no-install-recommends \ - gcc-arm-none-eabi \ - libnewlib-arm-none-eabi - -COPY scripts/sccache.sh /scripts/ -RUN sh /scripts/sccache.sh - -ENV TARGETS=thumbv6m-none-eabi -ENV TARGETS=$TARGETS,thumbv7m-none-eabi -ENV TARGETS=$TARGETS,thumbv7em-none-eabi -ENV TARGETS=$TARGETS,thumbv7em-none-eabihf - -ENV RUST_CONFIGURE_ARGS --disable-docs -ENV SCRIPT python2.7 ../x.py dist --target $TARGETS From 862c839fb9e0ad5615443b7e8fa21b421e2e74eb Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 3 Apr 2018 08:29:09 +0200 Subject: [PATCH 4/7] extend no-std-ness check to all *-none-* targets --- src/bootstrap/sanity.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index cd67f1eb46414..1b1cec5f18c07 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -169,7 +169,7 @@ pub fn check(build: &mut Build) { panic!("the iOS target is only supported on macOS"); } - if target.starts_with("thumbv") { + if target.contains("-none-") { if build.no_std(*target).is_none() { let target = build.config.target_config.entry(target.clone()) .or_insert(Default::default()); @@ -178,7 +178,7 @@ pub fn check(build: &mut Build) { } if build.no_std(*target) == Some(false) { - panic!("All the THUMB targets are no-std targets") + panic!("All the *-none-* targets are no-std targets") } } From 14768f9b636ef345320ded41da5e9f3da7af3a81 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 4 Apr 2018 19:24:57 +0200 Subject: [PATCH 5/7] create a nostd crate the goal is to build, in a single Cargo invocation, several no-std crates that we want to put in the rust-std component of no-std targets. The nostd crate builds these crates: - core - compiler-builtin (with the "c" and "mem" features enabled) - alloc - std_unicode --- src/Cargo.lock | 10 ++++++++++ src/Cargo.toml | 1 + src/bootstrap/compile.rs | 8 ++++---- src/libnostd/Cargo.toml | 17 +++++++++++++++++ src/libnostd/lib.rs | 3 +++ 5 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 src/libnostd/Cargo.toml create mode 100644 src/libnostd/lib.rs diff --git a/src/Cargo.lock b/src/Cargo.lock index 1f7cf84cedbda..42ac9b3c49dee 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1081,6 +1081,16 @@ name = "nodrop" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "nostd" +version = "0.0.0" +dependencies = [ + "alloc 0.0.0", + "compiler_builtins 0.0.0", + "core 0.0.0", + "std_unicode 0.0.0", +] + [[package]] name = "num" version = "0.1.42" diff --git a/src/Cargo.toml b/src/Cargo.toml index 814c054c51e41..babf35d570b51 100644 --- a/src/Cargo.toml +++ b/src/Cargo.toml @@ -2,6 +2,7 @@ members = [ "bootstrap", "rustc", + "libnostd", "libstd", "libtest", "librustc_trans", diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index eaf4ab272c68e..a93b26ac2bae0 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -145,10 +145,10 @@ pub fn std_cargo(build: &Builder, } if build.no_std(target) == Some(true) { - // for no-std targets we only compile core and compiler-builtins - cargo.arg("--features").arg("c mem") - .arg("--manifest-path") - .arg(build.src.join("src/rustc/compiler_builtins_shim/Cargo.toml")); + // for no-std targets we compile a minimal nostd crate that only depends on crates that work + // without an OS + cargo.arg("--manifest-path") + .arg(build.src.join("src/libnostd/Cargo.toml")); } else { let mut features = build.std_features(); diff --git a/src/libnostd/Cargo.toml b/src/libnostd/Cargo.toml new file mode 100644 index 0000000000000..6919390d3e2a7 --- /dev/null +++ b/src/libnostd/Cargo.toml @@ -0,0 +1,17 @@ +[package] +authors = ["The Rust Project Developers"] +name = "nostd" +version = "0.0.0" +license = "MIT/Apache-2.0" +repository = "https://github.com/rust-lang/rust.git" +description = "(not) The Rust Standard Library" + +[lib] +name = "nostd" +path = "lib.rs" + +[dependencies] +alloc = { path = "../liballoc" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim", features = ["c", "mem"] } +core = { path = "../libcore" } +std_unicode = { path = "../libstd_unicode" } \ No newline at end of file diff --git a/src/libnostd/lib.rs b/src/libnostd/lib.rs new file mode 100644 index 0000000000000..d28afe2838e28 --- /dev/null +++ b/src/libnostd/lib.rs @@ -0,0 +1,3 @@ +#![feature(staged_api)] +#![no_std] +#![unstable(feature = "nostd", issue = "0")] From bca569f57c53e219270be72ed5976b8167fcd246 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 4 Apr 2018 22:23:33 +0200 Subject: [PATCH 6/7] Revert "create a nostd crate" This reverts commit 14768f9b636ef345320ded41da5e9f3da7af3a81. --- src/Cargo.lock | 10 ---------- src/Cargo.toml | 1 - src/bootstrap/compile.rs | 8 ++++---- src/libnostd/Cargo.toml | 17 ----------------- src/libnostd/lib.rs | 3 --- 5 files changed, 4 insertions(+), 35 deletions(-) delete mode 100644 src/libnostd/Cargo.toml delete mode 100644 src/libnostd/lib.rs diff --git a/src/Cargo.lock b/src/Cargo.lock index 42ac9b3c49dee..1f7cf84cedbda 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1081,16 +1081,6 @@ name = "nodrop" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "nostd" -version = "0.0.0" -dependencies = [ - "alloc 0.0.0", - "compiler_builtins 0.0.0", - "core 0.0.0", - "std_unicode 0.0.0", -] - [[package]] name = "num" version = "0.1.42" diff --git a/src/Cargo.toml b/src/Cargo.toml index babf35d570b51..814c054c51e41 100644 --- a/src/Cargo.toml +++ b/src/Cargo.toml @@ -2,7 +2,6 @@ members = [ "bootstrap", "rustc", - "libnostd", "libstd", "libtest", "librustc_trans", diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index a93b26ac2bae0..eaf4ab272c68e 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -145,10 +145,10 @@ pub fn std_cargo(build: &Builder, } if build.no_std(target) == Some(true) { - // for no-std targets we compile a minimal nostd crate that only depends on crates that work - // without an OS - cargo.arg("--manifest-path") - .arg(build.src.join("src/libnostd/Cargo.toml")); + // for no-std targets we only compile core and compiler-builtins + cargo.arg("--features").arg("c mem") + .arg("--manifest-path") + .arg(build.src.join("src/rustc/compiler_builtins_shim/Cargo.toml")); } else { let mut features = build.std_features(); diff --git a/src/libnostd/Cargo.toml b/src/libnostd/Cargo.toml deleted file mode 100644 index 6919390d3e2a7..0000000000000 --- a/src/libnostd/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -authors = ["The Rust Project Developers"] -name = "nostd" -version = "0.0.0" -license = "MIT/Apache-2.0" -repository = "https://github.com/rust-lang/rust.git" -description = "(not) The Rust Standard Library" - -[lib] -name = "nostd" -path = "lib.rs" - -[dependencies] -alloc = { path = "../liballoc" } -compiler_builtins = { path = "../rustc/compiler_builtins_shim", features = ["c", "mem"] } -core = { path = "../libcore" } -std_unicode = { path = "../libstd_unicode" } \ No newline at end of file diff --git a/src/libnostd/lib.rs b/src/libnostd/lib.rs deleted file mode 100644 index d28afe2838e28..0000000000000 --- a/src/libnostd/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -#![feature(staged_api)] -#![no_std] -#![unstable(feature = "nostd", issue = "0")] From b1015f5c5a4dcd6118b86ef5361371f04a7bce8b Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 4 Apr 2018 22:42:56 +0200 Subject: [PATCH 7/7] compile other no-std crates --- src/bootstrap/compile.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index eaf4ab272c68e..51e7a78831585 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -145,8 +145,11 @@ pub fn std_cargo(build: &Builder, } if build.no_std(target) == Some(true) { - // for no-std targets we only compile core and compiler-builtins + // for no-std targets we only compile a few no_std crates cargo.arg("--features").arg("c mem") + .args(&["-p", "alloc"]) + .args(&["-p", "compiler_builtins"]) + .args(&["-p", "std_unicode"]) .arg("--manifest-path") .arg(build.src.join("src/rustc/compiler_builtins_shim/Cargo.toml")); } else {