Auto merge of #128639 - folkertdev:rmake-thumb-none-qemu, r=jieyouxu · rust-lang/rust@2048386 (original) (raw)
``
1
`+
//! This test runs a basic application for thumb targets, using the cortex-m crate.
`
``
2
`+
//!
`
``
3
`+
//! These targets are very bare-metal: the first instruction the core runs on
`
``
4
`+
//! power-on is already user code. The cortex-m-rt has to initialize the stack, .data,
`
``
5
`+
//! .bss, enable the FPU if present, etc.
`
``
6
`+
//!
`
``
7
`+
//! This test builds and runs the applications for various thumb targets using qemu.
`
``
8
`+
//!
`
``
9
`+
//! How to run this
`
``
10
`+
//! $ ./x.py clean
`
``
11
`+
//! $ ./x.py test --target thumbv6m-none-eabi,thumbv7m-none-eabi tests/run-make
`
``
12
`+
//!
`
``
13
`` +
//! For supported targets, see example/.cargo/config.toml
``
``
14
`+
//!
`
``
15
`+
//! FIXME: https://github.com/rust-lang/rust/issues/128733 this test uses external
`
``
16
`+
//! dependencies, and needs an active internet connection
`
``
17
`+
//!
`
``
18
`+
//! FIXME: https://github.com/rust-lang/rust/issues/128734 extract bootstrap cargo
`
``
19
`+
//! to a proper command
`
``
20
+
``
21
`+
//@ only-thumb
`
``
22
+
``
23
`+
use std::path::PathBuf;
`
``
24
+
``
25
`+
use run_make_support::{cmd, env_var, path_helpers, target};
`
``
26
+
``
27
`+
const CRATE: &str = "example";
`
``
28
+
``
29
`+
fn main() {
`
``
30
`+
std::env::set_current_dir(CRATE).unwrap();
`
``
31
+
``
32
`+
let bootstrap_cargo = env_var("BOOTSTRAP_CARGO");
`
``
33
`+
let path = env_var("PATH");
`
``
34
`+
let rustc = env_var("RUSTC");
`
``
35
+
``
36
`+
let target_dir = path_helpers::path("target");
`
``
37
`+
let manifest_path = path_helpers::path("Cargo.toml");
`
``
38
+
``
39
`+
let debug = {
`
``
40
`+
let mut cmd = cmd(&bootstrap_cargo);
`
``
41
`+
cmd.args(&["run", "--target", &target()])
`
``
42
`+
.env("RUSTFLAGS", "-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x")
`
``
43
`+
.env("CARGO_TARGET_DIR", &target_dir)
`
``
44
`+
.env("PATH", &path)
`
``
45
`+
.env("RUSTC", &rustc);
`
``
46
`+
cmd.run()
`
``
47
`+
};
`
``
48
+
``
49
`+
debug.assert_stdout_contains("x = 42");
`
``
50
+
``
51
`+
let release = {
`
``
52
`+
let mut cmd = cmd(&bootstrap_cargo);
`
``
53
`+
cmd.args(&["run", "--release", "--target", &target()])
`
``
54
`+
.env("RUSTFLAGS", "-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x")
`
``
55
`+
.env("CARGO_TARGET_DIR", &target_dir)
`
``
56
`+
.env("PATH", &path)
`
``
57
`+
.env("RUSTC", &rustc);
`
``
58
`+
cmd.run()
`
``
59
`+
};
`
``
60
+
``
61
`+
release.assert_stdout_contains("x = 42");
`
``
62
`+
}
`