Skip to content

Commit b1ebdb1

Browse files
committed
Auto merge of rust-lang#139242 - jieyouxu:run-make-artifact-names-cross, r=<try>
[WIP] 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` 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: i686-mingw-1 try-job: aarch64-apple try-job: x86_64-apple-1
2 parents 5337252 + 0e57f60 commit b1ebdb1

File tree

8 files changed

+294
-160
lines changed

8 files changed

+294
-160
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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");
@@ -14,15 +14,34 @@ pub fn static_lib_name(name: &str) -> String {
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+
format!("{}{name}.{}", dynamic_lib_prefix(), dynamic_lib_extension())
23+
}
24+
25+
fn dynamic_lib_prefix() -> &'static str {
26+
if target().contains("windows") { "" } else { "lib" }
2227
}
2328

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.
2645
#[track_caller]
2746
#[must_use]
2847
pub fn msvc_import_dynamic_lib_name(name: &str) -> String {
@@ -32,20 +51,28 @@ pub fn msvc_import_dynamic_lib_name(name: &str) -> String {
3251
format!("{name}.dll.lib")
3352
}
3453

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-
4154
/// Construct the name of a rust library (rlib).
55+
#[track_caller]
4256
#[must_use]
4357
pub fn rust_lib_name(name: &str) -> String {
4458
format!("lib{name}.rlib")
4559
}
4660

4761
/// Construct the binary (executable) name based on the target.
62+
#[track_caller]
4863
#[must_use]
4964
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+
}
5178
}
+27-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
1-
use run_make_support::{bin_name, rust_lib_name, rustc};
1+
use run_make_support::{bin_name, rust_lib_name, rustc, target};
22

33
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"));
64
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())
718
.print("file-names")
819
.crate_type("lib")
920
.arg("--test")
1021
.input("crate.rs")
1122
.run()
1223
.assert_stdout_equals(bin_name("foo"));
1324
rustc()
25+
.target(target())
1426
.print("file-names")
1527
.arg("--test")
1628
.input("lib.rs")
1729
.run()
1830
.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"));
2143
}

tests/run-make/crate-name-priority/rmake.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
// and the compiler flags, and checks that the flag is favoured each time.
55
// See https://github.com/rust-lang/rust/pull/15518
66

7-
use run_make_support::{bin_name, rfs, rustc};
7+
//@ ignore-nvptx64 (no target std)
8+
9+
use run_make_support::{bin_name, rfs, rustc, target};
810

911
fn main() {
10-
rustc().input("foo.rs").run();
12+
rustc().target(target()).input("foo.rs").run();
1113
rfs::remove_file(bin_name("foo"));
12-
rustc().input("foo.rs").crate_name("bar").run();
14+
rustc().target(target()).input("foo.rs").crate_name("bar").run();
1315
rfs::remove_file(bin_name("bar"));
14-
rustc().input("foo1.rs").run();
16+
rustc().target(target()).input("foo1.rs").run();
1517
rfs::remove_file(bin_name("foo"));
16-
rustc().input("foo1.rs").output(bin_name("bar1")).run();
18+
rustc().target(target()).input("foo1.rs").output(bin_name("bar1")).run();
1719
rfs::remove_file(bin_name("bar1"));
1820
}

tests/run-make/extra-filename-with-temp-outputs/rmake.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
// are named as expected.
77
// See https://github.com/rust-lang/rust/pull/15686
88

9-
use run_make_support::{bin_name, cwd, has_prefix, has_suffix, rfs, rustc, shallow_find_files};
9+
//@ ignore-nvptx64 (no target std)
10+
11+
use run_make_support::{
12+
bin_name, cwd, has_prefix, has_suffix, rfs, rustc, shallow_find_files, target,
13+
};
1014

1115
fn main() {
12-
rustc().extra_filename("bar").input("foo.rs").arg("-Csave-temps").run();
16+
rustc().target(target()).extra_filename("bar").input("foo.rs").arg("-Csave-temps").run();
1317
let object_files = shallow_find_files(cwd(), |path| {
1418
has_prefix(path, "foobar.foo") && has_suffix(path, "0.rcgu.o")
1519
});

0 commit comments

Comments
 (0)