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

Support for iOS cross compiling using cmake 3.14+ #87

Open
kylefleming opened this issue Sep 30, 2019 · 7 comments
Open

Support for iOS cross compiling using cmake 3.14+ #87

kylefleming opened this issue Sep 30, 2019 · 7 comments

Comments

@kylefleming
Copy link
Contributor

As of version 3.14, cmake has added support for cross compiling iOS (see https://cmake.org/cmake/help/latest/release/3.14.html?highlight=cross#platforms).

This means that -miphone-version-min style parameters get added automatically. This also means that currently when using cmake-rs, these parameters are being added twice, and often with conflicting values.

I've found that in order the support the new system, the following CMAKE variables need to be set:

  • CMAKE_SYSTEM_NAME (Set to iOS)
  • CMAKE_OSX_ARCHITECTURES (Set to one of: arm64, armv7, armv7s, i386, or x86_64)
  • CMAKE_OSX_DEPLOYMENT_TARGET (Could likely be pulled from the IPHONEOS_DEPLOYMENT_TARGET env variable)
  • CMAKE_OSX_SYSROOT (Set to either: iphoneos or iphonesimulator)

The target triplets for iOS are:

  • aarch64-apple-ios
  • armv7-apple-ios
  • armv7s-apple-ios
  • i386-apple-ios
  • x86_64-apple-ios

Additionally, I found that cmake-rs (via cc-rs) is setting the following compiler flags which are not added by cmake:

  • -fPIC
  • -fembed-bitcode

Note: cmake 3.14 also added support for tvOS and watchOS, but since I don't support them in my own app, I don't know what's required to support them.

@alexcrichton
Copy link
Member

Seems reasonable to me to support! I don't do much ios development myself but I'm more than willing to review PRs!

@davemilter
Copy link

Did #93 fix this issue? I try this "hello world" project:
https://github.com/davemilter/cmake_rs_hello_world

it builds without modification for Android, but for iOS:

-- Check for working C compiler: /usr/bin/cc - broken
clang: warning: using sysroot for 'MacOSX' but targeting 'iPhone' [-Wincompatible-sysroot]
 ld: warning: -headerpad_max_install_names is ignored when used with -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES)
ld: dynamic main executables must link with libSystem.dylib for architecture arm64

On this system cmake crosscomping for iOS works, if I manually invoke cmake,
but always pass properly crafted cmake toolchain file to cmake.

Should this work without toolchain file, or I have to pass it?
cc @simlay

@davemilter
Copy link

Or, it is actually works. The problem in that crate on crates.io has no #93 . @alexcrichton, any plans for new release with iOS support fix?

@alexcrichton
Copy link
Member

Oops sorry about that, published now!

@kylefleming
Copy link
Contributor Author

@alexcrichton Could you reopen this issue on account of the fix having been reverted, as described in #96?

@alexcrichton alexcrichton reopened this Sep 16, 2020
@alexcrichton
Copy link
Member

Sure!

@daxpedda
Copy link

I have encountered this issue while cross-compiling between Intel and Apple Silicon MacOS, I fixed it by simply applying CMAKE_OSX_ARCHITECTURES.

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

4 participants