trivalent/mac-cargo

44 lines
1.2 KiB
Text
Raw Permalink Normal View History

2019-06-11 12:39:20 +00:00
#!/bin/bash
# based on https://gist.github.com/luser/a33e5070d1c55a7d2c46fe763a9d1543
set -e
# ensures that the host and target compilers are explicitly set, including using
# wrappers for clang for the target to pass parameters to clang that help a lot
# of native code more reliably compile
export HOST_CC="gcc"
export HOST_CXX="g++"
export CC="mac-cc"
export CXX="mac-c++"
export CPP="mac-cc -E"
# these, along with the .cargo/config in mac-cargo, help resolve issues that can
# arise with assembly and linking
2019-06-11 18:20:02 +00:00
export AR="/usr/osxcross/bin/x86_64-apple-darwin17-ar"
export RANLIB="/usr/osxcross/bin/x86_64-apple-darwin17-ranlib"
export TOOLCHAIN_PREFIX="/usr/osxcross/bin/x86_64-apple-darwin17-"
2019-06-11 12:39:20 +00:00
mkdir -p .cargo
if [ -f .cargo/config ]
then
mv .cargo/config .cargo/config.bak
fi
# Point cargo at the cross-toolchain.
cat > .cargo/config <<EOF
[target.x86_64-apple-darwin]
linker = "/usr/local/bin/mac-cc"
2019-06-11 18:20:02 +00:00
ar = "/usr/osxcross/bin/x86_64-apple-darwin17-ar"
2019-06-11 12:39:20 +00:00
EOF
# Build it.
cmd="${1}"
shift 1
cargo "${cmd}" --target=x86_64-apple-darwin "$@"
if [ -f .cargo/config.bak ]
then
mv .cargo/config.bak .cargo/config
else
rm .cargo/config
fi
unset HOST_CC HOST_CXX CC CXX CPP AR RANLIB TOOLCHAIN_PREFIX