Skip to content

Commit 0fdfa4c

Browse files
committed
Auto merge of #127872 - Oneirical:antestral-traditions, r=<try>
Migrate `pointer-auth-link-with-c`, `c-dynamic-rlib` and `c-dynamic-dylib` `run-make` tests to rmake Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). Please try: try-job: x86_64-msvc try-job: i686-mingw try-job: aarch64-apple
2 parents f00f850 + 0fa1214 commit 0fdfa4c

File tree

9 files changed

+101
-56
lines changed

9 files changed

+101
-56
lines changed

Diff for: src/tools/run-make-support/src/external_deps/c_build.rs

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use std::path::PathBuf;
22

3-
use crate::artifact_names::static_lib_name;
3+
use super::cygpath::get_windows_path;
4+
use crate::artifact_names::{dynamic_lib_name, static_lib_name};
45
use crate::external_deps::cc::cc;
56
use crate::external_deps::llvm::llvm_ar;
67
use crate::path_helpers::path;
7-
use crate::targets::is_msvc;
8+
use crate::targets::{is_darwin, is_msvc, is_windows};
89

910
/// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name.
1011
#[track_caller]
@@ -25,3 +26,33 @@ pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
2526
llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run();
2627
path(lib_path)
2728
}
29+
30+
/// Builds a dynamic lib (`.dll` on Windows, `.dylib` on OSX and `.so` for Linux) with the given
31+
/// name.
32+
#[track_caller]
33+
pub fn build_native_dynamic_lib(lib_name: &str) -> PathBuf {
34+
let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
35+
let src = format!("{lib_name}.c");
36+
let lib_path = dynamic_lib_name(lib_name);
37+
if is_msvc() {
38+
cc().arg("-c").out_exe(&obj_file).input(src).run();
39+
} else {
40+
cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
41+
};
42+
let obj_file = if is_msvc() { format!("{lib_name}.obj") } else { format!("{lib_name}.o") };
43+
if is_msvc() {
44+
let mut out_arg = "-out".to_owned();
45+
out_arg.push_str(&get_windows_path(&lib_path));
46+
cc().input(&obj_file).args(&["-link", "-dll", &out_arg]).run();
47+
} else if is_darwin() {
48+
cc().out_exe(&lib_path)
49+
.input(&obj_file)
50+
.args(&["-shared", &format!("-Wl,--out-implib={lib_path}.a")])
51+
.run();
52+
} else if is_windows() {
53+
cc().out_exe(&lib_path).input(&obj_file).args(&["-dynamiclib", "-Wl,-dylib"]).run();
54+
} else {
55+
cc().out_exe(&lib_path).input(&obj_file).arg("-shared").run();
56+
}
57+
path(lib_path)
58+
}

Diff for: src/tools/run-make-support/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub use wasmparser;
3737
pub use external_deps::{c_build, cc, clang, htmldocck, llvm, python, rustc, rustdoc};
3838

3939
// These rely on external dependencies.
40-
pub use c_build::build_native_static_lib;
40+
pub use c_build::{build_native_dynamic_lib, build_native_static_lib};
4141
pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
4242
pub use clang::{clang, Clang};
4343
pub use htmldocck::htmldocck;

Diff for: src/tools/tidy/src/allowed_run_make_makefiles.txt

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
run-make/archive-duplicate-names/Makefile
22
run-make/atomic-lock-free/Makefile
33
run-make/branch-protection-check-IBT/Makefile
4-
run-make/c-dynamic-dylib/Makefile
5-
run-make/c-dynamic-rlib/Makefile
64
run-make/c-static-dylib/Makefile
75
run-make/c-static-rlib/Makefile
86
run-make/c-unwind-abi-catch-lib-panic/Makefile
@@ -88,7 +86,6 @@ run-make/pdb-buildinfo-cl-cmd/Makefile
8886
run-make/pgo-gen-lto/Makefile
8987
run-make/pgo-gen-no-imp-symbols/Makefile
9088
run-make/pgo-indirect-call-promotion/Makefile
91-
run-make/pointer-auth-link-with-c/Makefile
9289
run-make/print-calling-conventions/Makefile
9390
run-make/print-target-list/Makefile
9491
run-make/raw-dylib-alt-calling-convention/Makefile

