Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
TY-1786 build dart example (#71)
Browse files Browse the repository at this point in the history
add build dart example 

Co-authored-by: janpetschexain <58227040+janpetschexain@users.noreply.github.com>
  • Loading branch information
Robert-Steiner and janpetschexain authored May 20, 2021
1 parent 8e6995a commit bb23d87
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 45 deletions.
175 changes: 147 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:
# takes a considerable amount of time if it is compiled with the default opt-level
# for tests. Therefore, we compile them with a higher opt-level to run them faster.
OPT_TESTS_RUSTFLAGS: '-C opt-level=3 -C debug-assertions=yes -D warnings'
FLUTTER_VERSION: '2.0.0'
FLUTTER_VERSION: '2.0.6'
JAVA_VERSION: '12.x'
DART_WORKSPACE: ${{ github.workspace }}/bindings/dart
CARGO_INCREMENTAL: 0
Expand Down Expand Up @@ -180,6 +180,8 @@ jobs:
needs: [registry-cache, check]
runs-on: ubuntu-20.04
timeout-minutes: 20
outputs:
cache-key: ${{ steps.cache-key.outputs.key }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -201,11 +203,16 @@ jobs:
~/.cargo/git
key: ${{ needs.registry-cache.outputs.cache-key }}

- name: Generate build artifacts key
id: cache-key
shell: bash
run: echo "::set-output name=key::$(echo "${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.rustc }}-tests-${{ needs.registry-cache.outputs.cache-date }}-${{ hashFiles('**/Cargo.lock') }}")"

- name: Cache build artifacts
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/target
key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.rustc }}-tests-${{ needs.registry-cache.outputs.cache-date }}-${{ hashFiles('**/Cargo.lock') }}
key: ${{ steps.cache-key.outputs.key }}
restore-keys: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.rustc }}-tests-${{ needs.registry-cache.outputs.cache-date }}-

- name: Download data
Expand Down Expand Up @@ -387,6 +394,19 @@ jobs:
working-directory: ./xayn-ai-ffi-c
run: cargo lipo --targets ${{ matrix.target }}

- name: Prepare lib for upload
run: |
dir=target/${{ matrix.target }}/debug
mv $dir/libxayn_ai_ffi_c.a $dir/libxayn_ai_ffi_c_${{ matrix.target }}.a
- name: Upload library artifacts
uses: actions/upload-artifact@v2
with:
name: build-ios-${{ matrix.target }}-${{ github.sha }}
retention-days: 1
if-no-files-found: error
path: target/${{ matrix.target}}/debug/libxayn_ai_ffi_c_${{ matrix.target }}.a

test-wasm-lib:
name: test-wasm-lib
needs: [registry-cache, test]
Expand Down Expand Up @@ -431,8 +451,8 @@ jobs:
RUSTFLAGS: ${{ env.OPT_TESTS_RUSTFLAGS }}
run: wasm-pack test --firefox --chrome --headless

build-xain-ai-lib:
name: build-xain-ai-lib
build-linux-lib:
name: build-linux-lib
needs: [registry-cache, test]
runs-on: ubuntu-20.04
outputs:
Expand All @@ -459,28 +479,35 @@ jobs:
~/.cargo/git
key: ${{ needs.registry-cache.outputs.cache-key }}

- name: Cache build artifacts
uses: actions/cache@v2
- name: Restore build artifacts
uses: actions/cache@v2.1.4
with:
path: ${{ github.workspace }}/target
key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.rustc }}-build-xain-ai-lib-${{ needs.registry-cache.outputs.cache-date }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.rustc }}-build-xain-ai-lib-${{ needs.registry-cache.outputs.cache-date }}-
key: ${{ needs.test.outputs.cache-key }}

- name: Build xayn-ai-ffi-c lib
- name: Build linux lib
# We have to use the same RUSTFLAGS that are used in the test
# job in order to be able to reuse the cache. If we do not do this,
# the compiler will recompile all the libraries from scratch.
env:
RUSTFLAGS: "-D warnings"
run: cargo build

- name: Generate lib cache key
- name: Generate lib artifacts key
id: cache-key
shell: bash
run: echo "::set-output name=key::$(echo libxayn_ai_ffi_c-${{ hashFiles('target/debug/libxayn_ai_ffi_c.so', 'xayn-ai-ffi-c/ffi.h') }})"
run: echo "::set-output name=key::$(echo build-x86_64-unknown-linux-gnu-${{ hashFiles('target/debug/libxayn_ai_ffi_c.so', 'xayn-ai-ffi-c/ffi.h') }})"

- name: Cache library artifacts
uses: actions/cache@v2
- name: Upload library artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ steps.cache-key.outputs.key }}
retention-days: 1
if-no-files-found: error
path: |
${{ github.workspace }}/target/debug/libxayn_ai_ffi_c.so
${{ github.workspace }}/xayn-ai-ffi-c/ffi.h
key: ${{ steps.cache-key.outputs.key }}
${{ env.DART_WORKSPACE }}/ios/Classes/XaynAiFfiDartPlugin.h
flutter-format:
name: flutter-format
Expand Down Expand Up @@ -514,7 +541,7 @@ jobs:

flutter-analyze:
name: flutter-analyze
needs: build-xain-ai-lib
needs: build-linux-lib
runs-on: ubuntu-20.04
timeout-minutes: 10
steps:
Expand All @@ -541,13 +568,17 @@ jobs:
with:
flutter-version: ${{ env.FLUTTER_VERSION }}

- name: Restore ${{ needs.build-xain-ai-lib.outputs.cache-key }} cache
uses: actions/cache@v2.1.4
- name: Download ${{ needs.build-linux-lib.outputs.cache-key }} artifacts
uses: actions/download-artifact@v2
with:
path: |
${{ github.workspace }}/target/debug/libxayn_ai_ffi_c.so
${{ github.workspace }}/xayn-ai-ffi-c/ffi.h
key: ${{ needs.build-xain-ai-lib.outputs.cache-key }}
name: ${{ needs.build-linux-lib.outputs.cache-key }}
path: ${{ runner.temp }}/${{ needs.build-linux-lib.outputs.cache-key }}

- name: Move C-header and linux lib
working-directory: ${{ runner.temp }}/${{ needs.build-linux-lib.outputs.cache-key }}
run: |
mv xayn-ai-ffi-c/ffi.h ${{ github.workspace }}/xayn-ai-ffi-c/ffi.h
cp -R target ${{ github.workspace }}
- name: Download data
run: sh download_data.sh
Expand All @@ -566,7 +597,7 @@ jobs:

flutter-test:
name: flutter-test
needs: build-xain-ai-lib
needs: build-linux-lib
runs-on: ubuntu-20.04
timeout-minutes: 10
steps:
Expand All @@ -592,13 +623,17 @@ jobs:
with:
flutter-version: ${{ env.FLUTTER_VERSION }}

- name: Restore ${{ needs.build-xain-ai-lib.outputs.cache-key }} cache
uses: actions/cache@v2.1.4
- name: Download ${{ needs.build-linux-lib.outputs.cache-key }} artifacts
uses: actions/download-artifact@v2
with:
path: |
${{ github.workspace }}/target/debug/libxayn_ai_ffi_c.so
${{ github.workspace }}/xayn-ai-ffi-c/ffi.h
key: ${{ needs.build-xain-ai-lib.outputs.cache-key }}
name: ${{ needs.build-linux-lib.outputs.cache-key }}
path: ${{ runner.temp }}/${{ needs.build-linux-lib.outputs.cache-key }}

- name: Move C-header and linux lib
working-directory: ${{ runner.temp }}/${{ needs.build-linux-lib.outputs.cache-key }}
run: |
mv xayn-ai-ffi-c/ffi.h ${{ github.workspace }}/xayn-ai-ffi-c/ffi.h
cp -R target ${{ github.workspace }}
- name: Install flutter dependencies
working-directory: ${{ env.DART_WORKSPACE }}
Expand All @@ -614,3 +649,87 @@ jobs:
- name: Run flutter tests
working-directory: ${{ env.DART_WORKSPACE }}
run: flutter test

flutter-build-example:
name: flutter-build-example
needs: [build-linux-lib, build-ios-libs]
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, macos-10.15]
include:
- os: ubuntu-20.04
cmd: flutter build apk --debug --split-per-abi
- os: macos-10.15
cmd: flutter build ios --debug --no-codesign
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup java ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v1
with:
java-version: ${{ env.JAVA_VERSION }}

