veilid/veilid-flutter/rust/macos_build.sh

53 lines
1.6 KiB
Bash
Raw Normal View History

2022-01-29 21:25:21 -05:00
#!/bin/bash
2022-01-30 18:36:19 -05:00
# Setup varaiables
2022-01-29 21:25:21 -05:00
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
2022-01-30 18:36:19 -05:00
FLUTTER_DIR=$(dirname `which flutter`)
HOMEBREW_DIR=$(dirname `which brew`)
CARGO_DIR=$(dirname `which cargo`)
2022-01-30 17:47:46 -05:00
CARGO_MANIFEST_PATH=$(python -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))")
TARGET_DIR=$(dirname `cargo locate-project --message-format plain`)/target
2022-01-29 21:25:21 -05:00
2022-01-30 18:36:19 -05:00
# Configure outputs
OUTPUT_FILENAME=libveilid_flutter.dylib
2022-01-30 21:28:27 -05:00
OUTPUT_DIR=$TARGET_DIR/macos_lib
2022-01-30 18:36:19 -05:00
# Get Rust configurations from xcode configurations
2022-01-29 21:25:21 -05:00
if [ "$CONFIGURATION" == "Debug" ]; then
EXTRA_CARGO_OPTIONS="$@"
2022-01-30 17:47:46 -05:00
RUST_CONFIGURATION="debug"
2022-01-29 21:25:21 -05:00
else
EXTRA_CARGO_OPTIONS="$@ --release"
2022-01-30 17:47:46 -05:00
RUST_CONFIGURATION="release"
2022-01-29 21:25:21 -05:00
fi
2022-01-30 18:36:19 -05:00
# Build all the matching architectures for the xcode configurations
2022-01-29 23:23:50 -05:00
ARCHS=${ARCHS:=x86_64}
2022-01-30 17:47:46 -05:00
echo ARCHS: $ARCHS
2022-01-30 18:36:19 -05:00
LIPO_LIST=""
2022-01-29 21:25:21 -05: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 18:36:19 -05:00
# Cargo build
2022-01-29 23:23:50 -05: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 18:36:19 -05:00
# Add output to lipo list
LIPO_LIST="$LIPO_LIST $TARGET_DIR/$CARGO_TARGET/$RUST_CONFIGURATION/$OUTPUT_FILENAME"
2022-01-29 21:25:21 -05:00
done
2022-01-30 18:36:19 -05:00
# Lipo the architectures together
2022-01-30 17:47:46 -05:00
mkdir -p $OUTPUT_DIR
2022-01-30 18:36:19 -05:00
lipo -output "$OUTPUT_DIR/$OUTPUT_FILENAME" -create $LIPO_LIST