diff --git a/tests/run-make/autodiff/rlib/dep.rs b/tests/run-make/autodiff/rlib/dep.rs new file mode 100644 index 000000000000..6fc9b2c2473f --- /dev/null +++ b/tests/run-make/autodiff/rlib/dep.rs @@ -0,0 +1,7 @@ +pub fn f(x: f64, y: f64) -> f64 { + 2.0 * x + y +} + +pub fn g(x: f64) -> f64 { + 2.0 * x +} diff --git a/tests/run-make/autodiff/rlib/lib.rs b/tests/run-make/autodiff/rlib/lib.rs new file mode 100644 index 000000000000..b459fed643a1 --- /dev/null +++ b/tests/run-make/autodiff/rlib/lib.rs @@ -0,0 +1,13 @@ +#![feature(autodiff)] +extern crate simple_dep; +use std::autodiff::*; + +#[inline(never)] +pub fn f2(x: f64) -> f64 { + x.sin() +} + +#[autodiff_forward(df1_lib, Dual, Dual)] +pub fn _f1(x: f64) -> f64 { + simple_dep::f(x, x) * f2(x) +} diff --git a/tests/run-make/autodiff/rlib/main.rs b/tests/run-make/autodiff/rlib/main.rs new file mode 100644 index 000000000000..a3e5fcde0381 --- /dev/null +++ b/tests/run-make/autodiff/rlib/main.rs @@ -0,0 +1,8 @@ +extern crate foo; + +fn main() { + //dbg!("Running main.rs"); + let enzyme_y1_lib = foo::df1_lib(1.5, 1.0); + println!("output1: {:?}", enzyme_y1_lib.0); + println!("output2: {:?}", enzyme_y1_lib.1); +} diff --git a/tests/run-make/autodiff/rlib/rmake.rs b/tests/run-make/autodiff/rlib/rmake.rs new file mode 100644 index 000000000000..59eaa836864c --- /dev/null +++ b/tests/run-make/autodiff/rlib/rmake.rs @@ -0,0 +1,66 @@ +//@ needs-enzyme +//@ ignore-cross-compile + +use run_make_support::{cwd, run, rustc}; + +fn main() { + // Build the dependency crate. + rustc() + .input("dep.rs") + .arg("-Zautodiff=Enable") + .arg("--edition=2024") + .arg("-Copt-level=3") + .arg("--crate-name=simple_dep") + .arg("-Clinker-plugin-lto") + .arg("--crate-type=lib") + .emit("dep-info,metadata,link") + .run(); + + let cwd = cwd(); + let cwd_str = cwd.to_string_lossy(); + + let mydep = format!("-Ldependency={cwd_str}"); + + let simple_dep_rlib = + format!("--extern=simple_dep={}", cwd.join("libsimple_dep.rlib").to_string_lossy()); + + // Build the main library that depends on `simple_dep`. + rustc() + .input("lib.rs") + .arg("-Zautodiff=Enable") + .arg("--edition=2024") + .arg("-Copt-level=3") + .arg("--crate-name=foo") + .arg("-Clinker-plugin-lto") + .arg("--crate-type=lib") + .emit("dep-info,metadata,link") + .arg(&mydep) + .arg(&simple_dep_rlib) + .run(); + + let foo_rlib = format!("--extern=foo={}", cwd.join("libfoo.rlib").to_string_lossy()); + + // Build the final binary linking both rlibs. + rustc() + .input("main.rs") + .arg("-Zautodiff=Enable") + .arg("--edition=2024") + .arg("-Copt-level=3") + .arg("--crate-name=foo") + .arg("-Clto=fat") + .arg("--crate-type=bin") + .emit("dep-info,link") + .arg(&mydep) + .arg(&foo_rlib) + .arg(&simple_dep_rlib) + .run(); + + // Run the binary and check its output. + let binary = run("foo"); + assert!(binary.status().success(), "binary failed to run"); + + let binary_out = binary.stdout(); + let output = String::from_utf8_lossy(&binary_out); + assert!(output.contains("output1: 4.488727439718245")); + assert!(output.contains("output2: 3.3108023673168265")); +}