BlueGit

timfa posprint

Offer to install missing build deps in interactive shells.

Linux/Arch/Windows scripts detect absent Rust and OS packages and prompt before installing; CI/non-TTY still exits with instructions.

Co-authored-by: Cursor <cursoragent@cursor.com>

timfa Tim Falken · pushed by timfa

Authored 2026-07-16 · 4 months ago

Hash
2fc6ad6ac3aa8a62b03b168d3462d2f47ab2fa6f
Parent
e14a2040
4 files changed +275 −22
docs/BUILD.md +9 −1
@@ -17,6 +17,8 @@ sudo pacman -S --needed rust
17 17
18 18 Also install the platform build libraries under **Linux build dependencies** below before `cargo test` / `cargo build`.
19 19
20 **Interactive shells:** the build scripts detect missing requirements (Rust, apt/pacman packages, `cargo-deb`, `base-devel`) and ask whether to install them automatically. Non-interactive runs (CI/pipes) never prompt; they print install instructions and exit.
21
20 22 ## Windows
21 23
22 24 ```powershell
@@ -25,10 +27,12 @@ Also install the platform build libraries under **Linux build dependencies** bel
25 27
26 28 Output: `target\release\posprint.exe`
27 29
30 If `cargo`/`rustc` are missing and the shell is interactive, the script offers to install Rust via **winget** (`Rustlang.Rustup`) or **rustup-init**.
31
28 32 Options:
29 33
30 34 ```powershell
31 .\scripts\build-windows.ps1 -Deb:$false # exe only (default)
35 .\scripts\build-windows.ps1 -SkipTests
32 36 ```
33 37
34 38 ## Linux
@@ -40,6 +44,8 @@ chmod +x scripts/build-linux.sh
40 44 ./scripts/build-linux.sh --deb --install # build .deb and install with apt
41 45 ```
42 46
47 On a TTY, missing **apt** build packages and (with `--deb`) **cargo-deb** are offered for install before building.
48
43 49 On **Arch Linux**:
44 50
45 51 ```bash
@@ -48,6 +54,8 @@ chmod +x scripts/build-arch.sh
48 54 ./scripts/build-arch.sh --install # build and install with pacman
49 55 ```
50 56
57 On a TTY, missing **base-devel**, Rust, and common pacman build libs are offered for install before building.
58
51 59 `build-arch.sh` accepts a **rustup** toolchain on `PATH`. If the pacman `rust`/`cargo` packages are not installed, it runs `makepkg --nodeps` after verifying `rustc`/`cargo` work (the PKGBUILD still lists those packages for AUR/CI).
52 60
53 61 After a successful package build, both scripts ask whether to install (TTY only). Pass `--install` to skip the prompt and install automatically. Non-interactive runs (CI/pipes) never prompt.
@@ -17,6 +17,8 @@ sudo pacman -S --needed rust
17
17
18Also install the platform build libraries under **Linux build dependencies** below before `cargo test` / `cargo build`.
18Also install the platform build libraries under **Linux build dependencies** below before `cargo test` / `cargo build`.
19
19
20**Interactive shells:** the build scripts detect missing requirements (Rust, apt/pacman packages, `cargo-deb`, `base-devel`) and ask whether to install them automatically. Non-interactive runs (CI/pipes) never prompt; they print install instructions and exit.
21
20## Windows
22## Windows
21
23
22```powershell
24```powershell
@@ -25,10 +27,12 @@ Also install the platform build libraries under **Linux build dependencies** bel
25
27
26Output: `target\release\posprint.exe`
28Output: `target\release\posprint.exe`
27
29
30If `cargo`/`rustc` are missing and the shell is interactive, the script offers to install Rust via **winget** (`Rustlang.Rustup`) or **rustup-init**.
31
28Options:
32Options:
29
33
30```powershell
34```powershell
31.\scripts\build-windows.ps1 -Deb:$false # exe only (default)
35.\scripts\build-windows.ps1 -SkipTests
32```
36```
33
37
34## Linux
38## Linux
@@ -40,6 +44,8 @@ chmod +x scripts/build-linux.sh
40./scripts/build-linux.sh --deb --install # build .deb and install with apt
44./scripts/build-linux.sh --deb --install # build .deb and install with apt
41```
45```
42
46
47On a TTY, missing **apt** build packages and (with `--deb`) **cargo-deb** are offered for install before building.
48
43On **Arch Linux**:
49On **Arch Linux**:
44
50
45```bash
51```bash
@@ -48,6 +54,8 @@ chmod +x scripts/build-arch.sh
48./scripts/build-arch.sh --install # build and install with pacman
54./scripts/build-arch.sh --install # build and install with pacman
49```
55```
50
56
57On a TTY, missing **base-devel**, Rust, and common pacman build libs are offered for install before building.
58
51`build-arch.sh` accepts a **rustup** toolchain on `PATH`. If the pacman `rust`/`cargo` packages are not installed, it runs `makepkg --nodeps` after verifying `rustc`/`cargo` work (the PKGBUILD still lists those packages for AUR/CI).
59`build-arch.sh` accepts a **rustup** toolchain on `PATH`. If the pacman `rust`/`cargo` packages are not installed, it runs `makepkg --nodeps` after verifying `rustc`/`cargo` work (the PKGBUILD still lists those packages for AUR/CI).
52
60
53After a successful package build, both scripts ask whether to install (TTY only). Pass `--install` to skip the prompt and install automatically. Non-interactive runs (CI/pipes) never prompt.
61After a successful package build, both scripts ask whether to install (TTY only). Pass `--install` to skip the prompt and install automatically. Non-interactive runs (CI/pipes) never prompt.
scripts/build-arch.sh +104 −13
@@ -18,6 +18,7 @@ for arg in "$@"; do
18 18 echo "Usage: $0 [--skip-tests] [--asroot] [--install]"
19 19 echo "Builds packaging/arch/posprint-<ver>-<rel>-x86_64.pkg.tar.zst"
20 20 echo " --install install the package with pacman after building"
21 echo "On a TTY, missing build dependencies are offered for automatic install."
21 22 echo "Without --install, prompts interactively when stdin is a TTY."
22 23 echo "Uses rustup/cargo on PATH; runs makepkg --nodeps if pacman rust/cargo are absent."
23 24 exit 0
@@ -26,33 +27,123 @@ for arg in "$@"; do
26 27 esac
27 28 done
28 29
30 is_interactive() {
31 [[ -t 0 ]]
32 }
33
34 ask_yes_no() {
35 local prompt="$1"
36 if ! is_interactive; then
37 return 1
38 fi
39 local answer
40 read -r -p "$prompt [y/N] " answer
41 [[ "$answer" =~ ^[Yy]([Ee][Ss])?$ ]]
42 }
43
29 44 want_install() {
30 45 if [[ "$INSTALL" == "true" ]]; then
31 46 return 0
32 47 fi
33 if [[ ! -t 0 ]]; then
48 if ! is_interactive; then
34 49 return 1
35 50 fi
36 local answer
37 read -r -p "Install the package now with pacman? [y/N] " answer
38 [[ "$answer" =~ ^[Yy]([Ee][Ss])?$ ]]
51 ask_yes_no "Install the package now with pacman?"
39 52 }
40 53
41 if ! command -v makepkg &>/dev/null; then
42 echo "makepkg not found. On Arch, install base-devel: sudo pacman -S base-devel"
43 exit 1
44 fi
45
46 54 # Ensure rustup toolchains are visible to makepkg's build().
47 55 if [[ -f "$HOME/.cargo/env" ]]; then
48 56 # shellcheck source=/dev/null
49 57 source "$HOME/.cargo/env"
50 58 fi
51 59
52 if ! command -v cargo &>/dev/null || ! command -v rustc &>/dev/null; then
53 echo "cargo/rustc not found. Install via rustup (https://rustup.rs) or: sudo pacman -S rust"
54 exit 1
55 fi
60 ensure_makepkg() {
61 if command -v makepkg &>/dev/null; then
62 return 0
63 fi
64
65 echo "makepkg not found (base-devel)."
66 if ask_yes_no "Install base-devel with pacman now?"; then
67 sudo pacman -S --needed --noconfirm base-devel
68 else
69 echo "Install manually: sudo pacman -S base-devel"
70 exit 1
71 fi
72
73 if ! command -v makepkg &>/dev/null; then
74 echo "makepkg still not found after install."
75 exit 1
76 fi
77 }
78
79 ensure_rust() {
80 if command -v cargo &>/dev/null && command -v rustc &>/dev/null; then
81 return 0
82 fi
83
84 echo "cargo/rustc not found."
85 if ask_yes_no "Install Rust via rustup now?"; then
86 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
87 # shellcheck source=/dev/null
88 source "$HOME/.cargo/env"
89 elif ask_yes_no "Install pacman rust/cargo packages instead?"; then
90 sudo pacman -S --needed --noconfirm rust
91 else
92 echo "Install via rustup (https://rustup.rs) or: sudo pacman -S rust"
93 exit 1
94 fi
95
96 if ! command -v cargo &>/dev/null || ! command -v rustc &>/dev/null; then
97 echo "Rust install finished but cargo/rustc still not on PATH. Open a new shell or: source \"\$HOME/.cargo/env\""
98 exit 1
99 fi
100 }
101
102 ensure_arch_build_deps() {
103 if ! command -v pacman &>/dev/null; then
104 return 0
105 fi
106
107 # Runtime/build libs commonly needed for egui + serialport (beyond base-devel).
108 local pkgs=(
109 pkgconf
110 openssl
111 libxkbcommon
112 libxcb
113 dbus
114 wayland
115 libx11
116 fontconfig
117 freetype2
118 libglvnd
119 git
120 rsync
121 )
122 local missing=()
123 local pkg
124 for pkg in "${pkgs[@]}"; do
125 if ! pacman -Q "$pkg" &>/dev/null; then
126 missing+=("$pkg")
127 fi
128 done
129
130 if [[ ${#missing[@]} -eq 0 ]]; then
131 return 0
132 fi
133
134 echo "Missing pacman packages: ${missing[*]}"
135 if ask_yes_no "Install them with pacman now?"; then
136 sudo pacman -S --needed --noconfirm "${missing[@]}"
137 else
138 echo "Install manually, then re-run:"
139 echo " sudo pacman -S --needed ${missing[*]}"
140 exit 1
141 fi
142 }
143
144 ensure_makepkg
145 ensure_rust
146 ensure_arch_build_deps
56 147
57 148 # PKGBUILD lists pacman rust/cargo as makedepends. rustup installs don't register
58 149 # those packages, so skip dep resolution when the toolchain is already on PATH.
@@ -18,6 +18,7 @@ for arg in "$@"; do
18 echo "Usage: $0 [--skip-tests] [--asroot] [--install]"
18 echo "Usage: $0 [--skip-tests] [--asroot] [--install]"
19 echo "Builds packaging/arch/posprint-<ver>-<rel>-x86_64.pkg.tar.zst"
19 echo "Builds packaging/arch/posprint-<ver>-<rel>-x86_64.pkg.tar.zst"
20 echo " --install install the package with pacman after building"
20 echo " --install install the package with pacman after building"
21 echo "On a TTY, missing build dependencies are offered for automatic install."
21 echo "Without --install, prompts interactively when stdin is a TTY."
22 echo "Without --install, prompts interactively when stdin is a TTY."
22 echo "Uses rustup/cargo on PATH; runs makepkg --nodeps if pacman rust/cargo are absent."
23 echo "Uses rustup/cargo on PATH; runs makepkg --nodeps if pacman rust/cargo are absent."
23 exit 0
24 exit 0
@@ -26,33 +27,123 @@ for arg in "$@"; do
26 esac
27 esac
27done
28done
28
29
30is_interactive() {
31 [[ -t 0 ]]
32}
33
34ask_yes_no() {
35 local prompt="$1"
36 if ! is_interactive; then
37 return 1
38 fi
39 local answer
40 read -r -p "$prompt [y/N] " answer
41 [[ "$answer" =~ ^[Yy]([Ee][Ss])?$ ]]
42}
43
29want_install() {
44want_install() {
30 if [[ "$INSTALL" == "true" ]]; then
45 if [[ "$INSTALL" == "true" ]]; then
31 return 0
46 return 0
32 fi
47 fi
33 if [[ ! -t 0 ]]; then
48 if ! is_interactive; then
34 return 1
49 return 1
35 fi
50 fi
36 local answer
51 ask_yes_no "Install the package now with pacman?"
37 read -r -p "Install the package now with pacman? [y/N] " answer
38 [[ "$answer" =~ ^[Yy]([Ee][Ss])?$ ]]
39}
52}
40
53
41if ! command -v makepkg &>/dev/null; then
42 echo "makepkg not found. On Arch, install base-devel: sudo pacman -S base-devel"
43 exit 1
44fi
45
46# Ensure rustup toolchains are visible to makepkg's build().
54# Ensure rustup toolchains are visible to makepkg's build().
47if [[ -f "$HOME/.cargo/env" ]]; then
55if [[ -f "$HOME/.cargo/env" ]]; then
48 # shellcheck source=/dev/null
56 # shellcheck source=/dev/null
49 source "$HOME/.cargo/env"
57 source "$HOME/.cargo/env"
50fi
58fi
51
59
52if ! command -v cargo &>/dev/null || ! command -v rustc &>/dev/null; then
60ensure_makepkg() {
53 echo "cargo/rustc not found. Install via rustup (https://rustup.rs) or: sudo pacman -S rust"
61 if command -v makepkg &>/dev/null; then
54 exit 1
62 return 0
55fi
63 fi
64
65 echo "makepkg not found (base-devel)."
66 if ask_yes_no "Install base-devel with pacman now?"; then
67 sudo pacman -S --needed --noconfirm base-devel
68 else
69 echo "Install manually: sudo pacman -S base-devel"
70 exit 1
71 fi
72
73 if ! command -v makepkg &>/dev/null; then
74 echo "makepkg still not found after install."
75 exit 1
76 fi
77}
78
79ensure_rust() {
80 if command -v cargo &>/dev/null && command -v rustc &>/dev/null; then
81 return 0
82 fi
83
84 echo "cargo/rustc not found."
85 if ask_yes_no "Install Rust via rustup now?"; then
86 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
87 # shellcheck source=/dev/null
88 source "$HOME/.cargo/env"
89 elif ask_yes_no "Install pacman rust/cargo packages instead?"; then
90 sudo pacman -S --needed --noconfirm rust
91 else
92 echo "Install via rustup (https://rustup.rs) or: sudo pacman -S rust"
93 exit 1
94 fi
95
96 if ! command -v cargo &>/dev/null || ! command -v rustc &>/dev/null; then
97 echo "Rust install finished but cargo/rustc still not on PATH. Open a new shell or: source \"\$HOME/.cargo/env\""
98 exit 1
99 fi
100}
101
102ensure_arch_build_deps() {
103 if ! command -v pacman &>/dev/null; then
104 return 0
105 fi
106
107 # Runtime/build libs commonly needed for egui + serialport (beyond base-devel).
108 local pkgs=(
109 pkgconf
110 openssl
111 libxkbcommon
112 libxcb
113 dbus
114 wayland
115 libx11
116 fontconfig
117 freetype2
118 libglvnd
119 git
120 rsync
121 )
122 local missing=()
123 local pkg
124 for pkg in "${pkgs[@]}"; do
125 if ! pacman -Q "$pkg" &>/dev/null; then
126 missing+=("$pkg")
127 fi
128 done
129
130 if [[ ${#missing[@]} -eq 0 ]]; then
131 return 0
132 fi
133
134 echo "Missing pacman packages: ${missing[*]}"
135 if ask_yes_no "Install them with pacman now?"; then
136 sudo pacman -S --needed --noconfirm "${missing[@]}"
137 else
138 echo "Install manually, then re-run:"
139 echo " sudo pacman -S --needed ${missing[*]}"
140 exit 1
141 fi
142}
143
144ensure_makepkg
145ensure_rust
146ensure_arch_build_deps
56
147
57# PKGBUILD lists pacman rust/cargo as makedepends. rustup installs don't register
148# PKGBUILD lists pacman rust/cargo as makedepends. rustup installs don't register
58# those packages, so skip dep resolution when the toolchain is already on PATH.
149# those packages, so skip dep resolution when the toolchain is already on PATH.
scripts/build-linux.sh +100 −8
@@ -18,6 +18,7 @@ for arg in "$@"; do
18 18 echo "Builds target/release/posprint (and optionally a .deb)."
19 19 echo " --deb also build a Debian package with cargo-deb"
20 20 echo " --install install the .deb with apt after building (implies --deb)"
21 echo "On a TTY, missing build dependencies are offered for automatic install."
21 22 echo "Without --install, prompts interactively for .deb install when stdin is a TTY."
22 23 exit 0
23 24 ;;
@@ -29,18 +30,112 @@ if [[ "$INSTALL" == "true" ]]; then
29 30 BUILD_DEB=true
30 31 fi
31 32
33 is_interactive() {
34 [[ -t 0 ]]
35 }
36
37 ask_yes_no() {
38 local prompt="$1"
39 if ! is_interactive; then
40 return 1
41 fi
42 local answer
43 read -r -p "$prompt [y/N] " answer
44 [[ "$answer" =~ ^[Yy]([Ee][Ss])?$ ]]
45 }
46
32 47 want_install() {
33 48 if [[ "$INSTALL" == "true" ]]; then
34 49 return 0
35 50 fi
36 if [[ ! -t 0 ]]; then
51 if ! is_interactive; then
37 52 return 1
38 53 fi
39 local answer
40 read -r -p "Install the .deb now with apt? [y/N] " answer
41 [[ "$answer" =~ ^[Yy]([Ee][Ss])?$ ]]
54 ask_yes_no "Install the .deb now with apt?"
55 }
56
57 # Make rustup toolchains visible when installed but not yet on PATH.
58 if [[ -f "$HOME/.cargo/env" ]]; then
59 # shellcheck source=/dev/null
60 source "$HOME/.cargo/env"
61 fi
62
63 ensure_rust() {
64 if command -v cargo &>/dev/null && command -v rustc &>/dev/null; then
65 return 0
66 fi
67
68 echo "cargo/rustc not found."
69 if ask_yes_no "Install Rust via rustup now?"; then
70 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
71 # shellcheck source=/dev/null
72 source "$HOME/.cargo/env"
73 else
74 echo "Install Rust from https://rustup.rs (or your distro packages), then re-run."
75 exit 1
76 fi
77
78 if ! command -v cargo &>/dev/null || ! command -v rustc &>/dev/null; then
79 echo "Rust install finished but cargo/rustc still not on PATH. Open a new shell or: source \"\$HOME/.cargo/env\""
80 exit 1
81 fi
42 82 }
43 83
84 ensure_debian_build_deps() {
85 if ! command -v apt-get &>/dev/null; then
86 return 0
87 fi
88
89 local pkgs=(
90 build-essential
91 pkg-config
92 libxcb-render0-dev
93 libxcb-shape0-dev
94 libxcb-xfixes0-dev
95 libxkbcommon-dev
96 libssl-dev
97 libudev-dev
98 )
99 local missing=()
100 local pkg
101 for pkg in "${pkgs[@]}"; do
102 if ! dpkg -s "$pkg" &>/dev/null; then
103 missing+=("$pkg")
104 fi
105 done
106
107 if [[ ${#missing[@]} -eq 0 ]]; then
108 return 0
109 fi
110
111 echo "Missing apt packages: ${missing[*]}"
112 if ask_yes_no "Install them with apt now?"; then
113 sudo apt-get update
114 sudo apt-get install -y "${missing[@]}"
115 else
116 echo "Install manually, then re-run:"
117 echo " sudo apt-get install -y ${missing[*]}"
118 exit 1
119 fi
120 }
121
122 ensure_cargo_deb() {
123 if command -v cargo-deb &>/dev/null; then
124 return 0
125 fi
126
127 echo "cargo-deb not found (needed for --deb)."
128 if ask_yes_no "Install cargo-deb with cargo now?"; then
129 cargo install cargo-deb --locked
130 else
131 echo "Install manually: cargo install cargo-deb --locked"
132 exit 1
133 fi
134 }
135
136 ensure_rust
137 ensure_debian_build_deps
138
44 139 echo "Building posprint for Linux (x86_64)..."
45 140
46 141 if [[ "$SKIP_TESTS" != "true" ]]; then
@@ -53,10 +148,7 @@ echo "OK: $BIN"
53 148 ls -lh "$BIN"
54 149
55 150 if [[ "$BUILD_DEB" == "true" ]]; then
56 if ! command -v cargo-deb &>/dev/null; then
57 echo "Installing cargo-deb..."
58 cargo install cargo-deb --locked
59 fi
151 ensure_cargo_deb
60 152 cargo deb
61 153 shopt -s nullglob
62 154 DEBS=("$ROOT"/target/debian/*.deb)
@@ -18,6 +18,7 @@ for arg in "$@"; do
18 echo "Builds target/release/posprint (and optionally a .deb)."
18 echo "Builds target/release/posprint (and optionally a .deb)."
19 echo " --deb also build a Debian package with cargo-deb"
19 echo " --deb also build a Debian package with cargo-deb"
20 echo " --install install the .deb with apt after building (implies --deb)"
20 echo " --install install the .deb with apt after building (implies --deb)"
21 echo "On a TTY, missing build dependencies are offered for automatic install."
21 echo "Without --install, prompts interactively for .deb install when stdin is a TTY."
22 echo "Without --install, prompts interactively for .deb install when stdin is a TTY."
22 exit 0
23 exit 0
23 ;;
24 ;;
@@ -29,18 +30,112 @@ if [[ "$INSTALL" == "true" ]]; then
29 BUILD_DEB=true
30 BUILD_DEB=true
30fi
31fi
31
32
33is_interactive() {
34 [[ -t 0 ]]
35}
36
37ask_yes_no() {
38 local prompt="$1"
39 if ! is_interactive; then
40 return 1
41 fi
42 local answer
43 read -r -p "$prompt [y/N] " answer
44 [[ "$answer" =~ ^[Yy]([Ee][Ss])?$ ]]
45}
46
32want_install() {
47want_install() {
33 if [[ "$INSTALL" == "true" ]]; then
48 if [[ "$INSTALL" == "true" ]]; then
34 return 0
49 return 0
35 fi
50 fi
36 if [[ ! -t 0 ]]; then
51 if ! is_interactive; then
37 return 1
52 return 1
38 fi
53 fi
39 local answer
54 ask_yes_no "Install the .deb now with apt?"
40 read -r -p "Install the .deb now with apt? [y/N] " answer
55}
41 [[ "$answer" =~ ^[Yy]([Ee][Ss])?$ ]]
56
57# Make rustup toolchains visible when installed but not yet on PATH.
58if [[ -f "$HOME/.cargo/env" ]]; then
59 # shellcheck source=/dev/null
60 source "$HOME/.cargo/env"
61fi
62
63ensure_rust() {
64 if command -v cargo &>/dev/null && command -v rustc &>/dev/null; then
65 return 0
66 fi
67
68 echo "cargo/rustc not found."
69 if ask_yes_no "Install Rust via rustup now?"; then
70 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
71 # shellcheck source=/dev/null
72 source "$HOME/.cargo/env"
73 else
74 echo "Install Rust from https://rustup.rs (or your distro packages), then re-run."
75 exit 1
76 fi
77
78 if ! command -v cargo &>/dev/null || ! command -v rustc &>/dev/null; then
79 echo "Rust install finished but cargo/rustc still not on PATH. Open a new shell or: source \"\$HOME/.cargo/env\""
80 exit 1
81 fi
42}
82}
43
83
84ensure_debian_build_deps() {
85 if ! command -v apt-get &>/dev/null; then
86 return 0
87 fi
88
89 local pkgs=(
90 build-essential
91 pkg-config
92 libxcb-render0-dev
93 libxcb-shape0-dev
94 libxcb-xfixes0-dev
95 libxkbcommon-dev
96 libssl-dev
97 libudev-dev
98 )
99 local missing=()
100 local pkg
101 for pkg in "${pkgs[@]}"; do
102 if ! dpkg -s "$pkg" &>/dev/null; then
103 missing+=("$pkg")
104 fi
105 done
106
107 if [[ ${#missing[@]} -eq 0 ]]; then
108 return 0
109 fi
110
111 echo "Missing apt packages: ${missing[*]}"
112 if ask_yes_no "Install them with apt now?"; then
113 sudo apt-get update
114 sudo apt-get install -y "${missing[@]}"
115 else
116 echo "Install manually, then re-run:"
117 echo " sudo apt-get install -y ${missing[*]}"
118 exit 1
119 fi
120}
121
122ensure_cargo_deb() {
123 if command -v cargo-deb &>/dev/null; then
124 return 0
125 fi
126
127 echo "cargo-deb not found (needed for --deb)."
128 if ask_yes_no "Install cargo-deb with cargo now?"; then
129 cargo install cargo-deb --locked
130 else
131 echo "Install manually: cargo install cargo-deb --locked"
132 exit 1
133 fi
134}
135
136ensure_rust
137ensure_debian_build_deps
138
44echo "Building posprint for Linux (x86_64)..."
139echo "Building posprint for Linux (x86_64)..."
45
140
46if [[ "$SKIP_TESTS" != "true" ]]; then
141if [[ "$SKIP_TESTS" != "true" ]]; then
@@ -53,10 +148,7 @@ echo "OK: $BIN"
53ls -lh "$BIN"
148ls -lh "$BIN"
54
149
55if [[ "$BUILD_DEB" == "true" ]]; then
150if [[ "$BUILD_DEB" == "true" ]]; then
56 if ! command -v cargo-deb &>/dev/null; then
151 ensure_cargo_deb
57 echo "Installing cargo-deb..."
58 cargo install cargo-deb --locked
59 fi
60 cargo deb
152 cargo deb
61 shopt -s nullglob
153 shopt -s nullglob
62 DEBS=("$ROOT"/target/debian/*.deb)
154 DEBS=("$ROOT"/target/debian/*.deb)
scripts/build-windows.ps1 +62 −0
@@ -7,6 +7,68 @@ $ErrorActionPreference = "Stop"
7 7 $Root = Split-Path -Parent $PSScriptRoot
8 8 Set-Location $Root
9 9
10 function Test-IsInteractive {
11 try {
12 return [Environment]::UserInteractive -and -not [Console]::IsInputRedirected
13 } catch {
14 return $Host.Name -eq "ConsoleHost"
15 }
16 }
17
18 function Ask-YesNo([string]$Prompt) {
19 if (-not (Test-IsInteractive)) {
20 return $false
21 }
22 $answer = Read-Host "$Prompt [y/N]"
23 return $answer -match '^[Yy]([Ee][Ss])?$'
24 }
25
26 function Ensure-Rust {
27 if ((Get-Command cargo -ErrorAction SilentlyContinue) -and (Get-Command rustc -ErrorAction SilentlyContinue)) {
28 return
29 }
30
31 $cargoEnv = Join-Path $env:USERPROFILE ".cargo\env"
32 if (Test-Path $cargoEnv) {
33 # Best-effort: put cargo on PATH for this session if rustup is installed.
34 $cargoBin = Join-Path $env:USERPROFILE ".cargo\bin"
35 if ((Test-Path $cargoBin) -and ($env:PATH -notlike "*$cargoBin*")) {
36 $env:PATH = "$cargoBin;$env:PATH"
37 }
38 }
39
40 if ((Get-Command cargo -ErrorAction SilentlyContinue) -and (Get-Command rustc -ErrorAction SilentlyContinue)) {
41 return
42 }
43
44 Write-Host "cargo/rustc not found."
45
46 $winget = Get-Command winget -ErrorAction SilentlyContinue
47 if ($winget -and (Ask-YesNo "Install Rust via winget (Rustlang.Rustup) now?")) {
48 & winget install --id Rustlang.Rustup -e --accept-package-agreements --accept-source-agreements
49 $cargoBin = Join-Path $env:USERPROFILE ".cargo\bin"
50 if ((Test-Path $cargoBin) -and ($env:PATH -notlike "*$cargoBin*")) {
51 $env:PATH = "$cargoBin;$env:PATH"
52 }
53 } elseif (Ask-YesNo "Download and run rustup-init.exe now?") {
54 $tmp = Join-Path $env:TEMP "rustup-init.exe"
55 Invoke-WebRequest -Uri "https://win.rustup.rs/x86_64" -OutFile $tmp
56 & $tmp -y
57 $cargoBin = Join-Path $env:USERPROFILE ".cargo\bin"
58 if ((Test-Path $cargoBin) -and ($env:PATH -notlike "*$cargoBin*")) {
59 $env:PATH = "$cargoBin;$env:PATH"
60 }
61 } else {
62 Write-Error "Install Rust from https://rustup.rs (or: winget install Rustlang.Rustup), then re-run this script."
63 }
64
65 if (-not (Get-Command cargo -ErrorAction SilentlyContinue) -or -not (Get-Command rustc -ErrorAction SilentlyContinue)) {
66 Write-Error "Rust install finished but cargo/rustc are still not on PATH. Open a new PowerShell window and re-run."
67 }
68 }
69
70 Ensure-Rust
71
10 72 Write-Host "Building posprint for Windows (x64)..."
11 73
12 74 if (-not $SkipTests) {
@@ -7,6 +7,68 @@ $ErrorActionPreference = "Stop"
7$Root = Split-Path -Parent $PSScriptRoot
7$Root = Split-Path -Parent $PSScriptRoot
8Set-Location $Root
8Set-Location $Root
9
9
10function Test-IsInteractive {
11 try {
12 return [Environment]::UserInteractive -and -not [Console]::IsInputRedirected
13 } catch {
14 return $Host.Name -eq "ConsoleHost"
15 }
16}
17
18function Ask-YesNo([string]$Prompt) {
19 if (-not (Test-IsInteractive)) {
20 return $false
21 }
22 $answer = Read-Host "$Prompt [y/N]"
23 return $answer -match '^[Yy]([Ee][Ss])?$'
24}
25
26function Ensure-Rust {
27 if ((Get-Command cargo -ErrorAction SilentlyContinue) -and (Get-Command rustc -ErrorAction SilentlyContinue)) {
28 return
29 }
30
31 $cargoEnv = Join-Path $env:USERPROFILE ".cargo\env"
32 if (Test-Path $cargoEnv) {
33 # Best-effort: put cargo on PATH for this session if rustup is installed.
34 $cargoBin = Join-Path $env:USERPROFILE ".cargo\bin"
35 if ((Test-Path $cargoBin) -and ($env:PATH -notlike "*$cargoBin*")) {
36 $env:PATH = "$cargoBin;$env:PATH"
37 }
38 }
39
40 if ((Get-Command cargo -ErrorAction SilentlyContinue) -and (Get-Command rustc -ErrorAction SilentlyContinue)) {
41 return
42 }
43
44 Write-Host "cargo/rustc not found."
45
46 $winget = Get-Command winget -ErrorAction SilentlyContinue
47 if ($winget -and (Ask-YesNo "Install Rust via winget (Rustlang.Rustup) now?")) {
48 & winget install --id Rustlang.Rustup -e --accept-package-agreements --accept-source-agreements
49 $cargoBin = Join-Path $env:USERPROFILE ".cargo\bin"
50 if ((Test-Path $cargoBin) -and ($env:PATH -notlike "*$cargoBin*")) {
51 $env:PATH = "$cargoBin;$env:PATH"
52 }
53 } elseif (Ask-YesNo "Download and run rustup-init.exe now?") {
54 $tmp = Join-Path $env:TEMP "rustup-init.exe"
55 Invoke-WebRequest -Uri "https://win.rustup.rs/x86_64" -OutFile $tmp
56 & $tmp -y
57 $cargoBin = Join-Path $env:USERPROFILE ".cargo\bin"
58 if ((Test-Path $cargoBin) -and ($env:PATH -notlike "*$cargoBin*")) {
59 $env:PATH = "$cargoBin;$env:PATH"
60 }
61 } else {
62 Write-Error "Install Rust from https://rustup.rs (or: winget install Rustlang.Rustup), then re-run this script."
63 }
64
65 if (-not (Get-Command cargo -ErrorAction SilentlyContinue) -or -not (Get-Command rustc -ErrorAction SilentlyContinue)) {
66 Write-Error "Rust install finished but cargo/rustc are still not on PATH. Open a new PowerShell window and re-run."
67 }
68}
69
70Ensure-Rust
71
10Write-Host "Building posprint for Windows (x64)..."
72Write-Host "Building posprint for Windows (x64)..."
11
73
12if (-not $SkipTests) {
74if (-not $SkipTests) {