Skip to content

pkg-config: set pkg-config-rs-compatible env vars#196333

Open
alyssais wants to merge 4 commits intoNixOS:stagingfrom
alyssais:cargo-cross
Open

pkg-config: set pkg-config-rs-compatible env vars#196333
alyssais wants to merge 4 commits intoNixOS:stagingfrom
alyssais:cargo-cross

Conversation

@alyssais
Copy link
Member

Description of changes
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.11 Release Notes (or backporting 22.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@alyssais alyssais added 6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. 6.topic: cross-compilation Building packages on a different platform than they will be used on labels Oct 17, 2022
@alyssais alyssais requested review from LnL7, Mic92 and zowoq as code owners October 17, 2022 00:20
@ofborg ofborg bot added 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. labels Oct 17, 2022
@ofborg ofborg bot added 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Oct 17, 2022
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really approve of this rust-specific thing being added in all derivations that use pkg-config, even non-rust ones. I also don't disapprove, but for a quick merge you could move this change out of this PR and let me review only the cargo stuff (with that PKG_CONFIG_ variable being set just like in rustc).

Copy link
Member

@Mic92 Mic92 Oct 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it was in the cargo setuphook? Than as soon as you add rustc to a build, you would get it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the pkg-config wrapper is the right place for this. It's the only place that makes sense that is shared between the rustc build, and all the builds that use Cargo.

Technically, it doesn't have anything to do with pkg-config (since it comes from the pkg-config crate), but it doesn't have anything to do with Cargo either. It's also extremely similar to PKG_CONFIG_FOR_BUILD, defined on the line above, so it makes sense to set both very similar environment variables in one place.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it doesn't go here.

We can have a separate setup hook that Rust. buildRustCrate, buildRustPackage, etc. all use.

Copy link
Member

@Ericson2314 Ericson2314 Oct 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust-lang/pkg-config-rs#139 Also, I opened an issue in the relevant package build.rs file use, so we can nip this in the bud.

Copy link
Member

@Ericson2314 Ericson2314 Nov 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a small amount of code, but changing it is mass rebuild. So I think about the "mass rebuild" costs of these sorts of things too.

The rebuild could be indirect from changing the toRustTarget stuff too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also think how if we do two setup hooks it's easy to combine later, but if we do one setup hook it's hard to split later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be an extremely rare change to make, especially for the limited set of architectures we actually build for. We do full rebuilds every couple of weeks anyway, so I don't think it's at all worth optimising for avoidance of mass-rebuilds in infrastructural stuff like this. Indeed, avoiding mass rebuilds is how we end up with unnecessary conditionals making maintenance more complicated forever, because it avoided mass rebuilds once. And Rust is so widely used that any change to it is going to cause huge rebuilds anyway, regardless of whether it affects pkg-config.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And having a separate setup hook just for this (cargoPkgConfigSetupHook?) would mean broken cross packages forever, because since it would only be required for cross, nobody would ever remember to apply it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we did this, would we want to put this same logic sort of in bintools-wrapper and cc-wrapper too?

@alyssais alyssais mentioned this pull request Oct 27, 2022
13 tasks
Copy link
Contributor

@yu-re-ka yu-re-ka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first time I looked at this, it was not obvious that PKG_CONFIG_FOR_BUILD is set directly above the newly added code, and that it is autoconf/meson specific.
I now think this might be fine, but would give @Ericson2314 the last word (to change their mind or explain why this is still a bad idea)

@Mindavi
Copy link
Contributor

Mindavi commented Jan 12, 2023

@Ericson2314 and @alyssais, what would be a good way to move this forward? I do kinda agree that it feels wrong to modify the pkg-config wrapper, if a hook were to be added, could that be added to buildRustPackage or injected when cargo or rust is added? Then there might be less of a need to remember to add it.

@alyssais
Copy link
Member Author

@Ericson2314 and @alyssais, what would be a good way to move this forward? I do kinda agree that it feels wrong to modify the pkg-config wrapper, if a hook were to be added, could that be added to buildRustPackage or injected when cargo or rust is added? Then there might be less of a need to remember to add it.

I asked John to expand on his most recent comment on Matrix, and AIUI we're still waiting for him to find the time to talk it through with me.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/unable-to-build-pkgsstatic-gcc/27795/6

@alyssais alyssais added the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 13, 2023
@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 2 This PR was reviewed and approved by two persons. label Jun 25, 2025
alyssais added 3 commits July 17, 2025 14:30
This was already set by the rustc derivation, but by doing it
everywhere pkg-config is used, the necessary environment variables will
also be set for other Rust packages that need them, like cargo.
This is no longer required now that this variable is set by the
pkg-config wrapper.
This is obsolete now that the pkg-config wrapper sets variables for
Rust triples.
@nixpkgs-ci nixpkgs-ci bot removed 2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md labels Jul 18, 2025
It's not possible to run installCheckPhase when cross-compiling, so we
have to tack this on to postInstall instead.
@alyssais alyssais changed the title cargo: fix cross pkg-config: set pkg-config-rs-compatible env vars Jul 18, 2025
@alyssais alyssais marked this pull request as ready for review July 18, 2025 12:10
@alyssais alyssais requested review from K900 and emilazy and removed request for cstrahan, retrry and winterqt July 18, 2025 13:23
Copy link
Contributor

@K900 K900 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, we discussed this a bit on Matrix earlier.

@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 3+ This PR was reviewed and approved by three or more persons. and removed 12.approvals: 2 This PR was reviewed and approved by two persons. labels Jul 18, 2025
@emilazy
Copy link
Member

emilazy commented Jul 18, 2025

We may be able to drop PKG_CONFIG_ALLOW_CROSS now. It will mean that targets without a pkg-config dependency will fail to use pkg-config and maybe fall back to non‐pkg-config methods, but that’s at least consistent with the non‐cross behaviour. Otherwise it will run plain pkg-config when there isn’t a variable for the appropriate target, because we set PKG_CONFIG_ALLOW_CROSS, and that seems bad.

The other alternative is setting PKG_CONFIG_SYSROOT_DIR per target and using one pkg-config, but I think our wrappers don’t work well with that at present?

@alyssais alyssais mentioned this pull request Jul 20, 2025
13 tasks
@alyssais
Copy link
Member Author

Will need to do some more testing with this — it turns out that Cargo cross compiles correctly without any workarounds even without this change, so I didn't catch that this wasn't actually doing anything! Need to find another test case.

@alyssais alyssais mentioned this pull request Jul 22, 2025
13 tasks
@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 25, 2025
@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. 12.approvals: 3+ This PR was reviewed and approved by three or more persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants