unify ios mac build

This commit is contained in:
John Smith
2022-12-01 20:38:57 -05:00
parent 46504e44b8
commit ef313133cf
9 changed files with 78 additions and 126 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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]

View File

@@ -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

View File

@@ -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