Auto merge of #139242 - jieyouxu:run-make-artifact-names-cross, r=Kobzol

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-1
This commit is contained in:
bors 2025-04-12 16:54:16 +00:00
commit 9ffde4b089
8 changed files with 81 additions and 19 deletions

View file

@ -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())
}
/// Construct the name of the import library for the dynamic library, exclusive to MSVC and
/// accepted by link.exe.
fn dynamic_lib_prefix() -> &'static str {
if target().contains("windows") { "" } else { "lib" }
}
/// 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()
}
}