|
| 1 | +//@ needs-enzyme |
| 2 | +//@ ignore-cross-compile |
| 3 | + |
| 4 | +use run_make_support::{cwd, run, rustc}; |
| 5 | + |
| 6 | +fn main() { |
| 7 | + // Build the dependency crate. |
| 8 | + rustc() |
| 9 | + .input("dep.rs") |
| 10 | + .arg("-Zautodiff=Enable") |
| 11 | + .arg("--edition=2024") |
| 12 | + .arg("-Copt-level=3") |
| 13 | + .arg("--crate-name=simple_dep") |
| 14 | + .arg("-Clinker-plugin-lto") |
| 15 | + .arg("--crate-type=lib") |
| 16 | + .emit("dep-info,metadata,link") |
| 17 | + .run(); |
| 18 | + |
| 19 | + let cwd = cwd(); |
| 20 | + let cwd_str = cwd.to_string_lossy(); |
| 21 | + |
| 22 | + let mydep = format!("-Ldependency={cwd_str}"); |
| 23 | + |
| 24 | + let simple_dep_rlib = |
| 25 | + format!("--extern=simple_dep={}", cwd.join("libsimple_dep.rlib").to_string_lossy()); |
| 26 | + |
| 27 | + // Build the main library that depends on `simple_dep`. |
| 28 | + rustc() |
| 29 | + .input("lib.rs") |
| 30 | + .arg("-Zautodiff=Enable") |
| 31 | + .arg("--edition=2024") |
| 32 | + .arg("-Copt-level=3") |
| 33 | + .arg("--crate-name=foo") |
| 34 | + .arg("-Clinker-plugin-lto") |
| 35 | + .arg("--crate-type=lib") |
| 36 | + .emit("dep-info,metadata,link") |
| 37 | + .arg(&mydep) |
| 38 | + .arg(&simple_dep_rlib) |
| 39 | + .run(); |
| 40 | + |
| 41 | + let foo_rlib = format!("--extern=foo={}", cwd.join("libfoo.rlib").to_string_lossy()); |
| 42 | + |
| 43 | + // Build the final binary linking both rlibs. |
| 44 | + rustc() |
| 45 | + .input("main.rs") |
| 46 | + .arg("-Zautodiff=Enable") |
| 47 | + .arg("--edition=2024") |
| 48 | + .arg("-Copt-level=3") |
| 49 | + .arg("--crate-name=foo") |
| 50 | + .arg("-Clto=fat") |
| 51 | + .arg("--crate-type=bin") |
| 52 | + .emit("dep-info,link") |
| 53 | + .arg(&mydep) |
| 54 | + .arg(&foo_rlib) |
| 55 | + .arg(&simple_dep_rlib) |
| 56 | + .run(); |
| 57 | + |
| 58 | + // Run the binary and check its output. |
| 59 | + let binary = run("foo"); |
| 60 | + assert!(binary.status().success(), "binary failed to run"); |
| 61 | + |
| 62 | + let binary_out = binary.stdout(); |
| 63 | + let output = String::from_utf8_lossy(&binary_out); |
| 64 | + assert!(output.contains("output1: 4.488727439718245")); |
| 65 | + assert!(output.contains("output2: 3.3108023673168265")); |
| 66 | +} |
0 commit comments