Skip to content

cgo changes the time of libgo.h even if its content doesn't changed, causes build.rs rerun in every cargo check #83

@zhongxinghong

Description

@zhongxinghong

After introducing rust2go to our project, the elasped time of cargo check has increased. Currently in vscode I have to wait about 20s after I pressing Ctrl+S :(

cargo check --verbose shows that the rust2go generated project rebuild in every cargo check because the time of libgo.h has changed, but its content is the same as before. This lead to all other workspace members depended on this project rebuilding in every cargo check.

$ cargo check --verbose
 // ......
       Dirty idl v0.1.0 (/a/b/c/ffi_wrapper/idl): the file `target/debug/build/idl-fed367a4f829698f/out/libgo.h` has changed (1748510343.060202936s, 6s after last build at 1748510337.641699389s)
   Compiling idl v0.1.0 (/a/b/c/ffi_wrapper/idl)
// ......
       Dirty sort v0.1.0 (/a/b/c/sort): the dependency idl was rebuilt
    Checking sort v0.1.0 (/a/b/c/sort)
       Dirty dynamic v0.1.0 (/a/b/c/dynamic): the dependency idl was rebuilt
    Checking dynamic v0.1.0 (/a/b/c/dynamic)
// ......

The build.rs under this project:

// ffi_wrapper/idl/build.rs
use rust2go::RegenArgs;

fn main() {
    rust2go::Builder::new()
        .with_go_src("../wrapper")
        .with_regen_arg(RegenArgs {
            src: "./src/idl.rs".into(),
            dst: "../wrapper/gen.go".into(),
            go118: true,
            ..Default::default()
        })
        .build();
}

The target/debug/build/idl-fed367a4f829698f/output file:

../wrapper/gen.go
cargo:rerun-if-env-changed=TARGET
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64-apple-darwin
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64_apple_darwin
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
cargo:rerun-if-changed=/a/b/c/target/debug/build/idl-fed367a4f829698f/out/libgo.h
cargo:rerun-if-changed=/Library/Developer/CommandLineTools/usr/lib/clang/17/include/stddef.h
// ......

In my humble opinion, rust2go should reset the file time of libgo.h if its content doesn't actually changed, or directly watch the go source files.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions