Rust What Is The Target Triple For Macos
- Rust What Is The Target Triple For Macos 7
- Rust What Is The Target Triple For Macos Pc
- Rust What Is The Target Triple For Macos Download
I’ve recently been working on a Rust project at work which requires compiling for Linux (GNU), Linux (musl - for Alpine Linux) and macOS. I use Linux Mint nearly all the time, so building for macOS targets has required asking very nicely to borrow a spare Macbook Air. This is naturally a bit crap, so I set out to find a Linux-only solution to cross compile for macOS using osxcross. A weekend of pain later, and I have the following post. Hopefully it spares you a weekend of your own pain.
Environment
This constant is set to the Rust target triple for the platform on which wezterm was built. This can be useful when you wish to conditionally adjust. This constant is set to the Rust target triple for the platform on which wezterm was built. This can be useful when you wish to conditionally adjust your configuration based on the platform.
This process should work in any modern-ish Debian-based environment. This is the setup I used:
Built-in Targets. Rustc ships with the ability to compile to many targets automatically, we call these 'built-in' targets, and they generally correspond to targets that the team is supporting directly. MacOS Sierra Version 10.12.6) Which is below the recommended, and closer to the minimum requirements. I was able to play the game pretty well on the potato graphics setting, at certain points I was able to play on 60 FPS, however, I was faced with constant freezes, FPS drops, incredibly long load times. I also did the Ray Tracing in One Weekend tutorial in both Rust and Go, and just finished the 2nd 'Ray Tracking: The Next Week' part of the series in Rust. Overall, Rust has been an awesome language to learn, and I think it solves many of the common issues/bugs in C (which is kind of the whole point). By default rustup on Windows configures Rust to target the MSVC ABI, that is a target triple of either i686-pc-windows-msvc or x8664-pc-windows-msvc depending on the CPU architecture of the host Windows OS. Those will just be special versions of gcc, ld, etc. That are prefixed with the target triple. The triple will probably be something like x8664-unknown-linux-gnu. I would use brew to install crosstool-ng, and then use it to install the tool chain. The second thing you'll need will be the Rust cross-compiler and runtime. That's easy thanks to.
- Linux Mint 19.1, Dell XPS1 15, Intel i9 x64
- Rust 1.32.0 (with Rustup)
- Clang 6.0.0
I’ve also tested this process in CircleCI and it seems to be working fine.
The only device I have to test on at time of writing is a Macbook Air with macOS Mojave on it. This process should work for other macOS versions, but is untested.
Requirements
There are a few system dependencies required to work with osxcross. I don’t think the version requirements are too strict for the packages listed below. You may want to check the osxcross requirements as well if you’re having problems.
Building osxcross
The following process is based on this tutorial on Reddit and some trial and error. I’m using the macOS 10.10 SDK as I had the least problems getting up and running with it.
Rust What Is The Target Triple For Macos 7
Add the following to a script called osxcross_setup.sh
and make it executable.
Not a lot to it, thanks to the hard work put in by the osxcross developers. Running ./osxcross_setup.sh
should create a folder named osxcross
with everything you need in it to cross compile to macOS with Clang. This doesn’t modify $PATH
or install any system files, so is useful for CI as well.
Append ./build_gcc.sh
to osxcross_setup.sh
if you want to use GCC to cross compile.
Configuring Cargo
Rust What Is The Target Triple For Macos Pc
Cargo needs to be told to use the correct linker for the x86_64-apple-darwin
target, so add the following to your project’s .cargo/config
file:
If you’ve used a different macOS SDK version, you might need to replace darwin14
with darwin15
. To check what binary to use, look in osxcross/target/bin
.
Building the project
Because I chose not to install osxcross at the system level, the $PATH
variable must be modified for Cargo to pick up the linker binaries specified previously. The build command changes to:
This adds [pwd]/osxcross/target/bin
to $PATH
, which means the linker binaries should get picked up. The path must be absolute to work properly, hence $(pwd)
.
Now you should have a binary in target/x86_64-apple-darwin/[debug release]
which works on macOS! /best-routes-for-el-capitan.html.
Building *-sys
crates
You can stop here if none of your crates require any C bindings to function. Quite a few of them do, so read on if you run into compilation or linking errors.
The project I’m cross compiling uses the git2 crate which has libz-sys in its dependency tree. Unfortunately this means digging out a C compiler. The build uses the host system compiler by default, so the architectures for the final binary (target arch) and these linked libraries (host arch) don’t match up.
The solution to this is to set the CC
and CXX
environment variables in our build command:
This uses o64-clang
and o64-clang++
in osxcross/target/bin
.
Now git2 compiles, but fails to link! This is due to the fact that libz-sys attempts to link to the host system zlib
library. Because I’m building on a Linux machine, this is a Linux-native library which won’t work on macOS.
Luckily, libz-sys supports building its own statically linked version of zlib. According to libz-sys’ build.rs
, if LIBZ_SYS_STATIC=1
is set in the environment a bundled version of zlib will be built. Because we set CC
and CXX
, this statically linked code will be compiled for a macOS target. The full build command ends up looking like this:
CI
I got the above process working in CircleCI, but it should be pretty easy to get any Debian-based CI service to work.
It should be possible to cache the osxcross
folder so it doesn’t have to be built for every job. The cache should be invalidated when your build script(s) change. For example, I use the cache checksum project-v1-
to ensure the osxcross
folder is regenerated correctly.
Wrapping up
The final build command is pretty long, so I’d suggest putting it in a script. In my case, I have a build script containing the following snippet:
Rust What Is The Target Triple For Macos Download
Now you can just run ./osxcross_setup.sh
and ./build_macos.sh
in your CI.