- name: Install libclang-10-dev
if: matrix.os == 'ubuntu-20.04'
run: sudo apt-get install libclang-10-dev

- name: Download ${{ needs.build-linux-lib.outputs.cache-key }} artifacts
uses: actions/download-artifact@v2
with:
name: ${{ needs.build-linux-lib.outputs.cache-key }}
path: ${{ runner.temp }}/${{ needs.build-linux-lib.outputs.cache-key }}

- name: Move C-header
working-directory: ${{ runner.temp }}/${{ needs.build-linux-lib.outputs.cache-key }}
run: mv xayn-ai-ffi-c/ffi.h ${{ github.workspace }}/xayn-ai-ffi-c/ffi.h

- name: Download iOS aarch64 artifacts
if: matrix.os == 'macos-10.15'
uses: actions/download-artifact@v2
with:
name: build-ios-aarch64-apple-ios-${{ github.sha }}
path: ${{ runner.temp }}/build-ios-${{ github.sha }}

- name: Download iOS x84_64 artifacts
if: matrix.os == 'macos-10.15'
uses: actions/download-artifact@v2
with:
name: build-ios-x86_64-apple-ios-${{ github.sha }}
path: ${{ runner.temp }}/build-ios-${{ github.sha }}

- name: Move iOS artifacts
if: matrix.os == 'macos-10.15'
run: |
cd ${{ runner.temp }}/${{ needs.build-linux-lib.outputs.cache-key }}
cp bindings/dart/ios/Classes/XaynAiFfiDartPlugin.h ${{ env.DART_WORKSPACE }}/ios/Classes/
cd ${{ runner.temp }}/build-ios-${{ github.sha }}
find . -iname '*.a' -exec cp \{\} ${{ env.DART_WORKSPACE }}/ios \;
- name: Set path or install flutter
uses: subosito/flutter-action@v1
with:
flutter-version: ${{ env.FLUTTER_VERSION }}

- name: Install flutter dependencies
working-directory: ${{ env.DART_WORKSPACE }}
run: flutter pub get

- name: Generate flutter ffi
working-directory: ${{ env.DART_WORKSPACE }}
run: flutter pub run ffigen

- name: Download data
run: sh download_data.sh

- name: Build flutter example
working-directory: ${{ env.DART_WORKSPACE }}/example
run: ${{ matrix.cmd }}

- name: Build archive
if: matrix.os == 'macos-10.15'
working-directory: ${{ env.DART_WORKSPACE }}/example
run: xcodebuild -workspace ios/Runner.xcworkspace -scheme Runner archive -configuration release -archivePath build/Runner.xcarchive CODE_SIGNING_ALLOWED="NO"
2 changes: 1 addition & 1 deletion bindings/dart/example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>8.0</string>
<string>12.1</string>
</dict>
</plist>
6 changes: 5 additions & 1 deletion bindings/dart/example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
platform :ios, '12.1'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down Expand Up @@ -37,5 +37,9 @@ end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
config.build_settings["EXCLUDED_ARCHS"] = "armv7"
end
end
end
28 changes: 28 additions & 0 deletions bindings/dart/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
PODS:
- Flutter (1.0.0)
- path_provider (0.0.1):
- Flutter
- xayn_ai_ffi_dart (0.0.1):
- Flutter

DEPENDENCIES:
- Flutter (from `Flutter`)
- path_provider (from `.symlinks/plugins/path_provider/ios`)
- xayn_ai_ffi_dart (from `.symlinks/plugins/xayn_ai_ffi_dart/ios`)

EXTERNAL SOURCES:
Flutter:
:path: Flutter
path_provider:
:path: ".symlinks/plugins/path_provider/ios"
xayn_ai_ffi_dart:
:path: ".symlinks/plugins/xayn_ai_ffi_dart/ios"

SPEC CHECKSUMS:
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c
xayn_ai_ffi_dart: 286b391bc1afb0c5b9c3d3e15cf1a54df623ffda

PODFILE CHECKSUM: 8462e319511eccc6fb15d8c90ec86661a5952ac8

COCOAPODS: 1.10.1
Loading

0 comments on commit bb23d87

Please sign in to comment.