From 1b93724b06b2f258e368593e5059045e9cbe20d4 Mon Sep 17 00:00:00 2001 From: Robert Steiner Date: Tue, 15 Feb 2022 14:38:33 +0000 Subject: [PATCH] TY-2366 build ios prod (#135) Ticket: - [TY-2366] **Update:** lto error was addressed in #140 --- can't use `lto` because of: https://github.com/rust-lang/rust/issues/51009 running: `RUSTFLAGS="-Ccodegen-units=1 -Clto=on -Cembed-bitcode=yes" just compile-ios-local` gives the error: ``` error: lto can only be run for executables, cdylibs and static library outputs error: could not compile `hyper` due to previous error ``` but `-Ccodegen-units=1` alone still decreases the size from 221mb to 144mb [TY-2366]: https://xainag.atlassian.net/browse/TY-2366?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --- .env | 2 ++ .github/workflows/ci_build_ios.yml | 23 ++++++++++++++++++----- .github/workflows/release.yml | 5 +++++ justfile | 18 ++++++++++++++---- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/.env b/.env index b6d4d2378..eac2db30b 100644 --- a/.env +++ b/.env @@ -14,6 +14,8 @@ ANDROID_PLATFORM_VERSION="21" IOS_TARGETS="aarch64-apple-ios x86_64-apple-ios" IOS_LIB_BASE="libxayn_discovery_engine_bindings" +PRODUCTION_RUSTFLAGS="-Ccodegen-units=1 -Clto=on -Cembed-bitcode=yes" + JUST_VERSION=0.10.5 # In the cases we want to use nightly we use the following version RUST_NIGHTLY=nightly-2021-09-09 diff --git a/.github/workflows/ci_build_ios.yml b/.github/workflows/ci_build_ios.yml index a236b2bcd..65ee4bae4 100644 --- a/.github/workflows/ci_build_ios.yml +++ b/.github/workflows/ci_build_ios.yml @@ -2,6 +2,12 @@ name: Build iOS library on: workflow_call: + inputs: + production: + description: Builds iOS libraries for production release (with additional optimizations) + default: false + required: false + type: boolean outputs: artifact-dir-base: description: The base name of artifact directory (without the target suffix) @@ -14,10 +20,8 @@ jobs: strategy: matrix: target: ["aarch64-apple-ios", "x86_64-apple-ios"] - env: - ARTIFACT_DIR_BASE: ${{ github.job }} outputs: - artifact-dir-base: ${{ env.ARTIFACT_DIR_BASE }} + artifact-dir-base: ${{ steps.build.outputs.artifact-dir-base }} steps: - uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0 @@ -29,7 +33,16 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} - name: Build iOS library ${{ matrix.target }} - run: just compile-ios ${{ matrix.target }} + id: build + run: | + ARTIFACT_DIR_BASE=${{ github.job }} + if ${{ inputs.production }}; then + just compile-ios-ci ${{ matrix.target }} --prod + ARTIFACT_DIR_BASE+="production" + else + just compile-ios-ci ${{ matrix.target }} + fi + echo "::set-output name=artifact-dir-base::$ARTIFACT_DIR_BASE" - name: Prepare lib for upload id: lib @@ -43,7 +56,7 @@ jobs: - name: Upload library artifacts uses: actions/upload-artifact@82c141cc518b40d92cc801eee768e7aafc9c2fa2 # v2.3.1 with: - name: ${{ env.ARTIFACT_DIR_BASE }}-${{ matrix.target }}-${{ github.sha }} + name: ${{ steps.build.outputs.artifact-dir-base }}-${{ matrix.target }}-${{ github.sha }} retention-days: 1 if-no-files-found: error path: ${{ steps.lib.outputs.path }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ece1878b1..43630c7d8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,6 +10,11 @@ permissions: contents: read jobs: + build-ios-libs: + uses: ./.github/workflows/ci_build_ios.yml + with: + production: true + release: runs-on: ubuntu-20.04 timeout-minutes: 10 diff --git a/justfile b/justfile index 0fc03cfd8..0b8bda4d8 100644 --- a/justfile +++ b/justfile @@ -232,20 +232,30 @@ compile-android-local: done # Compiles the bindings for the given iOS target -compile-ios target: _codegen-order-workaround +_compile-ios target: cd "$RUST_WORKSPACE"; \ - cargo build --target {{target}} -p xayn-discovery-engine-bindings --release + cargo build --target {{target}} -p xayn-discovery-engine-bindings --release --locked # Compiles the bindings for iphoneos (aarch64) and iphonesimulator (x86_64) # and copies the binaries to the flutter project -compile-ios-local: +compile-ios-local: _codegen-order-workaround #!/usr/bin/env sh set -eu for TARGET in $IOS_TARGETS; do - {{just_executable()}} compile-ios $TARGET + {{just_executable()}} _compile-ios $TARGET cp "$RUST_WORKSPACE/target/$TARGET/release/${IOS_LIB_BASE}.a" "$FLUTTER_WORKSPACE/ios/${IOS_LIB_BASE}_${TARGET}.a" done +compile-ios-ci target prod_flag="\"\"": _codegen-order-workaround + #!/usr/bin/env sh + set -eu + if [[ {{prod_flag}} == "--prod" ]]; then + RUSTFLAGS=$PRODUCTION_RUSTFLAGS {{just_executable()}} _compile-ios {{target}} + strip -S -x -r "$RUST_WORKSPACE/target/{{target}}/release/${IOS_LIB_BASE}.a" + else + {{just_executable()}} _compile-ios {{target}} + fi + alias d := dart-test alias r := rust-test alias t := test