[swift-dev] Cross-compile for Android armv7 from OSX

ChrisBieneman beanz at apple.com
Fri Jan 22 11:26:13 CST 2016


Can I provide an alternate suggestion?

Clang can be cross-compiled for alternate platforms with seemingly a single CMake invocation. This is accomplished by having a model where the user configures the cross-build, and LLVM's CMake detects that you are cross compiling and it handles configuring the host tools and hooking the dependencies up.

This does lead to some pretty gnarly CMake scripting, but I think it provides a very good user experience.

As an example instructions for cross-compiling LLVM are here: http://llvm.org/docs/GettingStarted.html#cross-compiling-llvm

That simple configuration command handles everything, all a user has to do is run ninja once.

-Chris

Sent from my iPad

> On Jan 21, 2016, at 11:38 AM, Dmitri Gribenko via swift-dev <swift-dev at swift.org> wrote:
> 
>> On Thu, Jan 21, 2016 at 11:04 AM, Tom Birch <froody at gmail.com> wrote:
>> Ok, thanks, I'll run with that. I see
>> SWIFT_NATIVE_(LLVM|CLANG|SWIFT)_TOOLS_PATH, is currently used/supported
>> anywhere?
> 
> Yes, it is supported and can be used to compile the libraries with an
> existing swift compiler, while cross-compiling the compiler.  It can
> be used for some cross-compilation workflows.
> 
>> My current plan is to:
>> 1) Build everything (llvm/clang, cmark, swift) for macosx-x86_64
>> 2) Setup SWIFT_NATIVE_*_TOOLS_PATH to point to the respective dirs created
>> in (1)
>> 3) Create a swift-android-armv7 build dir
>> 4) Invoke CMake in swift-android-armv7 with vars from (2), plus a
>> Toolchain-android-armv7.cmake to set CMAKE_SYSTEM_NAME, CMAKE_SYSROOT, etc
>> for the android build
> 
> Right, except the step (2) actually happens inside of step (4).
> That's exactly how it is supposed to work.
> 
>> Ideally I'd only build the stdlib and tests for android, skipping the tools
>> and and llvm/clang builds. Does this seem feasible? I know the runtime
>> depends on llvm headers, but I can either use the macosx-x86_64 llvm
>> headers, or do a partial headers-only install of llvm-android-armv7. Are
>> there any binaries/tools needed to be built for the target (i.e
>> android-armv7) in order to build stdlib?
> 
> Yes, you can do that with appropriate skip-build-* flags, but you
> would still need to configure llvm/clang.  build-script should take
> care of that if you give it appropriate flags.
> 
>> Anything else I should know/watch
>> out for?
> 
> Nothing that I know of right now.
> 
> Dmitri
> 
> -- 
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
> _______________________________________________
> swift-dev mailing list
> swift-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev


More information about the swift-dev mailing list