From 04dd86b2d0f91b3f2ccd4874c820720c72a33a96 Mon Sep 17 00:00:00 2001 From: Bug Magnet Date: Tue, 12 Mar 2024 11:42:47 +0100 Subject: [PATCH 1/2] Enable building features in crates on iOS --- ios/build-rust-library.sh | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/ios/build-rust-library.sh b/ios/build-rust-library.sh index e5aed2069170..b8b8ee05a838 100644 --- a/ios/build-rust-library.sh +++ b/ios/build-rust-library.sh @@ -2,16 +2,24 @@ set -euvx -if [ "$#" -ne 1 ] +if [ "$#" -gt 2 ] then echo "Usage (note: only call inside xcode!):" - echo "build-rust-library.sh " + echo "build-rust-library.sh [FFI_FEATURES]" exit 1 fi # what to pass to cargo build -p, e.g. your_lib_ffi FFI_TARGET=$1 +# Enable cargo features by passing feature names to this script, i.e. build-rust-library.sh mullvad-api api-override +FEATURE_FLAGS= +if [[ "$#" -eq 2 ]] ; then +FEATURE_FLAGS=$2 +echo ${FEATURE_FLAGS:+--features "$FEATURE_FLAGS"} +fi + + RELFLAG= if [[ "$CONFIGURATION" == "Release" ]]; then RELFLAG=--release @@ -43,18 +51,18 @@ for arch in $ARCHS; do # Intel iOS simulator export CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios" - "$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib $RELFLAG --target x86_64-apple-ios - "$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib --target x86_64-apple-ios + "$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib $RELFLAG --target x86_64-apple-ios ${FEATURE_FLAGS:+--features "$FEATURE_FLAGS"} + "$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib --target x86_64-apple-ios ${FEATURE_FLAGS:+--features "$FEATURE_FLAGS"} ;; arm64) if [ $IS_SIMULATOR -eq 0 ]; then # Hardware iOS targets - "$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib $RELFLAG --target aarch64-apple-ios - "$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib --target aarch64-apple-ios + "$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib $RELFLAG --target aarch64-apple-ios ${FEATURE_FLAGS:+--features "$FEATURE_FLAGS"} + "$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib --target aarch64-apple-ios ${FEATURE_FLAGS:+--features "$FEATURE_FLAGS"} else - "$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib $RELFLAG --target aarch64-apple-ios-sim - "$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib --target aarch64-apple-ios-sim + "$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib $RELFLAG --target aarch64-apple-ios-sim ${FEATURE_FLAGS:+--features "$FEATURE_FLAGS"} + "$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib --target aarch64-apple-ios-sim ${FEATURE_FLAGS:+--features "$FEATURE_FLAGS"} fi esac done From 4d7e5efc235512d07537ea7b17d77d8a7eb0451c Mon Sep 17 00:00:00 2001 From: Bug Magnet Date: Tue, 12 Mar 2024 13:57:16 +0100 Subject: [PATCH 2/2] PR feedback --- ios/build-rust-library.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ios/build-rust-library.sh b/ios/build-rust-library.sh index b8b8ee05a838..5de58559b07c 100644 --- a/ios/build-rust-library.sh +++ b/ios/build-rust-library.sh @@ -2,7 +2,7 @@ set -euvx -if [ "$#" -gt 2 ] +if [ "$#" -gt 2 ] || [ "$#" -eq 0 ] then echo "Usage (note: only call inside xcode!):" echo "build-rust-library.sh [FFI_FEATURES]" @@ -13,6 +13,8 @@ fi FFI_TARGET=$1 # Enable cargo features by passing feature names to this script, i.e. build-rust-library.sh mullvad-api api-override +# If more than one feature flag needs to be enabled, pass in a single argument all the features flags separated by spaces +# build-rust-library.sh mullvad-api "featureA featureB featureC" FEATURE_FLAGS= if [[ "$#" -eq 2 ]] ; then FEATURE_FLAGS=$2