Skip to content

Commit

Permalink
Add ability to specify target for Microkit tool
Browse files Browse the repository at this point in the history
Add the `--tool-target-triple` option to specify which target
to build the tool for. Unfortunately Rust does not allow you to
cross-compile from Linux to macOS, however this will allow x64 macOS
hosts to cross-compile to ARM64 macOS. In theory the reverse would
work as well but I have not tried it.

Signed-off-by: Ivan Velickovic <[email protected]>
  • Loading branch information
Ivan-Velickovic committed Jan 27, 2024
1 parent 6eb7b31 commit 34befbc
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions build_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,32 +152,34 @@ def tar_filter(tarinfo: TarInfo) -> TarInfo:
return tarinfo


def test_tool() -> None:
r = system(
f"{executable} -m unittest discover -s tool -v"
)
assert r == 0


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")

def get_tool_target_triple() -> str:
host_system = host_platform.system()
if host_system == "Linux":
target_triple = "x86_64-unknown-linux-musl"
return "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"
return "x86_64-apple-darwin"
elif host_arch == "arm64":
target_triple = "aarch64-apple-darwin"
return "aarch64-apple-darwin"
else:
raise Exception(f"Unexpected Darwin architecture: {host_arch}")
else:
raise Exception(f"The platform \"{host_system}\" is not supported")


def test_tool() -> None:
r = system(
f"{executable} -m unittest discover -s tool -v"
)
assert r == 0


def build_tool(tool_target: Path, target_triple: str) -> None:
pyoxidizer = ENV_BIN_DIR / "pyoxidizer"
if not pyoxidizer.exists():
raise Exception("pyoxidizer does not appear to be installed in your Python environment")

r = system(
f"{pyoxidizer} build --release --path tool --target-triple {target_triple}"
)
Expand Down Expand Up @@ -357,6 +359,7 @@ def build_lib_component(
def main() -> None:
parser = ArgumentParser()
parser.add_argument("--sel4", type=Path, required=True)
parser.add_argument("--tool-target-triple", default=get_tool_target_triple(), help="Compile the Microkit tool for this target triple")
args = parser.parse_args()
sel4_dir = args.sel4.expanduser()
if not sel4_dir.exists():
Expand Down Expand Up @@ -402,7 +405,7 @@ def main() -> None:

if not tool_target.exists():
test_tool()
build_tool(tool_target)
build_tool(tool_target, args.tool_target_triple)

build_doc(root_dir)

Expand Down

0 comments on commit 34befbc

Please sign in to comment.