Skip to content

Commit 3b495bb

Browse files
committed
rewrite prune-link-args to rmake format
1 parent b55fa8f commit 3b495bb

File tree

8 files changed

+99
-80
lines changed

8 files changed

+99
-80
lines changed

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::Path;
22

33
use crate::command::Command;
4-
use crate::{bin_name, cygpath_windows, env_var, is_msvc, is_windows, uname};
4+
use crate::{cygpath_windows, env_var, is_msvc, is_windows, uname};
55

66
/// Construct a new platform-specific C compiler invocation.
77
///
@@ -68,9 +68,14 @@ impl Cc {
6868
// endif
6969
// ```
7070

71+
let mut path = std::path::PathBuf::from(name);
72+
7173
if is_msvc() {
72-
let fe_path = cygpath_windows(bin_name(name));
73-
let fo_path = cygpath_windows(format!("{name}.obj"));
74+
path.set_extension("exe");
75+
let fe_path = cygpath_windows(&path);
76+
path.set_extension("");
77+
path.set_extension("obj");
78+
let fo_path = cygpath_windows(path);
7479
self.cmd.arg(format!("-Fe:{fe_path}"));
7580
self.cmd.arg(format!("-Fo:{fo_path}"));
7681
} else {

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

+20
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,26 @@ pub fn not_contains<P: AsRef<Path>>(path: P, expected: &str) -> bool {
294294
!path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().contains(expected))
295295
}
296296

297+
/// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name.
298+
#[track_caller]
299+
pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
300+
let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
301+
let src = format!("{lib_name}.c");
302+
let lib_path = static_lib_name(lib_name);
303+
if is_msvc() {
304+
cc().arg("-c").out_exe(&obj_file).input(src).run();
305+
} else {
306+
cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
307+
};
308+
let mut obj_file = PathBuf::from(format!("{lib_name}.o"));
309+
if is_msvc() {
310+
obj_file.set_extension("");
311+
obj_file.set_extension("obj");
312+
}
313+
ar(&[obj_file], &lib_path);
314+
path(lib_path)
315+
}
316+
297317
/// Returns true if the filename at `path` is not in `expected`.
298318
pub fn filename_not_in_denylist<P: AsRef<Path>, V: AsRef<[String]>>(path: P, expected: V) -> bool {
299319
let expected = expected.as_ref();

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ impl Rustc {
135135
self.cmd.arg("--remap-path-prefix");
136136
self.cmd.arg(format!("{from}={to}"));
137137

138+
self
139+
}
140+
138141
/// Specify path to the input file.
139142
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
140143
self.cmd.arg(path.as_ref());
@@ -239,7 +242,8 @@ impl Rustc {
239242
self
240243
}
241244

242-
/// Add a directory to the library search path with a restriction. Equivalent to `-L KIND=PATH` in rustc.
245+
/// Add a directory to the library search path with a restriction, where `kind` is a dependency
246+
/// type. Equivalent to `-L KIND=PATH` in rustc.
243247
pub fn specific_library_search_path<P: AsRef<Path>>(
244248
&mut self,
245249
kind: &str,

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ run-make/pgo-indirect-call-promotion/Makefile
9494
run-make/pointer-auth-link-with-c/Makefile
9595
run-make/print-calling-conventions/Makefile
9696
run-make/print-target-list/Makefile
97-
run-make/prune-link-args/Makefile
9897
run-make/raw-dylib-alt-calling-convention/Makefile
9998
run-make/raw-dylib-c/Makefile
10099
run-make/raw-dylib-custom-dlltool/Makefile

tests/run-make/compiler-lookup-paths/rmake.rs

+44-63
Original file line numberDiff line numberDiff line change
@@ -5,99 +5,80 @@
55
// fail to be used by the compiler.
66
// See https://github.com./rust-lang/rust/pull/19941
77

8-
use run_make_support::fs_wrapper;
9-
use run_make_support::{rmake_out_path, rustc};
8+
//@ ignore-wasm32
9+
//@ ignore-wasm64
10+
// Reason: a C compiler is required for build_native_static_lib
11+
12+
use run_make_support::{build_native_static_lib, fs_wrapper, rustc, static_lib_name};
1013

1114
fn main() {
12-
assert!(rmake_out_path("libnative.a").exists());
13-
fs_wrapper::create_dir_all(rmake_out_path("crate"));
14-
fs_wrapper::create_dir_all(rmake_out_path("native"));
15-
fs_wrapper::rename(rmake_out_path("libnative.a"), rmake_out_path("native"));
15+
build_native_static_lib("native");
16+
let lib_native = static_lib_name("native");
17+
fs_wrapper::create_dir_all("crate");
18+
fs_wrapper::create_dir_all("native");
19+
fs_wrapper::rename(&lib_native, format!("native/{}", &lib_native));
1620
rustc().input("a.rs").run();
17-
fs_wrapper::rename(rmake_out_path("liba.a"), rmake_out_path("crate"));
18-
rustc()
19-
.input("b.rs")
20-
.specific_library_search_path("native", rmake_out_path("crate"))
21-
.run_fail();
22-
rustc()
23-
.input("b.rs")
24-
.specific_library_search_path("dependency", rmake_out_path("crate"))
25-
.run_fail();
26-
rustc().input("b.rs").specific_library_search_path("crate", rmake_out_path("crate")).run();
27-
rustc().input("b.rs").specific_library_search_path("all", rmake_out_path("crate")).run();
21+
fs_wrapper::rename("liba.rlib", "crate/liba.rlib");
22+
rustc().input("b.rs").specific_library_search_path("native", "crate").run_fail();
23+
rustc().input("b.rs").specific_library_search_path("dependency", "crate").run_fail();
24+
rustc().input("b.rs").specific_library_search_path("crate", "crate").run();
25+
rustc().input("b.rs").specific_library_search_path("all", "crate").run();
2826

29-
rustc()
30-
.input("c.rs")
31-
.specific_library_search_path("native", rmake_out_path("crate"))
32-
.run_fail();
33-
rustc().input("c.rs").specific_library_search_path("crate", rmake_out_path("crate")).run_fail();
34-
rustc().input("c.rs").specific_library_search_path("dependency", rmake_out_path("crate")).run();
35-
rustc().input("c.rs").specific_library_search_path("all", rmake_out_path("crate")).run();
27+
rustc().input("c.rs").specific_library_search_path("native", "crate").run_fail();
28+
rustc().input("c.rs").specific_library_search_path("crate", "crate").run_fail();
29+
rustc().input("c.rs").specific_library_search_path("dependency", "crate").run();
30+
rustc().input("c.rs").specific_library_search_path("all", "crate").run();
3631

37-
rustc()
38-
.input("d.rs")
39-
.specific_library_search_path("dependency", rmake_out_path("native"))
40-
.run_fail();
41-
rustc()
42-
.input("d.rs")
43-
.specific_library_search_path("crate", rmake_out_path("native"))
44-
.run_fail();
45-
rustc().input("d.rs").specific_library_search_path("native", rmake_out_path("native")).run();
46-
rustc().input("d.rs").specific_library_search_path("all", rmake_out_path("native")).run();
32+
rustc().input("d.rs").specific_library_search_path("dependency", "native").run_fail();
33+
rustc().input("d.rs").specific_library_search_path("crate", "native").run_fail();
34+
rustc().input("d.rs").specific_library_search_path("native", "native").run();
35+
rustc().input("d.rs").specific_library_search_path("all", "native").run();
4736

4837
// Deduplication tests.
49-
fs_wrapper::create_dir_all(rmake_out_path("e1"));
50-
fs_wrapper::create_dir_all(rmake_out_path("e2"));
38+
fs_wrapper::create_dir_all("e1");
39+
fs_wrapper::create_dir_all("e2");
5140

52-
rustc().input("e.rs").output(rmake_out_path("e1/libe.rlib")).run();
53-
rustc().input("e.rs").output(rmake_out_path("e2/libe.rlib")).run();
41+
rustc().input("e.rs").output("e1/libe.rlib").run();
42+
rustc().input("e.rs").output("e2/libe.rlib").run();
5443
// If the library hash is correct, compilation should succeed.
44+
rustc().input("f.rs").library_search_path("e1").library_search_path("e2").run();
5545
rustc()
5646
.input("f.rs")
57-
.library_search_path(rmake_out_path("e1"))
58-
.library_search_path(rmake_out_path("e2"))
59-
.run();
60-
rustc()
61-
.input("f.rs")
62-
.specific_library_search_path("crate", rmake_out_path("e1"))
63-
.library_search_path(rmake_out_path("e2"))
47+
.specific_library_search_path("crate", "e1")
48+
.library_search_path("e2")
6449
.run();
6550
rustc()
6651
.input("f.rs")
67-
.specific_library_search_path("crate", rmake_out_path("e1"))
68-
.specific_library_search_path("crate", rmake_out_path("e2"))
52+
.specific_library_search_path("crate", "e1")
53+
.specific_library_search_path("crate", "e2")
6954
.run();
7055
// If the library has a different hash, errors should occur.
71-
rustc().input("e2.rs").output(rmake_out_path("e2/libe.rlib")).run();
72-
rustc()
73-
.input("f.rs")
74-
.library_search_path(rmake_out_path("e1"))
75-
.library_search_path(rmake_out_path("e2"))
76-
.run_fail();
56+
rustc().input("e2.rs").output("e2/libe.rlib").run();
57+
rustc().input("f.rs").library_search_path("e1").library_search_path("e2").run_fail();
7758
rustc()
7859
.input("f.rs")
79-
.specific_library_search_path("crate", rmake_out_path("e1"))
80-
.library_search_path(rmake_out_path("e2"))
60+
.specific_library_search_path("crate", "e1")
61+
.library_search_path("e2")
8162
.run_fail();
8263
rustc()
8364
.input("f.rs")
84-
.specific_library_search_path("crate", rmake_out_path("e1"))
85-
.specific_library_search_path("crate", rmake_out_path("e2"))
65+
.specific_library_search_path("crate", "e1")
66+
.specific_library_search_path("crate", "e2")
8667
.run_fail();
8768
// Native and dependency paths do not cause errors.
8869
rustc()
8970
.input("f.rs")
90-
.specific_library_search_path("native", rmake_out_path("e1"))
91-
.library_search_path(rmake_out_path("e2"))
71+
.specific_library_search_path("native", "e1")
72+
.library_search_path("e2")
9273
.run();
9374
rustc()
9475
.input("f.rs")
95-
.specific_library_search_path("dependency", rmake_out_path("e1"))
96-
.library_search_path(rmake_out_path("e2"))
76+
.specific_library_search_path("dependency", "e1")
77+
.library_search_path("e2")
9778
.run();
9879
rustc()
9980
.input("f.rs")
100-
.specific_library_search_path("dependency", rmake_out_path("e1"))
101-
.specific_library_search_path("crate", rmake_out_path("e2"))
81+
.specific_library_search_path("dependency", "e1")
82+
.specific_library_search_path("crate", "e2")
10283
.run();
10384
}

tests/run-make/dump-mono-stats/rmake.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
use run_make_support::{cwd, fs_wrapper, rustc};
88

99
fn main() {
10-
rustc().crate_type("lib").input("foo.rs").dump_mono_stats(cwd()).arg("-Zdump-mono-stats-format=json").run();
11-
assert!(fs_wrapper::read_to_string("foo.mono_items.json").contains("\"name\":\"bar\"");
10+
rustc()
11+
.crate_type("lib")
12+
.input("foo.rs")
13+
.arg(format!("-Zdump-mono-stats={}", cwd().display()))
14+
.arg("-Zdump-mono-stats-format=json")
15+
.run();
16+
assert!(fs_wrapper::read_to_string("foo.mono_items.json").contains(r#""name":"bar""#));
1217
}

tests/run-make/prune-link-args/Makefile

-10
This file was deleted.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Passing link-args with an unexpected space
2+
// could result in the flag being parsed and receiving
3+
// an unexpected, empty linker argument. This test
4+
// ensures successful compilation even when a space is
5+
// present.
6+
// See https://github.com./rust-lang/rust/pull/10749
7+
8+
//@ ignore-cross-compile
9+
10+
use run_make_support::rustc;
11+
12+
fn main() {
13+
// Notice the space at the end of -lc, which emulates the output of pkg-config.
14+
rustc().arg("-Clink-args=-lc ").input("empty.rs").run();
15+
}

0 commit comments

Comments
 (0)