diff --git a/Makefile b/Makefile index 1644050c..3913d30c 100644 --- a/Makefile +++ b/Makefile @@ -16,11 +16,11 @@ C_OFF := \033[0m .PHONY: help release mxrun mxrun-init mxrun-toggle set-local-builds set-remote-builds build dev all all-dev modules modules-dev modules-dist-dev modules-refresh-dev modules-refresh clean check fix setup smoke-test \ - stats man test test-core test-modules test-sensors test-integration tar dev-tls advisory \ + stats man test test-core test-modules test-sensors test-integration tar dev-tls advisory dist \ _dev _all_dev _all _build _modules_dev _modules _modules_dist_dev _test _test_core _test_modules _test_sensors _test_integration ifeq ($(UNAME_S),Linux) -.PHONY: musl-aarch64-dev musl-aarch64 musl-x86_64-dev musl-x86_64 +.PHONY: musl-aarch64-dev musl-aarch64 musl-x86_64-dev musl-x86_64 musl-x86_64-dist musl-aarch64-dist endif help: @@ -37,6 +37,7 @@ help: @printf ' $(C_MX)%-20s$(C_OFF) %s\n' "all" "Compile core plus modules in release mode." @printf ' $(C_MX)%-20s$(C_OFF) %s\n' "modules" "Compile modules only in release mode." @printf ' $(C_MX)%-20s$(C_OFF) %s\n' "modules-refresh" "Rebuild Linux musl module repo and refresh current minion slot." + @printf ' $(C_MX)%-20s$(C_OFF) %s\n' "dist" "Assemble release distribution tree for current platform." ifeq ($(UNAME_S),Linux) @printf '\n$(C_GRN)%s$(C_OFF)\n' "Cross Build" @printf ' $(C_BLD)%-30s$(C_OFF) %s\n' "musl-x86_64" "Build static x86_64 Linux release artifacts." @@ -47,14 +48,8 @@ ifeq ($(UNAME_S),Linux) @printf ' $(C_BLD)%-30s$(C_OFF) %s\n' "musl-x86_64-modules-dist-dev" "Build static x86_64 Linux debug modules distribution." @printf ' $(C_BLD)%-30s$(C_OFF) %s\n' "musl-aarch64-modules-dist" "Build static AArch64 Linux release modules distribution." @printf ' $(C_BLD)%-30s$(C_OFF) %s\n' "musl-aarch64-modules-dist-dev" "Build static AArch64 Linux debug modules distribution." - @printf ' $(C_BLD)%-30s$(C_OFF) %s\n' "musl-x86_64" "Build static x86_64 Linux release artifacts." - @printf ' $(C_BLD)%-30s$(C_OFF) %s\n' "musl-x86_64-dev" "Build static x86_64 Linux debug artifacts." - @printf ' $(C_BLD)%-30s$(C_OFF) %s\n' "musl-aarch64" "Build static AArch64 Linux release artifacts." - @printf ' $(C_BLD)%-30s$(C_OFF) %s\n' "musl-aarch64-dev" "Build static AArch64 Linux debug artifacts." - @printf ' $(C_BLD)%-30s$(C_OFF) %s\n' "musl-x86_64-modules-dist" "Build static x86_64 Linux release modules distribution." - @printf ' $(C_BLD)%-30s$(C_OFF) %s\n' "musl-x86_64-modules-dist-dev" "Build static x86_64 Linux debug modules distribution." - @printf ' $(C_BLD)%-30s$(C_OFF) %s\n' "musl-aarch64-modules-dist" "Build static AArch64 Linux release modules distribution." - @printf ' $(C_BLD)%-30s$(C_OFF) %s\n' "musl-aarch64-modules-dist-dev" "Build static AArch64 Linux debug modules distribution." + @printf ' $(C_BLD)%-30s$(C_OFF) %s\n' "musl-x86_64-dist" "Assemble static x86_64 release distribution tree." + @printf ' $(C_BLD)%-30s$(C_OFF) %s\n' "musl-aarch64-dist" "Assemble static AArch64 release distribution tree." endif @printf '\n$(C_GRN)%s$(C_OFF)\n' "Testing" @printf ' $(C_MX)%-20s$(C_OFF) %s\n' "test" "Run the full nextest suite for this platform." @@ -106,6 +101,9 @@ set-remote-builds: release: build +dist: setup all + @sh scripts/assemble-dist.sh + mxrun-init: setup @command -v $(MXRUN_BIN) >/dev/null 2>&1 || { echo "Missing $(MXRUN_BIN). Install it first." >&2; exit 1; } @if [ ! -f mxrun.conf ]; then echo "local" > mxrun.conf; fi @@ -153,6 +151,9 @@ musl-aarch64: $(call stage_profile_modules,release,aarch64-unknown-linux-musl) $(call stage_profile_minion,release,aarch64-unknown-linux-musl) +musl-aarch64-dist: setup musl-aarch64 + @sh scripts/assemble-dist.sh --musl aarch64-unknown-linux-musl + musl-x86_64-dev: @sh scripts/run-musl-cargo.sh x86_64-unknown-linux-musl x86_64-linux-musl-gcc build -v --workspace $(MUSL_WORKSPACE_EXCLUDES) --target x86_64-unknown-linux-musl $(call stage_profile_modules,debug,x86_64-unknown-linux-musl) @@ -162,6 +163,9 @@ musl-x86_64: @sh scripts/run-musl-cargo.sh x86_64-unknown-linux-musl x86_64-linux-musl-gcc build --release --workspace $(MUSL_WORKSPACE_EXCLUDES) --target x86_64-unknown-linux-musl $(call stage_profile_modules,release,x86_64-unknown-linux-musl) $(call stage_profile_minion,release,x86_64-unknown-linux-musl) + +musl-x86_64-dist: setup musl-x86_64 + @sh scripts/assemble-dist.sh --musl x86_64-unknown-linux-musl endif musl-x86_64-modules-dist-dev: diff --git a/scripts/assemble-dist.sh b/scripts/assemble-dist.sh new file mode 100755 index 00000000..6695c709 --- /dev/null +++ b/scripts/assemble-dist.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env sh +set -eu + +PROFILE="release" +MUSL_TRIPLE="" + +while [ $# -gt 0 ]; do + case "$1" in + --musl) + MUSL_TRIPLE="$2" + shift 2 + ;; + *) + echo "assemble-dist.sh: unknown argument: $1" >&2 + exit 1 + ;; + esac +done + +PLATFORM=$(uname -s | tr '[:upper:]' '[:lower:]') +ARCH=$(uname -m) +case "$ARCH" in + aarch64|arm64) ARCH="arm64" ;; +esac + +if [ -n "$MUSL_TRIPLE" ]; then + PREFIX="musl" + CARGO_TARGET="target/${MUSL_TRIPLE}/${PROFILE}" +else + PREFIX="dyn" + CARGO_TARGET="target/${PROFILE}" +fi + +LABEL="${PREFIX}-${ARCH}-dist" +DEST="build/${PLATFORM}/${LABEL}" + +echo "=== sysinspect distribution assembly ===" +echo " platform: $PLATFORM" +echo " arch: $ARCH" +echo " profile: $PROFILE" +echo " prefix: $PREFIX" +echo " dest: $DEST" +echo "" + +rm -rf "$DEST" +mkdir -p "${DEST}/bin" "${DEST}/master" "${DEST}/models" "${DEST}/modules" + +echo "--- core binaries ---" +for bin in sysinspect sysmaster sysminion; do + src="${CARGO_TARGET}/${bin}" + if [ ! -f "$src" ]; then + echo "FATAL: missing core binary: $src" >&2 + exit 1 + fi + cp "$src" "${DEST}/bin/" + chmod +x "${DEST}/bin/${bin}" + echo " bin/${bin}" +done + +echo "" +echo "--- modules ---" +find modules -maxdepth 3 -name Cargo.toml | sort | while read toml; do + pkg=$(awk '/^[[:space:]]*name[[:space:]]*=/ { + gsub(/"/, "", $3); name=$3; exit + } + END { if (name=="") name=""; print name }' "$toml") + [ -n "$pkg" ] || continue + + src_dir=$(dirname "$toml") + spec="${src_dir}/src/mod_doc.yaml" + bin="${CARGO_TARGET}/${pkg}" + + if [ ! -f "$bin" ]; then + echo " skip (no binary): $pkg" >&2 + continue + fi + if [ ! -f "$spec" ]; then + echo " skip (no spec): $pkg" >&2 + continue + fi + + mkdir -p "${DEST}/modules/${pkg}" + cp "$bin" "${DEST}/modules/${pkg}/${pkg}" + cp "$spec" "${DEST}/modules/${pkg}/${pkg}.spec" + chmod +x "${DEST}/modules/${pkg}/${pkg}" + echo " modules/${pkg}/" +done + +echo "" +echo "--- models ---" +MODEL_SRC="examples/demos/infoping" +if [ -f "${MODEL_SRC}/model.cfg" ]; then + mkdir -p "${DEST}/models/infoping" + cp "${MODEL_SRC}/model.cfg" "${DEST}/models/infoping/" + echo " models/infoping/" +else + echo " skip (not found): infoping" >&2 +fi + +echo "" +echo "=== done: ${DEST} ===" +echo "" +find "$DEST" -type d -o -type f | sort | while read entry; do + rel="${entry#${DEST}/}" + if [ "$rel" = "$entry" ]; then + continue + fi + if [ -d "$entry" ]; then + echo " ${rel}/" + else + echo " ${rel}" + fi +done diff --git a/scripts/maybe-mxrun.sh b/scripts/maybe-mxrun.sh index 7b5bad2e..7a076c5a 100755 --- a/scripts/maybe-mxrun.sh +++ b/scripts/maybe-mxrun.sh @@ -12,7 +12,23 @@ ACTIVE=no if [ "$ACTIVE" = "yes" ] && [ -f mxrun.conf ]; then command -v mxrun >/dev/null 2>&1 || { echo "Missing mxrun binary. Install it first." >&2; exit 1; } - MXRUN_CONFIG=mxrun.conf mxrun run "$ENTRY" || true + case "$ENTRY" in + dev|all-dev|modules-dev|modules-dist-dev|modules-refresh-dev) + LABEL="Development Build Mode" ;; + test) + LABEL="Testing Everything" ;; + test-core) + LABEL="Testing Core Libraries" ;; + test-modules) + LABEL="Testing Modules" ;; + test-sensors) + LABEL="Testing Sensors" ;; + test-integration) + LABEL="Integration Tests" ;; + *) + LABEL="Production Build Mode" ;; + esac + MXRUN_CONFIG=mxrun.conf mxrun run --label="$LABEL" "$ENTRY" || true # mxrun handled it (or was interrupted) — do not fall through to local build. exit 0 fi