From ef313133cf6f33f0c00cff56b9b9a91f81c79bd2 Mon Sep 17 00:00:00 2001 From: John Smith Date: Thu, 1 Dec 2022 20:38:57 -0500 Subject: [PATCH] unify ios mac build --- scripts/ios_build.sh | 9 ++- scripts/macos_build.sh | 61 +++++++++++++++++++ .../project.pbxproj | 2 +- veilid-flutter/ios/veilid.podspec | 11 ++-- veilid-flutter/macos/veilid.podspec | 7 ++- veilid-flutter/rust/Cargo.toml | 3 +- veilid-flutter/rust/ios_build.sh | 55 ----------------- veilid-flutter/rust/macos_build.sh | 54 ---------------- .../project.pbxproj | 2 +- 9 files changed, 78 insertions(+), 126 deletions(-) create mode 100755 scripts/macos_build.sh delete mode 100755 veilid-flutter/rust/ios_build.sh delete mode 100755 veilid-flutter/rust/macos_build.sh diff --git a/scripts/ios_build.sh b/scripts/ios_build.sh index 4062014b..8242c693 100755 --- a/scripts/ios_build.sh +++ b/scripts/ios_build.sh @@ -4,10 +4,10 @@ CARGO=`which cargo` CARGO=${CARGO:=~/.cargo/bin/cargo} CARGO_DIR=$(dirname $CARGO) -WORKING_DIR=$1 -shift -echo $WORKING_DIR -pushd $WORKING_DIR >/dev/null +# WORKING_DIR=$1 +# shift +# echo $WORKING_DIR +# pushd $WORKING_DIR >/dev/null echo PWD: `pwd` CARGO_MANIFEST_PATH=$(python3 -c "import os; import json; print(json.loads(os.popen('$CARGO locate-project').read())['root'])") @@ -40,7 +40,6 @@ do else CARGO_TARGET=aarch64-apple-ios fi - #CARGO_TOOLCHAIN=+ios-arm64-1.57.0 CARGO_TOOLCHAIN= elif [ "$arch" == "x86_64" ]; then echo x86_64 diff --git a/scripts/macos_build.sh b/scripts/macos_build.sh new file mode 100755 index 00000000..0ef14c81 --- /dev/null +++ b/scripts/macos_build.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +CARGO=`which cargo` +CARGO=${CARGO:=~/.cargo/bin/cargo} +CARGO_DIR=$(dirname $CARGO) + +# WORKING_DIR=$1 +# shift +# echo $WORKING_DIR +# pushd $WORKING_DIR >/dev/null +# echo PWD: `pwd` + +CARGO_MANIFEST_PATH=$(python3 -c "import os; import json; print(json.loads(os.popen('$CARGO locate-project').read())['root'])") +CARGO_WORKSPACE_PATH=$(python3 -c "import os; import json; print(json.loads(os.popen('$CARGO locate-project --workspace').read())['root'])") +TARGET_PATH=$(python3 -c "import os; print(os.path.realpath(\"$CARGO_WORKSPACE_PATH/../target\"))") +PACKAGE_NAME=$1 +shift + +if [ "$CONFIGURATION" == "Debug" ]; then + EXTRA_CARGO_OPTIONS="$@" + BUILD_MODE="debug" +else + EXTRA_CARGO_OPTIONS="$@ --release" + BUILD_MODE="release" +fi +ARCHS=${ARCHS:=arm64} + +LIPO_OUT_NAME="lipo-darwin" + +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 + + # Choose arm64 brew for unit tests by default if we are on M1 + if [ -f /opt/homebrew/bin/brew ]; then + HOMEBREW_DIR=/opt/homebrew/bin + elif [ -f /usr/local/bin/brew ]; then + HOMEBREW_DIR=/usr/local/bin + else + HOMEBREW_DIR=$(dirname `which brew`) + fi + + env -i PATH=/usr/bin:/bin:$HOMEBREW_DIR:$CARGO_DIR HOME="$HOME" USER="$USER" cargo $CARGO_TOOLCHAIN build $EXTRA_CARGO_OPTIONS --target $CARGO_TARGET --manifest-path $CARGO_MANIFEST_PATH + + LIPOS="$LIPOS $TARGET_PATH/$CARGO_TARGET/$BUILD_MODE/lib$PACKAGE_NAME.a" + +done + +mkdir -p "$TARGET_PATH/$LIPO_OUT_NAME/$BUILD_MODE/" +lipo $LIPOS -create -output "$TARGET_PATH/$LIPO_OUT_NAME/$BUILD_MODE/lib$PACKAGE_NAME.a" diff --git a/veilid-core/src/tests/ios/veilidcore-tests/veilidcore-tests.xcodeproj/project.pbxproj b/veilid-core/src/tests/ios/veilidcore-tests/veilidcore-tests.xcodeproj/project.pbxproj index 85356d38..2b35a5b9 100644 --- a/veilid-core/src/tests/ios/veilidcore-tests/veilidcore-tests.xcodeproj/project.pbxproj +++ b/veilid-core/src/tests/ios/veilidcore-tests/veilidcore-tests.xcodeproj/project.pbxproj @@ -167,7 +167,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "../../../../../scripts/ios_build.sh ../../../../ veilid_core --features veilid_core_ios_tests,rt-tokio\n"; + shellScript = "../../../../../scripts/ios_build.sh veilid_core --features veilid_core_ios_tests,rt-tokio\n"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/veilid-flutter/ios/veilid.podspec b/veilid-flutter/ios/veilid.podspec index 9088b982..003442e7 100644 --- a/veilid-flutter/ios/veilid.podspec +++ b/veilid-flutter/ios/veilid.podspec @@ -23,18 +23,19 @@ Veilid Network Plugin require 'json' require 'pathname' - cargo_target_dir = File.join(File.dirname(JSON.parse(`cargo locate-project`)['root']), 'target') + workspace_dir = File.dirname(JSON.parse(`cargo locate-project --workspace`)['root']) + cargo_target_dir = File.join(workspace_dir, 'target') s.xcconfig = { - 'OTHER_LDFLAGS' => "-Wl,-force_load,#{File.join(cargo_target_dir, 'ios_lib', 'libveilid_flutter.a')}", - "LIBRARY_SEARCH_PATHS" => File.join(cargo_target_dir, 'ios_lib') + 'OTHER_LDFLAGS' => "-Wl,-force_load,#{File.join(cargo_target_dir, 'lipo-ios', 'libveilid_flutter.a')}", + "LIBRARY_SEARCH_PATHS" => File.join(cargo_target_dir, 'lipo-ios') } s.script_phase = { :name => 'Cargo Build', - :script => File.join(File.dirname(__dir__), 'rust', 'ios_build.sh'), + :script => File.join(workspace_dir, 'scripts', 'ios_build.sh') + ' veilid_flutter', :execution_position => :before_compile - # :output_files => [ File.join(cargo_target_dir, 'ios_lib', 'libveilid_flutter.a') ] + # :output_files => [ File.join(cargo_target_dir, 'lipo-ios', 'libveilid_flutter.a') ] } end diff --git a/veilid-flutter/macos/veilid.podspec b/veilid-flutter/macos/veilid.podspec index c4139cd2..6b169c1d 100644 --- a/veilid-flutter/macos/veilid.podspec +++ b/veilid-flutter/macos/veilid.podspec @@ -22,13 +22,14 @@ Veilid Network Plugin require 'json' require 'pathname' - cargo_target_dir = File.join(File.dirname(JSON.parse(`cargo locate-project`)['root']), 'target') + workspace_dir = File.dirname(JSON.parse(`cargo locate-project --workspace`)['root']) + cargo_target_dir = File.join(workspace_dir, 'target') s.script_phase = { :name => 'Cargo Build', - :script => File.join(File.dirname(__dir__), 'rust', 'macos_build.sh'), + :script => File.join(workspace_dir, 'scripts', 'macos_build.sh') + ' veilid_flutter', :execution_position => :before_compile - #:output_files => [ File.join(cargo_target_dir, 'macos_lib', 'libveilid_flutter.dylib') ] + #:output_files => [ File.join(cargo_target_dir, 'lipo-darwin', 'libveilid_flutter.dylib') ] } end diff --git a/veilid-flutter/rust/Cargo.toml b/veilid-flutter/rust/Cargo.toml index 1967f5e1..933a37df 100644 --- a/veilid-flutter/rust/Cargo.toml +++ b/veilid-flutter/rust/Cargo.toml @@ -12,6 +12,7 @@ rt-async-std = [ "veilid-core/rt-async-std", "async-std", "opentelemetry/rt-asyn rt-tokio = [ "veilid-core/rt-tokio", "tokio", "tokio-stream", "tokio-util", "opentelemetry/rt-tokio"] [dependencies] +veilid-core = { path="../../veilid-core" } tracing = { version = "^0", features = ["log", "attributes"] } tracing-subscriber = "^0" parking_lot = "^0" @@ -25,7 +26,6 @@ data-encoding = { version = "^2" } # Dependencies for native builds only # Linux, Windows, Mac, iOS, Android [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -veilid-core = { path="../../veilid-core" } tracing-opentelemetry = "^0" opentelemetry = { version = "^0" } opentelemetry-otlp = { version = "^0" } @@ -41,7 +41,6 @@ hostname = "^0" # Dependencies for WASM builds only [target.'cfg(target_arch = "wasm32")'.dependencies] -veilid-core = { path="../../veilid-core" } # Dependencies for Android builds only [target.'cfg(target_os = "android")'.dependencies] diff --git a/veilid-flutter/rust/ios_build.sh b/veilid-flutter/rust/ios_build.sh deleted file mode 100755 index 7c05d493..00000000 --- a/veilid-flutter/rust/ios_build.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash -set -e -echo Running veilid-flutter rust iOS build script - -# Setup varaiables -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=$(python3 -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))") -TARGET_DIR=$(dirname `cargo locate-project --message-format plain`)/target - -# Configure outputs -OUTPUT_FILENAME=libveilid_flutter.a -OUTPUT_DIR=$TARGET_DIR/ios_lib - -# Get Rust configurations from xcode configurations -if [ "$CONFIGURATION" == "Debug" ]; then - EXTRA_CARGO_OPTIONS="$@" - RUST_CONFIGURATION="debug" -else - EXTRA_CARGO_OPTIONS="$@ --release" - RUST_CONFIGURATION="release" -fi - -# Build all the matching architectures for the xcode configurations -ARCHS=${ARCHS:=arm64} -echo ARCHS: $ARCHS -LIPO_LIST="" -for arch in $ARCHS -do - if [ "$arch" == "arm64" ]; then - echo arm64 - CARGO_TARGET=aarch64-apple-ios - #CARGO_TOOLCHAIN=+ios-arm64-1.57.0 - CARGO_TOOLCHAIN= - elif [ "$arch" == "x86_64" ]; then - echo x86_64 - CARGO_TARGET=x86_64-apple-ios - CARGO_TOOLCHAIN= - else - echo Unsupported ARCH: $arch - continue - fi - - # Cargo build - 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 - - # Add output to lipo list - LIPO_LIST="$LIPO_LIST $TARGET_DIR/$CARGO_TARGET/$RUST_CONFIGURATION/$OUTPUT_FILENAME" -done - -# Lipo the architectures together -mkdir -p $OUTPUT_DIR -lipo -output "$OUTPUT_DIR/$OUTPUT_FILENAME" -create $LIPO_LIST diff --git a/veilid-flutter/rust/macos_build.sh b/veilid-flutter/rust/macos_build.sh deleted file mode 100755 index 29f180bc..00000000 --- a/veilid-flutter/rust/macos_build.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash -set -e -echo Running veilid-flutter rust MacOS build script - -# Setup varaiables -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=$(python3 -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))") -TARGET_DIR=$(dirname `cargo locate-project --message-format plain`)/target - -# Configure outputs -OUTPUT_FILENAME=libveilid_flutter.dylib -OUTPUT_DIR=$TARGET_DIR/macos_lib - -# Get Rust configurations from xcode configurations -if [ "$CONFIGURATION" == "Debug" ]; then - EXTRA_CARGO_OPTIONS="$@" - RUST_CONFIGURATION="debug" -else - EXTRA_CARGO_OPTIONS="$@ --release" - RUST_CONFIGURATION="release" -fi - -# Build all the matching architectures for the xcode configurations -ARCHS=${ARCHS:=x86_64} -echo ARCHS: $ARCHS -LIPO_LIST="" -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 - - # Cargo build - 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 - - # Add output to lipo list - LIPO_LIST="$LIPO_LIST $TARGET_DIR/$CARGO_TARGET/$RUST_CONFIGURATION/$OUTPUT_FILENAME" -done - -# Lipo the architectures together -mkdir -p $OUTPUT_DIR -lipo -output "$OUTPUT_DIR/$OUTPUT_FILENAME" -create $LIPO_LIST diff --git a/veilid-tools/src/tests/ios/veilidtools-tests/veilidtools-tests.xcodeproj/project.pbxproj b/veilid-tools/src/tests/ios/veilidtools-tests/veilidtools-tests.xcodeproj/project.pbxproj index 153d3208..c34e5d62 100644 --- a/veilid-tools/src/tests/ios/veilidtools-tests/veilidtools-tests.xcodeproj/project.pbxproj +++ b/veilid-tools/src/tests/ios/veilidtools-tests/veilidtools-tests.xcodeproj/project.pbxproj @@ -167,7 +167,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "../../../../../scripts/ios_build.sh ../../../../ veilid_tools --features veilid_tools_ios_tests,rt-tokio\n"; + shellScript = "../../../../../scripts/ios_build.sh veilid_tools --features veilid_tools_ios_tests,rt-tokio\n"; }; /* End PBXShellScriptBuildPhase section */