| 17 | |
| 18 | |
| 19 | def main() -> int: |
| 20 | parser = argparse.ArgumentParser( |
| 21 | prog="xcompile", |
| 22 | description="Facilitates cross compilation of Rust binaries.", |
| 23 | epilog="For additional help on a subcommand, run:\n\n %(prog)s <command> -h", |
| 24 | ) |
| 25 | parser.add_argument( |
| 26 | "--arch", |
| 27 | default=mzbuild.Arch.X86_64, |
| 28 | help="the CPU architecture to build for", |
| 29 | type=mzbuild.Arch, |
| 30 | choices=mzbuild.Arch, |
| 31 | ) |
| 32 | |
| 33 | parser.add_argument( |
| 34 | "--channel", |
| 35 | default="nightly" if os.getenv("CI_SANITIZER", "none") else None, |
| 36 | help="Rust compiler channel to use", |
| 37 | ) |
| 38 | |
| 39 | subparsers = parser.add_subparsers( |
| 40 | dest="command", metavar="<command>", required=True |
| 41 | ) |
| 42 | |
| 43 | cargo_parser = subparsers.add_parser( |
| 44 | "cargo", help="run a cross-compiling cargo command" |
| 45 | ) |
| 46 | cargo_parser.add_argument( |
| 47 | "--rustflags", |
| 48 | action="append", |
| 49 | default=[], |
| 50 | help="override the default flags to the Rust compiler", |
| 51 | ) |
| 52 | |
| 53 | cargo_parser.add_argument("subcommand", help="the cargo subcommand to invoke") |
| 54 | cargo_parser.add_argument( |
| 55 | "subargs", nargs=argparse.REMAINDER, help="the arguments to pass to cargo" |
| 56 | ) |
| 57 | |
| 58 | tool_parser = subparsers.add_parser( |
| 59 | "tool", help="run a cross-compiling binutils tool" |
| 60 | ) |
| 61 | tool_parser.add_argument( |
| 62 | "--name-target-prefix", |
| 63 | default=True, |
| 64 | action=argparse.BooleanOptionalAction, |
| 65 | help="whether the tool name should be prefixed with the target name", |
| 66 | ) |
| 67 | tool_parser.add_argument("tool", metavar="TOOL", help="the binutils tool to invoke") |
| 68 | tool_parser.add_argument( |
| 69 | "subargs", nargs=argparse.REMAINDER, help="the arguments to pass to the tool" |
| 70 | ) |
| 71 | |
| 72 | args = parser.parse_args() |
| 73 | if args.command == "cargo": |
| 74 | spawn.runv( |
| 75 | [ |
| 76 | *xcompile.cargo( |