From 8b75a9e731aaeb7acb2b46c8b3d9019bbdc6b1de Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Sat, 11 Jun 2022 12:04:58 +0200 Subject: [PATCH] Force linking with spectre-mitigated libraries if /Qspectre is passed. --- src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 21185a7fe..c9ba69aba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1041,6 +1041,29 @@ impl Build { atlmfc_lib.display() )); } + + let compiler = self.try_get_compiler()?; + for arg in compiler.args.iter() { + if arg.to_str().unwrap().contains("Qspectre") { + for (var, val) in compiler.env.iter() { + if var == "LIB" { + for path in env::split_paths(&val) { + if let Some(last) = path.iter().last() { + // check upon .../lib/{platform}/../spectre/{platform} + let spectre = path.parent().unwrap().join("spectre").join(last); + if spectre.exists() { + self.print(&format!( + "cargo:rustc-link-search=native={}", + spectre.display() + )); + } + } + } + break; + } + } + } + } } if self.link_lib_modifiers.is_empty() {