about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-08 16:54:10 +0000
committerbors <bors@rust-lang.org>2024-08-08 16:54:10 +0000
commit2048386fe2898febe7315c0feb915458e41c7aa5 (patch)
tree07e4109e9bc3a67144a3f0f6abd5d58a7540851d
parentd3a393932eeafa4638ae22f5ecbc38bf38760d0e (diff)
parent3e5885f7d2ad5c22a39b23e4b37b3b8483470e1e (diff)
downloadrust-2048386fe2898febe7315c0feb915458e41c7aa5.tar.gz
rust-2048386fe2898febe7315c0feb915458e41c7aa5.zip
Auto merge of #128639 - folkertdev:rmake-thumb-none-qemu, r=jieyouxu
migrate `thumb-none-qemu` to rmake

tracking issue: https://github.com/rust-lang/rust/issues/121876

I think this one is actually simpler than https://github.com/rust-lang/rust/pull/128636, we invoke `cargo run` with the right target and see if the expected result appears.

r? `@jieyouxu`

try-job: armhf-gnu
try-job: dist-various-1
try-job: test-various
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt1
-rw-r--r--tests/run-make/thumb-none-qemu/Makefile27
-rw-r--r--tests/run-make/thumb-none-qemu/example/.cargo/config.toml (renamed from tests/run-make/thumb-none-qemu/example/.cargo/config)5
-rw-r--r--tests/run-make/thumb-none-qemu/rmake.rs62
-rw-r--r--tests/run-make/thumb-none-qemu/script.sh20
5 files changed, 64 insertions, 51 deletions
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 5ad688b5528..14f0a9cd23d 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -22,6 +22,5 @@ run-make/rlib-format-packed-bundled-libs/Makefile
 run-make/split-debuginfo/Makefile
 run-make/symbol-mangling-hashed/Makefile
 run-make/sysroot-crates-are-unstable/Makefile
-run-make/thumb-none-qemu/Makefile
 run-make/translation/Makefile
 run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile
diff --git a/tests/run-make/thumb-none-qemu/Makefile b/tests/run-make/thumb-none-qemu/Makefile
deleted file mode 100644
index eea6ca34992..00000000000
--- a/tests/run-make/thumb-none-qemu/Makefile
+++ /dev/null
@@ -1,27 +0,0 @@
-include ../tools.mk
-
-# only-thumb
-
-# How to run this
-# $ ./x.py clean
-# $ ./x.py test --target thumbv7m-none-eabi tests/run-make
-
-# For cargo setting
-export RUSTC := $(RUSTC_ORIGINAL)
-export LD_LIBRARY_PATH := $(HOST_RPATH_DIR)
-# We need to be outside of 'src' dir in order to run cargo
-export WORK_DIR := $(TMPDIR)
-export HERE := $(shell pwd)
-
-## clean up unused env variables which might cause harm.
-unexport RUSTC_LINKER
-unexport RUSTC_BOOTSTRAP
-unexport RUST_BUILD_STAGE
-unexport RUST_TEST_THREADS
-unexport RUST_TEST_TMPDIR
-unexport AR
-unexport CC
-unexport CXX
-
-all:
-	bash script.sh
diff --git a/tests/run-make/thumb-none-qemu/example/.cargo/config b/tests/run-make/thumb-none-qemu/example/.cargo/config.toml
index 8b30310e7d4..7152e81b502 100644
--- a/tests/run-make/thumb-none-qemu/example/.cargo/config
+++ b/tests/run-make/thumb-none-qemu/example/.cargo/config.toml
@@ -1,6 +1,5 @@
 [target.thumbv6m-none-eabi]
-# FIXME: Should be Cortex-M0, but Qemu used by CI is too old
-runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
+runner = "qemu-system-arm -cpu cortex-m0 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
 
 [target.thumbv7m-none-eabi]
 runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
@@ -12,7 +11,7 @@ runner = "qemu-system-arm -cpu cortex-m4 -machine lm3s6965evb -nographic -semiho
 runner = "qemu-system-arm -cpu cortex-m4 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
 
 [target.thumbv8m.base-none-eabi]
