Skip to content

cxx-build: target/cxxbridge out of sync when build cache is reused #1718

Description

@Chaoses-Ib

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions