Add '--macos_cpus' option to 'build_qt.py'

This is a preparation to support universal binaries for macOS (#801).

With this commit, you can start building Qt6 as universal binaries as follows.

 # Build universal binaries
 python3 build_tools/build_qt.py --release --confirm_license  \
                                 --macos_cpus=x86_64,arm64

Under the hood, '-DCMAKE_OSX_ARCHITECTURES' option is passed to the configure
options of Qt6 [1].

You can also build Intel64 binaries on arm64 Mac as follows.

 # Build Intel64 binaries
 python3 build_tools/build_qt.py --release --confirm_license  \
                                 --macos_cpus=x86_64

A known limitation is that building arm64 binaries on Intel64 mac does not
currently work though.

If '--macos_cpus' is not specified, Qt6 binaries will be built for the host CPU
architecture as it used to be.

 [1]: https://doc.qt.io/qt-6.5/macos-building.html#step-2-build-the-qt-library

PiperOrigin-RevId: 562439404
This commit is contained in:
Yohei Yukawa
2023-09-04 03:53:49 +00:00
committed by Hiroyuki Komatsu
parent 91e56ec4a7
commit 2f68b502dd
2 changed files with 36 additions and 1 deletions

View File

@@ -85,6 +85,18 @@ You can also specify `--debug` option to build debug version of Mozc.
python3 build_tools/build_qt.py --release --debug --confirm_license python3 build_tools/build_qt.py --release --debug --confirm_license
``` ```
You can also specify `--macos_cpus` option, which has the same semantics as the
[same name option in Bazel](https://bazel.build/reference/command-line-reference#flag--macos_cpus),
for cross-build including building a Universal macOS Binary.
```
# Building x86_64 binaries regardless of the host CPU architecture.
python3 build_tools/build_qt.py --release --debug --confirm_license --macos_cpus=x86_64
# Building Universal macOS Binary for both x86_64 and arm64.
python3 build_tools/build_qt.py --release --debug --confirm_license --macos_cpus=x86_64,arm64
```
You can skip this process if you have already installed Qt prebuilt binaries. You can skip this process if you have already installed Qt prebuilt binaries.
----- -----

View File

@@ -253,6 +253,7 @@ def make_configure_options(args: argparse.Namespace) -> list[str]:
A list of configure options to be passed to configure of Qt. A list of configure options to be passed to configure of Qt.
Raises: Raises:
ValueError: When Qt major version is not 6. ValueError: When Qt major version is not 6.
ValueError: When --macos_cpus=arm64 is set on Intel64 mac.
""" """
qt_version = get_qt_version(args) qt_version = get_qt_version(args)
@@ -283,6 +284,7 @@ def make_configure_options(args: argparse.Namespace) -> list[str]:
'-nomake', 'examples', '-nomake', 'examples',
'-nomake', 'tests', '-nomake', 'tests',
] ]
cmake_options = []
if is_mac(): if is_mac():
qt_configure_options += [ qt_configure_options += [
@@ -290,6 +292,20 @@ def make_configure_options(args: argparse.Namespace) -> list[str]:
'-qt-libpng', '-qt-libpng',
'-qt-pcre', '-qt-pcre',
] ]
if args.macos_cpus:
macos_cpus = args.macos_cpus.split(',')
host_arch = os.uname().machine
if host_arch == 'x86_64' and macos_cpus == ['arm64']:
# Haven't figured out how to make this work...
raise ValueError('--macos_cpus=arm64 on Intel64 mac is not supported.')
# 'x86_64' needs to be the first entry if exists.
# https://doc-snapshots.qt.io/qt6-6.5/macos-building.html#step-2-build-the-qt-library
if 'x86_64' in macos_cpus and macos_cpus[0] != 'x86_64':
macos_cpus.remove('x86_64')
macos_cpus = ['x86_64'] + macos_cpus
cmake_options += [
'-DCMAKE_OSX_ARCHITECTURES:STRING=' + ';'.join(macos_cpus),
]
elif is_windows(): elif is_windows():
qt_configure_options += ['-c++std', 'c++20', qt_configure_options += ['-c++std', 'c++20',
'-force-debug-info', '-force-debug-info',
@@ -312,7 +328,8 @@ def make_configure_options(args: argparse.Namespace) -> list[str]:
if qt_src_dir != qt_dest_dir: if qt_src_dir != qt_dest_dir:
qt_configure_options += ['-prefix', str(qt_dest_dir)] qt_configure_options += ['-prefix', str(qt_dest_dir)]
return qt_configure_options return qt_configure_options + ((['--'] + cmake_options) if cmake_options
else [])
def parse_args() -> argparse.Namespace: def parse_args() -> argparse.Namespace:
@@ -339,6 +356,12 @@ def parse_args() -> argparse.Namespace:
if is_windows(): if is_windows():
parser.add_argument('--vcvarsall_path', help='Path of vcvarsall.bat', parser.add_argument('--vcvarsall_path', help='Path of vcvarsall.bat',
type=str, default=None) type=str, default=None)
elif is_mac():
parser.add_argument('--macos_cpus',
help=('comma-separated CPU archs for mac Build (e.g. '
'"arm64", "x86_64,arm64"). Corresponds to the '
'same option in Bazel.'),
type=str, default=None)
return parser.parse_args() return parser.parse_args()