anki/qt/mac/helper_build.py
Damien Elmes d9c8addbc1 switch AnkiHelper to Swift
More pleasant to work with than ObjectiveC, which will help with the
following commit.

Swift libraries weren't added to macOS until 10.14.4, so theme
autodetection will fail on 10.14.0-10.14.3. The Qt6 build will have its
minimum version bumped to 10.14.4; the Qt5 build will remain on 10.13.4.

Bazel's rules_swift doesn't currently support building Swift dylibs, so
we need to invoke swiftc directly via a genrule().
2021-12-07 18:48:24 +10:00

30 lines
721 B
Python

# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import subprocess
import sys
import platform
from pathlib import Path
out_dylib, compile_mode, *src_files = sys.argv[1:]
out_dir = Path(out_dylib).parent.resolve()
src_dir = Path(src_files[0]).parent.resolve()
if platform.machine() == "arm64":
target = "arm64-apple-macos11"
else:
target = "x86_64-apple-macos10.14"
args = [
"swiftc",
"-target",
target,
"-emit-library",
"-module-name",
"ankihelper",
]
if compile_mode == "opt":
args.append("-O")
args.extend(src_dir / Path(file).name for file in src_files)
subprocess.run(args, check=True, cwd=out_dir)