veilid/veilid-flutter/rust/macos_build.sh

55 lines
1.7 KiB
Bash
Raw Normal View History

2022-01-30 02:25:21 +00:00
#!/bin/bash
2022-06-10 21:07:10 +00:00
set -e
echo Running veilid-flutter rust MacOS build script
2022-01-30 02:25:21 +00:00
2022-01-30 23:36:19 +00:00
# Setup varaiables
2022-01-30 02:25:21 +00:00
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
2022-01-30 23:36:19 +00:00
FLUTTER_DIR=$(dirname `which flutter`)
HOMEBREW_DIR=$(dirname `which brew`)
CARGO_DIR=$(dirname `which cargo`)
2022-06-10 21:07:10 +00:00
CARGO_MANIFEST_PATH=$(python3 -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))")
2022-01-30 22:47:46 +00:00
TARGET_DIR=$(dirname `cargo locate-project --message-format plain`)/target
2022-01-30 02:25:21 +00:00
2022-01-30 23:36:19 +00:00
# Configure outputs
OUTPUT_FILENAME=libveilid_flutter.dylib
2022-01-31 02:28:27 +00:00
OUTPUT_DIR=$TARGET_DIR/macos_lib
2022-01-30 23:36:19 +00:00
# Get Rust configurations from xcode configurations
2022-01-30 02:25:21 +00:00
if [ "$CONFIGURATION" == "Debug" ]; then
EXTRA_CARGO_OPTIONS="$@"
2022-01-30 22:47:46 +00:00
RUST_CONFIGURATION="debug"
2022-01-30 02:25:21 +00:00
else
EXTRA_CARGO_OPTIONS="$@ --release"
2022-01-30 22:47:46 +00:00
RUST_CONFIGURATION="release"
2022-01-30 02:25:21 +00:00
fi
2022-01-30 23:36:19 +00:00
# Build all the matching architectures for the xcode configurations
2022-01-30 04:23:50 +00:00
ARCHS=${ARCHS:=x86_64}
2022-01-30 22:47:46 +00:00
echo ARCHS: $ARCHS
2022-01-30 23:36:19 +00:00
LIPO_LIST=""
2022-01-30 02:25:21 +00:00
for arch in $ARCHS
do
if [ "$arch" == "arm64" ]; then
echo arm64
CARGO_TARGET=aarch64-apple-darwin
CARGO_TOOLCHAIN=
elif [ "$arch" == "x86_64" ]; then
echo x86_64
CARGO_TARGET=x86_64-apple-darwin
CARGO_TOOLCHAIN=
else
echo Unsupported ARCH: $arch
continue
fi
2022-01-30 23:36:19 +00:00
# Cargo build
2022-01-30 04:23:50 +00:00
env -i PATH=/usr/bin:/bin:/usr/local/bin:$HOMEBREW_DIR:$FLUTTER_DIR:$CARGO_DIR HOME="$HOME" USER="$USER" cargo $CARGO_TOOLCHAIN build $EXTRA_CARGO_OPTIONS --target $CARGO_TARGET --manifest-path $CARGO_MANIFEST_PATH
2022-01-30 23:36:19 +00:00
# Add output to lipo list
LIPO_LIST="$LIPO_LIST $TARGET_DIR/$CARGO_TARGET/$RUST_CONFIGURATION/$OUTPUT_FILENAME"
2022-01-30 02:25:21 +00:00
done
2022-01-30 23:36:19 +00:00
# Lipo the architectures together
2022-01-30 22:47:46 +00:00
mkdir -p $OUTPUT_DIR
2022-01-30 23:36:19 +00:00
lipo -output "$OUTPUT_DIR/$OUTPUT_FILENAME" -create $LIPO_LIST