Skip to content

Commit 1548218

Browse files
committed
rewrite manual-link to rmake
1 parent 03c2439 commit 1548218

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,26 @@ pub fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str)
328328
count
329329
}
330330

331+
/// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name.
332+
#[track_caller]
333+
pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
334+
let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
335+
let src = format!("{lib_name}.c");
336+
let lib_path = static_lib_name(lib_name);
337+
if is_msvc() {
338+
cc().arg("-c").out_exe(&obj_file).input(src).run();
339+
} else {
340+
cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
341+
};
342+
let mut obj_file = PathBuf::from(format!("{lib_name}.o"));
343+
if is_msvc() {
344+
obj_file.set_extension("");
345+
obj_file.set_extension("obj");
346+
}
347+
llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run();
348+
path(lib_path)
349+
}
350+
331351
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
332352
/// available on the platform!
333353
#[track_caller]

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ run-make/lto-linkage-used-attr/Makefile
7373
run-make/lto-no-link-whole-rlib/Makefile
7474
run-make/lto-smoke-c/Makefile
7575
run-make/macos-deployment-target/Makefile
76-
run-make/manual-link/Makefile
7776
run-make/min-global-align/Makefile
7877
run-make/missing-crate-dependency/Makefile
7978
run-make/native-link-modifier-bundle/Makefile

tests/run-make/manual-link/Makefile

-7
This file was deleted.

tests/run-make/manual-link/rmake.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// A smoke test for the `-l` command line rustc flag, which manually links to the selected
2+
// library. Useful for native libraries, this is roughly equivalent to `#[link]` in Rust code.
3+
// If compilation succeeds, the flag successfully linked the native library.
4+
// See https://github.com/rust-lang/rust/pull/18470
5+
6+
//@ ignore-cross-compile
7+
// Reason: the compiled binary is executed
8+
9+
use run_make_support::{build_native_static_lib, run, rustc};
10+
11+
fn main() {
12+
build_native_static_lib("bar");
13+
rustc().input("foo.rs").arg("-lstatic=bar").run();
14+
rustc().input("main.rs").run();
15+
run("main");
16+
}

0 commit comments

Comments
 (0)