Skip to content

Commit 11f2105

Browse files
committed
build and link rust as a static archive
1 parent 8188248 commit 11f2105

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ pub fn rustc_cargo(
12291229

12301230
if let Some(llvm_config) = builder.llvm_config(builder.config.host_target) {
12311231
let llvm_version_major = llvm::get_llvm_version_major(builder, &llvm_config);
1232-
cargo.rustflag("-l").rustflag(&format!("Enzyme-{llvm_version_major}"));
1232+
cargo.rustflag("-l").rustflag(&format!("EnzymeStatic-{llvm_version_major}"));
12331233
}
12341234
}
12351235

@@ -2124,8 +2124,8 @@ impl Step for Assemble {
21242124
let enzyme_install = builder.ensure(llvm::Enzyme { target: build_compiler.host });
21252125
if let Some(llvm_config) = builder.llvm_config(builder.config.host_target) {
21262126
let llvm_version_major = llvm::get_llvm_version_major(builder, &llvm_config);
2127-
let lib_ext = std::env::consts::DLL_EXTENSION;
2128-
let libenzyme = format!("libEnzyme-{llvm_version_major}");
2127+
let lib_ext = "a";
2128+
let libenzyme = format!("libEnzymeStatic-{llvm_version_major}");
21292129
let src_lib =
21302130
enzyme_install.join("build/Enzyme").join(&libenzyme).with_extension(lib_ext);
21312131
let libdir = builder.sysroot_target_libdir(build_compiler, build_compiler.host);

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,6 @@ impl Step for Llvm {
541541
}
542542
};
543543

544-
// FIXME(ZuseZ4): Do we need that for Enzyme too?
545544
// When building LLVM with LLVM_LINK_LLVM_DYLIB for macOS, an unversioned
546545
// libLLVM.dylib will be built. However, llvm-config will still look
547546
// for a versioned path like libLLVM-14.dylib. Manually create a symbolic
@@ -977,6 +976,7 @@ impl Step for Enzyme {
977976
.env("LLVM_CONFIG_REAL", &llvm_config)
978977
.define("LLVM_ENABLE_ASSERTIONS", "ON")
979978
.define("ENZYME_EXTERNAL_SHARED_LIB", "ON")
979+
.define("ENZYME_STATIC_LIB", "ON")
980980
.define("LLVM_DIR", builder.llvm_out(target));
981981

982982
cfg.build();

tests/codegen/autodiffv2.rs renamed to tests/codegen/autodiff/autodiffv2.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,13 @@
1818
// but each shadow argument is `width` times larger (thus 16 and 20 elements here).
1919
// `d_square3` instead takes `width` (4) shadow arguments, which are all the same size as the
2020
// original function arguments.
21-
//
22-
// FIXME(autodiff): We currently can't test `d_square1` and `d_square3` in the same file, since they
23-
// generate the same dummy functions which get merged by LLVM, breaking pieces of our pipeline which
24-
// try to rewrite the dummy functions later. We should consider to change to pure declarations both
25-
// in our frontend and in the llvm backend to avoid these issues.
2621

2722
#![feature(autodiff)]
2823

2924
use std::autodiff::autodiff;
3025

3126
#[no_mangle]
32-
//#[autodiff(d_square1, Forward, Dual, Dual)]
27+
#[autodiff(d_square1, Forward, Dual, Dual)]
3328
#[autodiff(d_square2, Forward, 4, Dualv, Dualv)]
3429
#[autodiff(d_square3, Forward, 4, Dual, Dual)]
3530
fn square(x: &[f32], y: &mut [f32]) {
@@ -42,6 +37,9 @@ fn square(x: &[f32], y: &mut [f32]) {
4237
y[4] = 1.0 * x[0] + 2.0 * x[1] + 3.0 * x[2] + 4.0 * x[3];
4338
}
4439

40+
// FIXME
41+
// CHECK: start:
42+
4543
fn main() {
4644
let x1 = std::hint::black_box(vec![0.0, 1.0, 2.0, 3.0]);
4745

@@ -78,25 +76,25 @@ fn main() {
7876
let mut dy3_4 = std::hint::black_box(vec![0.0; 5]);
7977

8078
// scalar.
81-
//d_square1(&x1, &z1, &mut y1, &mut dy1_1);
82-
//d_square1(&x1, &z2, &mut y2, &mut dy1_2);
83-
//d_square1(&x1, &z3, &mut y3, &mut dy1_3);
84-
//d_square1(&x1, &z4, &mut y4, &mut dy1_4);
79+
d_square1(&x1, &z1, &mut y1, &mut dy1_1);
80+
d_square1(&x1, &z2, &mut y2, &mut dy1_2);
81+
d_square1(&x1, &z3, &mut y3, &mut dy1_3);
82+
d_square1(&x1, &z4, &mut y4, &mut dy1_4);
8583

8684
// assert y1 == y2 == y3 == y4
87-
//for i in 0..5 {
88-
// assert_eq!(y1[i], y2[i]);
89-
// assert_eq!(y1[i], y3[i]);
90-
// assert_eq!(y1[i], y4[i]);
91-
//}
85+
for i in 0..5 {
86+
assert_eq!(y1[i], y2[i]);
87+
assert_eq!(y1[i], y3[i]);
88+
assert_eq!(y1[i], y4[i]);
89+
}
9290

9391
// batch mode A)
9492
d_square2(&x1, &z5, &mut y5, &mut dy2);
9593

9694
// assert y1 == y2 == y3 == y4 == y5
97-
//for i in 0..5 {
98-
// assert_eq!(y1[i], y5[i]);
99-
//}
95+
for i in 0..5 {
96+
assert_eq!(y1[i], y5[i]);
97+
}
10098

10199
// batch mode B)
102100
d_square3(&x1, &z1, &z2, &z3, &z4, &mut y6, &mut dy3_1, &mut dy3_2, &mut dy3_3, &mut dy3_4);

0 commit comments

Comments
 (0)