Skip to content

Commit

Permalink
feat: support build arm64 macOS package on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Aug 5, 2023
1 parent 4b35a23 commit dbbe76d
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 103 deletions.
266 changes: 176 additions & 90 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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: |
Expand Down
12 changes: 12 additions & 0 deletions frontend/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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"
Expand Down
37 changes: 25 additions & 12 deletions frontend/appflowy_flutter/macos/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions frontend/scripts/makefile/flutter.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit dbbe76d

Please sign in to comment.