clean up mac build

This commit is contained in:
John Smith 2022-01-30 18:36:19 -05:00
parent ccfde9977f
commit b33b19358c

View File

@ -1,10 +1,18 @@
#!/bin/bash #!/bin/bash
# Setup varaiables
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
FLUTTER_DIR=$(dirname `which flutter`)
HOMEBREW_DIR=$(dirname `which brew`)
CARGO_DIR=$(dirname `which cargo`)
CARGO_MANIFEST_PATH=$(python -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))") CARGO_MANIFEST_PATH=$(python -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))")
TARGET_DIR=$(dirname `cargo locate-project --message-format plain`)/target TARGET_DIR=$(dirname `cargo locate-project --message-format plain`)/target
# echo CARGO_MANIFEST_PATH: $CARGO_MANIFEST_PATH
# Configure outputs
OUTPUT_FILENAME=libveilid_flutter.dylib
OUTPUT_DIR=$SCRIPTDIR/../macos/lib
# Get Rust configurations from xcode configurations
if [ "$CONFIGURATION" == "Debug" ]; then if [ "$CONFIGURATION" == "Debug" ]; then
EXTRA_CARGO_OPTIONS="$@" EXTRA_CARGO_OPTIONS="$@"
RUST_CONFIGURATION="debug" RUST_CONFIGURATION="debug"
@ -12,8 +20,11 @@ else
EXTRA_CARGO_OPTIONS="$@ --release" EXTRA_CARGO_OPTIONS="$@ --release"
RUST_CONFIGURATION="release" RUST_CONFIGURATION="release"
fi fi
# Build all the matching architectures for the xcode configurations
ARCHS=${ARCHS:=x86_64} ARCHS=${ARCHS:=x86_64}
echo ARCHS: $ARCHS echo ARCHS: $ARCHS
LIPO_LIST=""
for arch in $ARCHS for arch in $ARCHS
do do
if [ "$arch" == "arm64" ]; then if [ "$arch" == "arm64" ]; then
@ -28,15 +39,14 @@ do
echo Unsupported ARCH: $arch echo Unsupported ARCH: $arch
continue continue
fi fi
FLUTTER_DIR=$(dirname `which flutter`)
HOMEBREW_DIR=$(dirname `which brew`) # Cargo build
CARGO_DIR=$(dirname `which cargo`)
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 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
# xxx add to lipo list?
# Add output to lipo list
LIPO_LIST="$LIPO_LIST $TARGET_DIR/$CARGO_TARGET/$RUST_CONFIGURATION/$OUTPUT_FILENAME"
done done
OUTPUT_DIR=$SCRIPTDIR/../macos/lib # Lipo the architectures together
mkdir -p $OUTPUT_DIR mkdir -p $OUTPUT_DIR
# xxx use lipo library? lipo -output "$OUTPUT_DIR/$OUTPUT_FILENAME" -create $LIPO_LIST
cp $TARGET_DIR/x86_64-apple-darwin/$RUST_CONFIGURATION/libveilid_flutter.dylib $OUTPUT_DIR