From 6eb7b3101949cc01cb39b4163309c9c1d7b40db4 Mon Sep 17 00:00:00 2001 From: Ivan-Velickovic Date: Fri, 5 May 2023 12:35:13 +1000 Subject: [PATCH] Add ability to build SDK for macOS hosts The Microkit tool can now be built for x64 macOS as well as ARM64 macOS, allowing the use of the Microkit SDK in macOS environments. Note that unlike the Linux Microkit tool, the macOS one will be dynamically linked due to macOS not supporting statically linked binaries. Signed-off-by: Ivan Velickovic --- build_sdk.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/build_sdk.py b/build_sdk.py index 7f2be1b91..4e1aacff1 100644 --- a/build_sdk.py +++ b/build_sdk.py @@ -19,6 +19,7 @@ from dataclasses import dataclass from sys import executable from tarfile import open as tar_open, TarInfo +import platform as host_platform from typing import Dict, Union, List, Tuple @@ -162,12 +163,27 @@ def build_tool(tool_target: Path) -> None: pyoxidizer = ENV_BIN_DIR / "pyoxidizer" if not pyoxidizer.exists(): raise Exception("pyoxidizer does not appear to be installed in your Python environment") + + host_system = host_platform.system() + if host_system == "Linux": + target_triple = "x86_64-unknown-linux-musl" + elif host_system == "Darwin": + host_arch = host_platform.machine() + if host_arch == "x86_64": + target_triple = "x86_64-apple-darwin" + elif host_arch == "arm64": + target_triple = "aarch64-apple-darwin" + else: + raise Exception(f"Unexpected Darwin architecture: {host_arch}") + else: + raise Exception(f"The platform \"{host_system}\" is not supported") + r = system( - f"{pyoxidizer} build --release --path tool --target-triple x86_64-unknown-linux-musl" + f"{pyoxidizer} build --release --path tool --target-triple {target_triple}" ) assert r == 0 - tool_output = "./tool/build/x86_64-unknown-linux-musl/release/install/microkit" + tool_output = f"./tool/build/{target_triple}/release/install/microkit" r = system(f"strip {tool_output}") assert r == 0