Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build script that compiles a crate: Re-run if its local "path dependencies" have changed #8091

Open
timotree3 opened this issue Apr 10, 2020 · 1 comment
Labels
A-build-scripts Area: build.rs scripts C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@timotree3
Copy link

Describe the problem you are trying to solve

I'm writing a library that contains several smaller crates, compiles them to Wasm, and exports those Wasm blobs as constants.

In order to be able to export them as constants, I'm using a build.rs to compile them using cargo. It looks something like this:

fn main() {
    let out_dir = std::env::var_os("OUT_DIR").unwrap();

    let cargo_toml = std::path::Path::new("foo/Cargo.toml");

    let cargo_command = std::env::var_os("CARGO");
    let cargo_command = cargo_command
        .as_ref()
        .map(|s| &**s)
        .unwrap_or_else(|| "cargo".as_ref());

    let status = std::process::Command::new(cargo_command)
        .arg("build")
        .arg("--manifest-path")
        .arg(cargo_toml)
        .arg("--release")
        .arg("--target")
        .arg("wasm32-unknown-unknown")
        .env("CARGO_TARGET_DIR", out_dir)
        .status()
        .unwrap();

    assert!(status.success());
}

Unfortunately, this breaks down when foo has local "path dependencies" that it needs to keep up-to-date with: Since the build.rs is only re-run if files in its parent directory change, I can arrive at confusing situations where I've changed foo's dependency and I've changed my test to account for the new behavior, but foo doesn't actually update because nothing in the relevant directory has changed.

Describe the solution you'd like

I would like to be able to express to Cargo that my build script compiles a crate, and should be re-run whenever that crate's source changes or whenever one of it's dependencies would no longer be valid to use (i.e. a yanked crate or a change path dependency)

Notes

In the meantime, my solution is to emit cargo:rerun-if-changed=A file name that I know won't exist. This has the behavior of re-running my build script upon every single build of my library, which probably isn't ideal.

@timotree3 timotree3 added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Apr 10, 2020
@ehuss ehuss added the A-build-scripts Area: build.rs scripts label Apr 15, 2020
@epage
Copy link
Contributor

epage commented Nov 3, 2023

#8084 would work for this though it would cause extra re-runs of the build script.

@epage epage added the S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. label Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-scripts Area: build.rs scripts C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

3 participants