about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-07-25 04:43:19 +0200
committerGitHub <noreply@github.com>2024-07-25 04:43:19 +0200
commit04e4569ffd3fcb7ed94f1a214bab4e245907fe80 (patch)
treec64ab851fedfe4d16652e9a76554ae8c14c3a460 /src/tools
parentcce2db06c0206949c5d19d52472fd480ca2d60c0 (diff)
parent710e7b0c7581efcbb2d913738d1ec17f0a726387 (diff)
downloadrust-04e4569ffd3fcb7ed94f1a214bab4e245907fe80.tar.gz
rust-04e4569ffd3fcb7ed94f1a214bab4e245907fe80.zip
Rollup merge of #127872 - Oneirical:antestral-traditions, r=jieyouxu
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
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/run-make-support/src/external_deps/c_build.rs37
-rw-r--r--src/tools/run-make-support/src/fs.rs15
-rw-r--r--src/tools/run-make-support/src/lib.rs2
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt3
4 files changed, 50 insertions, 7 deletions
diff --git a/src/tools/run-make-support/src/external_deps/c_build.rs b/src/tools/run-make-support/src/external_deps/c_build.rs
index 35b2bf75c95..86c9c081831 100644
--- a/src/tools/run-make-support/src/external_deps/c_build.rs
+++ b/src/tools/run-make-support/src/external_deps/c_build.rs
@@ -1,10 +1,13 @@
 use std::path::PathBuf;
 
-use crate::artifact_names::static_lib_name;
+use super::cygpath::get_windows_path;
+use crate::artifact_names::{dynamic_lib_name, static_lib_name};
 use crate::external_deps::cc::cc;
 use crate::external_deps::llvm::llvm_ar;
 use crate::path_helpers::path;
-use crate::targets::is_msvc;
+use crate::targets::{is_darwin, is_msvc, is_windows};
+
+// FIXME(Oneirical): These native build functions should take a Path-based generic.
 
 /// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name.
 #[track_caller]
@@ -25,3 +28,33 @@ pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
     llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run();
     path(lib_path)
 }
+
+/// Builds a dynamic lib. The filename is computed in a target-dependent manner, relying on
+/// [`std::env::consts::DLL_PREFIX`] and [`std::env::consts::DLL_EXTENSION`].
+#[track_caller]
+pub fn build_native_dynamic_lib(lib_name: &str) -> PathBuf {
+    let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
+    let src = format!("{lib_name}.c");
+    let lib_path = dynamic_lib_name(lib_name);
+    if is_msvc() {
+        cc().arg("-c").out_exe(&obj_file).input(src).run();
+    } else {
+        cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
+    };
+    let obj_file = if is_msvc() { format!("{lib_name}.obj") } else { format!("{lib_name}.o") };
+    if is_msvc() {
+        let mut out_arg = "-out:".to_owned();
+        out_arg.push_str(&get_windows_path(&lib_path));
+        cc().input(&obj_file).args(&["-link", "-dll", &out_arg]).run();
+    } else if is_darwin() {
+        cc().out_exe(&lib_path).input(&obj_file).args(&["-dynamiclib", "-Wl,-dylib"]).run();
+    } else if is_windows() {
+        cc().out_exe(&lib_path)
+            .input(&obj_file)
+            .args(&["-shared", &format!("-Wl,--out-implib={lib_path}.a")])
+            .run();
+    } else {
+        cc().out_exe(&lib_path).input(&obj_file).arg("-shared").run();
+    }
+    path(lib_path)
+}
diff --git a/src/tools/run-make-support/src/fs.rs b/src/tools/run-make-support/src/fs.rs
index f346e983aea..0a796161633 100644
--- a/src/tools/run-make-support/src/fs.rs
+++ b/src/tools/run-make-support/src/fs.rs
@@ -1,5 +1,5 @@
 use std::io;
-use std::path::Path;
+use std::path::{Path, PathBuf};
 
 // FIXME(jieyouxu): modify create_symlink to panic on windows.
 
@@ -176,3 +176,16 @@ pub fn set_permissions<P: AsRef<Path>>(path: P, perm: std::fs::Permissions) {
         path.as_ref().display()
     ));
 }
+
+/// A function which prints all file names in the directory `dir` similarly to Unix's `ls`.
+/// Useful for debugging.
+/// Usage: `eprintln!("{:#?}", shallow_find_dir_entries(some_dir));`
+#[track_caller]
+pub fn shallow_find_dir_entries<P: AsRef<Path>>(dir: P) -> Vec<PathBuf> {
+    let paths = read_dir(dir);
+    let mut output = Vec::new();
+    for path in paths {
+        output.push(path.unwrap().path());
+    }
+    output
+}
diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs
index b85191970de..a4bb9056346 100644
--- a/src/tools/run-make-support/src/lib.rs
+++ b/src/tools/run-make-support/src/lib.rs
@@ -43,7 +43,7 @@ pub use wasmparser;
 pub use external_deps::{c_build, cc, clang, htmldocck, llvm, python, rustc, rustdoc};
 
 // These rely on external dependencies.
-pub use c_build::build_native_static_lib;
+pub use c_build::{build_native_dynamic_lib, build_native_static_lib};
 pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
 pub use clang::{clang, Clang};
 pub use htmldocck::htmldocck;
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 4042bac8dac..f5d7b1adf51 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -1,6 +1,4 @@
 run-make/branch-protection-check-IBT/Makefile
-run-make/c-dynamic-dylib/Makefile
-run-make/c-dynamic-rlib/Makefile
 run-make/c-unwind-abi-catch-lib-panic/Makefile
 run-make/cat-and-grep-sanity-check/Makefile
 run-make/cdylib-dylib-linkage/Makefile
@@ -51,7 +49,6 @@ run-make/panic-abort-eh_frame/Makefile
 run-make/pdb-buildinfo-cl-cmd/Makefile
 run-make/pgo-gen-lto/Makefile
 run-make/pgo-indirect-call-promotion/Makefile
-run-make/pointer-auth-link-with-c/Makefile
 run-make/print-calling-conventions/Makefile
 run-make/print-target-list/Makefile
 run-make/raw-dylib-alt-calling-convention/Makefile