From ab661467e7a74e202428dc0f24e147f6101853d7 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Mon, 9 Jun 2025 18:32:00 -0600 Subject: [PATCH] Meta: Support Swift_Release preset in ladybird.py --- Meta/find_compiler.py | 26 ++++++++++++++++++++++++++ Meta/ladybird.py | 10 +++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Meta/find_compiler.py b/Meta/find_compiler.py index 104edb18ad5..e2814934ac3 100755 --- a/Meta/find_compiler.py +++ b/Meta/find_compiler.py @@ -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() diff --git a/Meta/ladybird.py b/Meta/ladybird.py index 3e086de90fd..86a55050ed0 100755 --- a/Meta/ladybird.py +++ b/Meta/ladybird.py @@ -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,7 +184,10 @@ def configure_main(platform: Platform, preset: str, cc: str, cxx: str) -> Path: return build_preset_dir validate_cmake_version() - (cc, cxx) = pick_host_compiler(platform, cc, cxx) + 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 = [ "cmake", @@ -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", }