Skip to content

Commit f8e3584

Browse files
committed
Rollup merge of #49563 - japaric:std-thumb, r=alexcrichton
add a dist builder to build rust-std components for the THUMB targets the rust-std component only contains the core and compiler-builtins (+c +mem) crates cc #49382 - I'm not entirely sure if this PR alone will produce rust-std components installable by rustup or if something else needs to be changed - I could have done the THUMB builds in an existing builder / image; I wasn't sure if that was a good idea so I added a new image - I could build other crates like alloc into the rust-std component but, AFAICT, that would require calling Cargo a second time (one for alloc and one for compiler-builtins), or have alloc depend on compiler-builtins (#49503 will perform that change) *and* have alloc resurface the "c" and "mem" Cargo features. r? @alexcrichton
2 parents 1191bb1 + b1015f5 commit f8e3584

File tree

7 files changed

+78
-36
lines changed

7 files changed

+78
-36
lines changed

src/bootstrap/compile.rs

+44-34
Original file line numberDiff line numberDiff line change
@@ -140,48 +140,58 @@ 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 a few no_std crates
149+
cargo.arg("--features").arg("c mem")
150+
.args(&["-p", "alloc"])
151+
.args(&["-p", "compiler_builtins"])
152+
.args(&["-p", "std_unicode"])
153+
.arg("--manifest-path")
154+
.arg(build.src.join("src/rustc/compiler_builtins_shim/Cargo.toml"));
155+
} else {
156+
let mut features = build.std_features();
157+
158+
// When doing a local rebuild we tell cargo that we're stage1 rather than
159+
// stage0. This works fine if the local rust and being-built rust have the
160+
// same view of what the default allocator is, but fails otherwise. Since
161+
// we don't have a way to express an allocator preference yet, work
162+
// around the issue in the case of a local rebuild with jemalloc disabled.
163+
if compiler.stage == 0 && build.local_rebuild && !build.config.use_jemalloc {
164+
features.push_str(" force_alloc_system");
165+
}
157166

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

173-
cargo.arg("--features").arg(features)
174-
.arg("--manifest-path")
175-
.arg(build.src.join("src/libstd/Cargo.toml"));
182+
cargo.arg("--features").arg(features)
183+
.arg("--manifest-path")
184+
.arg(build.src.join("src/libstd/Cargo.toml"));
176185

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);
186+
if let Some(target) = build.config.target_config.get(&target) {
187+
if let Some(ref jemalloc) = target.jemalloc {
188+
cargo.env("JEMALLOC_OVERRIDE", jemalloc);
189+
}
180190
}
181-
}
182-
if target.contains("musl") {
183-
if let Some(p) = build.musl_root(target) {
184-
cargo.env("MUSL_ROOT", p);
191+
if target.contains("musl") {
192+
if let Some(p) = build.musl_root(target) {
193+
cargo.env("MUSL_ROOT", p);
194+
}
185195
}
186196
}
187197
}

src/bootstrap/config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ pub struct Target {
161161
pub crt_static: Option<bool>,
162162
pub musl_root: Option<PathBuf>,
163163
pub qemu_rootfs: Option<PathBuf>,
164+
pub no_std: bool,
164165
}
165166

166167
/// 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
@@ -642,7 +642,12 @@ impl Step for Std {
642642
if build.hosts.iter().any(|t| t == target) {
643643
builder.ensure(compile::Rustc { compiler, target });
644644
} else {
645-
builder.ensure(compile::Test { compiler, target });
645+
if build.no_std(target) == Some(true) {
646+
// the `test` doesn't compile for no-std targets
647+
builder.ensure(compile::Std { compiler, target });
648+
} else {
649+
builder.ensure(compile::Test { compiler, target });
650+
}
646651
}
647652

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

src/bootstrap/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,12 @@ impl Build {
750750
.map(|p| &**p)
751751
}
752752

753+
/// Returns true if this is a no-std `target`, if defined
754+
fn no_std(&self, target: Interned<String>) -> Option<bool> {
755+
self.config.target_config.get(&target)
756+
.map(|t| t.no_std)
757+
}
758+
753759
/// Returns whether the target will be tested using the `remote-test-client`
754760
/// and `remote-test-server` binaries.
755761
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.contains("-none-") {
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 *-none-* 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,

src/ci/docker/dist-various-1/Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2020
bzip2 \
2121
patch \
2222
libssl-dev \
23-
pkg-config
23+
pkg-config \
24+
gcc-arm-none-eabi \
25+
libnewlib-arm-none-eabi
2426

2527
WORKDIR /build
2628

@@ -86,6 +88,10 @@ ENV TARGETS=$TARGETS,armv7-unknown-linux-musleabihf
8688
ENV TARGETS=$TARGETS,aarch64-unknown-linux-musl
8789
ENV TARGETS=$TARGETS,sparc64-unknown-linux-gnu
8890
ENV TARGETS=$TARGETS,x86_64-unknown-redox
91+
ENV TARGETS=$TARGETS,thumbv6m-none-eabi
92+
ENV TARGETS=$TARGETS,thumbv7m-none-eabi
93+
ENV TARGETS=$TARGETS,thumbv7em-none-eabi
94+
ENV TARGETS=$TARGETS,thumbv7em-none-eabihf
8995

9096
# FIXME: remove armv5te vars after https://github.com/alexcrichton/cc-rs/issues/271
9197
# get fixed and cc update

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)