From b66678b45c9f935930a95aac8b0e379b9b7d3dea Mon Sep 17 00:00:00 2001 From: Nicholas Rodrigues Lordello Date: Thu, 16 Nov 2023 20:35:13 +0100 Subject: [PATCH] Fix LTO Detection in LLVM Intrinsic Build (#36) Fixes #33 This PR fixes LTO detection in the LLVM intrinsic build script. It turns out that around Rust 1.55, `cargo` stopped propagating `RUSTFLAGS` environment variable to the build script invocation (and even actively removing it). It is replaced with `CARGO_ENCODED_RUSTFLAGS` which is meant to more accurately set the actual `rustc` flags that are being used. Turning this on yields an immediate improvement in benchmarks: ``` U256::add time: [15.726 ns 15.764 ns 15.808 ns] change: [-34.507% -34.304% -34.099%] (p = 0.00 < 0.05) Performance has improved. ``` --- intrinsics/build/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/intrinsics/build/main.rs b/intrinsics/build/main.rs index bb063cf..3df9168 100644 --- a/intrinsics/build/main.rs +++ b/intrinsics/build/main.rs @@ -50,8 +50,7 @@ fn main() -> Result<(), Box> { let mut build = Build::new(); build.compiler(&clang).file(intrinsics_ir_path).opt_level(3); - let linker_plugin_lto = - matches!(env::var("RUSTFLAGS"), Ok(flags) if flags.contains("-Clinker-plugin-lto")); + let linker_plugin_lto = matches!(env::var("CARGO_ENCODED_RUSTFLAGS"), Ok(flags) if flags.contains("-Clinker-plugin-lto")); if linker_plugin_lto { build.flag("-flto=thin"); }