From b0e4a7596f4a377ee3e4a62a665fcdf8db911674 Mon Sep 17 00:00:00 2001 From: Matthew Kelch Date: Sun, 22 Nov 2026 14:24:48 -0500 Subject: [PATCH] Enable mbx Cargo wrapper across macOS (arm64), Linux, and Windows --- .github/workflows/validate.yml | 5 ++- docs/profiles.md | 10 ++--- home/.chezmoidata.toml | 3 +- ...hange_after_02-install-mise-tools.ps1.tmpl | 37 ++++++++++++++++--- ...change_after_02-install-mise-tools.sh.tmpl | 2 +- home/Documents/WindowsPowerShell/profile.ps1 | 18 ++++----- home/dot_config/fish/config.fish | 2 +- home/dot_config/mise/conf.d/mbx.toml.tmpl | 18 +++++---- home/dot_config/shell/env.sh | 2 +- tests/test_profiles.py | 20 ++++++---- 10 files changed, 76 insertions(+), 41 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 008ea73..dd527af 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -121,11 +121,10 @@ jobs: run: | mise ls --global test -z "$(mise ls --global --missing)" - for tool in claude codex uv node python; do mise exec -- "$tool" --version; done + for tool in claude codex uv node python mbx; do mise exec -- "$tool" --version; done # Use mise's gh, not the runner's preinstalled one. "$(mise which gh)" extension list | grep -q github/gh-stack if [ "$(uname -s)" = "Darwin" ]; then - mise exec -- mbx --version test -x "$HOME/.local/bin/hidden-display" test -x "$HOME/.local/share/mise/command-wrappers/bin/cargo" test "$(zsh -c 'command -v cargo')" = "$HOME/.local/share/mise/command-wrappers/bin/cargo" @@ -134,4 +133,6 @@ jobs: exit 1 fi python3 -m unittest -v tests.test_hidden_display + else + test -f "$LOCALAPPDATA/mise/command-wrappers/bin/cargo.exe" || test -f "$LOCALAPPDATA/mise/command-wrappers/bin/cargo.cmd" fi diff --git a/docs/profiles.md b/docs/profiles.md index a487e4c..15a9282 100644 --- a/docs/profiles.md +++ b/docs/profiles.md @@ -7,7 +7,7 @@ A profile supplies module defaults on initialization. Every resulting switch is | `desktop` | Personal Hyprland input/appearance overrides (Omarchy only) | Off | Off | | `git` | Personal Git include, its include block, and a bounded 1Password block in SSH config (the `git` module owns both) | On | On | | `agents` | Shared instructions/skills and the OpenCode Go provider invariant | On | On | -| `tools` | mise harnesses, gh, uv, updater environment, harness update task; on macOS, `mbx` Cargo wrapper and `hidden-display` helper | On | On | +| `tools` | mise harnesses, gh, uv, `mbx` Cargo wrapper (except Intel macOS), updater environment, harness update task; on macOS, `hidden-display` helper | On | On | | `runtimes` | Global Node LTS, Python 3.12, Python environment and Rust version-file settings | On | Off | | `tools-re` | REA CLI, Ghidra on macOS, and local skill when `agents` is enabled | Off | Off | | `shell` | Bash/Zsh/Fish/PowerShell startup files and shared shell environment | On | Off | @@ -108,12 +108,12 @@ Earlier versions documented global REA registration. On a machine that used it, The REA version belongs in `dotfiles.pins.rea` in `.chezmoidata.toml`; `harness:update` leaves it pinned. Ghidra follows Homebrew's formula. REA 6.8.0 accepts only Ghidra 12.1.x, while Homebrew supplies 12.2. Direct Ghidra analysis remains available; the local skill uses that route when REA rejects the installed version. A newer REA release can be tested and pinned when published. See the [released provider requirements](https://github.com/morluto/rea/blob/rea-agents-6.8.0/docs/installation.md#ghidra). -## macOS tools (`mbx` and `hidden-display`) +## Extra tools (`mbx` and `hidden-display`) -On macOS, the `tools` module also deploys two platform-specific helpers (ignored on Linux and Windows): +The `tools` module also deploys two helpers alongside the core harnesses: -- **Mr. Boxington (`~/.config/mise/conf.d/mbx.toml`, Apple Silicon macOS):** pins `mr-boxington` in `.chezmoidata.toml`, sets `MBX_CACHE_DIR` to `~/Library/Caches/mbx` with a `100GiB` soft budget (`MBX_GC_MAX_TOTAL_SIZE`), and adds a `[wrappers.cargo]` command wrapper (`MBX_CARGO_SHIM_MODE=1`) so plain `cargo` runs share APFS copy-on-write build outputs across worktrees. Projects that set `CARGO_TARGET_DIR`, `--target-dir`, or `build.target-dir` keep their own target directory; `build.build-dir` is also left intact (with the check lane disabled). Bypass `mbx` for one command with `MBX_DISABLE=1 cargo ...`. After enabling or updating it without bootstrap, run `mise install && mise reshim`. Note that `[env]` settings apply to shells with mise active, mise shims/wrappers, and `mise exec`; direct non-mise `mbx` calls and `rust-analyzer` use `mbx`'s own settings (`mbx settings set gc.max_total_size 100GiB` / `mbx setup`) unless configured separately. -- **Shared hidden display (`~/.local/bin/hidden-display`):** compiled from `~/.local/share/hidden-display/hidden-display.m` by bootstrap step 7 (or manually with `mkdir -p ~/.local/bin && clang -Wall -Wextra -fobjc-arc -framework Foundation -framework CoreGraphics ~/.local/share/hidden-display/hidden-display.m -o ~/.local/bin/hidden-display`). Keeps one per-user virtual display alive across GUI test runs (`hidden-display ensure|status|stop`); the `gui-testing` skill documents when and how agents use it. +- **Mr. Boxington (`~/.config/mise/conf.d/mbx.toml`):** deployed on Apple Silicon macOS, Linux, and Windows (skipped on Intel macOS, where `mr-boxington` has no release binary). Pins `mr-boxington` in `.chezmoidata.toml`, sets a `100GiB` soft budget (`MBX_GC_MAX_TOTAL_SIZE`), uses `mbx`'s native per-OS cache directory (`~/Library/Caches/mbx`, `~/.cache/mbx`, `%LOCALAPPDATA%\mbx`), and adds a `[wrappers.cargo]` command wrapper (`MBX_CARGO_SHIM_MODE=1`) so plain `cargo` runs share cached compilations and copy-on-write outputs on APFS, Btrfs, XFS, or ReFS Dev Drive (hard links on ext4; copies on plain NTFS; managed `target` symlinks on Windows use Developer Mode). Projects that set `CARGO_TARGET_DIR`, `--target-dir`, or `build.target-dir` keep their own target directory; `build.build-dir` is also left intact (with the check lane disabled). Bypass `mbx` for one command with `MBX_DISABLE=1 cargo ...` (or `$env:MBX_DISABLE="1"; try { cargo ... } finally { Remove-Item Env:MBX_DISABLE }` in PowerShell). After enabling or updating without bootstrap, run `mise install && mise reshim`. Note that `[env]` settings apply to shells with mise active, mise shims/wrappers, and `mise exec`; direct non-mise `mbx` calls and `rust-analyzer` use `mbx`'s own settings (`mbx settings set gc.max_total_size 100GiB` / `mbx setup`) unless configured separately. +- **Shared hidden display (`~/.local/bin/hidden-display`, macOS only):** compiled from `~/.local/share/hidden-display/hidden-display.m` by bootstrap step 7 (or manually with `mkdir -p ~/.local/bin && clang -Wall -Wextra -fobjc-arc -framework Foundation -framework CoreGraphics ~/.local/share/hidden-display/hidden-display.m -o ~/.local/bin/hidden-display`). Keeps one per-user virtual display alive across GUI test runs (`hidden-display ensure|status|stop`); the `gui-testing` skill documents when and how agents use it. ## Extending the repo diff --git a/home/.chezmoidata.toml b/home/.chezmoidata.toml index 49684fb..6d7c9aa 100644 --- a/home/.chezmoidata.toml +++ b/home/.chezmoidata.toml @@ -115,7 +115,6 @@ darwin = [ ".config/iterm2", ".config/iterm2/**", ".config/mise/conf.d/github-public-ro.toml", - ".config/mise/conf.d/mbx.toml", ".local/share/hidden-display", ".local/share/hidden-display/**", ] @@ -148,5 +147,5 @@ ghStack = "v0.2.0" ghStackCommit = "d4ab7ab47e5b3e3708a27c8c42abcdf4bc321419" # REA is an optional analysis driver; its workflow skill is maintained locally. rea = "6.8.0" -# Mr. Boxington (`mbx`) for APFS-backed shared Rust build caching on macOS. +# Mr. Boxington (`mbx`) for shared Rust build caching across worktrees. mrBoxington = "1.30.0" diff --git a/home/.chezmoiscripts/run_onchange_after_02-install-mise-tools.ps1.tmpl b/home/.chezmoiscripts/run_onchange_after_02-install-mise-tools.ps1.tmpl index cb45c49..0778624 100644 --- a/home/.chezmoiscripts/run_onchange_after_02-install-mise-tools.ps1.tmpl +++ b/home/.chezmoiscripts/run_onchange_after_02-install-mise-tools.ps1.tmpl @@ -1,5 +1,6 @@ {{- if and .bootstrap .modules.tools (eq .chezmoi.os "windows") -}} # hash: {{ includeTemplate "mise/config.toml" . | sha256sum }} +# mbx: {{ .dotfiles.pins.mrBoxington }} {{ include "dot_config/mise/conf.d/mbx.toml.tmpl" | sha256sum }} # Pick up PATH entries a fresh winget install added, keeping the session PATH $env:Path = $env:Path + ";" + [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User") @@ -15,12 +16,38 @@ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } -# Add mise shims to persistent user PATH so non-shell programs (e.g. VS Code) can find tools. -# This is the Windows equivalent of adding shims to PATH in .zprofile on macOS. +mise reshim +if ($LASTEXITCODE -ne 0) { + Write-Error "mise reshim failed with exit code $LASTEXITCODE" + exit $LASTEXITCODE +} + +# Add mise command wrappers and shims to persistent user PATH so non-shell programs +# (e.g. VS Code, coding agents) resolve wrapped tools like `cargo` through mise. $shimDir = Join-Path $env:LOCALAPPDATA "mise\shims" +$wrapperDir = Join-Path $env:LOCALAPPDATA "mise\command-wrappers\bin" $userPath = [System.Environment]::GetEnvironmentVariable("Path", "User") -if ($userPath -notlike "*$shimDir*") { - [System.Environment]::SetEnvironmentVariable("Path", "$shimDir;$userPath", "User") - Write-Host "Added mise shims to user PATH: $shimDir" +$entries = @() +if ($userPath) { + $entries = @($userPath -split ';' | Where-Object { $_ -ne '' }) +} +$updated = $false +if (-not ($entries -icontains $shimDir)) { + $entries = @($shimDir) + $entries + $updated = $true +} +$wrapperIdx = -1 +$shimIdx = -1 +for ($i = 0; $i -lt $entries.Count; $i++) { + if ($wrapperIdx -lt 0 -and $entries[$i] -ieq $wrapperDir) { $wrapperIdx = $i } + if ($shimIdx -lt 0 -and $entries[$i] -ieq $shimDir) { $shimIdx = $i } +} +if ($wrapperIdx -lt 0 -or $wrapperIdx -gt $shimIdx) { + $entries = @($wrapperDir) + @($entries | Where-Object { $_ -ine $wrapperDir }) + $updated = $true +} +if ($updated) { + [System.Environment]::SetEnvironmentVariable("Path", ($entries -join ';'), "User") + Write-Host "Updated user PATH for mise command wrappers and shims." } {{- end }} diff --git a/home/.chezmoiscripts/run_onchange_after_02-install-mise-tools.sh.tmpl b/home/.chezmoiscripts/run_onchange_after_02-install-mise-tools.sh.tmpl index 0559969..8d1ba9a 100644 --- a/home/.chezmoiscripts/run_onchange_after_02-install-mise-tools.sh.tmpl +++ b/home/.chezmoiscripts/run_onchange_after_02-install-mise-tools.sh.tmpl @@ -3,7 +3,7 @@ set -euo pipefail # hash: {{ includeTemplate "mise/config.toml" . | sha256sum }} -{{- if and (eq .chezmoi.os "darwin") (eq .chezmoi.arch "arm64") }} +{{- if not (and (eq .chezmoi.os "darwin") (ne .chezmoi.arch "arm64")) }} # mbx: {{ .dotfiles.pins.mrBoxington }} {{ include "dot_config/mise/conf.d/mbx.toml.tmpl" | sha256sum }} {{- end }} diff --git a/home/Documents/WindowsPowerShell/profile.ps1 b/home/Documents/WindowsPowerShell/profile.ps1 index be46090..84da31e 100644 --- a/home/Documents/WindowsPowerShell/profile.ps1 +++ b/home/Documents/WindowsPowerShell/profile.ps1 @@ -1,11 +1,11 @@ -# Add ~/.local/bin to PATH -$localBin = Join-Path $HOME ".local\bin" -if (-not (($env:PATH -split ';') -icontains $localBin)) { - $env:PATH = "$localBin;$env:PATH" -} - -# mise (shims only — mise activate does not support Windows PowerShell 5.1) +# mise (shims + command wrappers — mise activate does not support Windows PowerShell 5.1) +# Prepend low-to-high so precedence is: ~/.local/bin > command-wrappers\bin > shims. $miseShims = Join-Path $HOME "AppData\Local\mise\shims" -if (-not (($env:PATH -split ';') -icontains $miseShims)) { - $env:PATH = "$miseShims;$env:PATH" +$miseWrappers = Join-Path $HOME "AppData\Local\mise\command-wrappers\bin" +$localBin = Join-Path $HOME ".local\bin" +foreach ($dir in @($miseShims, $miseWrappers, $localBin)) { + if (Test-Path $dir) { + $rest = ($env:PATH -split ';') | Where-Object { $_ -ne '' -and $_ -ine $dir } + $env:PATH = (@($dir) + $rest) -join ';' + } } diff --git a/home/dot_config/fish/config.fish b/home/dot_config/fish/config.fish index 932cba4..3f19ebe 100644 --- a/home/dot_config/fish/config.fish +++ b/home/dot_config/fish/config.fish @@ -12,7 +12,7 @@ for brew_bin in /opt/homebrew/bin/brew /home/linuxbrew/.linuxbrew/bin/brew $HOME end # Add ~/.cargo/bin (rustup proxies + `cargo install` bins) BEFORE `mise activate` so -# mise-managed toolchains and command wrappers (e.g. `mbx` for `cargo` on macOS) stay +# mise-managed toolchains and command wrappers (e.g. `mbx` for `cargo`) stay # ahead of ~/.cargo/bin in both interactive and non-interactive fish shells. Use --move # so inherited PATH entries still land in deterministic order; add ~/.local/bin last # so it stays highest priority. diff --git a/home/dot_config/mise/conf.d/mbx.toml.tmpl b/home/dot_config/mise/conf.d/mbx.toml.tmpl index 7db3560..90dd578 100644 --- a/home/dot_config/mise/conf.d/mbx.toml.tmpl +++ b/home/dot_config/mise/conf.d/mbx.toml.tmpl @@ -1,18 +1,20 @@ -{{- if and (eq .chezmoi.os "darwin") (eq .chezmoi.arch "arm64") -}} -# Route plain `cargo` calls through Mr. Boxington (`mbx`) on Apple Silicon macOS -# so per-worktree Rust builds share APFS copy-on-write blocks under a bounded -# cache budget. Projects that set CARGO_TARGET_DIR, --target-dir, or -# build.target-dir keep their own target directory; build.build-dir is also -# preserved (without the check lane). +{{- if not (and (eq .chezmoi.os "darwin") (ne .chezmoi.arch "arm64")) -}} +# Route plain `cargo` calls through Mr. Boxington (`mbx`) so per-worktree Rust +# builds share cached compilations and copy-on-write outputs (APFS, Btrfs, XFS, +# ReFS Dev Drive) under a bounded cache budget. Uses mbx's native per-OS cache +# directory (`~/Library/Caches/mbx`, `~/.cache/mbx`, `%LOCALAPPDATA%\mbx`). +# Projects that set CARGO_TARGET_DIR, --target-dir, or build.target-dir keep +# their own target directory; build.build-dir is also preserved (without the +# check lane). # # Bypass for one command: -# MBX_DISABLE=1 cargo build +# POSIX: MBX_DISABLE=1 cargo build +# PowerShell: $env:MBX_DISABLE="1"; try { cargo build } finally { Remove-Item Env:MBX_DISABLE } [tools] mr-boxington = "{{ .dotfiles.pins.mrBoxington }}" [env] -MBX_CACHE_DIR = "{{ `{{ env.HOME }}` }}/Library/Caches/mbx" MBX_GC_MAX_TOTAL_SIZE = "100GiB" [wrappers.cargo] diff --git a/home/dot_config/shell/env.sh b/home/dot_config/shell/env.sh index 42c8470..2eae404 100644 --- a/home/dot_config/shell/env.sh +++ b/home/dot_config/shell/env.sh @@ -42,7 +42,7 @@ unset _brew # Precedence (highest first): ~/.local/bin > mise command-wrappers > mise shims > cargo > brew > system. # Listed low-to-high because path_prepend moves each to the front. # -# Rust: cargo/rustc resolve via mise's command-wrappers (when configured, e.g. mbx on macOS) +# Rust: cargo/rustc resolve via mise's command-wrappers (when configured, e.g. mbx) # and shims. mise's rust backend delegates to rustup, so ~/.cargo/bin holds rustup's proxies # (cargo -> rustup, ...) plus `cargo install` binaries — kept below mise so wrappers and # per-repo rust-toolchain.toml switching stay authoritative. (We deliberately don't source diff --git a/tests/test_profiles.py b/tests/test_profiles.py index 98f1300..23072c1 100644 --- a/tests/test_profiles.py +++ b/tests/test_profiles.py @@ -585,10 +585,11 @@ def test_gui_testing_skill_is_deployed_to_all_harnesses(self): for harness in [".claude/skills", ".codex/skills", ".pi/agent/skills"]: self.assertEqual((self.home / harness / "gui-testing").resolve(), skill.resolve()) - def test_mbx_and_hidden_display_are_scoped_to_macos_tools(self): + def test_mbx_and_hidden_display_scoping(self): pin = tomllib.loads((ROOT / "home/.chezmoidata.toml").read_text())["dotfiles"]["pins"]["mrBoxington"] build_script = ROOT / "home/.chezmoiscripts/run_onchange_after_07-install-hidden-display-darwin.sh.tmpl" - mise_script = ROOT / "home/.chezmoiscripts/run_onchange_after_02-install-mise-tools.sh.tmpl" + mise_sh_script = ROOT / "home/.chezmoiscripts/run_onchange_after_02-install-mise-tools.sh.tmpl" + mise_ps1_script = ROOT / "home/.chezmoiscripts/run_onchange_after_02-install-mise-tools.ps1.tmpl" targets = [ ("darwin", "arm64"), ("darwin", "amd64"), @@ -607,7 +608,7 @@ def test_mbx_and_hidden_display_are_scoped_to_macos_tools(self): ) managed = self.chezmoi("managed").stdout.splitlines() expect_darwin = platform == "darwin" and tools_enabled - expect_mbx = expect_darwin and arch == "arm64" + expect_mbx = tools_enabled and not (platform == "darwin" and arch != "arm64") self.assertEqual(".config/mise/conf.d/mbx.toml" in managed, expect_mbx) self.assertEqual(".local/share/hidden-display/hidden-display.m" in managed, expect_darwin) self.assertNotIn(".local/bin", managed) @@ -621,26 +622,31 @@ def test_mbx_and_hidden_display_are_scoped_to_macos_tools(self): mbx_body = self.chezmoi("cat", str(self.home / ".config/mise/conf.d/mbx.toml")).stdout mbx_cfg = tomllib.loads(mbx_body) self.assertEqual(mbx_cfg["tools"]["mr-boxington"], pin) - self.assertEqual(mbx_cfg["env"]["MBX_CACHE_DIR"], "{{ env.HOME }}/Library/Caches/mbx") + self.assertNotIn("MBX_CACHE_DIR", mbx_cfg["env"]) self.assertEqual(mbx_cfg["env"]["MBX_GC_MAX_TOTAL_SIZE"], "100GiB") self.assertEqual( mbx_cfg["wrappers"]["cargo"], {"command": "mbx", "env": {"MBX_CARGO_SHIM_MODE": "1"}}, ) - rendered_mise = self.chezmoi("execute-template", "-f", str(mise_script)).stdout if platform != "windows" and tools_enabled: + rendered_mise = self.chezmoi("execute-template", "-f", str(mise_sh_script)).stdout self.assertIn("mise install", rendered_mise) self.assertIn("mise reshim", rendered_mise) self.assertEqual("# mbx:" in rendered_mise, expect_mbx) - # Windows with runtimes and tools keeps .local/bin/python3.cmd without .local/share. + if platform == "windows" and tools_enabled: + rendered_ps1 = self.chezmoi("execute-template", "-f", str(mise_ps1_script)).stdout + self.assertIn("# mbx:", rendered_ps1) + self.assertIn("mise reshim", rendered_ps1) + self.assertIn(r"mise\command-wrappers\bin", rendered_ps1) + # Windows with runtimes and tools keeps .local/bin/python3.cmd and mbx.toml without .local/share. self.platform = "windows" self.arch = "amd64" self.configure("standalone", bootstrap=False, modules={"tools": True, "runtimes": True}) win_managed = self.chezmoi("managed").stdout.splitlines() self.assertIn(".local/bin/python3.cmd", win_managed) + self.assertIn(".config/mise/conf.d/mbx.toml", win_managed) self.assertNotIn(".local/share", win_managed) self.assertNotIn(".local/share/hidden-display/hidden-display.m", win_managed) - self.assertNotIn(".config/mise/conf.d/mbx.toml", win_managed) def test_hidden_display_build_script_installs_into_local_bin(self): self.platform = "darwin"