Fix #910: Use python venv for macOS build

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
This commit is contained in:
Yohei Yukawa
2024-04-02 10:59:27 +00:00
committed by Hiroyuki Komatsu
parent 9c5fc40cba
commit e8d25a2bee
3 changed files with 49 additions and 12 deletions

View File

@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
.gitignore vendored
View File

@ -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

View File

@ -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.
@ -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
```