From dbbe76da441218088a1194da51af46d442adca19 Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Sat, 5 Aug 2023 12:21:55 +0800 Subject: [PATCH] feat: support build arm64 macOS package on CI --- .github/workflows/release.yml | 266 ++++++++++++------ frontend/Makefile.toml | 12 + frontend/appflowy_flutter/macos/Podfile | 37 ++- .../build_universal_package_for_macos.sh | 2 +- frontend/scripts/makefile/flutter.toml | 9 + 5 files changed, 223 insertions(+), 103 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 416bd3fd3e42..fbc4133acf22 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -132,95 +132,95 @@ jobs: asset_name: ${{ env.WINDOWS_INSTALLER_NAME }}.exe asset_content_type: application/octet-stream - build-for-macOS-x86_64: - name: ${{ matrix.job.target }} (${{ matrix.job.os }}) [${{ matrix.job.extra-build-args }}] - runs-on: ${{ matrix.job.os }} - needs: create-release - env: - MACOS_APP_RELEASE_PATH: frontend/appflowy_flutter/product/${{ github.ref_name }}/macos/Release - MACOS_X86_ZIP_NAME: AppFlowy_${{ github.ref_name }}_macos-x86_64.zip - MACOS_DMG_NAME: AppFlowy_${{ github.ref_name }}_macos-x86_64 - strategy: - fail-fast: false - matrix: - job: - - { target: x86_64-apple-darwin, os: macos-11, extra-build-args: "" } - steps: - - name: Checkout source code - uses: actions/checkout@v3 - - - name: Install flutter - uses: subosito/flutter-action@v2 - with: - channel: "stable" - flutter-version: ${{ env.FLUTTER_VERSION }} - cache: true - - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ env.RUST_TOOLCHAIN }} - target: ${{ matrix.job.target }} - override: true - components: rustfmt - profile: minimal - - - uses: Swatinem/rust-cache@v2 - with: - prefix-key: appflowy-lib-cache - key: ${{ matrix.job.os }}-${{ matrix.job.target }} - - - name: Install prerequisites - working-directory: frontend - run: | - cargo install --force cargo-make - cargo install --force duckscript_cli - - - name: Build AppFlowy - working-directory: frontend - run: | - flutter config --enable-macos-desktop - dart ./scripts/flutter_release_build/build_flowy.dart . ${{ github.ref_name }} - - - name: Create macOS dmg - run: | - brew install create-dmg - create-dmg \ - --volname ${{ env.MACOS_DMG_NAME }} \ - --hide-extension "AppFlowy.app" \ - --background frontend/scripts/dmg_assets/AppFlowyInstallerBackground.jpg \ - --window-size 600 450 \ - --icon-size 94 \ - --icon "AppFlowy.app" 141 249 \ - --app-drop-link 458 249 \ - "${{ env.MACOS_APP_RELEASE_PATH }}/${{ env.MACOS_DMG_NAME }}.dmg" \ - "${{ env.MACOS_APP_RELEASE_PATH }}/AppFlowy.app" - - - name: Archive Asset - working-directory: ${{ env.MACOS_APP_RELEASE_PATH }} - run: zip --symlinks -qr ${{ env.MACOS_X86_ZIP_NAME }} AppFlowy.app - - - name: Upload Asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.create-release.outputs.upload_url }} - asset_path: ${{ env.MACOS_APP_RELEASE_PATH }}/${{ env.MACOS_X86_ZIP_NAME }} - asset_name: ${{ env.MACOS_X86_ZIP_NAME }} - asset_content_type: application/octet-stream - - - name: Upload DMG Asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.create-release.outputs.upload_url }} - asset_path: ${{ env.MACOS_APP_RELEASE_PATH }}/${{ env.MACOS_DMG_NAME }}.dmg - asset_name: ${{ env.MACOS_DMG_NAME }}.dmg - asset_content_type: application/octet-stream - - build-for-macOS-aarch64: + # build-for-macOS-x86_64: + # name: ${{ matrix.job.target }} (${{ matrix.job.os }}) [${{ matrix.job.extra-build-args }}] + # runs-on: ${{ matrix.job.os }} + # needs: create-release + # env: + # MACOS_APP_RELEASE_PATH: frontend/appflowy_flutter/product/${{ github.ref_name }}/macos/Release + # MACOS_X86_ZIP_NAME: AppFlowy_${{ github.ref_name }}_macos-x86_64.zip + # MACOS_DMG_NAME: AppFlowy_${{ github.ref_name }}_macos-x86_64 + # strategy: + # fail-fast: false + # matrix: + # job: + # - { target: x86_64-apple-darwin, os: macos-11, extra-build-args: "" } + # steps: + # - name: Checkout source code + # uses: actions/checkout@v3 + + # - name: Install flutter + # uses: subosito/flutter-action@v2 + # with: + # channel: "stable" + # flutter-version: ${{ env.FLUTTER_VERSION }} + # cache: true + + # - name: Install Rust toolchain + # uses: actions-rs/toolchain@v1 + # with: + # toolchain: ${{ env.RUST_TOOLCHAIN }} + # target: ${{ matrix.job.target }} + # override: true + # components: rustfmt + # profile: minimal + + # - uses: Swatinem/rust-cache@v2 + # with: + # prefix-key: appflowy-lib-cache + # key: ${{ matrix.job.os }}-${{ matrix.job.target }} + + # - name: Install prerequisites + # working-directory: frontend + # run: | + # cargo install --force cargo-make + # cargo install --force duckscript_cli + + # - name: Build AppFlowy + # working-directory: frontend + # run: | + # flutter config --enable-macos-desktop + # dart ./scripts/flutter_release_build/build_flowy.dart . ${{ github.ref_name }} + + # - name: Create macOS dmg + # run: | + # brew install create-dmg + # create-dmg \ + # --volname ${{ env.MACOS_DMG_NAME }} \ + # --hide-extension "AppFlowy.app" \ + # --background frontend/scripts/dmg_assets/AppFlowyInstallerBackground.jpg \ + # --window-size 600 450 \ + # --icon-size 94 \ + # --icon "AppFlowy.app" 141 249 \ + # --app-drop-link 458 249 \ + # "${{ env.MACOS_APP_RELEASE_PATH }}/${{ env.MACOS_DMG_NAME }}.dmg" \ + # "${{ env.MACOS_APP_RELEASE_PATH }}/AppFlowy.app" + + # - name: Archive Asset + # working-directory: ${{ env.MACOS_APP_RELEASE_PATH }} + # run: zip --symlinks -qr ${{ env.MACOS_X86_ZIP_NAME }} AppFlowy.app + + # - name: Upload Asset + # uses: actions/upload-release-asset@v1 + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # with: + # upload_url: ${{ needs.create-release.outputs.upload_url }} + # asset_path: ${{ env.MACOS_APP_RELEASE_PATH }}/${{ env.MACOS_X86_ZIP_NAME }} + # asset_name: ${{ env.MACOS_X86_ZIP_NAME }} + # asset_content_type: application/octet-stream + + # - name: Upload DMG Asset + # uses: actions/upload-release-asset@v1 + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # with: + # upload_url: ${{ needs.create-release.outputs.upload_url }} + # asset_path: ${{ env.MACOS_APP_RELEASE_PATH }}/${{ env.MACOS_DMG_NAME }}.dmg + # asset_name: ${{ env.MACOS_DMG_NAME }}.dmg + # asset_content_type: application/octet-stream + + build-for-macOS-arm64: name: ${{ matrix.job.target }} (${{ matrix.job.os }}) [${{ matrix.job.extra-build-args }}] runs-on: ${{ matrix.job.os }} needs: create-release @@ -308,6 +308,92 @@ jobs: asset_name: ${{ env.MACOS_DMG_NAME }}.dmg asset_content_type: application/octet-stream + # build-for-macOS-universal: + # name: ${{ matrix.job.target }} (${{ matrix.job.os }}) [${{ matrix.job.extra-build-args }}] + # runs-on: ${{ matrix.job.os }} + # needs: create-release + # env: + # MACOS_APP_RELEASE_PATH: frontend/appflowy_flutter/product/${{ github.ref_name }}/macos/Release + # MACOS_AARCH64_ZIP_NAME: AppFlowy_${{ github.ref_name }}_macos-universal.zip + # MACOS_DMG_NAME: AppFlowy_${{ github.ref_name }}_macos-universal + # strategy: + # fail-fast: false + # matrix: + # job: + # - { targets: 'aarch64-apple-darwin,x86_64-apple-darwin', os: macos-11, extra-build-args: "" } + # steps: + # - name: Checkout source code + # uses: actions/checkout@v3 + + # - name: Install flutter + # uses: subosito/flutter-action@v2 + # with: + # channel: "stable" + # flutter-version: ${{ env.FLUTTER_VERSION }} + # cache: true + + # - name: Install Rust toolchain + # uses: dtolnay/rust-toolchain@stable + # with: + # toolchain: ${{ env.RUST_TOOLCHAIN }} + # targets: ${{ matrix.job.targets }} + # components: rustfmt + + # - uses: Swatinem/rust-cache@v2 + # with: + # prefix-key: appflowy-lib-cache + # key: ${{ matrix.job.os }}-${{ matrix.job.target }} + + # - name: Install prerequisites + # working-directory: frontend + # run: | + # cargo install --force cargo-make + # cargo install --force duckscript_cli + + # - name: Build AppFlowy + # working-directory: frontend + # run: | + # flutter config --enable-macos-desktop + # sh scripts/flutter_release_build/build_universal_package_for_macos.sh + + # - name: Create macOS dmg + # run: | + # brew install create-dmg + # create-dmg \ + # --volname ${{ env.MACOS_DMG_NAME }} \ + # --hide-extension "AppFlowy.app" \ + # --background frontend/scripts/dmg_assets/AppFlowyInstallerBackground.jpg \ + # --window-size 600 450 \ + # --icon-size 94 \ + # --icon "AppFlowy.app" 141 249 \ + # --app-drop-link 458 249 \ + # "${{ env.MACOS_APP_RELEASE_PATH }}/${{ env.MACOS_DMG_NAME }}.dmg" \ + # "${{ env.MACOS_APP_RELEASE_PATH }}/AppFlowy.app" + + # - name: Archive Asset + # working-directory: ${{ env.MACOS_APP_RELEASE_PATH }} + # run: zip --symlinks -qr ${{ env.MACOS_AARCH64_ZIP_NAME }} AppFlowy.app + + # - name: Upload Asset + # uses: actions/upload-release-asset@v1 + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # with: + # upload_url: ${{ needs.create-release.outputs.upload_url }} + # asset_path: ${{ env.MACOS_APP_RELEASE_PATH }}/${{ env.MACOS_AARCH64_ZIP_NAME }} + # asset_name: ${{ env.MACOS_AARCH64_ZIP_NAME }} + # asset_content_type: application/octet-stream + + # - name: Upload DMG Asset + # uses: actions/upload-release-asset@v1 + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # with: + # upload_url: ${{ needs.create-release.outputs.upload_url }} + # asset_path: ${{ env.MACOS_APP_RELEASE_PATH }}/${{ env.MACOS_DMG_NAME }}.dmg + # asset_name: ${{ env.MACOS_DMG_NAME }}.dmg + # asset_content_type: application/octet-stream + build-for-linux: name: ${{ matrix.job.target }} (${{ matrix.job.os }}) [${{ matrix.job.extra-build-args }}] runs-on: ${{ matrix.job.os }} @@ -456,7 +542,7 @@ jobs: notify-discord: runs-on: ubuntu-latest - needs: [build-for-linux, build-for-windows, build-for-macOS-x86_64, build-for-macOS-aarch64] + needs: [build-for-linux, build-for-windows, build-for-macOS-arm64] steps: - name: Notify Discord run: | diff --git a/frontend/Makefile.toml b/frontend/Makefile.toml index ed8e90af0416..e9d49ebaddf7 100644 --- a/frontend/Makefile.toml +++ b/frontend/Makefile.toml @@ -60,6 +60,7 @@ BUILD_FLAG = "debug" FLUTTER_OUTPUT_DIR = "Debug" PRODUCT_EXT = "app" BUILD_ARCHS = "arm64" +BUILD_ACTIVE_ARCHS_ONLY = true CRATE_TYPE = "staticlib" [env.development-mac-x86_64] @@ -70,6 +71,7 @@ BUILD_FLAG = "debug" FLUTTER_OUTPUT_DIR = "Debug" PRODUCT_EXT = "app" BUILD_ARCHS = "x86_64" +BUILD_ACTIVE_ARCHS_ONLY = true CRATE_TYPE = "staticlib" [env.production-mac-arm64] @@ -80,6 +82,7 @@ FLUTTER_OUTPUT_DIR = "Release" PRODUCT_EXT = "app" APP_ENVIRONMENT = "production" BUILD_ARCHS = "arm64" +BUILD_ACTIVE_ARCHS_ONLY = false CRATE_TYPE = "staticlib" [env.production-mac-x86_64] @@ -90,8 +93,17 @@ FLUTTER_OUTPUT_DIR = "Release" PRODUCT_EXT = "app" APP_ENVIRONMENT = "production" BUILD_ARCHS = "x86_64" +BUILD_ACTIVE_ARCHS_ONLY = false CRATE_TYPE = "staticlib" +[env.production-mac-universal] +BUILD_FLAG = "release" +TARGET_OS = "macos" +FLUTTER_OUTPUT_DIR = "Release" +PRODUCT_EXT = "app" +BUILD_ACTIVE_ARCHS_ONLY = false +APP_ENVIRONMENT = "production" + [env.development-windows-x86] TARGET_OS = "windows" RUST_COMPILE_TARGET = "x86_64-pc-windows-msvc" diff --git a/frontend/appflowy_flutter/macos/Podfile b/frontend/appflowy_flutter/macos/Podfile index 715baa2d3856..e22f3fddd7a1 100644 --- a/frontend/appflowy_flutter/macos/Podfile +++ b/frontend/appflowy_flutter/macos/Podfile @@ -27,18 +27,31 @@ require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelpe flutter_macos_podfile_setup def build_specify_archs_only - # if ENV.has_key?('BUILD_ARCHS') - # xcodeproj_path = File.dirname(__FILE__) + '/Runner.xcodeproj' - # project = Xcodeproj::Project.open(xcodeproj_path) - # project.targets.each do |target| - # if target.name == 'Runner' - # target.build_configurations.each do |config| - # config.build_settings['ARCHS'] = ENV['BUILD_ARCHS'] - # end - # end - # end - # project.save() - # end + if ENV.has_key?('BUILD_ACTIVE_ARCHS_ONLY') + xcodeproj_path = File.dirname(__FILE__) + '/Runner.xcodeproj' + project = Xcodeproj::Project.open(xcodeproj_path) + project.targets.each do |target| + if target.name == 'Runner' + target.build_configurations.each do |config| + config.build_settings['ONLY_ACTIVE_ARCH'] = ENV['BUILD_ACTIVE_ARCHS_ONLY'] + end + end + end + project.save() + end + + if ENV.has_key?('BUILD_ARCHS') + xcodeproj_path = File.dirname(__FILE__) + '/Runner.xcodeproj' + project = Xcodeproj::Project.open(xcodeproj_path) + project.targets.each do |target| + if target.name == 'Runner' + target.build_configurations.each do |config| + config.build_settings['ARCHS'] = ENV['BUILD_ARCHS'] + end + end + end + project.save() + end end build_specify_archs_only() diff --git a/frontend/scripts/flutter_release_build/build_universal_package_for_macos.sh b/frontend/scripts/flutter_release_build/build_universal_package_for_macos.sh index fe073a1fe743..a5c90dc1945b 100644 --- a/frontend/scripts/flutter_release_build/build_universal_package_for_macos.sh +++ b/frontend/scripts/flutter_release_build/build_universal_package_for_macos.sh @@ -24,4 +24,4 @@ cp -rf rust-lib/target/libdart_ffi.a \ echo '🚀 ---------------------------------------------------' echo '🚀 building the flutter application for macOS' -flutter build macos --release +cargo make --profile production-mac-universal appflowy-macos-unviersal diff --git a/frontend/scripts/makefile/flutter.toml b/frontend/scripts/makefile/flutter.toml index 9d56b0e564c0..379b29763d0a 100644 --- a/frontend/scripts/makefile/flutter.toml +++ b/frontend/scripts/makefile/flutter.toml @@ -13,6 +13,15 @@ run_task = { name = [ ] } script_runner = "@shell" +[tasks.appflowy-macos-unviersal] +run_task = { name = [ + "code_generation", + "set-app-version", + "flutter-build", + "copy-to-product", +] } +script_runner = "@shell" + [tasks.appflowy-windows] dependencies = ["appflowy-core-release"] run_task = { name = [