Skip to content

Commit

Permalink
Fix #910: Use python venv for macOS build
Browse files Browse the repository at this point in the history
With this commit macOS build starts using Python virtual environment so
that our build steps can comply with PEP 668 [1].

This is only about the build procedure. There must be no behavior change
in the build artifacts.

#codehealth

 [1]: https://peps.python.org/pep-0668/

PiperOrigin-RevId: 621123606
  • Loading branch information
yukawa authored and hiroyuki-komatsu committed Apr 2, 2024
1 parent 9c5fc40 commit e8d25a2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
37 changes: 27 additions & 10 deletions .github/workflows/macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

env:
PYTHON_VENV_ROOT: ${{ github.workspace }}/src/python-venv

jobs:
build_arm64:
# https://github.com/actions/virtual-environments/blob/main/images/macos/macos-14-Readme.md
Expand All @@ -23,9 +26,10 @@ jobs:
with:
submodules: 'recursive'

- name: Install pip dependencies
working-directory: ./src
- name: Setup Python
run: |
python3 -m venv ${PYTHON_VENV_ROOT}
source ${PYTHON_VENV_ROOT}/bin/activate
python3 -m pip install requests
- name: Try to restore update_deps cache
Expand All @@ -38,11 +42,13 @@ jobs:
working-directory: ./src
# This command uses src/third_party_cache as the download cache.
run: |
source ${PYTHON_VENV_ROOT}/bin/activate
python3 build_tools/update_deps.py
- name: Build Qt
working-directory: ./src
run: |
source ${PYTHON_VENV_ROOT}/bin/activate
python3 build_tools/build_qt.py --release --confirm_license --macos_cpus=arm64
echo "MOZC_QT_PATH=${PWD}/third_party/qt" >> $GITHUB_ENV
Expand All @@ -69,9 +75,10 @@ jobs:
with:
submodules: 'recursive'

- name: Install pip dependencies
working-directory: ./src
- name: Setup Python
run: |
python3 -m venv ${PYTHON_VENV_ROOT}
source ${PYTHON_VENV_ROOT}/bin/activate
python3 -m pip install requests
- name: Try to restore update_deps cache
Expand All @@ -84,11 +91,13 @@ jobs:
working-directory: ./src
# This command uses src/third_party_cache as the download cache.
run: |
source ${PYTHON_VENV_ROOT}/bin/activate
python3 build_tools/update_deps.py
- name: Build Qt
working-directory: ./src
run: |
source ${PYTHON_VENV_ROOT}/bin/activate
python3 build_tools/build_qt.py --release --confirm_license --macos_cpus=x86_64
echo "MOZC_QT_PATH=${PWD}/third_party/qt" >> $GITHUB_ENV
Expand All @@ -115,9 +124,10 @@ jobs:
with:
submodules: 'recursive'

- name: Install pip dependencies
working-directory: ./src
- name: Setup Python
run: |
python3 -m venv ${PYTHON_VENV_ROOT}
source ${PYTHON_VENV_ROOT}/bin/activate
python3 -m pip install requests
- name: Try to restore update_deps cache
Expand All @@ -130,11 +140,13 @@ jobs:
working-directory: ./src
# This command uses src/third_party_cache as the download cache.
run: |
source ${PYTHON_VENV_ROOT}/bin/activate
python3 build_tools/update_deps.py
- name: Build Qt
working-directory: ./src
run: |
source ${PYTHON_VENV_ROOT}/bin/activate
python3 build_tools/build_qt.py --release --confirm_license --macos_cpus=x86_64,arm64
echo "MOZC_QT_PATH=${PWD}/third_party/qt" >> $GITHUB_ENV
Expand All @@ -161,9 +173,10 @@ jobs:
with:
submodules: 'recursive'

- name: Install pip dependencies
working-directory: ./src
- name: Setup Python
run: |
python3 -m venv ${PYTHON_VENV_ROOT}
source ${PYTHON_VENV_ROOT}/bin/activate
python3 -m pip install requests
- name: Try to restore update_deps cache
Expand All @@ -176,11 +189,13 @@ jobs:
working-directory: ./src
# This command uses src/third_party_cache as the download cache.
run: |
source ${PYTHON_VENV_ROOT}/bin/activate
python3 build_tools/update_deps.py
- name: Build Qt
working-directory: ./src
run: |
source ${PYTHON_VENV_ROOT}/bin/activate
python3 build_tools/build_qt.py --release --confirm_license
echo "MOZC_QT_PATH=${PWD}/third_party/qt" >> $GITHUB_ENV
Expand All @@ -201,9 +216,10 @@ jobs:
- name: checkout
uses: actions/checkout@v4

- name: Install pip dependencies
working-directory: ./src
- name: Setup Python
run: |
python3 -m venv ${PYTHON_VENV_ROOT}
source ${PYTHON_VENV_ROOT}/bin/activate
python3 -m pip install requests
- name: Try to restore update_deps cache
Expand All @@ -216,4 +232,5 @@ jobs:
working-directory: ./src
# This command uses src/third_party_cache as the download cache.
run: |
source ${PYTHON_VENV_ROOT}/bin/activate
python3 build_tools/update_deps.py --cache_only
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
/src-*
/src_*

# Python venv dir used to conform PEP 668
# https://peps.python.org/pep-0668/
/src/python-venv

# Mozc build artifacts by Bazel (symbolic links)
/src/bazel-bin
/src/bazel-out
Expand Down
20 changes: 18 additions & 2 deletions docs/build_mozc_in_osx.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ If you are not sure what the following commands do, please check the description
and make sure the operations before running them.

```
python3 -m pip install requests
git clone https://github.com/google/mozc.git
cd mozc/src
export PYTHON_VENV_ROOT=${PWD}/python-venv
python3 -m venv ${PYTHON_VENV_ROOT}
source ${PYTHON_VENV_ROOT}/bin/activate
python3 -m pip install requests
python3 build_tools/update_deps.py
# CMake is also required to build Qt.
Expand Down Expand Up @@ -62,6 +65,19 @@ cd mozc/src

Hereafter you can do all the operations without changing directory.

### Set up and enable Python virtual environment

The following commands set up Python virtual environment under `mozc/src/python-venv`.

```
export PYTHON_VENV_ROOT=${PWD}/python-venv
python3 -m venv ${PYTHON_VENV_ROOT}
source ${PYTHON_VENV_ROOT}/bin/activate
python3 -m pip install requests
```

Using `mozc/src/python-venv` as the virtual environment location is not mandatory. Any other location should also work.

### Check out additional build dependencies

```
Expand Down

0 comments on commit e8d25a2

Please sign in to comment.