diff --git a/src/doc/rustc-dev-guide/src/tests/directives.md b/src/doc/rustc-dev-guide/src/tests/directives.md index 81aa35f1a4653..747c5f950d773 100644 --- a/src/doc/rustc-dev-guide/src/tests/directives.md +++ b/src/doc/rustc-dev-guide/src/tests/directives.md @@ -190,8 +190,13 @@ settings: specified atomic widths, e.g. the test with `//@ needs-target-has-atomic: 8, 16, ptr` will only run if it supports the comma-separated list of atomic widths. -- `needs-dynamic-linking` - ignores if target does not support dynamic linking +- `needs-dynamic-linking` — ignores if target does not support dynamic linking (which is orthogonal to it being unable to create `dylib` and `cdylib` crate types) +- `needs-crate-type` — ignores if target platform does not support one or more + of the comma-delimited list of specified crate types. For example, + `//@ needs-crate-type: cdylib, proc-macro` will cause the test to be ignored + on `wasm32-unknown-unknown` target because the target does not support the + `proc-macro` crate type. The following directives will check LLVM support: diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 9e35d2b466763..9999c26e8df87 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -398,6 +398,7 @@ pub struct Config { pub target_cfgs: OnceLock, pub builtin_cfg_names: OnceLock>, + pub supported_crate_types: OnceLock>, pub nocapture: bool, @@ -475,6 +476,11 @@ impl Config { self.builtin_cfg_names.get_or_init(|| builtin_cfg_names(self)) } + /// Get the list of crate types that the target platform supports. + pub fn supported_crate_types(&self) -> &HashSet { + self.supported_crate_types.get_or_init(|| supported_crate_types(self)) + } + pub fn has_threads(&self) -> bool { // Wasm targets don't have threads unless `-threads` is in the target // name, such as `wasm32-wasip1-threads`. @@ -748,6 +754,31 @@ fn builtin_cfg_names(config: &Config) -> HashSet { .collect() } +pub const KNOWN_CRATE_TYPES: &[&str] = + &["bin", "cdylib", "dylib", "lib", "proc-macro", "rlib", "staticlib"]; + +fn supported_crate_types(config: &Config) -> HashSet { + let crate_types: HashSet<_> = rustc_output( + config, + &["--target", &config.target, "--print=supported-crate-types", "-Zunstable-options"], + Default::default(), + ) + .lines() + .map(|l| l.to_string()) + .collect(); + + for crate_type in crate_types.iter() { + assert!( + KNOWN_CRATE_TYPES.contains(&crate_type.as_str()), + "unexpected crate type `{}`: known crate types are {:?}", + crate_type, + KNOWN_CRATE_TYPES + ); + } + + crate_types +} + fn rustc_output(config: &Config, args: &[&str], envs: HashMap) -> String { let mut command = Command::new(&config.rustc_path); add_dylib_path(&mut command, iter::once(&config.compile_lib_path)); diff --git a/src/tools/compiletest/src/directive-list.rs b/src/tools/compiletest/src/directive-list.rs index b2ad5a3b3d0bb..8741a7971b84e 100644 --- a/src/tools/compiletest/src/directive-list.rs +++ b/src/tools/compiletest/src/directive-list.rs @@ -132,6 +132,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ "min-llvm-version", "min-system-llvm-version", "needs-asm-support", + "needs-crate-type", "needs-deterministic-layouts", "needs-dlltool", "needs-dynamic-linking", diff --git a/src/tools/compiletest/src/header/needs.rs b/src/tools/compiletest/src/header/needs.rs index 12f0790fb1040..2ace40c490bf3 100644 --- a/src/tools/compiletest/src/header/needs.rs +++ b/src/tools/compiletest/src/header/needs.rs @@ -1,4 +1,4 @@ -use crate::common::{Config, KNOWN_TARGET_HAS_ATOMIC_WIDTHS, Sanitizer}; +use crate::common::{Config, KNOWN_CRATE_TYPES, KNOWN_TARGET_HAS_ATOMIC_WIDTHS, Sanitizer}; use crate::header::{IgnoreDecision, llvm_has_libzstd}; pub(super) fn handle_needs( @@ -6,7 +6,7 @@ pub(super) fn handle_needs( config: &Config, ln: &str, ) -> IgnoreDecision { - // Note thet we intentionally still put the needs- prefix here to make the file show up when + // Note that we intentionally still put the needs- prefix here to make the file show up when // grepping for a directive name, even though we could technically strip that. let needs = &[ Need { @@ -224,6 +224,50 @@ pub(super) fn handle_needs( } } + // FIXME(jieyouxu): share multi-value directive logic with `needs-target-has-atomic` above. + if name == "needs-crate-type" { + let Some(rest) = rest else { + return IgnoreDecision::Error { + message: + "expected `needs-crate-type` to have a comma-separated list of crate types" + .to_string(), + }; + }; + + // Expect directive value to be a list of comma-separated crate-types. + let specified_crate_types = rest + .split(',') + .map(|crate_type| crate_type.trim()) + .map(ToString::to_string) + .collect::>(); + + for crate_type in &specified_crate_types { + if !KNOWN_CRATE_TYPES.contains(&crate_type.as_str()) { + return IgnoreDecision::Error { + message: format!( + "unknown crate type specified in `needs-crate-type`: `{crate_type}` is not \ + a known crate type, known values are `{:?}`", + KNOWN_CRATE_TYPES + ), + }; + } + } + + let satisfies_all_crate_types = specified_crate_types + .iter() + .all(|specified| config.supported_crate_types().contains(specified)); + if satisfies_all_crate_types { + return IgnoreDecision::Continue; + } else { + return IgnoreDecision::Ignore { + reason: format!( + "skipping test as target does not support all of the crate types `{:?}`", + specified_crate_types + ), + }; + } + } + if !name.starts_with("needs-") { return IgnoreDecision::Continue; } diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index ff6bc49b72a13..50d8bb2b23def 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -905,3 +905,42 @@ fn test_rustc_abi() { assert!(!check_ignore(&config, "//@ ignore-rustc_abi-x86-sse2")); assert!(check_ignore(&config, "//@ only-rustc_abi-x86-sse2")); } + +#[cfg(not(bootstrap))] +#[test] +fn test_supported_crate_types() { + // Basic assumptions check on under-test compiler's `--print=supported-crate-types` output based + // on knowledge about the cherry-picked `x86_64-unknown-linux-gnu` and `wasm32-unknown-unknown` + // targets. Also smoke tests the `needs-crate-type` directive itself. + + use std::collections::HashSet; + + let config = cfg().target("x86_64-unknown-linux-gnu").build(); + assert_eq!( + config.supported_crate_types().iter().map(String::as_str).collect::>(), + HashSet::from(["bin", "cdylib", "dylib", "lib", "proc-macro", "rlib", "staticlib"]), + ); + assert!(!check_ignore(&config, "//@ needs-crate-type: rlib")); + assert!(!check_ignore(&config, "//@ needs-crate-type: dylib")); + assert!(!check_ignore( + &config, + "//@ needs-crate-type: bin, cdylib, dylib, lib, proc-macro, rlib, staticlib" + )); + + let config = cfg().target("wasm32-unknown-unknown").build(); + assert_eq!( + config.supported_crate_types().iter().map(String::as_str).collect::>(), + HashSet::from(["bin", "cdylib", "lib", "rlib", "staticlib"]), + ); + + // rlib is supported + assert!(!check_ignore(&config, "//@ needs-crate-type: rlib")); + // dylib is not + assert!(check_ignore(&config, "//@ needs-crate-type: dylib")); + // If multiple crate types are specified, then all specified crate types need to be supported. + assert!(check_ignore(&config, "//@ needs-crate-type: cdylib, dylib")); + assert!(check_ignore( + &config, + "//@ needs-crate-type: bin, cdylib, dylib, lib, proc-macro, rlib, staticlib" + )); +} diff --git a/src/tools/compiletest/src/lib.rs b/src/tools/compiletest/src/lib.rs index 8145ae1c1bced..fdcc80f6afd62 100644 --- a/src/tools/compiletest/src/lib.rs +++ b/src/tools/compiletest/src/lib.rs @@ -433,6 +433,7 @@ pub fn parse_config(args: Vec) -> Config { target_cfgs: OnceLock::new(), builtin_cfg_names: OnceLock::new(), + supported_crate_types: OnceLock::new(), nocapture: matches.opt_present("no-capture"), diff --git a/src/tools/run-make-support/src/artifact_names.rs b/src/tools/run-make-support/src/artifact_names.rs index 8968f831542e6..b0d588d3550ac 100644 --- a/src/tools/run-make-support/src/artifact_names.rs +++ b/src/tools/run-make-support/src/artifact_names.rs @@ -1,11 +1,11 @@ //! A collection of helpers to construct artifact names, such as names of dynamic or static -//! librarys which are target-dependent. - -// FIXME(jieyouxu): convert these to return `PathBuf`s instead of strings! +//! libraries which are target-dependent. +use crate::target; use crate::targets::is_msvc; /// Construct the static library name based on the target. +#[track_caller] #[must_use] pub fn static_lib_name(name: &str) -> String { assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace"); @@ -14,15 +14,34 @@ pub fn static_lib_name(name: &str) -> String { } /// Construct the dynamic library name based on the target. +#[track_caller] #[must_use] pub fn dynamic_lib_name(name: &str) -> String { assert!(!name.contains(char::is_whitespace), "dynamic library name cannot contain whitespace"); - format!("{}{name}.{}", std::env::consts::DLL_PREFIX, std::env::consts::DLL_EXTENSION) + format!("{}{name}.{}", dynamic_lib_prefix(), dynamic_lib_extension()) +} + +fn dynamic_lib_prefix() -> &'static str { + if target().contains("windows") { "" } else { "lib" } } -/// Construct the name of the import library for the dynamic library, exclusive to MSVC and -/// accepted by link.exe. +/// Construct the dynamic library extension based on the target. +#[must_use] +pub fn dynamic_lib_extension() -> &'static str { + let target = target(); + + if target.contains("apple") { + "dylib" + } else if target.contains("windows") { + "dll" + } else { + "so" + } +} + +/// Construct the name of the import library for the dynamic library, exclusive to MSVC and accepted +/// by link.exe. #[track_caller] #[must_use] pub fn msvc_import_dynamic_lib_name(name: &str) -> String { @@ -32,20 +51,28 @@ pub fn msvc_import_dynamic_lib_name(name: &str) -> String { format!("{name}.dll.lib") } -/// Construct the dynamic library extension based on the target. -#[must_use] -pub fn dynamic_lib_extension() -> &'static str { - std::env::consts::DLL_EXTENSION -} - /// Construct the name of a rust library (rlib). +#[track_caller] #[must_use] pub fn rust_lib_name(name: &str) -> String { format!("lib{name}.rlib") } /// Construct the binary (executable) name based on the target. +#[track_caller] #[must_use] pub fn bin_name(name: &str) -> String { - format!("{name}{}", std::env::consts::EXE_SUFFIX) + let target = target(); + + if target.contains("windows") { + format!("{name}.exe") + } else if target.contains("uefi") { + format!("{name}.efi") + } else if target.contains("wasm") { + format!("{name}.wasm") + } else if target.contains("nvptx") { + format!("{name}.ptx") + } else { + name.to_string() + } } diff --git a/tests/run-make/crate-data-smoke/rmake.rs b/tests/run-make/crate-data-smoke/rmake.rs index 70f8e46b6d928..b5708d05a82b2 100644 --- a/tests/run-make/crate-data-smoke/rmake.rs +++ b/tests/run-make/crate-data-smoke/rmake.rs @@ -1,9 +1,20 @@ -use run_make_support::{bin_name, rust_lib_name, rustc}; +use run_make_support::{bin_name, rust_lib_name, rustc, target}; fn main() { - rustc().print("crate-name").input("crate.rs").run().assert_stdout_equals("foo"); - rustc().print("file-names").input("crate.rs").run().assert_stdout_equals(bin_name("foo")); rustc() + .target(target()) + .print("crate-name") + .input("crate.rs") + .run() + .assert_stdout_equals("foo"); + rustc() + .target(target()) + .print("file-names") + .input("crate.rs") + .run() + .assert_stdout_equals(bin_name("foo")); + rustc() + .target(target()) .print("file-names") .crate_type("lib") .arg("--test") @@ -11,11 +22,22 @@ fn main() { .run() .assert_stdout_equals(bin_name("foo")); rustc() + .target(target()) .print("file-names") .arg("--test") .input("lib.rs") .run() .assert_stdout_equals(bin_name("mylib")); - rustc().print("file-names").input("lib.rs").run().assert_stdout_equals(rust_lib_name("mylib")); - rustc().print("file-names").input("rlib.rs").run().assert_stdout_equals(rust_lib_name("mylib")); + rustc() + .target(target()) + .print("file-names") + .input("lib.rs") + .run() + .assert_stdout_equals(rust_lib_name("mylib")); + rustc() + .target(target()) + .print("file-names") + .input("rlib.rs") + .run() + .assert_stdout_equals(rust_lib_name("mylib")); } diff --git a/tests/run-make/crate-name-priority/rmake.rs b/tests/run-make/crate-name-priority/rmake.rs index 5bdb49b33ceac..283c5f342cbb4 100644 --- a/tests/run-make/crate-name-priority/rmake.rs +++ b/tests/run-make/crate-name-priority/rmake.rs @@ -4,15 +4,17 @@ // and the compiler flags, and checks that the flag is favoured each time. // See https://github.com/rust-lang/rust/pull/15518 -use run_make_support::{bin_name, rfs, rustc}; +//@ ignore-cross-compile (relocations in generic ELF against `arm-unknown-linux-gnueabihf`) + +use run_make_support::{bin_name, rfs, rustc, target}; fn main() { - rustc().input("foo.rs").run(); + rustc().target(target()).input("foo.rs").run(); rfs::remove_file(bin_name("foo")); - rustc().input("foo.rs").crate_name("bar").run(); + rustc().target(target()).input("foo.rs").crate_name("bar").run(); rfs::remove_file(bin_name("bar")); - rustc().input("foo1.rs").run(); + rustc().target(target()).input("foo1.rs").run(); rfs::remove_file(bin_name("foo")); - rustc().input("foo1.rs").output(bin_name("bar1")).run(); + rustc().target(target()).input("foo1.rs").output(bin_name("bar1")).run(); rfs::remove_file(bin_name("bar1")); } diff --git a/tests/run-make/extra-filename-with-temp-outputs/rmake.rs b/tests/run-make/extra-filename-with-temp-outputs/rmake.rs index 0910045bb8577..5490bcc2eb729 100644 --- a/tests/run-make/extra-filename-with-temp-outputs/rmake.rs +++ b/tests/run-make/extra-filename-with-temp-outputs/rmake.rs @@ -6,10 +6,14 @@ // are named as expected. // See https://github.com/rust-lang/rust/pull/15686 -use run_make_support::{bin_name, cwd, has_prefix, has_suffix, rfs, rustc, shallow_find_files}; +//@ ignore-cross-compile (relocations in generic ELF against `arm-unknown-linux-gnueabihf`) + +use run_make_support::{ + bin_name, cwd, has_prefix, has_suffix, rfs, rustc, shallow_find_files, target, +}; fn main() { - rustc().extra_filename("bar").input("foo.rs").arg("-Csave-temps").run(); + rustc().target(target()).extra_filename("bar").input("foo.rs").arg("-Csave-temps").run(); let object_files = shallow_find_files(cwd(), |path| { has_prefix(path, "foobar.foo") && has_suffix(path, "0.rcgu.o") }); diff --git a/tests/run-make/output-type-permutations/rmake.rs b/tests/run-make/output-type-permutations/rmake.rs index c0569af6e84a3..863407153ae57 100644 --- a/tests/run-make/output-type-permutations/rmake.rs +++ b/tests/run-make/output-type-permutations/rmake.rs @@ -4,11 +4,14 @@ // files are exactly what is expected, no more, no less. // See https://github.com/rust-lang/rust/pull/12020 +//@ ignore-cross-compile +// Reason: some cross-compiled targets don't support various crate types and fail to link. + use std::path::PathBuf; use run_make_support::{ bin_name, dynamic_lib_name, filename_not_in_denylist, rfs, rust_lib_name, rustc, - shallow_find_files, static_lib_name, + shallow_find_files, static_lib_name, target, }; // Each test takes 4 arguments: @@ -17,6 +20,7 @@ use run_make_support::{ // `dir`: the name of the directory where the test happens // `rustc_invocation`: the rustc command being tested // Any unexpected output files not listed in `must_exist` or `can_exist` will cause a failure. +#[track_caller] fn assert_expected_output_files(expectations: Expectations, rustc_invocation: impl Fn()) { let Expectations { expected_files: must_exist, allowed_files: can_exist, test_dir: dir } = expectations; @@ -81,6 +85,7 @@ fn main() { }, || { rustc() + .target(target()) .input("foo.rs") .out_dir("three-crates") .crate_type("rlib,dylib,staticlib") @@ -95,7 +100,7 @@ fn main() { test_dir: "bin-crate".to_string(), }, || { - rustc().input("foo.rs").crate_type("bin").out_dir("bin-crate").run(); + rustc().target(target()).input("foo.rs").crate_type("bin").out_dir("bin-crate").run(); }, ); @@ -106,7 +111,12 @@ fn main() { test_dir: "all-emit".to_string(), }, || { - rustc().input("foo.rs").emit("asm,llvm-ir,llvm-bc,obj,link").out_dir("all-emit").run(); + rustc() + .target(target()) + .input("foo.rs") + .emit("asm,llvm-ir,llvm-bc,obj,link") + .out_dir("all-emit") + .run(); }, ); @@ -117,7 +127,7 @@ fn main() { test_dir: "asm-emit".to_string(), }, || { - rustc().input("foo.rs").emit("asm").output("asm-emit/foo").run(); + rustc().target(target()).input("foo.rs").emit("asm").output("asm-emit/foo").run(); }, ); assert_expected_output_files( @@ -127,7 +137,7 @@ fn main() { test_dir: "asm-emit2".to_string(), }, || { - rustc().input("foo.rs").emit("asm=asm-emit2/foo").run(); + rustc().target(target()).input("foo.rs").emit("asm=asm-emit2/foo").run(); }, ); assert_expected_output_files( @@ -137,7 +147,7 @@ fn main() { test_dir: "asm-emit3".to_string(), }, || { - rustc().input("foo.rs").arg("--emit=asm=asm-emit3/foo").run(); + rustc().target(target()).input("foo.rs").arg("--emit=asm=asm-emit3/foo").run(); }, ); @@ -148,7 +158,12 @@ fn main() { test_dir: "llvm-ir-emit".to_string(), }, || { - rustc().input("foo.rs").emit("llvm-ir").output("llvm-ir-emit/foo").run(); + rustc() + .target(target()) + .input("foo.rs") + .emit("llvm-ir") + .output("llvm-ir-emit/foo") + .run(); }, ); assert_expected_output_files( @@ -158,7 +173,7 @@ fn main() { test_dir: "llvm-ir-emit2".to_string(), }, || { - rustc().input("foo.rs").emit("llvm-ir=llvm-ir-emit2/foo").run(); + rustc().target(target()).input("foo.rs").emit("llvm-ir=llvm-ir-emit2/foo").run(); }, ); assert_expected_output_files( @@ -168,7 +183,7 @@ fn main() { test_dir: "llvm-ir-emit3".to_string(), }, || { - rustc().input("foo.rs").arg("--emit=llvm-ir=llvm-ir-emit3/foo").run(); + rustc().target(target()).input("foo.rs").arg("--emit=llvm-ir=llvm-ir-emit3/foo").run(); }, ); @@ -179,7 +194,12 @@ fn main() { test_dir: "llvm-bc-emit".to_string(), }, || { - rustc().input("foo.rs").emit("llvm-bc").output("llvm-bc-emit/foo").run(); + rustc() + .target(target()) + .input("foo.rs") + .emit("llvm-bc") + .output("llvm-bc-emit/foo") + .run(); }, ); assert_expected_output_files( @@ -189,7 +209,7 @@ fn main() { test_dir: "llvm-bc-emit2".to_string(), }, || { - rustc().input("foo.rs").emit("llvm-bc=llvm-bc-emit2/foo").run(); + rustc().target(target()).input("foo.rs").emit("llvm-bc=llvm-bc-emit2/foo").run(); }, ); assert_expected_output_files( @@ -199,7 +219,7 @@ fn main() { test_dir: "llvm-bc-emit3".to_string(), }, || { - rustc().input("foo.rs").arg("--emit=llvm-bc=llvm-bc-emit3/foo").run(); + rustc().target(target()).input("foo.rs").arg("--emit=llvm-bc=llvm-bc-emit3/foo").run(); }, ); @@ -210,7 +230,7 @@ fn main() { test_dir: "obj-emit".to_string(), }, || { - rustc().input("foo.rs").emit("obj").output("obj-emit/foo").run(); + rustc().target(target()).input("foo.rs").emit("obj").output("obj-emit/foo").run(); }, ); assert_expected_output_files( @@ -220,7 +240,7 @@ fn main() { test_dir: "obj-emit2".to_string(), }, || { - rustc().input("foo.rs").emit("obj=obj-emit2/foo").run(); + rustc().target(target()).input("foo.rs").emit("obj=obj-emit2/foo").run(); }, ); assert_expected_output_files( @@ -230,7 +250,7 @@ fn main() { test_dir: "obj-emit3".to_string(), }, || { - rustc().input("foo.rs").arg("--emit=obj=obj-emit3/foo").run(); + rustc().target(target()).input("foo.rs").arg("--emit=obj=obj-emit3/foo").run(); }, ); @@ -241,7 +261,12 @@ fn main() { test_dir: "link-emit".to_string(), }, || { - rustc().input("foo.rs").emit("link").output("link-emit/".to_owned() + &bin_foo).run(); + rustc() + .target(target()) + .input("foo.rs") + .emit("link") + .output("link-emit/".to_owned() + &bin_foo) + .run(); }, ); assert_expected_output_files( @@ -251,7 +276,11 @@ fn main() { test_dir: "link-emit2".to_string(), }, || { - rustc().input("foo.rs").emit(&format!("link=link-emit2/{bin_foo}")).run(); + rustc() + .target(target()) + .input("foo.rs") + .emit(&format!("link=link-emit2/{bin_foo}")) + .run(); }, ); assert_expected_output_files( @@ -261,7 +290,11 @@ fn main() { test_dir: "link-emit3".to_string(), }, || { - rustc().input("foo.rs").arg(&format!("--emit=link=link-emit3/{bin_foo}")).run(); + rustc() + .target(target()) + .input("foo.rs") + .arg(&format!("--emit=link=link-emit3/{bin_foo}")) + .run(); }, ); @@ -272,7 +305,7 @@ fn main() { test_dir: "rlib".to_string(), }, || { - rustc().crate_type("rlib").input("foo.rs").output("rlib/foo").run(); + rustc().target(target()).crate_type("rlib").input("foo.rs").output("rlib/foo").run(); }, ); assert_expected_output_files( @@ -282,7 +315,12 @@ fn main() { test_dir: "rlib2".to_string(), }, || { - rustc().crate_type("rlib").input("foo.rs").emit("link=rlib2/foo").run(); + rustc() + .target(target()) + .crate_type("rlib") + .input("foo.rs") + .emit("link=rlib2/foo") + .run(); }, ); assert_expected_output_files( @@ -292,7 +330,12 @@ fn main() { test_dir: "rlib3".to_string(), }, || { - rustc().crate_type("rlib").input("foo.rs").arg("--emit=link=rlib3/foo").run(); + rustc() + .target(target()) + .crate_type("rlib") + .input("foo.rs") + .arg("--emit=link=rlib3/foo") + .run(); }, ); @@ -315,6 +358,7 @@ fn main() { }, || { rustc() + .target(target()) .crate_type("dylib") .input("foo.rs") .output("dylib/".to_owned() + &bin_foo) @@ -340,6 +384,7 @@ fn main() { }, || { rustc() + .target(target()) .crate_type("dylib") .input("foo.rs") .emit(&format!("link=dylib2/{bin_foo}")) @@ -365,6 +410,7 @@ fn main() { }, || { rustc() + .target(target()) .crate_type("dylib") .input("foo.rs") .arg(&format!("--emit=link=dylib3/{bin_foo}")) @@ -379,7 +425,12 @@ fn main() { test_dir: "staticlib".to_string(), }, || { - rustc().crate_type("staticlib").input("foo.rs").output("staticlib/foo").run(); + rustc() + .target(target()) + .crate_type("staticlib") + .input("foo.rs") + .output("staticlib/foo") + .run(); }, ); assert_expected_output_files( @@ -389,7 +440,12 @@ fn main() { test_dir: "staticlib2".to_string(), }, || { - rustc().crate_type("staticlib").input("foo.rs").emit("link=staticlib2/foo").run(); + rustc() + .target(target()) + .crate_type("staticlib") + .input("foo.rs") + .emit("link=staticlib2/foo") + .run(); }, ); assert_expected_output_files( @@ -399,7 +455,12 @@ fn main() { test_dir: "staticlib3".to_string(), }, || { - rustc().crate_type("staticlib").input("foo.rs").arg("--emit=link=staticlib3/foo").run(); + rustc() + .target(target()) + .crate_type("staticlib") + .input("foo.rs") + .arg("--emit=link=staticlib3/foo") + .run(); }, ); @@ -411,6 +472,7 @@ fn main() { }, || { rustc() + .target(target()) .crate_type("bin") .input("foo.rs") .output("bincrate/".to_owned() + &bin_foo) @@ -425,6 +487,7 @@ fn main() { }, || { rustc() + .target(target()) .crate_type("bin") .input("foo.rs") .emit(&format!("link=bincrate2/{bin_foo}")) @@ -439,6 +502,7 @@ fn main() { }, || { rustc() + .target(target()) .crate_type("bin") .input("foo.rs") .arg(&format!("--emit=link=bincrate3/{bin_foo}")) @@ -454,6 +518,7 @@ fn main() { }, || { rustc() + .target(target()) .input("foo.rs") .emit("llvm-ir=rlib-ir/ir") .emit("link") @@ -471,6 +536,7 @@ fn main() { }, || { rustc() + .target(target()) .input("foo.rs") .emit("asm=staticlib-all/asm") .emit("llvm-ir=staticlib-all/ir") @@ -489,6 +555,7 @@ fn main() { }, || { rustc() + .target(target()) .input("foo.rs") .arg("--emit=asm=staticlib-all2/asm") .arg("--emit") @@ -510,6 +577,7 @@ fn main() { }, || { rustc() + .target(target()) .input("foo.rs") .emit("asm,llvm-ir,llvm-bc,obj,link") .crate_type("staticlib") @@ -529,6 +597,7 @@ fn main() { || { rfs::rename("staticlib-all3/bar.bc", "rlib-emits/foo.bc"); rustc() + .target(target()) .input("foo.rs") .emit("llvm-bc,link") .crate_type("rlib") diff --git a/tests/run-make/reproducible-build/rmake.rs b/tests/run-make/reproducible-build/rmake.rs index 8a8b0d6d652be..93fc30de07d7e 100644 --- a/tests/run-make/reproducible-build/rmake.rs +++ b/tests/run-make/reproducible-build/rmake.rs @@ -20,6 +20,8 @@ // See https://github.com/rust-lang/rust/pull/32293 // Tracking Issue: https://github.com/rust-lang/rust/issues/129080 +//@ ignore-cross-compile (linker binary needs to run) + use run_make_support::{ bin_name, cwd, diff, is_darwin, is_windows, regex, rfs, run_in_tmpdir, rust_lib_name, rustc, }; diff --git a/tests/run-make/strip/rmake.rs b/tests/run-make/strip/rmake.rs index ef1acc26b4556..e2191634d0188 100644 --- a/tests/run-make/strip/rmake.rs +++ b/tests/run-make/strip/rmake.rs @@ -1,8 +1,9 @@ -//@ ignore-windows Windows does not actually strip +//@ ignore-windows (Windows does not actually strip) +//@ ignore-cross-compile (relocations in generic ELF against `arm-unknown-linux-gnueabihf`) // Test that -Cstrip correctly strips/preserves debuginfo and symbols. -use run_make_support::{bin_name, is_darwin, llvm_dwarfdump, llvm_nm, rustc}; +use run_make_support::{bin_name, is_darwin, llvm_dwarfdump, llvm_nm, rustc, target}; fn main() { // We use DW_ (the start of any DWARF name) to check that some debuginfo is present. @@ -20,21 +21,21 @@ fn main() { // for std. // -Cstrip=none should preserve symbols and debuginfo. - rustc().arg("hello.rs").arg("-Cdebuginfo=2").arg("-Cstrip=none").run(); + rustc().target(target()).arg("hello.rs").arg("-Cdebuginfo=2").arg("-Cstrip=none").run(); llvm_nm().input(binary).run().assert_stdout_contains(test_symbol); if do_debuginfo_check { llvm_dwarfdump().input(binary).run().assert_stdout_contains(dwarf_indicator); } // -Cstrip=debuginfo should preserve symbols and strip debuginfo. - rustc().arg("hello.rs").arg("-Cdebuginfo=2").arg("-Cstrip=debuginfo").run(); + rustc().target(target()).arg("hello.rs").arg("-Cdebuginfo=2").arg("-Cstrip=debuginfo").run(); llvm_nm().input(binary).run().assert_stdout_contains(test_symbol); if do_debuginfo_check { llvm_dwarfdump().input(binary).run().assert_stdout_not_contains(dwarf_indicator); } // -Cstrip=symbols should strip symbols and strip debuginfo. - rustc().arg("hello.rs").arg("-Cdebuginfo=2").arg("-Cstrip=symbols").run(); + rustc().target(target()).arg("hello.rs").arg("-Cdebuginfo=2").arg("-Cstrip=symbols").run(); llvm_nm().input(binary).run().assert_stderr_not_contains(test_symbol); if do_debuginfo_check { llvm_dwarfdump().input(binary).run().assert_stdout_not_contains(dwarf_indicator); diff --git a/tests/run-make/symbols-all-mangled/rmake.rs b/tests/run-make/symbols-all-mangled/rmake.rs index 1fb03c62399a0..b80a5e1806d87 100644 --- a/tests/run-make/symbols-all-mangled/rmake.rs +++ b/tests/run-make/symbols-all-mangled/rmake.rs @@ -1,16 +1,18 @@ // Check that all symbols in cdylibs, staticlibs and bins are mangled //@ only-elf some object file formats create multiple symbols for each function with different names +//@ ignore-nvptx64 (needs target std) +//@ ignore-cross-compile (host-only) use run_make_support::object::read::{Object, ObjectSymbol}; -use run_make_support::{bin_name, dynamic_lib_name, object, rfs, rustc, static_lib_name}; +use run_make_support::{bin_name, dynamic_lib_name, object, rfs, rustc, static_lib_name, target}; fn main() { let staticlib_name = static_lib_name("a_lib"); let cdylib_name = dynamic_lib_name("a_lib"); let exe_name = bin_name("an_executable"); - rustc().crate_type("cdylib").input("a_lib.rs").run(); - rustc().crate_type("staticlib").input("a_lib.rs").run(); - rustc().crate_type("bin").input("an_executable.rs").run(); + rustc().target(target()).crate_type("cdylib").input("a_lib.rs").run(); + rustc().target(target()).crate_type("staticlib").input("a_lib.rs").run(); + rustc().target(target()).crate_type("bin").input("an_executable.rs").run(); symbols_check_archive(&staticlib_name); symbols_check(&cdylib_name); diff --git a/tests/ui/invalid-compile-flags/crate-type-flag.rs b/tests/ui/invalid-compile-flags/crate-type-flag.rs index 8ccce97f7bfa0..61b35cf8c64fb 100644 --- a/tests/ui/invalid-compile-flags/crate-type-flag.rs +++ b/tests/ui/invalid-compile-flags/crate-type-flag.rs @@ -3,8 +3,6 @@ //! //! This test does not try to check if the output artifacts are valid. -// FIXME(#132309): add a proper `supports-crate-type` directive. - // Single valid crate types should pass //@ revisions: lib rlib staticlib dylib cdylib bin proc_dash_macro @@ -17,19 +15,18 @@ //@[staticlib] compile-flags: --crate-type=staticlib //@[staticlib] check-pass -//@[dylib] ignore-musl (dylib is supported, but musl libc is statically linked by default) -//@[dylib] ignore-wasm (dylib is not supported) +//@[dylib] needs-crate-type: dylib //@[dylib] compile-flags: --crate-type=dylib //@[dylib] check-pass -//@[cdylib] ignore-musl (cdylib is supported, but musl libc is statically linked by default) +//@[cdylib] needs-crate-type: cdylib //@[cdylib] compile-flags: --crate-type=cdylib //@[cdylib] check-pass //@[bin] compile-flags: --crate-type=bin //@[bin] check-pass -//@[proc_dash_macro] ignore-wasm (proc-macro is not supported) +//@[proc_dash_macro] needs-crate-type: proc-macro //@[proc_dash_macro] needs-unwind (panic=abort causes warning to be emitted) //@[proc_dash_macro] compile-flags: --crate-type=proc-macro //@[proc_dash_macro] check-pass diff --git a/tests/ui/linkage-attr/issue-12133-3.rs b/tests/ui/linkage-attr/issue-12133-3.rs index 473d5774c162f..df1b0b2f728e4 100644 --- a/tests/ui/linkage-attr/issue-12133-3.rs +++ b/tests/ui/linkage-attr/issue-12133-3.rs @@ -2,8 +2,7 @@ //@ aux-build:issue-12133-rlib.rs //@ aux-build:issue-12133-dylib.rs //@ aux-build:issue-12133-dylib2.rs -//@ ignore-wasm32 no dylib support -//@ ignore-musl +//@ needs-crate-type: dylib //@ needs-dynamic-linking diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.cdylib_.stderr b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.cdylib_.stderr index 1192b690e29c2..a9c0188674425 100644 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.cdylib_.stderr +++ b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.cdylib_.stderr @@ -1,11 +1,11 @@ error: crate `NonSnakeCase` should have a snake case name - --> $DIR/lint-non-snake-case-crate.rs:36:18 + --> $DIR/lint-non-snake-case-crate.rs:35:18 | LL | #![crate_name = "NonSnakeCase"] | ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case` | note: the lint level is defined here - --> $DIR/lint-non-snake-case-crate.rs:38:9 + --> $DIR/lint-non-snake-case-crate.rs:37:9 | LL | #![deny(non_snake_case)] | ^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.dylib_.stderr b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.dylib_.stderr index 1192b690e29c2..a9c0188674425 100644 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.dylib_.stderr +++ b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.dylib_.stderr @@ -1,11 +1,11 @@ error: crate `NonSnakeCase` should have a snake case name - --> $DIR/lint-non-snake-case-crate.rs:36:18 + --> $DIR/lint-non-snake-case-crate.rs:35:18 | LL | #![crate_name = "NonSnakeCase"] | ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case` | note: the lint level is defined here - --> $DIR/lint-non-snake-case-crate.rs:38:9 + --> $DIR/lint-non-snake-case-crate.rs:37:9 | LL | #![deny(non_snake_case)] | ^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.lib_.stderr b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.lib_.stderr index 1192b690e29c2..a9c0188674425 100644 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.lib_.stderr +++ b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.lib_.stderr @@ -1,11 +1,11 @@ error: crate `NonSnakeCase` should have a snake case name - --> $DIR/lint-non-snake-case-crate.rs:36:18 + --> $DIR/lint-non-snake-case-crate.rs:35:18 | LL | #![crate_name = "NonSnakeCase"] | ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case` | note: the lint level is defined here - --> $DIR/lint-non-snake-case-crate.rs:38:9 + --> $DIR/lint-non-snake-case-crate.rs:37:9 | LL | #![deny(non_snake_case)] | ^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.proc_macro_.stderr b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.proc_macro_.stderr index 1192b690e29c2..a9c0188674425 100644 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.proc_macro_.stderr +++ b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.proc_macro_.stderr @@ -1,11 +1,11 @@ error: crate `NonSnakeCase` should have a snake case name - --> $DIR/lint-non-snake-case-crate.rs:36:18 + --> $DIR/lint-non-snake-case-crate.rs:35:18 | LL | #![crate_name = "NonSnakeCase"] | ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case` | note: the lint level is defined here - --> $DIR/lint-non-snake-case-crate.rs:38:9 + --> $DIR/lint-non-snake-case-crate.rs:37:9 | LL | #![deny(non_snake_case)] | ^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rlib_.stderr b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rlib_.stderr index 1192b690e29c2..a9c0188674425 100644 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rlib_.stderr +++ b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rlib_.stderr @@ -1,11 +1,11 @@ error: crate `NonSnakeCase` should have a snake case name - --> $DIR/lint-non-snake-case-crate.rs:36:18 + --> $DIR/lint-non-snake-case-crate.rs:35:18 | LL | #![crate_name = "NonSnakeCase"] | ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case` | note: the lint level is defined here - --> $DIR/lint-non-snake-case-crate.rs:38:9 + --> $DIR/lint-non-snake-case-crate.rs:37:9 | LL | #![deny(non_snake_case)] | ^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rs b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rs index 6f701cd27c62c..a63e9c5ddf24e 100644 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rs +++ b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rs @@ -10,28 +10,27 @@ // But should fire on non-binary crates. -// FIXME(#132309): dylib crate type is not supported on wasm; we need a proper -// supports-crate-type directive. Also, needs-dynamic-linking should rule out -// musl since it supports neither dylibs nor cdylibs. -//@[dylib_] ignore-wasm -//@[dylib_] ignore-musl -//@[cdylib_] ignore-musl - -//@[dylib_] needs-dynamic-linking +//@[cdylib_] compile-flags: --crate-type=cdylib //@[cdylib_] needs-dynamic-linking -//@[proc_macro_] force-host -//@[proc_macro_] no-prefer-dynamic +//@[cdylib_] needs-crate-type: cdylib -//@[cdylib_] compile-flags: --crate-type=cdylib //@[dylib_] compile-flags: --crate-type=dylib +//@[dylib_] needs-dynamic-linking +//@[dylib_] needs-crate-type: dylib + //@[lib_] compile-flags: --crate-type=lib + +//@[proc_macro_] force-host +//@[proc_macro_] no-prefer-dynamic //@[proc_macro_] compile-flags: --crate-type=proc-macro +// The compiler may emit a warning that causes stderr output that contains a warning this test does +// not wish to check. +//@[proc_macro_] needs-unwind +//@[proc_macro_] needs-crate-type: proc-macro + //@[rlib_] compile-flags: --crate-type=rlib -//@[staticlib_] compile-flags: --crate-type=staticlib -// The compiler may emit a warning that causes stderr output -// that contains a warning this test does not wish to check. -//@[proc_macro_] needs-unwind +//@[staticlib_] compile-flags: --crate-type=staticlib #![crate_name = "NonSnakeCase"] //[cdylib_,dylib_,lib_,proc_macro_,rlib_,staticlib_]~^ ERROR crate `NonSnakeCase` should have a snake case name diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.staticlib_.stderr b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.staticlib_.stderr index 1192b690e29c2..a9c0188674425 100644 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.staticlib_.stderr +++ b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.staticlib_.stderr @@ -1,11 +1,11 @@ error: crate `NonSnakeCase` should have a snake case name - --> $DIR/lint-non-snake-case-crate.rs:36:18 + --> $DIR/lint-non-snake-case-crate.rs:35:18 | LL | #![crate_name = "NonSnakeCase"] | ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case` | note: the lint level is defined here - --> $DIR/lint-non-snake-case-crate.rs:38:9 + --> $DIR/lint-non-snake-case-crate.rs:37:9 | LL | #![deny(non_snake_case)] | ^^^^^^^^^^^^^^ diff --git a/tests/ui/panic-runtime/abort-link-to-unwind-dylib.rs b/tests/ui/panic-runtime/abort-link-to-unwind-dylib.rs index 8b782413f6a41..a691ceb566b0c 100644 --- a/tests/ui/panic-runtime/abort-link-to-unwind-dylib.rs +++ b/tests/ui/panic-runtime/abort-link-to-unwind-dylib.rs @@ -1,9 +1,7 @@ //@ build-fail //@ compile-flags:-C panic=abort -C prefer-dynamic //@ needs-unwind -//@ ignore-musl - no dylibs here -//@ ignore-emscripten -//@ ignore-sgx no dynamic lib support +//@ needs-crate-type: dylib // This is a test where the local crate, compiled with `panic=abort`, links to // the standard library **dynamically** which is already linked against