Add test to use decoder and disable LTO flags when these are detected#22
Conversation
|
actually, i tried this locally and i don't think it works — gcc takes the last so the same issue applies to my own PR — i didn't catch it because i validated by appending a working fix would need to either filter if let Ok(cflags) = std::env::var("CFLAGS") {
if cflags.contains("-flto") {
let filtered: String = cflags
.split_whitespace()
.filter(|f| !f.starts_with("-flto"))
.collect::<Vec<_>>()
.join(" ");
cmake.env("CFLAGS", filtered);
}
}will verify properly this time before saying it works. |
|
Ah I see... I would expect |
|
Looking at cmake crate, they just set CMAKE_C_FLAGS So I think if we do the same it will also fail, so we probably need to override CFLAGS env itself |
|
verified end-to-end this time using the original failing reproducer (kopuz on Arch with makepkg CFLAGS="... -flto=auto"): 1. PR #22 as-is — backported the exact logic into the registry's opusic-sys 0.5.8 build.rs, did a clean rebuild. Build still fails: The cmake invocation that gets emitted:
2. 3. Filter for var in ["CFLAGS", "CXXFLAGS"] {
if let Ok(value) = std::env::var(var) {
if value.contains("-flto") {
let filtered: String = value
.split_whitespace()
.filter(|f| !f.starts_with("-flto"))
.collect::<Vec<_>>()
.join(" ");
unsafe { std::env::set_var(var, filtered); }
}
}
}
let mut cmake = cmake::Config::new(CURRENT_DIR);After the fix:
happy to push this as a follow-up commit on top of #22 if you'd like — apologies for the noise on the first round, should've actually reproduced before commenting. |
This looks like bug in cmake crate |
|
@UMCEKO Sorry, Actually I just noticed one thing... We can override configure options via separate option 😓 Here is updated solution: //Disable LTO if someone tries to force it (e.g. Arch makepkg)
//This is necessary because cmake crate doesn't pass env variables at configure step
fn fix_build_env(cmake: &mut cmake::Config) {
for (var, cmake_var) in [("CFLAGS", "CMAKE_C_FLAGS"), ("CXXFLAGS", "CMAKE_CXX_FLAGS")] {
if let Ok(value) = std::env::var(var) {
if value.contains("-flto") {
println!("cargo:warning=env::{var} contains LTO option. Overriding it...");
let filtered: String = value
.split_whitespace()
.filter(|f| !f.starts_with("-flto"))
.collect::<Vec<_>>()
.join(" ");
cmake
.configure_arg(format!("-D{cmake_var}={filtered}"))
.env(var, filtered);
}
}
}
} |
|
tested the |
02f13ab to
c1e8bcf
Compare
|
I published new version 0.7.3 with this PR |
No description provided.