Created
May 26, 2016 18:29
-
-
Save luser/a33e5070d1c55a7d2c46fe763a9d1543 to your computer and use it in GitHub Desktop.
Cross-compile Servo from Linux to OS X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#TODO: you will need to manually get an OS X SDK. | |
set -e | |
# Install the proper Rust nightly with rustup, and add the OSX target. | |
rustup install nightly-`cat rust-nightly-date` | |
rustup override add nightly-`cat rust-nightly-date` | |
rustup target install x86_64-apple-darwin | |
# Configure Servo to use system rust. | |
cat > .servobuild <<EOF | |
[tools] | |
system-rust = true | |
system-cargo = true | |
rustc-with-gold = false | |
[build] | |
mode = "dev" | |
EOF | |
# Get a cross-toolchain. | |
# This is the toolchain Firefox cross-mac builds use. | |
mkdir -p toolchain | |
cd toolchain | |
curl https://raw.githubusercontent.com/mozilla/build-tooltool/master/tooltool.py > tooltool.py | |
curl https://hg.mozilla.org/mozilla-central/raw-file/default/browser/config/tooltool-manifests/macosx64/cross-releng.manifest > cross-releng.manifest | |
python tooltool.py -m cross-releng.manifest fetch cctools.tar.gz clang.tar.xz | |
# The clang from tooltool needs this. | |
export LD_LIBRARY_PATH=`pwd`/clang/lib | |
# Create wrapper scripts for clang/clang++ | |
# If cargo would accept linker arguments in .cargo/config this wouldn't | |
# be necessary. | |
cat > mac-cc <<EOF | |
#!/bin/sh | |
exec ${PWD}/clang/bin/clang -mmacosx-version-min=10.7 -target x86_64-apple-darwin10 -mlinker-version=136 -B ${PWD}/cctools/bin -isysroot ${PWD}/MacOSX10.7.sdk \$* | |
EOF | |
cat > mac-c++ <<EOF | |
#!/bin/sh | |
exec ${PWD}/clang/bin/clang++ -mmacosx-version-min=10.7 -target x86_64-apple-darwin10 -mlinker-version=136 -B ${PWD}/cctools/bin -isysroot ${PWD}/MacOSX10.7.sdk \$* | |
EOF | |
chmod +x mac-cc mac-c++ | |
export PATH=$PATH:`pwd` | |
echo "Copy an OS X 10.7 SDK to ${PWD}/MacOSX10.7.sdk, then press ENTER." | |
read | |
if test ! -d "${PWD}/MacOSX10.7.sdk"; then | |
echo "Didn't find an SDK at ${PWD}/MacOSX10.7.sdk" | |
exit 1 | |
fi | |
cd .. | |
# Point cargo at the cross-toolchain. | |
cat > .cargo/config <<EOF | |
[target.x86_64-apple-darwin] | |
linker = "${PWD}/toolchain/mac-cc" | |
ar = "${PWD}/toolchain/cctools/bin/x86_64-apple-darwin10-ar" | |
EOF | |
# Create a cmake toolchain for some build deps to use. | |
cat > cmake-toolchain <<EOF | |
set( CMAKE_AR "${PWD}/toolchain/cctools/bin/x86_64-apple-darwin10-ar" CACHE PATH "archive" ) | |
set( CMAKE_RANLIB "${PWD}/toolchain/cctools/bin/x86_64-apple-darwin10-ranlib" CACHE PATH "archive" ) | |
EOF | |
# Build it. | |
HOST_CC=gcc HOST_CXX=g++ \ | |
CC=mac-cc CXX=mac-c++ CPP="mac-cc -E" \ | |
AR="${PWD}/toolchain/cctools/bin/x86_64-apple-darwin10-ar" \ | |
RANLIB="${PWD}/toolchain/cctools/bin/x86_64-apple-darwin10-ranlib" \ | |
TOOLCHAIN_PREFIX="${PWD}/toolchain/cctools/bin/x86_64-apple-darwin10-" \ | |
CMAKE_TOOLCHAIN_FILE="${PWD}/cmake-toolchain" \ | |
./mach build --target x86_64-apple-darwin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment