Skip to content

Commit bfa10ac

Browse files
committed
rewrite manual-link to rmake
1 parent 034a4c5 commit bfa10ac

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
@@ -321,6 +321,26 @@ pub fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str)
321321
count
322322
}
323323

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

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ run-make/lto-linkage-used-attr/Makefile
7676
run-make/lto-no-link-whole-rlib/Makefile
7777
run-make/lto-smoke-c/Makefile
7878
run-make/macos-deployment-target/Makefile
79-
run-make/manual-link/Makefile
8079
run-make/min-global-align/Makefile
8180
run-make/missing-crate-dependency/Makefile
8281
run-make/mixing-libs/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)