]> git.lizzy.rs Git - rust.git/commitdiff
Support no-std targets and test it in CI
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 29 Jun 2022 13:29:35 +0000 (13:29 +0000)
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 30 Jun 2022 12:51:22 +0000 (12:51 +0000)
CONTRIBUTING.md
README.md
cargo-miri/bin.rs
ci.sh
tests/pass/no_std.rs [new file with mode: 0644]

index ad8bd2a17a6c7b548942c32f02739d19ea4f061c..7dfa9d73120f5f91922f2d9b69cda7acc3ef190b 100644 (file)
@@ -71,6 +71,16 @@ and you can (cross-)run the entire test suite using:
 MIRI_TEST_TARGET=i686-unknown-linux-gnu ./miri test
 ```
 
+If your target doesn't support libstd, you can run miri with
+
+```
+MIRI_NO_STD=1 MIRI_TEST_TARGET=thumbv7em-none-eabihf ./miri test tests/fail/alloc/no_global_allocator.rs
+MIRI_NO_STD=1 ./miri run tests/pass/no_std.rs --target thumbv7em-none-eabihf
+```
+
+to avoid attempting (and failing) to build libstd. Note that almost no tests will pass
+this way, but you can run individual tests.
+
 `./miri test FILTER` only runs those tests that contain `FILTER` in their
 filename (including the base directory, e.g. `./miri test fail` will run all
 compile-fail tests).
index bfc32d04a9d14fe8d8da36c556436c59625ed6fd..2d9609fb0b706eab22b2e6944e13e26814179d86 100644 (file)
--- a/README.md
+++ b/README.md
@@ -419,6 +419,8 @@ Moreover, Miri recognizes some environment variables:
 * `MIRI_TEST_TARGET` (recognized by the test suite) indicates which target
   architecture to test against.  `miri` and `cargo miri` accept the `--target`
   flag for the same purpose.
+* `MIRI_NO_STD` (recognized by `cargo miri` and the test suite) makes sure that the target's
+  sysroot is built without libstd. This allows testing and running no_std programs.
 * `MIRI_BLESS` (recognized by the test suite) overwrite all `stderr` and `stdout` files
   instead of checking whether the output matches.
 * `MIRI_SKIP_UI_CHECKS` (recognized by the test suite) don't check whether the
index 9627adeb2e792923a86515e6ff7306568509dd41..4c9f3aabaab49eb1518eb25142f94edc4c089b5c 100644 (file)
@@ -398,11 +398,12 @@ fn setup(subcommand: MiriCommand) {
     if !dir.exists() {
         fs::create_dir_all(&dir).unwrap();
     }
-    // The interesting bit: Xargo.toml
-    File::create(dir.join("Xargo.toml"))
-        .unwrap()
-        .write_all(
-            br#"
+    let mut xargo_toml = File::create(dir.join("Xargo.toml")).unwrap();
+    if std::env::var_os("MIRI_NO_STD").is_none() {
+        // The interesting bit: Xargo.toml (only needs content if we actually need std)
+        xargo_toml
+            .write_all(
+                br#"
 [dependencies.std]
 default_features = false
 # We support unwinding, so enable that panic runtime.
@@ -410,8 +411,9 @@ fn setup(subcommand: MiriCommand) {
 
 [dependencies.test]
 "#,
-        )
-        .unwrap();
+            )
+            .unwrap();
+    }
     // The boring bits: a dummy project for xargo.
     // FIXME: With xargo-check, can we avoid doing this?
     File::create(dir.join("Cargo.toml"))
@@ -428,7 +430,7 @@ fn setup(subcommand: MiriCommand) {
 "#,
         )
         .unwrap();
-    File::create(dir.join("lib.rs")).unwrap();
+    File::create(dir.join("lib.rs")).unwrap().write_all(b"#![no_std]").unwrap();
 
     // Determine architectures.
     // We always need to set a target so rustc bootstrap can tell apart host from target crates.
diff --git a/ci.sh b/ci.sh
index 1fa67f52139ed923c6e4765b01e5f1fb233e0fdc..e3a106308592cbeec12a8b8f1f93a3285507e2c7 100755 (executable)
--- a/ci.sh
+++ b/ci.sh
@@ -61,6 +61,7 @@ case $HOST_TARGET in
     MIRI_TEST_TARGET=aarch64-apple-darwin run_tests
     MIRI_TEST_TARGET=i686-pc-windows-msvc run_tests
     MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec
+    MIRI_NO_STD=1 ./miri run tests/pass/no_std.rs --target thumbv7em-none-eabihf # no_std embedded architecture minimal test
     ;;
   x86_64-apple-darwin)
     MIRI_TEST_TARGET=mips64-unknown-linux-gnuabi64 run_tests # big-endian architecture
diff --git a/tests/pass/no_std.rs b/tests/pass/no_std.rs
new file mode 100644 (file)
index 0000000..6808dab
--- /dev/null
@@ -0,0 +1,21 @@
+#![feature(lang_items, start)]
+#![no_std]
+// windows tls dtors go through libstd right now, thus this test
+// cannot pass. When windows tls dtors go through the special magic
+// windows linker section, we can run this test on windows again.
+// ignore-windows
+
+#[start]
+fn start(_: isize, _: *const *const u8) -> isize {
+    for _ in 0..10 {}
+
+    0
+}
+
+#[panic_handler]
+fn panic_handler(_: &core::panic::PanicInfo) -> ! {
+    loop {}
+}
+
+#[lang = "eh_personality"]
+fn eh_personality() {}