Skip to content

Commit 034a4c5

Browse files
committed
rewrite macos-fat-archive to rmake
1 parent a91f7d7 commit 034a4c5

File tree

5 files changed

+59
-13
lines changed

5 files changed

+59
-13
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
3030
pub use clang::{clang, Clang};
3131
pub use diff::{diff, Diff};
3232
pub use llvm::{
33-
llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmObjdump,
34-
LlvmProfdata, LlvmReadobj,
33+
llvm_ar, llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr, LlvmFilecheck,
34+
LlvmObjdump, LlvmProfdata, LlvmReadobj,
3535
};
3636
pub use run::{cmd, run, run_fail, run_with_args};
3737
pub use rustc::{aux_build, bare_rustc, rustc, Rustc};

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ pub fn llvm_objdump() -> LlvmObjdump {
2929
LlvmObjdump::new()
3030
}
3131

32+
/// Construct a new `llvm-ar` invocation. This assumes that `llvm-ar` is available
33+
/// at `$LLVM_BIN_DIR/llvm-ar`.
34+
pub fn llvm_ar() -> LlvmAr {
35+
LlvmAr::new()
36+
}
37+
3238
/// A `llvm-readobj` invocation builder.
3339
#[derive(Debug)]
3440
#[must_use]
@@ -57,10 +63,18 @@ pub struct LlvmObjdump {
5763
cmd: Command,
5864
}
5965

66+
/// A `llvm-ar` invocation builder.
67+
#[derive(Debug)]
68+
#[must_use]
69+
pub struct LlvmAr {
70+
cmd: Command,
71+
}
72+
6073
crate::impl_common_helpers!(LlvmReadobj);
6174
crate::impl_common_helpers!(LlvmProfdata);
6275
crate::impl_common_helpers!(LlvmFilecheck);
6376
crate::impl_common_helpers!(LlvmObjdump);
77+
crate::impl_common_helpers!(LlvmAr);
6478

6579
/// Generate the path to the bin directory of LLVM.
6680
#[must_use]
@@ -204,3 +218,26 @@ impl LlvmObjdump {
204218
self
205219
}
206220
}
221+
222+
impl LlvmAr {
223+
/// Construct a new `llvm-ar` invocation. This assumes that `llvm-ar` is available
224+
/// at `$LLVM_BIN_DIR/llvm-ar`.
225+
pub fn new() -> Self {
226+
let llvm_ar = llvm_bin_dir().join("llvm-ar");
227+
let cmd = Command::new(llvm_ar);
228+
Self { cmd }
229+
}
230+
231+
pub fn obj_to_ar(&mut self) -> &mut Self {
232+
self.cmd.arg("rcus");
233+
self
234+
}
235+
236+
/// Provide an output, then an input file. Bundled in one function, as llvm-ar has
237+
/// no "--output"-style flag.
238+
pub fn output_input(&mut self, out: impl AsRef<Path>, input: impl AsRef<Path>) -> &mut Self {
239+
self.cmd.arg(out.as_ref());
240+
self.cmd.arg(input.as_ref());
241+
self
242+
}
243+
}

src/tools/tidy/src/allowed_run_make_makefiles.txt

Lines changed: 0 additions & 1 deletion
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/macos-fat-archive/Makefile
8079
run-make/manual-link/Makefile
8180
run-make/min-global-align/Makefile
8281
run-make/missing-crate-dependency/Makefile

tests/run-make/macos-fat-archive/Makefile

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// macOS (and iOS) has a concept of universal (fat) binaries which contain code for multiple CPU
2+
// architectures in the same file. Apple is migrating from x86_64 to aarch64 CPUs,
3+
// so for the next few years it will be important for macOS developers to
4+
// build "fat" binaries (executables and cdylibs).
5+
6+
// Rustc used to be unable to handle these special libraries, which was fixed in #98736. If
7+
// compilation in this test is successful, the native fat library was successfully linked to.
8+
// See https://github.com/rust-lang/rust/issues/55235
9+
10+
//@ only-apple
11+
12+
use run_make_support::{cc, llvm_ar, rustc};
13+
14+
fn main() {
15+
cc().args(&["-arch", "arm64", "-arch", "x86_64", "native-library.c", "-c"])
16+
.out_exe("native-library.o")
17+
.run();
18+
llvm_ar().obj_to_ar().output_input("libnative-library.a", "native-library.o").run();
19+
rustc().input("lib.rs").crate_type("lib").arg("-lstatic=native-library").run();
20+
}

0 commit comments

Comments
 (0)