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

Improving cross-compilation experience #109

Closed
kornelski opened this issue Jul 18, 2020 · 3 comments · Fixed by #113
Closed

Improving cross-compilation experience #109

kornelski opened this issue Jul 18, 2020 · 3 comments · Fixed by #113

Comments

@kornelski
Copy link
Contributor

Currently pkg-config-rs tries to prevent incorrect use of pkg-config for cross-compilation:

Cross compilation detected. Use PKG_CONFIG_ALLOW_CROSS=1 to override

However, judging by questions on the Rust forum, users don't understand the problem. They only set the variable as instructed, and are disappointed that it still doesn't work.

I suggest changing this message to point users to a more complete explanation, e.g:

pkg-config must be configured for cross-compilation. See https://github.com/rust-lang/pkg-config-rs#how-to-cross-compile

which would then instruct users to set sysroot, etc. first before enabling PKG_CONFIG_ALLOW_CROSS=1.

@ryankurte
Copy link

ryankurte commented Jul 21, 2020

I was about to open an issue requesting the ability to set this via configuration, so we don't need to surprise users with environmental variables when building crates.

I am however unclear on why this couldn't be done automatically (and with sane defaults) if we detect the target to be different to the host?

Somewhat related issue about building *-sys crates: rust-embedded#481

@sdroege
Copy link
Collaborator

sdroege commented Jul 21, 2020

I was about to open an issue requesting the ability to set this via configuration

What configuration are you thinking of, ooc? Apart from environment variables there is nothing really or is there?

I agree that this should be documented better though. Someone wants to give it a try?

@kornelski
Copy link
Contributor Author

kornelski commented Jul 21, 2020

I am however unclear on why this couldn't be done automatically

You mean setting "PKG_CONFIG_ALLOW_CROSS=1"? It's a totally artificial barrier added intentionally. It could be removed, but it would only lead to worse errors at later stages of the build.

The problem is that pkg-config doesn't support cross-compilation. User has to do some work first to trick pkg-config into doing the right thing for cross-compilation.

PKG_CONFIG_ALLOW_CROSS=1 is like a "ROAD CLOSED" sign. Yes, you can very easily remove the "ROAD CLOSED" sign! But it doesn't achieve anything, and only makes things worse.

The real instruction should be:

  1. Install libraries for the target system
  2. Configure pkg-config to use target system's sysroot
  3. Then try building again

Point (1) is a bit beyond scope of what Cargo crates should be doing, so it can't be automated.

Point (2) could be automated for some well-known setups.

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

Successfully merging a pull request may close this issue.

3 participants