Diff for: tests/run-make/c-dynamic-dylib/Makefile

-16
This file was deleted.

Diff for: tests/run-make/c-dynamic-dylib/rmake.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This test checks that dynamic Rust linking with C does not encounter any errors in both
2+
// compilation and execution, with dynamic dependencies given preference over static.
3+
// See https://github.com/rust-lang/rust/issues/10434
4+
5+
//@ ignore-cross-compile
6+
// Reason: the compiled binary is executed
7+
8+
//FIXME(Oneirical): test on apple because older versions of osx are failing apparently
9+
10+
use run_make_support::{build_native_dynamic_lib, dynamic_lib_name, rfs, run, run_fail, rustc};
11+
12+
fn main() {
13+
build_native_dynamic_lib("cfoo");
14+
rustc().input("foo.rs").arg("-Cprefer-dynamic").run();
15+
rustc().input("bar.rs").run();
16+
run("bar");
17+
rfs::remove_file(dynamic_lib_name("cfoo"));
18+
run_fail("bar");
19+
}

Diff for: tests/run-make/c-dynamic-rlib/Makefile

-19
This file was deleted.

Diff for: tests/run-make/c-dynamic-rlib/rmake.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This test checks that dynamic Rust linking with C does not encounter any errors in both
2+
// compilation and execution, with static dependencies given preference over dynamic.
3+
// (This is the default behaviour.)
4+
// See https://github.com/rust-lang/rust/issues/10434
5+
6+
//@ ignore-cross-compile
7+
// Reason: the compiled binary is executed
8+
9+
//FIXME(Oneirical): test on apple because older versions of osx are failing apparently
10+
11+
use run_make_support::{build_native_dynamic_lib, dynamic_lib_name, rfs, run, run_fail, rustc};
12+
13+
fn main() {
14+
build_native_dynamic_lib("cfoo");
15+
rustc().input("foo.rs").run();
16+
rustc().input("bar.rs").run();
17+
run("bar");
18+
rfs::remove_file(dynamic_lib_name("cfoo"));
19+
run_fail("bar");
20+
}

Diff for: tests/run-make/pointer-auth-link-with-c/Makefile

-15
This file was deleted.

Diff for: tests/run-make/pointer-auth-link-with-c/rmake.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// `-Z branch protection` is an unstable compiler feature which adds pointer-authentication
2+
// code (PAC), a useful hashing measure for verifying that pointers have not been modified.
3+
// This test checks that compilation and execution is successful when this feature is activated,
4+
// with some of its possible extra arguments (bti, pac-ret, leaf).
5+
// See https://github.com/rust-lang/rust/pull/88354
6+
7+
//@ only-aarch64
8+
// Reason: branch protection is not supported on other architectures
9+
//@ ignore-cross-compile
10+
// Reason: the compiled binary is executed
11+
12+
use run_make_support::{build_native_static_lib, cc, is_msvc, llvm_ar, run, rustc};
13+
14+
fn main() {
15+
build_native_static_lib("test");
16+
rustc().arg("-Zbranch-protection=bti,pac-ret,leaf").input("test.rs").run();
17+
run("test");
18+
cc().arg("-v")
19+
.arg("-c")
20+
.out_exe("test")
21+
.input("test.c")
22+
.arg("-mbranch-protection=bti+pac-ret+leaf")
23+
.run();
24+
let obj_file = if is_msvc() { "test.obj" } else { "test" };
25+
llvm_ar().obj_to_ar().output_input("libtest.a", &obj_file).run();
26+
rustc().arg("-Zbranch-protection=bti,pac-ret,leaf").input("test.rs").run();
27+
run("test");
28+
}

0 commit comments

Comments
 (0)