-# FIXME: Should be the Cortex-M23, bt Qemu does not currently support it
+# FIXME: Should be the Cortex-M23, but Qemu does not currently support it
 runner = "qemu-system-arm -cpu cortex-m33 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
 
 [target.thumbv8m.main-none-eabi]
diff --git a/tests/run-make/thumb-none-qemu/rmake.rs b/tests/run-make/thumb-none-qemu/rmake.rs
new file mode 100644
index 00000000000..d0f42bc8808
--- /dev/null
+++ b/tests/run-make/thumb-none-qemu/rmake.rs
@@ -0,0 +1,62 @@
+//! This test runs a basic application for thumb targets, using the cortex-m crate.
+//!
+//! These targets are very bare-metal: the first instruction the core runs on
+//! power-on is already user code. The cortex-m-rt has to initialize the stack, .data,
+//! .bss, enable the FPU if present, etc.
+//!
+//! This test builds and runs the applications for various thumb targets using qemu.
+//!
+//! How to run this
+//! $ ./x.py clean
+//! $ ./x.py test --target thumbv6m-none-eabi,thumbv7m-none-eabi tests/run-make
+//!
+//! For supported targets, see `example/.cargo/config.toml`
+//!
+//! FIXME: https://github.com/rust-lang/rust/issues/128733 this test uses external
+//! dependencies, and needs an active internet connection
+//!
+//! FIXME: https://github.com/rust-lang/rust/issues/128734 extract bootstrap cargo
+//! to a proper command
+
+//@ only-thumb
+
+use std::path::PathBuf;
+
+use run_make_support::{cmd, env_var, path_helpers, target};
+
+const CRATE: &str = "example";
+
+fn main() {
+    std::env::set_current_dir(CRATE).unwrap();
+
+    let bootstrap_cargo = env_var("BOOTSTRAP_CARGO");
+    let path = env_var("PATH");
+    let rustc = env_var("RUSTC");
+
+    let target_dir = path_helpers::path("target");
+    let manifest_path = path_helpers::path("Cargo.toml");
+
+    let debug = {
+        let mut cmd = cmd(&bootstrap_cargo);
+        cmd.args(&["run", "--target", &target()])
+            .env("RUSTFLAGS", "-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x")
+            .env("CARGO_TARGET_DIR", &target_dir)
+            .env("PATH", &path)
+            .env("RUSTC", &rustc);
+        cmd.run()
+    };
+
+    debug.assert_stdout_contains("x = 42");
+
+    let release = {
+        let mut cmd = cmd(&bootstrap_cargo);
+        cmd.args(&["run", "--release", "--target", &target()])
+            .env("RUSTFLAGS", "-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x")
+            .env("CARGO_TARGET_DIR", &target_dir)
+            .env("PATH", &path)
+            .env("RUSTC", &rustc);
+        cmd.run()
+    };
+
+    release.assert_stdout_contains("x = 42");
+}
diff --git a/tests/run-make/thumb-none-qemu/script.sh b/tests/run-make/thumb-none-qemu/script.sh
deleted file mode 100644
index a8aa72af184..00000000000
--- a/tests/run-make/thumb-none-qemu/script.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/sh
-set -exuo pipefail
-
-CRATE=example
-
-env | sort
-mkdir -p $WORK_DIR
-pushd $WORK_DIR
-    rm -rf $CRATE || echo OK
-    cp -a $HERE/example .
-    pushd $CRATE
-        # HACK(eddyb) sets `RUSTC_BOOTSTRAP=1` so Cargo can accept nightly features.
-        # These come from the top-level Rust workspace, that this crate is not a
-        # member of, but Cargo tries to load the workspace `Cargo.toml` anyway.
-        env RUSTC_BOOTSTRAP=1 RUSTFLAGS="-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x" \
-            $BOOTSTRAP_CARGO run --target $TARGET           | grep "x = 42"
-        env RUSTC_BOOTSTRAP=1 RUSTFLAGS="-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x" \
-            $BOOTSTRAP_CARGO run --target $TARGET --release | grep "x = 42"
-    popd
-popd