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

Define CMAKE_SYSTEM_NAME when compiling for Linux #136

Merged
merged 1 commit into from
Dec 2, 2021
Merged

Define CMAKE_SYSTEM_NAME when compiling for Linux #136

merged 1 commit into from
Dec 2, 2021

Conversation

messense
Copy link
Contributor

@messense messense commented Dec 1, 2021

The default value of CMAKE_SYSTEM_NAME is CMAKE_HOST_SYSTEM_NAME so when cross compiling from macOS to Linux cmake gets confused.

The motivation of this PR is to fix an issue posted on reddit: https://www.reddit.com/r/rust/comments/r60fzb/m1_users_how_are_you_cross_compiling/ , by define CMAKE_SYSTEM_NAME, audiopus_sys can be easily cross compiled once you have target cross compiler setup.

Helps with #80

@alexcrichton
Copy link
Member

Personally I don't know enough about cmake to know what to do here. I don't know what cmake does with this variable name and why it might be required for some cross compilations but not others. It doesn't feel right to single-out linux here as a cross-compile target and try to fix that without handling other platforms, though.

@messense
Copy link
Contributor Author

messense commented Dec 2, 2021

It doesn't feel right to single-out linux here as a cross-compile target and try to fix that without handling other platforms, though.

I understand that you want it to be a general solution. But it's not easy for anyone to write a implementation with proper testing on each platforms, the best I can do is try to implement it for Linux, macOS and maybe Windows.

IMO this already improves the status of quo for cross compiling and it doesn't add too much maintenance burden. We can iterate and come up with more general solution with feedbacks from real world usage.

Edit:

I've just done a test on linux using osxcross to cross compile https://github.com/Lakelezz/audiopus_sys to x86_64 macOS and it worked without any change:

root@5edd94ea1b1d:/io/audiopus_sys# env | grep x86_64
CC_x86_64_apple_darwin=x86_64-apple-darwin20.4-cc
CXX_x86_64_apple_darwin=x86_64-apple-darwin20.4-c++
AR_x86_64_apple_darwin=x86_64-apple-darwin20.4-ar
CARGO_TARGET_X86_64_APPLE_DARWIN=x86_64-apple-darwin20.4-cc
root@5edd94ea1b1d:/io/audiopus_sys# cargo build --target x86_64-apple-darwin
   Compiling log v0.4.14
   Compiling cfg-if v1.0.0
   Compiling cc v1.0.72
   Compiling pkg-config v0.3.22
   Compiling cmake v0.1.46
   Compiling audiopus_sys v0.2.1 (/io/audiopus_sys)
    Finished dev [unoptimized + debuginfo] target(s) in 1m 15s

Cross compile to x86_64-pc-windows-gnu target also works fine.

root@5edd94ea1b1d:/io/audiopus_sys# cat ~/.cargo/config.toml
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
ar = "x86_64-w64-mingw32-gcc-ar"
root@5edd94ea1b1d:/io/audiopus_sys# cargo build --target x86_64-pc-windows-gnu
   Compiling log v0.4.14
   Compiling cc v1.0.72
   Compiling cfg-if v1.0.0
   Compiling pkg-config v0.3.22
   Compiling cmake v0.1.46
   Compiling audiopus_sys v0.2.1 (/io/audiopus_sys)
    Finished dev [unoptimized + debuginfo] target(s) in 1m 48s

@alexcrichton
Copy link
Member

Ok, seems fine.

@alexcrichton alexcrichton merged commit 71c41f0 into rust-lang:master Dec 2, 2021
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 this pull request may close these issues.

2 participants