For example, if feature a will change FFI, with this build.rs:
fn main() {
_ = cxx_build::bridge("src/lib.rs");
println!("cargo:rerun-if-changed=src/lib.rs");
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_A");
}
The first cargo build and cargo build --features a will both produce correct files under target/cxxbridge. But if we run cargo build again, Cargo will reuse the build cache directly without rerunning build.rs, causing target/cxxbridge to stay on the --features a version.
A workaround I can think of is adding println!("cargo:rerun-if-changed=target/cxxbridge"). But because cxx-build will create new symlinks every time, it will cause build.rs to always rerun. Making cxx-build copy timestamps from the link source, or don't touch files if they don't change seems can fix this. I'm not sure if there is a clearer solution.
Tested cxx-build version: 1.0.194, 1.0.121
For example, if feature
awill change FFI, with thisbuild.rs:The first
cargo buildandcargo build --features awill both produce correct files undertarget/cxxbridge. But if we runcargo buildagain, Cargo will reuse the build cache directly without rerunningbuild.rs, causingtarget/cxxbridgeto stay on the--features aversion.A workaround I can think of is adding
println!("cargo:rerun-if-changed=target/cxxbridge"). But becausecxx-buildwill create new symlinks every time, it will causebuild.rsto always rerun. Makingcxx-buildcopy timestamps from the link source, or don't touch files if they don't change seems can fix this. I'm not sure if there is a clearer solution.Tested
cxx-buildversion: 1.0.194, 1.0.121