| author | bors <bors@rust-lang.org> 2025-04-12 16:54:16 UTC |
| committer | bors <bors@rust-lang.org> 2025-04-12 16:54:16 UTC |
| log | 9ffde4b089fe8e43d5891eb517001df27a8443ff |
| tree | f79b49a32473e09330f6aad716c3a234c1222596 |
| parent | 7cd6e2f94e18fa7ef92df03a2ede1b7aa773b27d |
| parent | 4362789eb0b3001905f338a6e865c437b4756461 |
run-make-support: Calculate artifact names for target platform, not host platform
This was implemented incorrectly during the porting process, where we relied on std consts. However, `run-make-support` is a host-only library, which meant that these artifact names were for the *host* and not the *target*.
Helps with #138066.
r? `@Kobzol`
try-job: armhf-gnu
try-job: test-various
try-job: x86_64-msvc-1
try-job: i686-msvc-1
try-job: x86_64-mingw-1
try-job: aarch64-apple
try-job: x86_64-apple-18 files changed, 81 insertions(+), 19 deletions(-)
src/tools/run-make-support/src/artifact_names.rs+40-13| ... | ... | @@ -1,11 +1,11 @@ |
| 1 | 1 | //! A collection of helpers to construct artifact names, such as names of dynamic or static |
| 2 | //! librarys which are target-dependent. | |
| 3 | ||
| 4 | // FIXME(jieyouxu): convert these to return `PathBuf`s instead of strings! | |
| 2 | //! libraries which are target-dependent. | |
| 5 | 3 | |
| 4 | use crate::target; | |
| 6 | 5 | use crate::targets::is_msvc; |
| 7 | 6 | |
| 8 | 7 | /// Construct the static library name based on the target. |
| 8 | #[track_caller] | |
| 9 | 9 | #[must_use] |
| 10 | 10 | pub fn static_lib_name(name: &str) -> String { |
| 11 | 11 | assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace"); |
| ... | ... | @@ -14,15 +14,34 @@ pub fn static_lib_name(name: &str) -> String { |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /// Construct the dynamic library name based on the target. |
| 17 | #[track_caller] | |
| 17 | 18 | #[must_use] |
| 18 | 19 | pub fn dynamic_lib_name(name: &str) -> String { |
| 19 | 20 | assert!(!name.contains(char::is_whitespace), "dynamic library name cannot contain whitespace"); |
| 20 | 21 | |
| 21 | format!("{}{name}.{}", std::env::consts::DLL_PREFIX, std::env::consts::DLL_EXTENSION) | |
| 22 | format!("{}{name}.{}", dynamic_lib_prefix(), dynamic_lib_extension()) | |
| 23 | } | |
| 24 | ||
| 25 | fn dynamic_lib_prefix() -> &'static str { | |
| 26 | if target().contains("windows") { "" } else { "lib" } | |
| 22 | 27 | } |
| 23 | 28 | |
| 24 | /// Construct the name of the import library for the dynamic library, exclusive to MSVC and | |
| 25 | /// accepted by link.exe. | |
| 29 | /// Construct the dynamic library extension based on the target. | |
| 30 | #[must_use] | |
| 31 | pub fn dynamic_lib_extension() -> &'static str { | |
| 32 | let target = target(); | |
| 33 | ||
| 34 | if target.contains("apple") { | |
| 35 | "dylib" | |
| 36 | } else if target.contains("windows") { | |
| 37 | "dll" | |
| 38 | } else { | |
| 39 | "so" | |
| 40 | } | |
| 41 | } | |
| 42 | ||
| 43 | /// Construct the name of the import library for the dynamic library, exclusive to MSVC and accepted | |
| 44 | /// by link.exe. | |
| 26 | 45 | #[track_caller] |
| 27 | 46 | #[must_use] |
| 28 | 47 | pub fn msvc_import_dynamic_lib_name(name: &str) -> String { |
| ... | ... | @@ -32,20 +51,28 @@ pub fn msvc_import_dynamic_lib_name(name: &str) -> String { |
| 32 | 51 | format!("{name}.dll.lib") |
| 33 | 52 | } |
| 34 | 53 | |
| 35 | /// Construct the dynamic library extension based on the target. | |
| 36 | #[must_use] | |
| 37 | pub fn dynamic_lib_extension() -> &'static str { | |
| 38 | std::env::consts::DLL_EXTENSION | |
| 39 | } | |
| 40 | ||
| 41 | 54 | /// Construct the name of a rust library (rlib). |
| 55 | #[track_caller] | |
| 42 | 56 | #[must_use] |
| 43 | 57 | pub fn rust_lib_name(name: &str) -> String { |
| 44 | 58 | format!("lib{name}.rlib") |
| 45 | 59 | } |
| 46 | 60 | |
| 47 | 61 | /// Construct the binary (executable) name based on the target. |
| 62 | #[track_caller] | |
| 48 | 63 | #[must_use] |
| 49 | 64 | pub fn bin_name(name: &str) -> String { |
| 50 | format!("{name}{}", std::env::consts::EXE_SUFFIX) | |
| 65 | let target = target(); | |
| 66 | ||
| 67 | if target.contains("windows") { | |
| 68 | format!("{name}.exe") | |
| 69 | } else if target.contains("uefi") { | |
| 70 | format!("{name}.efi") | |
| 71 | } else if target.contains("wasm") { | |
| 72 | format!("{name}.wasm") | |
| 73 | } else if target.contains("nvptx") { | |
| 74 | format!("{name}.ptx") | |
| 75 | } else { | |
| 76 | name.to_string() | |
| 77 | } | |
| 51 | 78 | } |
tests/run-make/crate-data-smoke/rmake.rs+27-5| ... | ... | @@ -1,9 +1,20 @@ |
| 1 | use run_make_support::{bin_name, rust_lib_name, rustc}; | |
| 1 | use run_make_support::{bin_name, rust_lib_name, rustc, target}; | |
| 2 | 2 | |
| 3 | 3 | fn main() { |
| 4 | rustc().print("crate-name").input("crate.rs").run().assert_stdout_equals("foo"); | |
| 5 | rustc().print("file-names").input("crate.rs").run().assert_stdout_equals(bin_name("foo")); | |
| 6 | 4 | rustc() |
| 5 | .target(target()) | |
| 6 | .print("crate-name") | |
| 7 | .input("crate.rs") | |
| 8 | .run() | |
| 9 | .assert_stdout_equals("foo"); | |
| 10 | rustc() | |
| 11 | .target(target()) | |
| 12 | .print("file-names") | |
| 13 | .input("crate.rs") | |
| 14 | .run() | |
| 15 | .assert_stdout_equals(bin_name("foo")); | |
| 16 | rustc() | |
| 17 | .target(target()) | |
| 7 | 18 | .print("file-names") |
| 8 | 19 | .crate_type("lib") |
| 9 | 20 | .arg("--test") |
| ... | ... | @@ -11,11 +22,22 @@ fn main() { |
| 11 | 22 | .run() |
| 12 | 23 | .assert_stdout_equals(bin_name("foo")); |
| 13 | 24 | rustc() |
| 25 | .target(target()) | |
| 14 | 26 | .print("file-names") |
| 15 | 27 | .arg("--test") |
| 16 | 28 | .input("lib.rs") |
| 17 | 29 | .run() |
| 18 | 30 | .assert_stdout_equals(bin_name("mylib")); |
| 19 | rustc().print("file-names").input("lib.rs").run().assert_stdout_equals(rust_lib_name("mylib")); | |
| 20 | rustc().print("file-names").input("rlib.rs").run().assert_stdout_equals(rust_lib_name("mylib")); | |
| 31 | rustc() | |
| 32 | .target(target()) | |
| 33 | .print("file-names") | |
| 34 | .input("lib.rs") | |
| 35 | .run() | |
| 36 | .assert_stdout_equals(rust_lib_name("mylib")); | |
| 37 | rustc() | |
| 38 | .target(target()) | |
| 39 | .print("file-names") | |
| 40 | .input("rlib.rs") | |
| 41 | .run() | |
| 42 | .assert_stdout_equals(rust_lib_name("mylib")); | |
| 21 | 43 | } |
tests/run-make/crate-name-priority/rmake.rs+2| ... | ... | @@ -4,6 +4,8 @@ |
| 4 | 4 | // and the compiler flags, and checks that the flag is favoured each time. |
| 5 | 5 | // See https://github.com/rust-lang/rust/pull/15518 |
| 6 | 6 | |
| 7 | //@ ignore-cross-compile (relocations in generic ELF against `arm-unknown-linux-gnueabihf`) | |
| 8 | ||
| 7 | 9 | use run_make_support::{bin_name, rfs, rustc}; |
| 8 | 10 | |
| 9 | 11 | fn main() { |
tests/run-make/extra-filename-with-temp-outputs/rmake.rs+2| ... | ... | @@ -6,6 +6,8 @@ |
| 6 | 6 | // are named as expected. |
| 7 | 7 | // See https://github.com/rust-lang/rust/pull/15686 |
| 8 | 8 | |
| 9 | //@ ignore-cross-compile (relocations in generic ELF against `arm-unknown-linux-gnueabihf`) | |
| 10 | ||
| 9 | 11 | use run_make_support::{bin_name, cwd, has_prefix, has_suffix, rfs, rustc, shallow_find_files}; |
| 10 | 12 | |
| 11 | 13 | fn main() { |
tests/run-make/output-type-permutations/rmake.rs+4| ... | ... | @@ -4,6 +4,9 @@ |
| 4 | 4 | // files are exactly what is expected, no more, no less. |
| 5 | 5 | // See https://github.com/rust-lang/rust/pull/12020 |
| 6 | 6 | |
| 7 | //@ ignore-cross-compile | |
| 8 | // Reason: some cross-compiled targets don't support various crate types and fail to link. | |
| 9 | ||
| 7 | 10 | use std::path::PathBuf; |
| 8 | 11 | |
| 9 | 12 | use run_make_support::{ |
| ... | ... | @@ -17,6 +20,7 @@ use run_make_support::{ |
| 17 | 20 | // `dir`: the name of the directory where the test happens |
| 18 | 21 | // `rustc_invocation`: the rustc command being tested |
| 19 | 22 | // Any unexpected output files not listed in `must_exist` or `can_exist` will cause a failure. |
| 23 | #[track_caller] | |
| 20 | 24 | fn assert_expected_output_files(expectations: Expectations, rustc_invocation: impl Fn()) { |
| 21 | 25 | let Expectations { expected_files: must_exist, allowed_files: can_exist, test_dir: dir } = |
| 22 | 26 | expectations; |
tests/run-make/reproducible-build/rmake.rs+2| ... | ... | @@ -20,6 +20,8 @@ |
| 20 | 20 | // See https://github.com/rust-lang/rust/pull/32293 |
| 21 | 21 | // Tracking Issue: https://github.com/rust-lang/rust/issues/129080 |
| 22 | 22 | |
| 23 | //@ ignore-cross-compile (linker binary needs to run) | |
| 24 | ||
| 23 | 25 | use run_make_support::{ |
| 24 | 26 | bin_name, cwd, diff, is_darwin, is_windows, regex, rfs, run_in_tmpdir, rust_lib_name, rustc, |
| 25 | 27 | }; |
tests/run-make/strip/rmake.rs+2-1| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | //@ ignore-windows Windows does not actually strip | |
| 1 | //@ ignore-windows (Windows does not actually strip) | |
| 2 | //@ ignore-cross-compile (relocations in generic ELF against `arm-unknown-linux-gnueabihf`) | |
| 2 | 3 | |
| 3 | 4 | // Test that -Cstrip correctly strips/preserves debuginfo and symbols. |
| 4 | 5 |
tests/run-make/symbols-all-mangled/rmake.rs+2| ... | ... | @@ -1,5 +1,7 @@ |
| 1 | 1 | // Check that all symbols in cdylibs, staticlibs and bins are mangled |
| 2 | 2 | //@ only-elf some object file formats create multiple symbols for each function with different names |
| 3 | //@ ignore-nvptx64 (needs target std) | |
| 4 | //@ ignore-cross-compile (host-only) | |
| 3 | 5 | |
| 4 | 6 | use run_make_support::object::read::{Object, ObjectSymbol}; |
| 5 | 7 | use run_make_support::{bin_name, dynamic_lib_name, object, rfs, rustc, static_lib_name}; |