-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement cross-compilation to Android #4513
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
Comments
the libraries to be cross compiled are
Other tasks:
|
As mentioned previously, this is my branch where I have been hacking on Rust's cross-compile: https://github.com/brson/rust/commits/cross2 All it does so far is add CFG_HOST_TRIPLES and CFG_BUILD_TRIPLE. Under this scheme, the target triples would be systems that we build core and std, and for the host triples we would build the entire compiler. The build triple is the architecture we bootstrap from. |
How can one specify multiple host-triples or target-triples? Separating with a space doesn't seem to work. |
It looks to me like that "for loop" of target-triples make each target directory. Assuming arm-unknown-android as target triples and x86_64-apple-darwin as host-triples, One possible way to make build directory is to adding host-triples value to target-triples, the other possible way is to modify configure script to handle host-triples and target-triples separately. |
@yichoi on the command line they are specified like |
@yichoi yeah, the host and target triples could be disjoint, though I've been assuming that target triples are a superset of host triples. |
@yichoi I pushed a cleanup commit to my cross2 branch that deletes a bunch of code to make further changes easier: brson@abb5c65 I'm going to do a little more cleanup to my cross2 branch to make sure it works like I think it does (I'm testing e.g. I have some examples below of how I imagine the configuration should work and the directory structure it should produce. In the makefiles on cross2 ''host' platforms are those for which we build ompilers; 'target' platforms are the platforms are the ones the 'host' compilers target. As an example, in a scenario where
In an even more complex scenario where we are building the entire compiler for multiple architectures (as indicated by multiple host triples) we would expect the following output (and the current build does this sort of thing already).
Some next steps (I'll leave these to you if you like):
|
@graydon @nikomatsakis you may be interested in this subject |
I did some tweaks and testing to my branch and it gets through the full build under several cross-compile scenarios (just using x86 and i686), but tests.mk isn't quite right. I'm going to leave it as is until I get some feedback from @yichoi. |
@nikomatsakis asked on IRC why we don't just build the compiler for ARM. That would allow us to leave the build as it is. I had a strong belief that one wouldn't usually want a compiler to run on ARM, but that may not be true. It could be simpler to build compilers everywhere. As an alternative to making this distinction between 'host' and 'target', which effectively just changes which binaries are built, we could teach the configure script to disable components or groups of components per target, and disable the ARM compiler by default. |
In case of x86_64-unknown-linux-gnu as host-triples, arm-unknown-android as target-triples. I've copied host-triples value to target-triples then made almost works except libstd of Rust building at stage2. I am investigating about that. x86_64-unknown-linux-gnu/stage2/bin/rustc --cfg stage2 -O --target=arm-unknown-android -o x86_64-unknown-linux-gnu/stage2/lib/rustc/arm-unknown-android/lib/libstd.so /home/yichoi/rust_latest/src/libstd/std.rc && touch x86_64-unknown-linux-gnu/stage2/lib/rustc/arm-unknown-android/lib/libstd.so
In case of x86_64-apple-darwin as host-triples, arm-unknown-android as target-triples, I am thinking a way to specify CFG_LIB_NAME=lib$(1).so or CFG_LIB_NAME=lib$(1).dylib for each target-triples. It might need to expand configuration method in platform.mk |
you may check https://github.com/yichoi/rust/commits/cross3. However libstd.so cannot built yet. |
I believe this is because of foreign function abi. |
https://github.com/yichoi/rust/commits/cross3 works with cabi_arm.rs regression patch. |
@yichoi Configuring with
Probably has to do with this line at the beginning of the output indicating I have duplicate target triples: Then later the build fails with:
Which is fixed by this patch: brson@7625022 The modifications to platform.mk look like they don't go far enough to me, requiring special cases in |
@yichoi Nice job, and thank you for working on this. |
hm. perhaps you were expecting me to configure like |
Under x86_64-unknown-linux-gnu, ../configure --target-triples=arm-unknown-android works. |
current arm latest working branch along with latest libuv |
@yichoi thanks. giving it a look now |
@yichoi I want to try to make some drastic changes to the makefiles so there are fewer ARM special cases. I'm thinking of paramaterizing all the toolchain-related variables over the target triple - basically removing the few variables that use My current branch: https://github.com/brson/rust/tree/cross4 |
@brson if you need help, please let me help you. Moreover I want to make Servo makefile for ARM with similar convention of Rust makefile if decided. |
What I have done :
|
@yichoi I made a bunch of changes to the makefiles and then reincorporated your Android changes to my cross5 branch. Sadly, I did not use any of your patches directly, since they no longer applied after all the refactoring, but I did copy and paste major pieces. I did two things slightly differently than you: 1) I am building and linking morestack.S, but it is empty; 2) I added an --android-ndk-path flag to rustc. With this branch I can build core and std for android when configuring with I'm sorry about all the back-and-forth on this issue, and hope it's not discouraging you. |
@brson oh, you did it ahead of me. I have been working to rewrite makefiles for various build host and arm target https://github.com/yichoi/rust/commits/cross5, which works successful and almost similar with what you did. |
We have been using |
@brson Build for ARM with your patch worked on linuxpc, failed on mac however it's morestack problem. if you disable morestack.a at link.rs, it will work on mac, too. as you know if we complete morestack for ARM, it will be unnecessary. |
@yichoi I am truly sorry I keep stepping on your toes here. Our patches are indeed quite similar. I like the way you handled platform.mk, just writing out the variable names like It also doesn't create a per-triple I'm going to run your branch through the try bots today and see what they think. Perhaps you can let me know how you think we should proceed from here. @sanxiyn Changing the triple sounds fine to me. Does LLVM accept either? |
Yes, LLVM accepts both. |
@yichoi fyi here are the results of pushing your branch to the try bots: http://buildbot.rust-lang.org/builders/try-win/builds/354/steps/clean/logs/stdio I'm not sure offhand why some would be segfaulting because of these changes. |
@brson Above logs resulted from libuv. when I changed to Basically, I have added flags for mingw32 my cross5, however I cannot fully test since rustc.exe in snapshot failed on my mingw32 environment at early stage0. |
@yichoi Your libuv branch includes some upstream commits that are more recent than our current branch, and it changes some structure definitions. If we can avoid it I'd prefer not to take those changes at the same time, so we don't have to worry about uv regressions. Can your patches work on top of uv commit da33bba7c04e0873b457a9a4290bed2adf620154? |
@brson yes, as long as native target triples (x86 linux, x86 mac). I will test more for android, mingw32, then make some patch based on |
@yichoi I've put another branch up at https://github.com/brson/rust/tree/cross6 that tries to apply your uv patches to the previously mentioned uv branch. It also includes some fixes to the makefiles that you'll want to grab. I'm going to try to get this passing the try bots tonight. Hopefully we can merge soon. Two things I haven't tested carefully yet though are |
@brson thanks. I will check your branch and try |
I've updated my branch to fix some problems I've seen on the bots, first that toolchain variables aren't defined for a few triples, including FreeBSD, and second to fix |
I've tested my makefile patches of cross5 on Rust/master branch
It looks to me that test supposes to perform build-triple only. It may be meaningless to test target-triples which is not build-triple.
|
I believe that plain |
As mentioned on IRC, I've taken your most recent branch and added a few more commits that fix the build in various scenarios, and pushed to my cross7 branch. I'm going to focus on merging this branch now. |
I've pushed the patch to pass android-cross-path to rustc. |
I opened a pull request to merge this. It doesn't include your latest patch to add an android ndk flag to rustc, so that can be done in a followup. |
I see that our branches have diverged a lot again, so I'm going to take yours and run it through the bots and try to get it merged. |
Ok, opened an updated pull request. I think this is the one! |
Looks like this has been merged. Thanks everyone. Please file any followups as new issues. FWIW, I think in the next few weeks we should be aiming to make it Android cross-compilation usable, at least for experimintation, in 0.6. From my perspective that means getting morestack in, writing some docs, adding whatever polish is missing, possibly working on getting the test suite to pass. |
We have Android code in tree but no way to build it. It should not be all that difficult to integrate the NDK since we have some minimal cross-compile support already.
The text was updated successfully, but these errors were encountered: