Skip to content

Commit

Permalink
Enable cross build for mac
Browse files Browse the repository at this point in the history
  • Loading branch information
yukawa committed Sep 3, 2023
1 parent 2be1ada commit b0c3510
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 7 deletions.
112 changes: 108 additions & 4 deletions .github/workflows/macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:
cancel-in-progress: true

jobs:
build:
build_arm64:
# https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md
runs-on: macos-11
timeout-minutes: 90
Expand Down Expand Up @@ -49,18 +49,122 @@ jobs:
- name: Build Qt
working-directory: ./src
run: |
python3 build_tools/build_qt.py --release --confirm_license
python3 build_tools/build_qt.py --release --confirm_license --macos_cpus=arm64
echo "MOZC_QT_PATH=${PWD}/third_party/qt" >> $GITHUB_ENV
- name: bazel build
working-directory: ./src
run: |
bazel build --config oss_macos package --macos_cpus=arm64
- name: upload artifacts
uses: actions/upload-artifact@v3
with:
name: Mozc.pkg(arm64)
path: src/bazel-bin/mac/Mozc.pkg
if-no-files-found: warn

build_intel64:
# https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md
runs-on: macos-11
timeout-minutes: 90

steps:
- name: checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Set up Python
uses: actions/setup-python@v4
with:
cache: 'pip'
python-version: '3.9'

- name: Install pip dependencies
working-directory: ./src
run: |
python3 -m pip install requests
- name: Try to restore update_deps cache
uses: actions/cache@v3
with:
path: src/third_party_cache
key: update_deps-${{ runner.os }}-${{ hashFiles('src/build_tools/update_deps.py') }}

- name: Install dependencies
working-directory: ./src
# This command uses src/third_party_cache as the download cache.
run: |
python3 build_tools/update_deps.py
- name: Build Qt
working-directory: ./src
run: |
python3 build_tools/build_qt.py --release --confirm_license --macos_cpus=x86_64
echo "MOZC_QT_PATH=${PWD}/third_party/qt" >> $GITHUB_ENV
- name: bazel build
working-directory: ./src
run: |
bazel build --config oss_macos package --macos_cpus=x86_64
- name: upload artifacts
uses: actions/upload-artifact@v3
with:
name: Mozc.pkg(intel64)
path: src/bazel-bin/mac/Mozc.pkg
if-no-files-found: warn

build_fat_binary:
# https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md
runs-on: macos-11
timeout-minutes: 90

steps:
- name: checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Set up Python
uses: actions/setup-python@v4
with:
cache: 'pip'
python-version: '3.9'

- name: Install pip dependencies
working-directory: ./src
run: |
python3 -m pip install requests
- name: Try to restore update_deps cache
uses: actions/cache@v3
with:
path: src/third_party_cache
key: update_deps-${{ runner.os }}-${{ hashFiles('src/build_tools/update_deps.py') }}

- name: Install dependencies
working-directory: ./src
# This command uses src/third_party_cache as the download cache.
run: |
python3 build_tools/update_deps.py
- name: Build Qt
working-directory: ./src
run: |
python3 build_tools/build_qt.py --release --confirm_license --macos_cpus=x86_64,arm64
echo "MOZC_QT_PATH=${PWD}/third_party/qt" >> $GITHUB_ENV
- name: bazel build
working-directory: ./src
run: |
bazel build --config oss_macos package
bazel build --config oss_macos package --macos_cpus=x86_64,arm64
- name: upload artifacts
uses: actions/upload-artifact@v3
with:
name: Mozc.pkg
name: Mozc.pkg(fat_binary)
path: src/bazel-bin/mac/Mozc.pkg
if-no-files-found: warn

Expand Down
23 changes: 20 additions & 3 deletions docs/build_mozc_in_osx.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ MOZC_QT_PATH=${PWD}/third_party/qt bazel build package --config oss_macos -c opt
open bazel-bin/mac/Mozc.pkg
```

Hint: With the above build steps, the target CPU architecture of the binaries in
💡 With the above build steps, the target CPU architecture of the binaries in
`Mozc.pkg` is the same as the CPU architecture of the build environment.
That is, if you build Mozc on arm64 environment, `Mozc.pkg` contains arm64
binaries.
binaries. See the [build installer](#build-installer) section about how to do
cross build.

Hint: You can also download `Mozc.pkg` from GitHub Actions. Check [Build with GitHub Actions](#build-with-github-actions) for details.
💡 You can also download `Mozc.pkg` from GitHub Actions. Check [Build with GitHub Actions](#build-with-github-actions) for details.

## Setup

Expand Down Expand Up @@ -110,6 +111,22 @@ MOZC_QT_PATH=${PWD}/third_party/qt bazel build package --config oss_macos -c opt
open bazel-bin/mac/Mozc.pkg
```

#### How to specify target CPU architectures

To build arm64 binaries regardless of the host CPU architectue.
```
python3 build_tools/build_qt.py --release --debug --confirm_license --macos_cpus=arm64
MOZC_QT_PATH=${PWD}/third_party/qt bazel build package --config oss_macos -c opt --macos_cpus=arm64
open bazel-bin/mac/Mozc.pkg
```

To build fat binaries for both arm64 and x86_64.
```
python3 build_tools/build_qt.py --release --debug --confirm_license --macos_cpus=x86_64,arm64
MOZC_QT_PATH=${PWD}/third_party/qt bazel build package --config oss_macos -c opt --macos_cpus=x86_64,arm64
open bazel-bin/mac/Mozc.pkg
```

### Unit tests

```
Expand Down

0 comments on commit b0c3510

Please sign in to comment.