forked from lix-project/lix-installer
64 lines
2 KiB
Plaintext
64 lines
2 KiB
Plaintext
|
#! /usr/bin/env nix-shell
|
||
|
#! nix-shell -i xonsh -p xonsh rustup cargo-zigbuild zig
|
||
|
#
|
||
|
# vim: ts=4 sw=4 et
|
||
|
#
|
||
|
# If the shebang line above was necessary, you probably should have used
|
||
|
# the flake, instead. But that's okay! You're valid. <3
|
||
|
#
|
||
|
""" Lix installer generation script.
|
||
|
|
||
|
This uses cargo-zigbuild to generate a cross-compiled variant for each platform,
|
||
|
and places the results in the `results` subdirectory of the current working dir.
|
||
|
"""
|
||
|
|
||
|
import sys
|
||
|
import xonsh
|
||
|
import functools
|
||
|
|
||
|
# Ensure we fail if any of our subcommands do.
|
||
|
$RAISE_SUBPROC_ERROR=True
|
||
|
|
||
|
# Specify the platforms we want to build for.
|
||
|
TARGET_PLATFORMS = [
|
||
|
"aarch64-apple-darwin",
|
||
|
"x86_64-apple-darwin",
|
||
|
"x86_64-unknown-linux-musl",
|
||
|
"aarch64-unknown-linux-musl",
|
||
|
]
|
||
|
|
||
|
# Create an alias for printing to stderr.
|
||
|
printerr = functools.partial(print, file=sys.stderr)
|
||
|
|
||
|
# Platform helpers.
|
||
|
IS_MACOS = not (xonsh.tools.ON_LINUX or xonsh.tools.ON_WINDOWS)
|
||
|
|
||
|
# Until our flake ships this with osxcross, we'll have to run this on macOS.
|
||
|
if not IS_MACOS:
|
||
|
printerr("This currently must be run from macOS due to cross-compile wonk. Sorry :(.")
|
||
|
sys.exit(-1)
|
||
|
|
||
|
|
||
|
# Pre-flight check: ensure we have all the rustup platforms we need.
|
||
|
all_targets_present = True
|
||
|
for platform in TARGET_PLATFORMS:
|
||
|
if platform not in $(rustup target list --installed):
|
||
|
printerr(f"ERROR: You don't have a rustup toolchain for {platform}! Install it with `rustup target add {platform}`")
|
||
|
all_targets_present = False
|
||
|
|
||
|
if not all_targets_present:
|
||
|
printerr("Failing out; install the platforms above and retry.")
|
||
|
sys.exit(-2)
|
||
|
|
||
|
# Build for each of our platforms.
|
||
|
printerr("> Building any platforms that need updating.")
|
||
|
for platform in TARGET_PLATFORMS:
|
||
|
|
||
|
# Build...
|
||
|
printerr(f"> Building for target {platform}")
|
||
|
cargo zigbuild --quiet --release --target=@(platform)
|
||
|
|
||
|
# ... and copy the output to the "results" directory.
|
||
|
mkdir -p ./results
|
||
|
cp target/@(platform)/release/lix-installer ./results/lix-installer-@(platform)
|