-
Notifications
You must be signed in to change notification settings - Fork 93
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
Cross-compiling from Linux to Mac #22
Comments
I know it's possible. I've heard at least of one report before. Which is why I used "don't" (intended as a recommendation) instead of "can't" (because it is possible). Perhaps the language can be changed to make my intent clearer?
Wow, that's some impressive feat! This is first time (*) I heard that someone managed to cross compile (across different OSes) a project with so many native dependencies. 👍 (*) OK, maybe the second. I think the servo team has infrastructure to compile servo from linux to android.
Definitively! The Rust tooling team has plans to extend rustup functionality to make it possible to install SDK and cross-toolchains with it (ideally, automatically or with minimal user intervention).
My worry with this would be licensing issues. clang and cctools seem okay as they are already available via tooltool. But can OSX SDKs downloaded from somewhere? Are there any licensing "gotchas"? As in: Does the user has to explicitly agree to some sort of EULA? etc. If you have the answers to those questions, I'm sure the Rust tooling team (@brson et al) would love to hear them. 😄 |
This does seem possible, and would be cool, as long as you never need to build any C code. There may even be clean-room redeclarations of various core Darwin libraries we could distribute that would cover some simple C/Obj-C cases, but I've never looked into it. |
Just more hand-waving: even if we can build and distribute our own gcc/clang that targets OS X, we'll have to have at least the headers for libc that are compatible with OS X's and free of licensing issues. I know that Mozilla has its own cross build of gcc for OS X but I believe they still need pieces of Apple's SDK. Don't know the details. Here's an old issue with details about what they did. |
I think Apple's libc bits are all BSD licensed. It can be hard to tease out exactly what's what on their open source site, but libc is definitely there: I was trying to sort out whether the CRT initialization bits were open source, and it turns out that someone else has already fixed that: re: cross-compiling Firefox, I did a lot of that work, and yeah, we just use a copy of an OS X SDK. Firefox is building a lot of C code though. For many Rust projects it might be feasible to get away with less. Since you're going to have to declare the things you need in Rust anyway, and not require the headers, it should be possible to provide fake versions of system libraries to link against. This is all a bit theoretical right now. |
I don't know if this project is still maintained, but this would be nice to have |
@luser Thank you for the gist in your first post. I came across this while trying to get a project using the jsonnet crate to cross compile on a Linux host for Mac users. I have been banging my head against cross compiling certain crates for months and your approach both works for me and I expect will be applicable across a lot more use cases. |
FYI, here's how I did it on a small Rust project pretty easily, via the crossbuild project: docker run -it --rm $(pwd):/workdir multiarch/crossbuild bash
cat > macbuild.sh <<EOF
#!/bin/bash
export CROSS_TRIPLE="x86_64-apple-darwin"
# Have to set the minimum macos version here for thread-local vars
exec crossbuild cc -mmacosx-version-min=10.7 "$@"
EOF
chmod +x macbuild.sh
cat > .cargo/config <<EOF
[target.x86_64-apple-darwin]
linker = "/workdir/macbuild.sh"
EOF
# Muck with the PATH so we can find dsymutil
PATH=/usr/bin:/root/.cargo/bin/:/usr/x86_64-apple-darwin14/bin/ cargo build --target x86_64-apple-darwin |
I've linked to @reissbaker's comment to a few others who I've seen ask the same question. So I put together an example repository showing how to use it. https://github.com/zmoazeni/rust-crossbuild |
Your FAQ says "you don't", but it's totally feasible. It'd be nice to make this easier. I cross-compiled Servo from Linux to Mac:
https://gist.github.com/luser/a33e5070d1c55a7d2c46fe763a9d1543
You need:
The gist above pulls the first two from Mozilla's tooltool (a content store), and requires you to provide the third yourself.
Getting plain Rust code to build is pretty straightforward, but once you hit a crate with a native code dependency it gets a little tricky, hence most of the stuff in the gist.
I think it would be possible to build a Rust-only OS X SDK that's redistributable since it doesn't need header files, which would make this a lot easier.
The text was updated successfully, but these errors were encountered: