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

Fix cross compiling for android on macOS #997

Merged

Conversation

keith
Copy link
Member

@keith keith commented Jan 6, 2023

The way rules_foreign_cc builds cross compilation targets isn't exactly what cmake expects. Because of this when targeting android on macOS, some macOS specific linker flags are added to cmake's test compile invocations, leading to failures. This works around this issue by setting some more variables to trick cmake into only using the expected settings.

Fixes #289

@keith keith force-pushed the ks/fix-cross-compiling-for-android-on-macos branch from 215bae4 to b2b81f0 Compare January 6, 2023 18:53
@@ -209,6 +209,7 @@ CC_EXTERNAL_RULE_ATTRIBUTES = {
cfg = "exec",
default = [],
),
"_android_constraint": attr.label(default = Label("@platforms//os:android")),
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 chose to only add this one for now since it's a bit of boilerplate to add more, but I can if folks want to

The way rules_foreign_cc builds cross compilation targets isn't exactly
what cmake expects. Because of this when targeting android on macOS,
some macOS specific linker flags are added to cmake's test compile
invocations, leading to failures. This works around this issue by
setting some more variables to trick cmake into only using the expected
settings.
@keith keith force-pushed the ks/fix-cross-compiling-for-android-on-macos branch from b2b81f0 to 0258fce Compare January 6, 2023 18:58
@jsharpe jsharpe enabled auto-merge (squash) February 22, 2023 21:39
@jsharpe jsharpe merged commit b7074f1 into bazel-contrib:main Feb 22, 2023
jungleraptor added a commit to jungleraptor/rules_foreign_cc that referenced this pull request Jun 19, 2023
Same as bazel-contrib#997 but for linux instead of android.
jsharpe pushed a commit that referenced this pull request Jun 27, 2023
Fixes cross-compiling from macos to linux.

see #997 for background.

I had to make a couple of extra changes to support this:

Setting CMAKE_SYSTEM_NAME manually causes CMAKE_SYSTEM_PROCESSOR to not be set. This breaks some builds that expect this variable to be set like libjpeg-turbo.
I made it so that the above variables are only set when cross-compilation is detected so that rules_foreign_cc only takes on responsibility of setting them when necessary.
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.

Cross compiling with CMake for Android
2 participants