Skip to content

Commit

Permalink
TY-2366 build ios prod (#135)
Browse files Browse the repository at this point in the history
Ticket:

- [TY-2366]


**Update:** lto error was addressed in #140 

---

can't use `lto` because of:
rust-lang/rust#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
  • Loading branch information
Robert-Steiner committed Feb 15, 2022
1 parent f55acee commit 1b93724
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 18 additions & 5 deletions .github/workflows/ci_build_ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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 }}
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1b93724

Please sign in to comment.