Meta: Support Swift_Release preset in ladybird.py

This commit is contained in:
Andrew Kaster 2025-06-09 18:32:00 -06:00 committed by Andrew Kaster
commit ab661467e7
Notes: github-actions[bot] 2025-06-11 17:56:04 +00:00
2 changed files with 35 additions and 1 deletions

View file

@ -168,6 +168,32 @@ def pick_host_compiler(platform: Platform, cc: str, cxx: str) -> tuple[str, str]
sys.exit(1)
def pick_swift_compilers(platform: Platform, project_root: Path) -> tuple[Path, Path, Path]:
if platform.host_system == HostSystem.Windows:
print("Swift builds are not supported on Windows", file=sys.stderr)
sys.exit(1)
if not shutil.which("swiftly"):
print("swiftly is required to manage Swift toolchains", file=sys.stderr)
sys.exit(1)
swiftly_toolchain_path = run_command(["swiftly", "use", "--print-location"], return_output=True, cwd=project_root)
if not swiftly_toolchain_path:
run_command(["swiftly", "install"], exit_on_failure=True, cwd=project_root)
swiftly_toolchain_path = run_command(
["swiftly", "use", "--print-location"], return_output=True, exit_on_failure=True, cwd=project_root
)
swiftly_toolchain_path = Path(swiftly_toolchain_path.strip())
swiftly_bin_dir = swiftly_toolchain_path.joinpath("usr", "bin")
if not swiftly_toolchain_path.exists() or not swiftly_bin_dir.exists():
print(f"swiftly toolchain path {swiftly_toolchain_path} does not exist", file=sys.stderr)
sys.exit(1)
return swiftly_bin_dir / "clang", swiftly_bin_dir / "clang++", swiftly_bin_dir / "swiftc"
def main():
platform = Platform()
(default_cc, default_cxx) = platform.default_compiler()

View file

@ -18,6 +18,7 @@ from typing import Optional
sys.path.append(str(Path(__file__).resolve().parent.parent))
from Meta.find_compiler import pick_host_compiler
from Meta.find_compiler import pick_swift_compilers
from Meta.host_platform import HostArchitecture
from Meta.host_platform import HostSystem
from Meta.host_platform import Platform
@ -183,6 +184,9 @@ def configure_main(platform: Platform, preset: str, cc: str, cxx: str) -> Path:
return build_preset_dir
validate_cmake_version()
if "Swift" in preset:
(cc, cxx, swiftc) = pick_swift_compilers(platform, ladybird_source_dir)
else:
(cc, cxx) = pick_host_compiler(platform, cc, cxx)
config_args = [
@ -197,6 +201,9 @@ def configure_main(platform: Platform, preset: str, cc: str, cxx: str) -> Path:
f"-DCMAKE_CXX_COMPILER={cxx}",
]
if "Swift" in preset:
config_args.append(f"-DCMAKE_Swift_COMPILER={swiftc}")
if platform.host_system == HostSystem.Linux and platform.host_architecture == HostArchitecture.AArch64:
config_args.extend(configure_skia_jemalloc())
@ -251,6 +258,7 @@ def configure_build_env(preset: str) -> tuple[Path, Path]:
"Distribution": build_root_dir / "distribution",
"Release": build_root_dir / "release",
"Sanitizer": build_root_dir / "sanitizers",
"Swift_Release": build_root_dir / "swift",
"Windows_CI": build_root_dir / "release",
"Windows_Experimental": build_root_dir / "debug",
}