acta 0.1.1

Make Tracing Great Again.
Documentation
#!/usr/bin/env python3
"""Auto-detect: use cargo for native builds, cargo-zigbuild for cross-compilation."""

import re
import subprocess
import sys


def get_host_target():
    result = subprocess.run(
        ["rustc", "-vV"], capture_output=True, text=True, check=True
    )
    match = re.search(r"host:\s+(\S+)", result.stdout)
    if not match:
        raise RuntimeError("Could not determine host target from rustc -vV")
    return match.group(1)


def get_target_from_args(args):
    for i, arg in enumerate(args):
        if arg == "--target" and i + 1 < len(args):
            return args[i + 1]
        if arg.startswith("--target="):
            return arg.split("=", 1)[1]
    return None


def main():
    args = sys.argv[1:]
    host = get_host_target()
    target = get_target_from_args(args)

    if target is None or target == host:
        command = ["cargo"]
    else:
        command = ["cargo", "zigbuild"]
        if args and args[0] == "build":
            args = args[1:]

    sys.exit(subprocess.call(command + args))


if __name__ == "__main__":
    main()