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

Dependency being constantly rebuilt due to 'env_metadata' being set to 'true' #112

Closed
Litarvan opened this issue Aug 2, 2020 · 8 comments

Comments

@Litarvan
Copy link

Litarvan commented Aug 2, 2020

Hello, I'm having an issue with openssl-sys due to the changes made by #105 in pkg-config-rs
@sfackler led me here after I posted an issue on rust-openssl, so I'll repost it here :

On NixOS, to build openssl-sys you must be in a temporary environment where pkg-config and openssl are presents and their environment variables too (such as PKG_CONFIG_PATH), using nix-shell -p pkg-config openssl --run 'cargo build'

Previously, running this command once to build the crate was enough, I could then leave the environment and use cargo commands normally. But now (probably since a recent update ?) every time I leave the shell, and use cargo run/build, the crate gets recompiled (and fails because pkg-config is missing which is normal). Apparently, the fact the PKG_CONFIG_PATH environment variable changed triggers that rebuild.

As my IDE runs clippy on the fly (and so, without the appropriate environment to build openssl-sys), this feature becomes unusable as soon as openssl-sys gets in my project dependencies :/ I also can't use the run button from my IDE anymore.

Is there any workaround ?

Thanks by advance

@sdroege
Copy link
Collaborator

sdroege commented Aug 3, 2020

I believe this is the intended behaviour. The general assumption of cargo is that the whole build happens in the same environment, and if your environment variables change in a way that affects any of the build steps then it will rebuild that part.

Why do you change your environment, what's the use-case of this?

@Litarvan
Copy link
Author

Litarvan commented Aug 3, 2020

It's one of the main goals of Nix/NixOS, instead of "polluting" your own environment with the dependencies of every project you ever done, you create temporary environments adapted to each project. Those environments can also be written down (like a Dockerfile I guess) and are reproducible.

Before #105 I had to go in such an environment (with pkg-config, openssl, etc.) only once => for the first build, and then I could leave it and use cargo build without any issue outside the said environment, as deps using pkg-config-rs were not getting rebuilt.

But now, if I leave this environment, the dependencies are getting rebuilt and so the build fails. If I also add a new package to the environment, it will rebuild every single dependency using pkg-config-rs, (on an amethyst project, ~10 dependencies + the one that depends on them, which is ~50 dependencies).

It is really annoying 😞 I can't use my IDE properly anymore. Building these environments also became very hard as any edit to the PKG_CONFIG_PATH will trigger tons of rebuilds. If you don't have any workaround, I will be forced to use a fork to revert this PR

@sdroege
Copy link
Collaborator

sdroege commented Aug 4, 2020

I don't think such a use-case is generally supported by cargo. This is not only an issue with pkg-config but also with other libraries linking to system libraries and taking information from environment variables (as most due), and correctly declaring that they use these environment variables.

I think you want to create an issue for cargo here about supporting "partial builds" in some way. This wouldn't be a problem if cargo allowed to output build results for all the dependencies separately and allowed to use those for building the final crate.

That this worked before for you was a bug, and the problem you're running into now is caused by the general design of cargo.

@sdroege sdroege closed this as completed Aug 4, 2020
@Litarvan
Copy link
Author

Litarvan commented Aug 4, 2020

Well I'll open an issue. The thing is, this is the kind of issue that will probably never get resolved, I guess I'll have to fork this repo.

@sdroege
Copy link
Collaborator

sdroege commented Aug 4, 2020

You'll probably sooner or later run into the same problem with other crates linking to system libraries and not using pkg-config though, so I guess this really needs to be solved in cargo for you or you need to change your workflow.

For cargo, this is just another of many things where its current build process and especially handling of system libraries is rather suboptimal. I think that needs some general redesigning, and as such I agree with you that this is probably not going to be solved anytime soon there.

@toothbrush
Copy link

Hey @Litarvan, i'm running into this issue on NixOS as well, was there a workaround, or another issue i can subscribe to to track progress of this bug? Thanks!

@Litarvan
Copy link
Author

I didn't open an issue since I knew it would never be resolved, I did a fork with the fix here : https://github.com/Litarvan/pkg-config-rs
That's the only solution I found

@toothbrush
Copy link

I didn't open an issue since I knew it would never be resolved, I did a fork with the fix here : https://github.com/Litarvan/pkg-config-rs
That's the only solution I found

Ah! Understandable. Thanks for pointing to your workaround though 👍

toothbrush added a commit to toothbrush/keez that referenced this issue Sep 18, 2020
There's a bug rust-lang/pkg-config-rs#112
where on NixOS because of the environment changing (env variables?
something else?) the `openssl-sys` package keeps getting rebuilt.
This is slow.

Anyway, our friend @Litarvan made a fork of `pkg-config` which has a
workaround, so for now let's just depend on that.  Seems pretty
harmless.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants