Skip to content

Commit c5e1340

Browse files
committed
Auto merge of rust-lang#139242 - jieyouxu:run-make-artifact-names-cross, r=<try>
Fix `run-make-support` artifact name calculations for target on cross-compile 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 rust-lang#138066. r? `@Kobzol` `@rustbot` author (needs try-jobs) try-job: armhf-gnu try-job: test-various try-job: `*windows*` try-job: `*apple*`
2 parents c9cd707 + cc4aee9 commit c5e1340

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed

src/bootstrap/src/utils/shared_helpers.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub fn dylib_path() -> Vec<std::path::PathBuf> {
4545

4646
/// Given an executable called `name`, return the filename for the
4747
/// executable for a particular target.
48+
// Intentionally duplicated with the `exe_name` helper in `build_helpers::artifact_names`.
4849
pub fn exe(name: &str, target: &str) -> String {
4950
if target.contains("windows") {
5051
format!("{name}.exe")
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/// Given a dynamic library name, construct its filename for the given target.
2+
pub fn dynamic_lib_name(name: &str, target: &str) -> String {
3+
format!("{}{name}.{}", dynamic_lib_prefix(target), dynamic_lib_extension(target))
4+
}
5+
6+
fn dynamic_lib_prefix(target: &str) -> &'static str {
7+
if target.contains("windows") { "" } else { "lib" }
8+
}
9+
10+
/// Get the dylib extension for the given target.
11+
pub fn dynamic_lib_extension(target: &str) -> &'static str {
12+
if target.contains("apple") {
13+
"dylib"
14+
} else if target.contains("windows") {
15+
"dll"
16+
} else {
17+
"so"
18+
}
19+
}
20+
21+
/// Given a dynamic library name, construct its filename for the given target.
22+
// Intentionally duplicated with the `exe` helper in `bootstrap::utils::shared_helpers`.
23+
pub fn exe_name(name: &str, target: &str) -> String {
24+
if target.contains("windows") {
25+
format!("{name}.exe")
26+
} else if target.contains("uefi") {
27+
format!("{name}.efi")
28+
} else if target.contains("wasm") {
29+
format!("{name}.wasm")
30+
} else {
31+
name.to_string()
32+
}
33+
}
34+
35+
/// Given a static library name, construct its filename for the given target.
36+
pub fn static_lib_name(name: &str, target: &str) -> String {
37+
if target.contains("msvc") { format!("{name}.lib") } else { format!("lib{name}.a") }
38+
}

src/build_helper/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Types and functions shared across tools in this workspace.
22
3+
pub mod artifact_names;
34
pub mod ci;
45
pub mod drop_bomb;
56
pub mod fs;

src/tools/run-make-support/src/artifact_names.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
//! 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.
53
4+
use crate::target;
65
use crate::targets::is_msvc;
76

87
/// Construct the static library name based on the target.
8+
#[track_caller]
99
#[must_use]
1010
pub fn static_lib_name(name: &str) -> String {
1111
assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
1212

13-
if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") }
13+
build_helper::artifact_names::static_lib_name(name, &target())
1414
}
1515

1616
/// Construct the dynamic library name based on the target.
17+
#[track_caller]
1718
#[must_use]
1819
pub fn dynamic_lib_name(name: &str) -> String {
1920
assert!(!name.contains(char::is_whitespace), "dynamic library name cannot contain whitespace");
2021

21-
format!("{}{name}.{}", std::env::consts::DLL_PREFIX, std::env::consts::DLL_EXTENSION)
22+
build_helper::artifact_names::dynamic_lib_name(name, &target())
2223
}
2324

2425
/// Construct the name of the import library for the dynamic library, exclusive to MSVC and
@@ -35,17 +36,19 @@ pub fn msvc_import_dynamic_lib_name(name: &str) -> String {
3536
/// Construct the dynamic library extension based on the target.
3637
#[must_use]
3738
pub fn dynamic_lib_extension() -> &'static str {
38-
std::env::consts::DLL_EXTENSION
39+
build_helper::artifact_names::dynamic_lib_extension(&target())
3940
}
4041

4142
/// Construct the name of a rust library (rlib).
43+
#[track_caller]
4244
#[must_use]
4345
pub fn rust_lib_name(name: &str) -> String {
4446
format!("lib{name}.rlib")
4547
}
4648

4749
/// Construct the binary (executable) name based on the target.
50+
#[track_caller]
4851
#[must_use]
4952
pub fn bin_name(name: &str) -> String {
50-
format!("{name}{}", std::env::consts::EXE_SUFFIX)
53+
build_helper::artifact_names::exe_name(name, &target())
5154
}

0 commit comments

Comments
 (0)