Skip to content

Commit 68b54a5

Browse files
committed
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
1 parent cb1f898 commit 68b54a5

File tree

7 files changed

+87
-35
lines changed

7 files changed

+87
-35
lines changed

src/bootstrap/compile.rs

+41-34
Original file line numberDiff line numberDiff line change
@@ -140,48 +140,55 @@ pub fn std_cargo(build: &Builder,
140140
compiler: &Compiler,
141141
target: Interned<String>,
142142
cargo: &mut Command) {
143-
let mut features = build.std_features();
144-
145143
if let Some(target) = env::var_os("MACOSX_STD_DEPLOYMENT_TARGET") {
146144
cargo.env("MACOSX_DEPLOYMENT_TARGET", target);
147145
}
148146

149-
// When doing a local rebuild we tell cargo that we're stage1 rather than
150-
// stage0. This works fine if the local rust and being-built rust have the
151-
// same view of what the default allocator is, but fails otherwise. Since
152-
// we don't have a way to express an allocator preference yet, work
153-
// around the issue in the case of a local rebuild with jemalloc disabled.
154-
if compiler.stage == 0 && build.local_rebuild && !build.config.use_jemalloc {
155-
features.push_str(" force_alloc_system");
156-
}
147+
if build.no_std(target) == Some(true) {
148+
// for no-std targets we only compile core and compiler-builtins
149+
cargo.arg("--features").arg("c mem")
150+
.arg("--manifest-path")
151+
.arg(build.src.join("src/rustc/compiler_builtins_shim/Cargo.toml"));
152+
} else {
153+
let mut features = build.std_features();
154+
155+
// When doing a local rebuild we tell cargo that we're stage1 rather than
156+
// stage0. This works fine if the local rust and being-built rust have the
157+
// same view of what the default allocator is, but fails otherwise. Since
158+
// we don't have a way to express an allocator preference yet, work
159+
// around the issue in the case of a local rebuild with jemalloc disabled.
160+
if compiler.stage == 0 && build.local_rebuild && !build.config.use_jemalloc {
161+
features.push_str(" force_alloc_system");
162+
}
157163

158-
if compiler.stage != 0 && build.config.sanitizers {
159-
// This variable is used by the sanitizer runtime crates, e.g.
160-
// rustc_lsan, to build the sanitizer runtime from C code
161-
// When this variable is missing, those crates won't compile the C code,
162-
// so we don't set this variable during stage0 where llvm-config is
163-
// missing
164-
// We also only build the runtimes when --enable-sanitizers (or its
165-
// config.toml equivalent) is used
166-
let llvm_config = build.ensure(native::Llvm {
167-
target: build.config.build,
168-
emscripten: false,
169-
});
170-
cargo.env("LLVM_CONFIG", llvm_config);
171-
}
164+
if compiler.stage != 0 && build.config.sanitizers {
165+
// This variable is used by the sanitizer runtime crates, e.g.
166+
// rustc_lsan, to build the sanitizer runtime from C code
167+
// When this variable is missing, those crates won't compile the C code,
168+
// so we don't set this variable during stage0 where llvm-config is
169+
// missing
170+
// We also only build the runtimes when --enable-sanitizers (or its
171+
// config.toml equivalent) is used
172+
let llvm_config = build.ensure(native::Llvm {
173+
target: build.config.build,
174+
emscripten: false,
175+
});
176+
cargo.env("LLVM_CONFIG", llvm_config);
177+
}
172178

173-
cargo.arg("--features").arg(features)
174-
.arg("--manifest-path")
175-
.arg(build.src.join("src/libstd/Cargo.toml"));
179+
cargo.arg("--features").arg(features)
180+
.arg("--manifest-path")
181+
.arg(build.src.join("src/libstd/Cargo.toml"));
176182

177-
if let Some(target) = build.config.target_config.get(&target) {
178-
if let Some(ref jemalloc) = target.jemalloc {
179-
cargo.env("JEMALLOC_OVERRIDE", jemalloc);
183+
if let Some(target) = build.config.target_config.get(&target) {
184+
if let Some(ref jemalloc) = target.jemalloc {
185+
cargo.env("JEMALLOC_OVERRIDE", jemalloc);
186+
}
180187
}
181-
}
182-
if target.contains("musl") {
183-
if let Some(p) = build.musl_root(target) {
184-
cargo.env("MUSL_ROOT", p);
188+
if target.contains("musl") {
189+
if let Some(p) = build.musl_root(target) {
190+
cargo.env("MUSL_ROOT", p);
191+
}
185192
}
186193
}
187194
}

src/bootstrap/config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ pub struct Target {
159159
pub crt_static: Option<bool>,
160160
pub musl_root: Option<PathBuf>,
161161
pub qemu_rootfs: Option<PathBuf>,
162+
pub no_std: bool,
162163
}
163164

164165
/// Structure of the `config.toml` file that configuration is read from.

src/bootstrap/dist.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,12 @@ impl Step for Std {
649649
if build.hosts.iter().any(|t| t == target) {
650650
builder.ensure(compile::Rustc { compiler, target });
651651
} else {
652-
builder.ensure(compile::Test { compiler, target });
652+
if build.no_std(target) == Some(true) {
653+
// the `test` doesn't compile for no-std targets
654+
builder.ensure(compile::Std { compiler, target });
655+
} else {
656+
builder.ensure(compile::Test { compiler, target });
657+
}
653658
}
654659

655660
let image = tmpdir(build).join(format!("{}-{}-image", name, target));

src/bootstrap/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,12 @@ impl Build {
709709
.map(|p| &**p)
710710
}
711711

712+
/// Returns true if this is a no-std `target`, if defined
713+
fn no_std(&self, target: Interned<String>) -> Option<bool> {
714+
self.config.target_config.get(&target)
715+
.map(|t| t.no_std)
716+
}
717+
712718
/// Returns whether the target will be tested using the `remote-test-client`
713719
/// and `remote-test-server` binaries.
714720
fn remote_tested(&self, target: Interned<String>) -> bool {

src/bootstrap/sanity.rs

+13
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,19 @@ pub fn check(build: &mut Build) {
169169
panic!("the iOS target is only supported on macOS");
170170
}
171171

172+
if target.starts_with("thumbv") {
173+
if build.no_std(*target).is_none() {
174+
let target = build.config.target_config.entry(target.clone())
175+
.or_insert(Default::default());
176+
177+
target.no_std = true;
178+
}
179+
180+
if build.no_std(*target) == Some(false) {
181+
panic!("All the THUMB targets are no-std targets")
182+
}
183+
}
184+
172185
// Make sure musl-root is valid
173186
if target.contains("musl") {
174187
// If this is a native target (host is also musl) and no musl-root is given,
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM ubuntu:17.10
2+
3+
COPY scripts/cross-apt-packages.sh /scripts/
4+
RUN sh /scripts/cross-apt-packages.sh
5+
6+
RUN apt-get build-dep -y clang llvm && apt-get install -y --no-install-recommends \
7+
gcc-arm-none-eabi \
8+
libnewlib-arm-none-eabi
9+
10+
COPY scripts/sccache.sh /scripts/
11+
RUN sh /scripts/sccache.sh
12+
13+
ENV TARGETS=thumbv6m-none-eabi
14+
ENV TARGETS=$TARGETS,thumbv7m-none-eabi
15+
ENV TARGETS=$TARGETS,thumbv7em-none-eabi
16+
ENV TARGETS=$TARGETS,thumbv7em-none-eabihf
17+
18+
ENV RUST_CONFIGURE_ARGS --disable-docs
19+
ENV SCRIPT python2.7 ../x.py dist --target $TARGETS

src/rustc/compiler_builtins_shim/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ cc = "1.0.1"
3535
[features]
3636
c = []
3737
default = ["c", "rustbuild", "compiler-builtins"]
38+
mem = []
3839
rustbuild = []
3940
compiler-builtins = []

0 commit comments

Comments
 (0)