From 36eea9fa1c689a00666e6e47f5e5ae6b8610dea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 5 Mar 2025 20:18:05 +0100 Subject: [PATCH 01/24] Enable automatic cross-compilation in run-make tests --- .../src/external_deps/rustc.rs | 24 +++++++++++++------ src/tools/run-make-support/src/macros.rs | 9 +++++++ .../run-make/apple-deployment-target/rmake.rs | 5 ---- tests/run-make/apple-sdk-version/rmake.rs | 9 +++---- tests/run-make/mte-ffi/rmake.rs | 6 +---- tests/run-make/rustc-macro-dep-files/rmake.rs | 2 +- tests/run-make/static-pie/rmake.rs | 1 - .../sysroot-crates-are-unstable/rmake.rs | 1 - 8 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/tools/run-make-support/src/external_deps/rustc.rs b/src/tools/run-make-support/src/external_deps/rustc.rs index a7081d4f86a29..72a1e062a38da 100644 --- a/src/tools/run-make-support/src/external_deps/rustc.rs +++ b/src/tools/run-make-support/src/external_deps/rustc.rs @@ -6,7 +6,7 @@ use crate::command::Command; use crate::env::env_var; use crate::path_helpers::cwd; use crate::util::set_host_compiler_dylib_path; -use crate::{is_aix, is_darwin, is_msvc, is_windows, uname}; +use crate::{is_aix, is_darwin, is_msvc, is_windows, target, uname}; /// Construct a new `rustc` invocation. This will automatically set the library /// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this. @@ -27,9 +27,15 @@ pub fn bare_rustc() -> Rustc { #[must_use] pub struct Rustc { cmd: Command, + target: Option, } -crate::macros::impl_common_helpers!(Rustc); +// Only fill in the target just before execution, so that it can be overridden. +crate::macros::impl_common_helpers!(Rustc, |rustc: &mut Rustc| { + if let Some(target) = &rustc.target { + rustc.cmd.arg(&format!("--target={target}")); + } +}); pub fn rustc_path() -> String { env_var("RUSTC") @@ -46,19 +52,22 @@ impl Rustc { // `rustc` invocation constructor methods /// Construct a new `rustc` invocation. This will automatically set the library - /// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this. + /// search path as `-L cwd()` and also the compilation target. + /// Use [`bare_rustc`] to avoid this. #[track_caller] pub fn new() -> Self { let mut cmd = setup_common(); cmd.arg("-L").arg(cwd()); - Self { cmd } + + // Automatically default to cross-compilation + Self { cmd, target: Some(target()) } } /// Construct a bare `rustc` invocation with no flags set. #[track_caller] pub fn bare() -> Self { let cmd = setup_common(); - Self { cmd } + Self { cmd, target: None } } // Argument provider methods @@ -234,8 +243,9 @@ impl Rustc { /// Specify the target triple, or a path to a custom target json spec file. pub fn target>(&mut self, target: S) -> &mut Self { - let target = target.as_ref(); - self.cmd.arg(format!("--target={target}")); + // We store the target as a separate field, so that it can be specified multiple times. + // This is in particular useful to override the default target set in Rustc::new(). + self.target = Some(target.as_ref().to_string()); self } diff --git a/src/tools/run-make-support/src/macros.rs b/src/tools/run-make-support/src/macros.rs index 94955aefe57aa..86db184929793 100644 --- a/src/tools/run-make-support/src/macros.rs +++ b/src/tools/run-make-support/src/macros.rs @@ -23,10 +23,16 @@ /// } /// ``` /// +/// You can pass an optional second parameter which should be a function that is passed +/// `&mut self` just before the command is executed. +/// /// [`Command`]: crate::command::Command /// [`CompletedProcess`]: crate::command::CompletedProcess macro_rules! impl_common_helpers { ($wrapper: ident) => { + $crate::macros::impl_common_helpers!($wrapper, |_| {}); + }; + ($wrapper: ident, $before_exec: expr) => { impl $wrapper { /// Specify an environment variable. pub fn env(&mut self, key: K, value: V) -> &mut Self @@ -118,12 +124,14 @@ macro_rules! impl_common_helpers { /// Run the constructed command and assert that it is successfully run. #[track_caller] pub fn run(&mut self) -> crate::command::CompletedProcess { + $before_exec(&mut *self); self.cmd.run() } /// Run the constructed command and assert that it does not successfully run. #[track_caller] pub fn run_fail(&mut self) -> crate::command::CompletedProcess { + $before_exec(&mut *self); self.cmd.run_fail() } @@ -133,6 +141,7 @@ macro_rules! impl_common_helpers { /// whenever possible. #[track_caller] pub fn run_unchecked(&mut self) -> crate::command::CompletedProcess { + $before_exec(&mut *self); self.cmd.run_unchecked() } diff --git a/tests/run-make/apple-deployment-target/rmake.rs b/tests/run-make/apple-deployment-target/rmake.rs index 839e21b7496d9..7297a8622240d 100644 --- a/tests/run-make/apple-deployment-target/rmake.rs +++ b/tests/run-make/apple-deployment-target/rmake.rs @@ -41,7 +41,6 @@ fn main() { // Remove env vars to get `rustc`'s default let output = rustc() - .target(target()) .env_remove("MACOSX_DEPLOYMENT_TARGET") .env_remove("IPHONEOS_DEPLOYMENT_TARGET") .env_remove("WATCHOS_DEPLOYMENT_TARGET") @@ -58,7 +57,6 @@ fn main() { run_in_tmpdir(|| { let rustc = || { let mut rustc = rustc(); - rustc.target(target()); rustc.crate_type("lib"); rustc.emit("obj"); rustc.input("foo.rs"); @@ -82,7 +80,6 @@ fn main() { let rustc = || { let mut rustc = rustc(); - rustc.target(target()); rustc.crate_type("dylib"); rustc.input("foo.rs"); rustc.output("libfoo.dylib"); @@ -108,7 +105,6 @@ fn main() { run_in_tmpdir(|| { let rustc = || { let mut rustc = rustc(); - rustc.target(target()); rustc.crate_type("bin"); rustc.input("foo.rs"); rustc.output("foo"); @@ -147,7 +143,6 @@ fn main() { run_in_tmpdir(|| { let rustc = || { let mut rustc = rustc(); - rustc.target(target()); rustc.incremental("incremental"); rustc.crate_type("lib"); rustc.emit("obj"); diff --git a/tests/run-make/apple-sdk-version/rmake.rs b/tests/run-make/apple-sdk-version/rmake.rs index 43e805772043e..1f4f0ab8aef86 100644 --- a/tests/run-make/apple-sdk-version/rmake.rs +++ b/tests/run-make/apple-sdk-version/rmake.rs @@ -24,8 +24,7 @@ fn has_sdk_version(file: &str, version: &str) { fn main() { // Fetch rustc's inferred deployment target. - let current_deployment_target = - rustc().target(target()).print("deployment-target").run().stdout_utf8(); + let current_deployment_target = rustc().print("deployment-target").run().stdout_utf8(); let current_deployment_target = current_deployment_target.split('=').last().unwrap().trim(); // Fetch current SDK version via. xcrun. @@ -45,7 +44,7 @@ fn main() { let current_sdk_version = current_sdk_version.trim(); // Check the SDK version in the object file produced by the codegen backend. - rustc().target(target()).crate_type("lib").emit("obj").input("foo.rs").output("foo.o").run(); + rustc().crate_type("lib").emit("obj").input("foo.rs").output("foo.o").run(); // Set to 0, which means not set or "n/a". has_sdk_version("foo.o", "n/a"); @@ -53,7 +52,7 @@ fn main() { // // This is just to ensure that we don't set some odd version in `create_object_file`, // if the rmeta file is packed in a different way in the future, this can safely be removed. - rustc().target(target()).crate_type("rlib").input("foo.rs").output("libfoo.rlib").run(); + rustc().crate_type("rlib").input("foo.rs").output("libfoo.rlib").run(); // Extra .rmeta file (which is encoded as an object file). cmd("ar").arg("-x").arg("libfoo.rlib").arg("lib.rmeta").run(); has_sdk_version("lib.rmeta", "n/a"); @@ -69,7 +68,6 @@ fn main() { // Test with clang let file_name = format!("foo_cc{file_ext}"); rustc() - .target(target()) .crate_type("bin") .arg("-Clinker-flavor=gcc") .input("foo.rs") @@ -80,7 +78,6 @@ fn main() { // Test with ld64 let file_name = format!("foo_ld{file_ext}"); rustc() - .target(target()) .crate_type("bin") .arg("-Clinker-flavor=ld") .input("foo.rs") diff --git a/tests/run-make/mte-ffi/rmake.rs b/tests/run-make/mte-ffi/rmake.rs index 50f5f14191b4c..a8da0dc0ee039 100644 --- a/tests/run-make/mte-ffi/rmake.rs +++ b/tests/run-make/mte-ffi/rmake.rs @@ -22,11 +22,7 @@ fn run_test(variant: &str) { flags }; println!("{variant} test..."); - rustc() - .input(format!("foo_{variant}.rs")) - .target(target()) - .linker("aarch64-linux-gnu-gcc") - .run(); + rustc().input(format!("foo_{variant}.rs")).linker("aarch64-linux-gnu-gcc").run(); gcc() .input(format!("bar_{variant}.c")) .input(dynamic_lib_name("foo")) diff --git a/tests/run-make/rustc-macro-dep-files/rmake.rs b/tests/run-make/rustc-macro-dep-files/rmake.rs index bc02a04c9b8f1..2bd5c3df62078 100644 --- a/tests/run-make/rustc-macro-dep-files/rmake.rs +++ b/tests/run-make/rustc-macro-dep-files/rmake.rs @@ -8,7 +8,7 @@ use run_make_support::{diff, rustc, target}; fn main() { rustc().input("foo.rs").run(); - rustc().input("bar.rs").target(target()).emit("dep-info").run(); + rustc().input("bar.rs").emit("dep-info").run(); // The emitted file should not contain "proc-macro source". diff().expected_file("correct.d").actual_file("bar.d").run(); } diff --git a/tests/run-make/static-pie/rmake.rs b/tests/run-make/static-pie/rmake.rs index 1557c170f56de..cb24c0495be8f 100644 --- a/tests/run-make/static-pie/rmake.rs +++ b/tests/run-make/static-pie/rmake.rs @@ -49,7 +49,6 @@ fn test(compiler: &str) { rustc() .input("test-aslr.rs") - .target(target()) .linker(compiler) .arg("-Clinker-flavor=gcc") .arg("-Ctarget-feature=+crt-static") diff --git a/tests/run-make/sysroot-crates-are-unstable/rmake.rs b/tests/run-make/sysroot-crates-are-unstable/rmake.rs index c81c7fafdab0b..20ad01bef61d6 100644 --- a/tests/run-make/sysroot-crates-are-unstable/rmake.rs +++ b/tests/run-make/sysroot-crates-are-unstable/rmake.rs @@ -31,7 +31,6 @@ fn check_crate_is_unstable(cr: &Crate) { // Trying to use this crate from a user program should fail. let output = rustc() .crate_type("rlib") - .target(target()) .extern_(name, path) .input("-") .stdin_buf(format!("extern crate {name};")) From e0957e7216dcc36672803621fd5355d24f0b6e86 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sun, 13 Apr 2025 10:38:47 +0800 Subject: [PATCH 02/24] [DO NOT MERGE] ----- commit stack separator ----- From 7913706435aa0cb17acd2b8a848751d4b8a35e4c Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Wed, 2 Apr 2025 17:14:13 +0800 Subject: [PATCH 03/24] run-make-support: enable automatic cross-compilation for `rustdoc` too --- .../src/external_deps/rustdoc.rs | 35 +++++++++++++++---- src/tools/run-make-support/src/lib.rs | 2 +- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/tools/run-make-support/src/external_deps/rustdoc.rs b/src/tools/run-make-support/src/external_deps/rustdoc.rs index 433a57cd9fa65..f5d3a7d835311 100644 --- a/src/tools/run-make-support/src/external_deps/rustdoc.rs +++ b/src/tools/run-make-support/src/external_deps/rustdoc.rs @@ -3,21 +3,35 @@ use std::path::Path; use crate::command::Command; use crate::env::env_var; +use crate::target; use crate::util::set_host_compiler_dylib_path; -/// Construct a new `rustdoc` invocation. +/// Construct a new `rustdoc` invocation with target automatically set to cross-compile target. Use +/// [`bare_rustdoc`] to avoid this. #[track_caller] pub fn rustdoc() -> Rustdoc { Rustdoc::new() } +/// Bare `rustdoc` invocation, no args set. +#[track_caller] +pub fn bare_rustdoc() -> Rustdoc { + Rustdoc::bare() +} + #[derive(Debug)] #[must_use] pub struct Rustdoc { cmd: Command, + target: Option, } -crate::macros::impl_common_helpers!(Rustdoc); +// Only fill in the target just before execution, so that it can be overridden. +crate::macros::impl_common_helpers!(Rustdoc, |rustdoc: &mut Rustdoc| { + if let Some(target) = &rustdoc.target { + rustdoc.cmd.arg(&format!("--target={target}")); + } +}); #[track_caller] fn setup_common() -> Command { @@ -28,11 +42,19 @@ fn setup_common() -> Command { } impl Rustdoc { - /// Construct a bare `rustdoc` invocation. + /// Construct a new `rustdoc` invocation with target automatically set to cross-compile target. + /// Use [`bare_rustdoc`] to avoid this. #[track_caller] pub fn new() -> Self { let cmd = setup_common(); - Self { cmd } + Self { cmd, target: Some(target()) } + } + + /// Bare `rustdoc` invocation, no args set. + #[track_caller] + pub fn bare() -> Self { + let cmd = setup_common(); + Self { cmd, target: None } } /// Specify where an external library is located. @@ -85,8 +107,9 @@ impl Rustdoc { /// Specify the target triple, or a path to a custom target json spec file. pub fn target>(&mut self, target: S) -> &mut Self { - let target = target.as_ref(); - self.cmd.arg(format!("--target={target}")); + // We store the target as a separate field, so that it can be specified multiple times. + // This is in particular useful to override the default target set in `Rustdoc::new()`. + self.target = Some(target.as_ref().to_string()); self } diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index f37b38ac0b151..947f815fd697c 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -68,7 +68,7 @@ pub use llvm::{ }; pub use python::python_command; pub use rustc::{bare_rustc, rustc, rustc_path, Rustc}; -pub use rustdoc::{rustdoc, Rustdoc}; +pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc}; /// [`diff`][mod@diff] is implemented in terms of the [similar] library. /// From 42000eb50e0338d1d21b800ab41e3d23210644f1 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Wed, 2 Apr 2025 17:14:57 +0800 Subject: [PATCH 04/24] tests: use `bare_rustdoc` for `rustdoc-default-output` --- tests/run-make/rustdoc-default-output/rmake.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/run-make/rustdoc-default-output/rmake.rs b/tests/run-make/rustdoc-default-output/rmake.rs index 5f9c501e5286b..1ed2e8d79bb02 100644 --- a/tests/run-make/rustdoc-default-output/rmake.rs +++ b/tests/run-make/rustdoc-default-output/rmake.rs @@ -3,10 +3,11 @@ // ensures the output of rustdoc's help menu is as expected. // See https://github.com/rust-lang/rust/issues/88756 -use run_make_support::{diff, rustdoc}; +use run_make_support::{bare_rustdoc, diff}; fn main() { - let out = rustdoc().run().stdout_utf8(); + // Use `bare_rustdoc` to ensure no `--target` is set. + let out = bare_rustdoc().run().stdout_utf8(); diff() .expected_file("output-default.stdout") .actual_text("actual", out) From e95fdc09620befc435dce6b0672ff185dadadc2d Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 11:55:21 +0800 Subject: [PATCH 05/24] tests: ignore some doctests on cross-compile --- tests/run-make/doctests-merge/rmake.rs | 2 ++ tests/run-make/doctests-runtool/rmake.rs | 2 ++ tests/run-make/rustdoc-test-args/rmake.rs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/tests/run-make/doctests-merge/rmake.rs b/tests/run-make/doctests-merge/rmake.rs index a88b050c50fa8..7893d4988ebba 100644 --- a/tests/run-make/doctests-merge/rmake.rs +++ b/tests/run-make/doctests-merge/rmake.rs @@ -1,3 +1,5 @@ +//@ ignore-cross-compile (needs to run doctests) + use std::path::Path; use run_make_support::{cwd, diff, rustc, rustdoc}; diff --git a/tests/run-make/doctests-runtool/rmake.rs b/tests/run-make/doctests-runtool/rmake.rs index c7be829c215e1..4f9e383b90831 100644 --- a/tests/run-make/doctests-runtool/rmake.rs +++ b/tests/run-make/doctests-runtool/rmake.rs @@ -1,5 +1,7 @@ // Tests behavior of rustdoc `--runtool`. +//@ ignore-cross-compile (attempts to run the doctests) + use std::path::PathBuf; use run_make_support::rfs::{create_dir, remove_dir_all}; diff --git a/tests/run-make/rustdoc-test-args/rmake.rs b/tests/run-make/rustdoc-test-args/rmake.rs index fddb3795402e1..3125a971b4bd0 100644 --- a/tests/run-make/rustdoc-test-args/rmake.rs +++ b/tests/run-make/rustdoc-test-args/rmake.rs @@ -1,3 +1,5 @@ +//@ ignore-cross-compile (need to run doctests) + use std::iter; use std::path::Path; From cbdcb855e1f0a1d3f5293c2f9d506166306e5028 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 11:55:41 +0800 Subject: [PATCH 06/24] tests: adjust `embed-metadata` for cross-compile --- tests/run-make/embed-metadata/rmake.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/run-make/embed-metadata/rmake.rs b/tests/run-make/embed-metadata/rmake.rs index acefb18648440..50b0c8412d7df 100644 --- a/tests/run-make/embed-metadata/rmake.rs +++ b/tests/run-make/embed-metadata/rmake.rs @@ -1,8 +1,13 @@ // Tests the -Zembed-metadata compiler flag. // Tracking issue: https://github.com/rust-lang/rust/issues/139165 +//@ needs-dynamic-linking +//@ needs-crate-type: dylib + use run_make_support::rfs::{create_dir, remove_file, rename}; -use run_make_support::{Rustc, dynamic_lib_name, path, run_in_tmpdir, rust_lib_name, rustc}; +use run_make_support::{ + Rustc, dynamic_lib_name, path, run_in_tmpdir, rust_lib_name, rustc, target, +}; #[derive(Debug, Copy, Clone)] enum LibraryKind { @@ -42,7 +47,7 @@ fn main() { fn lookup_rmeta_in_lib_dir(kind: LibraryKind) { run_in_tmpdir(|| { build_dep_rustc(kind).run(); - rustc().input("foo.rs").run(); + rustc().target(target()).input("foo.rs").run(); }); } @@ -54,6 +59,7 @@ fn lookup_rmeta_through_extern(kind: LibraryKind) { build_dep_rustc(kind).out_dir("deps").run(); let mut rustc = rustc(); + rustc.target(target()); kind.add_extern(&mut rustc, "dep1", "deps"); rustc.extern_("dep1", path("deps").join("libdep1.rmeta")); rustc.input("foo.rs").run(); @@ -67,6 +73,7 @@ fn lookup_rmeta_missing(kind: LibraryKind) { build_dep_rustc(kind).out_dir("deps").run(); let mut rustc = rustc(); + rustc.target(target()); kind.add_extern(&mut rustc, "dep1", "deps"); rustc.input("foo.rs").run_fail().assert_stderr_contains("only metadata stub found"); }); @@ -74,6 +81,7 @@ fn lookup_rmeta_missing(kind: LibraryKind) { fn build_dep_rustc(kind: LibraryKind) -> Rustc { let mut dep_rustc = rustc(); + dep_rustc.target(target()); dep_rustc .arg("-Zembed-metadata=no") .crate_type(kind.crate_type()) From 0fa62e2dc194e22bc50c29a8e1ac41e6cf7d0f6e Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 11:59:22 +0800 Subject: [PATCH 07/24] tests: adjust `embed-source-dwarf` --- tests/run-make/embed-source-dwarf/rmake.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/run-make/embed-source-dwarf/rmake.rs b/tests/run-make/embed-source-dwarf/rmake.rs index 550c8b9b3c903..85863860a0c48 100644 --- a/tests/run-make/embed-source-dwarf/rmake.rs +++ b/tests/run-make/embed-source-dwarf/rmake.rs @@ -1,5 +1,6 @@ -//@ ignore-windows -//@ ignore-apple +//@ ignore-apple (needs DWARF) +//@ ignore-windows-msvc (needs DWARF) +//@ ignore-cross-compile (cross-compiled target can produce artifacts `object` can't yet parse) // This test should be replaced with one in tests/debuginfo once we can easily // tell via GDB or LLDB if debuginfo contains source code. Cheap tricks in LLDB From 0d81211ca5f2e0f2c23943ab020671c2eaf04e11 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:01:19 +0800 Subject: [PATCH 08/24] tests: adjust `emit-stack-sizes` --- tests/run-make/emit-stack-sizes/rmake.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/run-make/emit-stack-sizes/rmake.rs b/tests/run-make/emit-stack-sizes/rmake.rs index 53cc9ee5943f8..9c52cc71981de 100644 --- a/tests/run-make/emit-stack-sizes/rmake.rs +++ b/tests/run-make/emit-stack-sizes/rmake.rs @@ -6,15 +6,18 @@ // this diagnostics information should be located. // See https://github.com/rust-lang/rust/pull/51946 -//@ ignore-windows -//@ ignore-apple -// Reason: this feature only works when the output object format is ELF. -// This won't be the case on Windows/OSX - for example, OSX produces a Mach-O binary. +//@ only-elf -use run_make_support::{llvm_readobj, rustc}; +use run_make_support::{llvm_readobj, rustc, target}; fn main() { - rustc().opt_level("3").arg("-Zemit-stack-sizes").emit("obj").input("foo.rs").run(); + rustc() + .target(target()) + .opt_level("3") + .arg("-Zemit-stack-sizes") + .emit("obj") + .input("foo.rs") + .run(); llvm_readobj() .arg("--section-headers") .input("foo.o") From da0521db7e14231f84ac8ff9fbab4d5bd690f63a Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:02:54 +0800 Subject: [PATCH 09/24] tests: adjust `invalid-so` --- tests/run-make/invalid-so/rmake.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/run-make/invalid-so/rmake.rs b/tests/run-make/invalid-so/rmake.rs index 754c53a49b924..49740c7a8741a 100644 --- a/tests/run-make/invalid-so/rmake.rs +++ b/tests/run-make/invalid-so/rmake.rs @@ -4,11 +4,14 @@ // explains that the file exists, but that its metadata is incorrect. // See https://github.com/rust-lang/rust/pull/88368 -use run_make_support::{dynamic_lib_name, rfs, rustc}; +//@ needs-crate-type: dylib + +use run_make_support::{dynamic_lib_name, rfs, rustc, target}; fn main() { rfs::create_file(dynamic_lib_name("foo")); rustc() + .target(target()) .crate_type("lib") .extern_("foo", dynamic_lib_name("foo")) .input("bar.rs") From 3a7ccb4babff48a96bb1ea7bfdccd5be761078e2 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:04:31 +0800 Subject: [PATCH 10/24] tests: ignore `env-dep-info` on cross-compile --- tests/run-make/env-dep-info/rmake.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/run-make/env-dep-info/rmake.rs b/tests/run-make/env-dep-info/rmake.rs index 5b51a5476f491..96127e7c1c220 100644 --- a/tests/run-make/env-dep-info/rmake.rs +++ b/tests/run-make/env-dep-info/rmake.rs @@ -4,6 +4,8 @@ // appear in the output dep-info files. // See https://github.com/rust-lang/rust/issues/40364 +//@ ignore-cross-compile (cross-compile targets can introduce complicated env differences) + use run_make_support::{diff, rustc}; fn main() { From df33a5bbcf34118cc720d5291d80ab542786de16 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:05:48 +0800 Subject: [PATCH 11/24] tests: ignore `link-args-order` on cross-compile --- tests/run-make/link-args-order/rmake.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/run-make/link-args-order/rmake.rs b/tests/run-make/link-args-order/rmake.rs index fe0d02926eff4..efc5b55822d8a 100644 --- a/tests/run-make/link-args-order/rmake.rs +++ b/tests/run-make/link-args-order/rmake.rs @@ -3,6 +3,8 @@ // checks that linker arguments remain intact and in the order they were originally passed in. // See https://github.com/rust-lang/rust/pull/70665 +//@ ignore-cross-compile (exercises host linker) + use run_make_support::{is_msvc, rustc}; fn main() { From ea09b0020936557204282319a0089dc2aebffbb7 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:06:33 +0800 Subject: [PATCH 12/24] tests: ignore `link-dedup` on cross-compile --- tests/run-make/link-dedup/rmake.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/run-make/link-dedup/rmake.rs b/tests/run-make/link-dedup/rmake.rs index f38603dee8cbb..d9091397e49ec 100644 --- a/tests/run-make/link-dedup/rmake.rs +++ b/tests/run-make/link-dedup/rmake.rs @@ -5,6 +5,8 @@ // Without the --cfg flag, there should be a single -ltesta, no more, no less. // See https://github.com/rust-lang/rust/pull/84794 +//@ ignore-cross-compile (exercises host linker) + use std::fmt::Write; use run_make_support::{is_msvc, rustc}; From d13088934bde8a76d9f1200815fbf453f5250789 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:07:25 +0800 Subject: [PATCH 13/24] tests: ignore `linker-warning` on cross-compile --- tests/run-make/linker-warning/rmake.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/run-make/linker-warning/rmake.rs b/tests/run-make/linker-warning/rmake.rs index bc21739fefc6e..255c75de125f1 100644 --- a/tests/run-make/linker-warning/rmake.rs +++ b/tests/run-make/linker-warning/rmake.rs @@ -1,3 +1,5 @@ +//@ ignore-cross-compile (exercises host linker) + use run_make_support::{Rustc, diff, regex, rustc}; fn run_rustc() -> Rustc { From 68357985a432d8babcb4a0801c3fe1d58545f67b Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:07:56 +0800 Subject: [PATCH 14/24] tests: ignore `native-link-modifier-verbatim-link` --- tests/run-make/native-link-modifier-verbatim-linker/rmake.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/run-make/native-link-modifier-verbatim-linker/rmake.rs b/tests/run-make/native-link-modifier-verbatim-linker/rmake.rs index 6868cb368ccc3..ec4fceeb9b888 100644 --- a/tests/run-make/native-link-modifier-verbatim-linker/rmake.rs +++ b/tests/run-make/native-link-modifier-verbatim-linker/rmake.rs @@ -3,6 +3,7 @@ // This test is the same as native-link-modifier-rustc, but without rlibs. // See https://github.com/rust-lang/rust/issues/99425 +//@ ignore-cross-compile (verbatim linking can fail due to `.ext` e.g. against `wasm32-wasip1`) //@ ignore-apple // Reason: linking fails due to the unusual ".ext" staticlib name. From a845409e7fb376a30e5d1c3ed71be0f8d06046ab Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:17:25 +0800 Subject: [PATCH 15/24] tests: ignore `no-builtins-attribute` --- tests/run-make/no-builtins-attribute/rmake.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/run-make/no-builtins-attribute/rmake.rs b/tests/run-make/no-builtins-attribute/rmake.rs index 7182c65a2c59e..9bb8fa58b144f 100644 --- a/tests/run-make/no-builtins-attribute/rmake.rs +++ b/tests/run-make/no-builtins-attribute/rmake.rs @@ -4,6 +4,9 @@ // being added to these function declarations. // See https://github.com/rust-lang/rust/pull/113716 +// FIXME: LLVM IR looks different, e.g. `declare void @foo()` was not found against `wasm32-waspi1`) +//@ ignore-cross-compile (FileCheck can fail on cross-compiled targets, see FIXME above) + use run_make_support::{llvm_filecheck, rfs, rustc}; fn main() { From 3104dd6830aa13872dbdb550462a443cf333c534 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:18:36 +0800 Subject: [PATCH 16/24] tests: fix `proc-macro-three-crates` --- tests/run-make/proc-macro-three-crates/rmake.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/run-make/proc-macro-three-crates/rmake.rs b/tests/run-make/proc-macro-three-crates/rmake.rs index d3735540fdd47..9258db1660145 100644 --- a/tests/run-make/proc-macro-three-crates/rmake.rs +++ b/tests/run-make/proc-macro-three-crates/rmake.rs @@ -5,6 +5,8 @@ // This was fixed in #37846, and this test checks // that this bug does not make a resurgence. +//@ needs-crate-type: proc-macro + use run_make_support::{bare_rustc, cwd, rust_lib_name, rustc}; fn main() { From 4a1308838720b490e40c98649fb4dcfb4540dd25 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:19:53 +0800 Subject: [PATCH 17/24] tests: ignore `repr128-dwarf` on cross-compile --- tests/run-make/repr128-dwarf/rmake.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/run-make/repr128-dwarf/rmake.rs b/tests/run-make/repr128-dwarf/rmake.rs index 8227c51516fa5..304bb47a3c29c 100644 --- a/tests/run-make/repr128-dwarf/rmake.rs +++ b/tests/run-make/repr128-dwarf/rmake.rs @@ -1,3 +1,4 @@ +//@ ignore-cross-compile (cross-compile targets can produce artifacts `object` can't parse) //@ ignore-windows // This test should be replaced with one in tests/debuginfo once GDB or LLDB support 128-bit enums. From 3e48b49da7069b3323231fa9cf140950a0537163 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:20:34 +0800 Subject: [PATCH 18/24] tests: fix `rustc-macro-dep-files` --- tests/run-make/rustc-macro-dep-files/rmake.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/run-make/rustc-macro-dep-files/rmake.rs b/tests/run-make/rustc-macro-dep-files/rmake.rs index 2bd5c3df62078..6762195cd2028 100644 --- a/tests/run-make/rustc-macro-dep-files/rmake.rs +++ b/tests/run-make/rustc-macro-dep-files/rmake.rs @@ -4,6 +4,8 @@ // that macro code is not falsely seen as coming from a different file in dep-info. // See https://github.com/rust-lang/rust/issues/36625 +//@ needs-crate-type: proc-macro + use run_make_support::{diff, rustc, target}; fn main() { From fc7ca19fe79e1038a5896889a4567889072eb8a0 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:21:30 +0800 Subject: [PATCH 19/24] tests: fix `share-generics-dylib` --- tests/run-make/share-generics-dylib/rmake.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/run-make/share-generics-dylib/rmake.rs b/tests/run-make/share-generics-dylib/rmake.rs index e0e647fe19955..49a29fa5b3e26 100644 --- a/tests/run-make/share-generics-dylib/rmake.rs +++ b/tests/run-make/share-generics-dylib/rmake.rs @@ -9,6 +9,9 @@ // // This is regression test for https://github.com/rust-lang/rust/issues/67276. +//@ needs-crate-type: dylib +//@ needs-dynamic-linking + use run_make_support::rustc; fn main() { From a62ec9bbeb056e62712a5877447d538c7d55446d Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:22:47 +0800 Subject: [PATCH 20/24] tests: fix `stdin-rustc` --- tests/run-make/stdin-rustc/rmake.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/run-make/stdin-rustc/rmake.rs b/tests/run-make/stdin-rustc/rmake.rs index 2d634dd455eb2..053a4fadf3b39 100644 --- a/tests/run-make/stdin-rustc/rmake.rs +++ b/tests/run-make/stdin-rustc/rmake.rs @@ -1,8 +1,8 @@ //! This test checks rustc `-` (stdin) support -use std::path::PathBuf; +use std::path::Path; -use run_make_support::{is_windows, rustc}; +use run_make_support::{bin_name, rustc}; const HELLO_WORLD: &str = r#" fn main() { @@ -15,11 +15,7 @@ const NOT_UTF8: &[u8] = &[0xff, 0xff, 0xff]; fn main() { // echo $HELLO_WORLD | rustc - rustc().arg("-").stdin_buf(HELLO_WORLD).run(); - assert!( - PathBuf::from(if !is_windows() { "rust_out" } else { "rust_out.exe" }) - .try_exists() - .unwrap() - ); + assert!(Path::new(&bin_name("rust_out")).exists()); // echo $NOT_UTF8 | rustc - rustc().arg("-").stdin_buf(NOT_UTF8).run_fail().assert_stderr_contains( From c334cb242967f9829bb348177a9f02dbc9210292 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:23:25 +0800 Subject: [PATCH 21/24] tests: fix `stdin-rustdoc` --- tests/run-make/stdin-rustdoc/rmake.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/run-make/stdin-rustdoc/rmake.rs b/tests/run-make/stdin-rustdoc/rmake.rs index 30f97b8a2cd75..e65d3cc988e35 100644 --- a/tests/run-make/stdin-rustdoc/rmake.rs +++ b/tests/run-make/stdin-rustdoc/rmake.rs @@ -1,3 +1,5 @@ +//@ ignore-cross-compile (need to run doctests) + //! This test checks rustdoc `-` (stdin) handling use std::path::PathBuf; From 89fce8534fbcf95fa6b672b5b8e5ba416064d70b Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:24:22 +0800 Subject: [PATCH 22/24] tests: fix `symbol-visibility` --- tests/run-make/symbol-visibility/rmake.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/run-make/symbol-visibility/rmake.rs b/tests/run-make/symbol-visibility/rmake.rs index ec936bc3b07fa..d554ffc10c3d6 100644 --- a/tests/run-make/symbol-visibility/rmake.rs +++ b/tests/run-make/symbol-visibility/rmake.rs @@ -4,6 +4,8 @@ // are exported, and that generics are only shown if explicitly requested. // See https://github.com/rust-lang/rust/issues/37530 +//@ needs-crate-type: cdylib, dylib, proc-macro + use run_make_support::object::read::Object; use run_make_support::{bin_name, dynamic_lib_name, is_msvc, object, regex, rfs, rustc}; From 96d6a8110e83e9d9f931125e8764da08af7c486f Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:24:50 +0800 Subject: [PATCH 23/24] tests: fix `track-path-dep-info` --- tests/run-make/track-path-dep-info/rmake.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/run-make/track-path-dep-info/rmake.rs b/tests/run-make/track-path-dep-info/rmake.rs index 9b21644c41bc5..6a00dc930a961 100644 --- a/tests/run-make/track-path-dep-info/rmake.rs +++ b/tests/run-make/track-path-dep-info/rmake.rs @@ -4,6 +4,8 @@ // output successfully added the file as a dependency. // See https://github.com/rust-lang/rust/pull/84029 +//@ needs-crate-type: proc-macro + use run_make_support::{rfs, rustc}; fn main() { From 150c4cc4a0a2834945eb3b79dc26539861c3c61e Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 12:25:42 +0800 Subject: [PATCH 24/24] tests: fix `used` --- tests/run-make/used/rmake.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/run-make/used/rmake.rs b/tests/run-make/used/rmake.rs index 39f36b2eea8f6..207401bf00e63 100644 --- a/tests/run-make/used/rmake.rs +++ b/tests/run-make/used/rmake.rs @@ -4,6 +4,8 @@ // It comes from #39987 which implements this RFC for the #[used] attribute: // https://rust-lang.github.io/rfcs/2386-used.html +//@ ignore-cross-compile (cross-compile targets can produce artifacts `object` can't yet parse) + use run_make_support::rustc; use run_make_support::symbols::any_symbol_contains;