Skip to content

Commit 198114e

Browse files
committed
Further clean up for windows
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
1 parent c36ca35 commit 198114e

10 files changed

Lines changed: 192 additions & 127 deletions

File tree

.copilot/skills/justfile-ci/SKILL.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This repo uses a **hierarchical Justfile** structure with a matching **GitHub Ac
1919
```
2020
Justfile (root) ← orchestrates everything
2121
├── mod wasm 'src/wasm_sandbox/Justfile'
22-
├── mod jssandbox 'src/javascript_sandbox/Justfile'
22+
├── mod js 'src/javascript_sandbox/Justfile'
2323
├── mod nanvix 'src/nanvix_sandbox/Justfile'
2424
├── mod python 'src/sdk/python/Justfile'
2525
└── mod examples_mod 'examples/Justfile'
@@ -99,3 +99,47 @@ test-rust:
9999
lint-rust:
100100
cargo clippy -p hyperlight-sandbox --all-targets --features test-utils -- -D warnings
101101
```
102+
103+
## Cross-Platform (Windows/Linux) Patterns
104+
105+
### Windows Shell
106+
- Add `set windows-shell := ["pwsh", "-NoLogo", "-Command"]` at the top of subproject Justfiles that need Windows support
107+
- Each recipe line is passed as a `-Command` argument; use `\` line continuations for multi-line PowerShell
108+
- Do NOT use `#!/usr/bin/env pwsh` shebangs — `just` writes temp files without `.ps1` extension and PowerShell refuses to run them
109+
110+
### Paths on Windows
111+
- `invocation_directory()` returns MSYS-style paths (`/c/Users/...`) when `just` is invoked with `set windows-shell` it breaks
112+
- Use `invocation_directory_native()` instead — always returns native OS paths (`C:\Users\...` on Windows, `/home/...` on Linux)
113+
- No `replace()` needed — PowerShell and cargo handle both `\` and `/`
114+
- Standard pattern: `repo-root := invocation_directory_native()`
115+
116+
### Environment Variables
117+
- Use `export WIT_WORLD := ...` instead of `WIT_WORLD=... command` prefix (bash-only syntax)
118+
- `export` is cross-platform and sets the env var for all recipes automatically
119+
120+
### Platform-Specific Recipes
121+
- Use `[unix]` and `[windows]` attributes for platform-specific recipe variants
122+
- Both variants must have the same recipe name; `just` picks the right one automatically
123+
- Prefix with `_` to hide helper recipes from `just --list`
124+
125+
```just
126+
[unix]
127+
_clean-stale:
128+
#!/usr/bin/env bash
129+
rm -rf some/path
130+
131+
[windows]
132+
_clean-stale:
133+
Remove-Item -Recurse -Force 'some/path' -ErrorAction SilentlyContinue
134+
```
135+
136+
### Bash → PowerShell Equivalents
137+
138+
| Bash | PowerShell |
139+
|------|------------|
140+
| `compgen -G "pattern"` | `Get-ChildItem -Path $dir -Filter 'pattern' -ErrorAction SilentlyContinue` |
141+
| `[ ! -f path ]` | `-not (Test-Path path)` |
142+
| `rm -rf path` | `Remove-Item -Recurse -Force path -ErrorAction SilentlyContinue` |
143+
| `echo "msg"` | `Write-Host 'msg'` |
144+
| `for x in a b; do ... done` | `foreach ($x in @('a','b')) { ... }` |
145+
| `command -v tool` | `Get-Command tool -ErrorAction SilentlyContinue` |

.copilot/skills/justfile-ci/references/architecture.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
| Recipe | Delegates to | Purpose |
66
|--------|-------------|---------|
7-
| `build-all` | `wasm::build`, `jssandbox::build`, `nanvix::build`, `python::build` | Build everything |
7+
| `build-all` | `wasm::build`, `jss::build`, `nanvix::build`, `python::build` | Build everything |
88
| `test` | `test-rust`, `wasm::test`, `python::python-test` | All tests |
99
| `test-rust` | (direct cargo) | Core crate unit + integration tests |
10-
| `lint` | `lint-rust`, `wasm::lint`, `jssandbox::lint`, `python::lint` | All linters |
10+
| `lint` | `lint-rust`, `wasm::lint`, `js::lint`, `python::lint` | All linters |
1111
| `fmt` | `fmt-rust`, `python::fmt` | Format all code |
1212
| `fmt-check` | `fmt-check-rust`, `python::fmt-check` | Check formatting |
13-
| `examples` | `wasm::examples`, `jssandbox::examples`, `python::examples` | Run all examples |
13+
| `examples` | `wasm::examples`, `js::examples`, `python::examples` | Run all examples |
1414
| `fuzz` | `python::python-fuzz` | Python fuzz tests |
1515
| `benchmark` | `python::python-sandbox-benchmark` | Python benchmark |
1616
| `clean` | `wasm::clean`, `python::clean` | Clean build artifacts |
@@ -21,7 +21,7 @@
2121
ci.yml
2222
├── rust — fmt-check-rust, lint-rust, test-rust
2323
├── wasm-sandbox — wasm build, lint, test, examples + python fmt-check/lint/build/examples/python-test/fuzz/benchmark/integration-examples
24-
├── javascript-sandbox — jssandbox build, lint, test, examples
24+
├── javascript-sandbox — js build, lint, test, examples
2525
└── nanvix-sandbox — nanvix build (examples skipped pending upstream)
2626
```
2727

@@ -34,7 +34,7 @@ ci.yml
3434
- Recipes: `guest-build`, `js-guest-build`, `build`, `test`, `examples`, `lint`, `clean`
3535
- `examples` is a flat recipe listing all `cargo run` commands (no per-example sub-recipes)
3636

37-
### jssandbox (`src/javascript_sandbox/Justfile`)
37+
### js (`src/javascript_sandbox/Justfile`)
3838
- Needs WIT world from wasm for compilation
3939
- Recipes: `build`, `test`, `examples`, `lint`
4040
- `examples` is a flat recipe listing all `cargo run` commands

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
- When running examples in this repository, use the `Justfile` recipes instead of invoking `cargo run` or `python` directly.
44
- Use `just examples` from the repository root to run the full example suite.
5-
- To run examples for a specific sandbox, use module-scoped recipes: `just wasm examples`, `just jssandbox examples`, `just python examples`.
5+
- To run examples for a specific sandbox, use module-scoped recipes: `just wasm examples`, `just js examples`, `just python examples`.
66
- Use `just build-all` from the repository root to build all subprojects and SDKs.
77
- Reason: the example commands depend on `WIT_WORLD` being set to `src/wasm_sandbox/wit/sandbox-world.wasm`; the `Justfile` handles that setup.
88

.github/workflows/ci.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
# Build JS sandbox first — the Python hyperlight-js backend shares the root
104104
# workspace target/ and needs hyperlight-js-runtime to be compiled.
105105
- name: Build JS sandbox
106-
run: just jssandbox build
106+
run: just js build
107107

108108
- name: Python SDK Format check
109109
run: just python fmt-check
@@ -137,6 +137,9 @@ jobs:
137137
python-wheelhouse:
138138
name: Python SDK wheelhouse test (${{ matrix.os }})
139139
runs-on: ${{ matrix.os }}
140+
strategy:
141+
matrix:
142+
os: [ubuntu-latest, windows-latest]
140143
steps:
141144
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
142145

@@ -215,16 +218,16 @@ jobs:
215218
run: just wasm guest-compile-wit
216219

217220
- name: Build
218-
run: just jssandbox build
221+
run: just js build
219222

220223
- name: Lint
221-
run: just jssandbox lint
224+
run: just js lint
222225

223226
- name: Tests
224-
run: just jssandbox test
227+
run: just js test
225228

226229
- name: Run examples
227-
run: just jssandbox examples
230+
run: just js examples
228231

229232
nanvix-sandbox:
230233
name: Nanvix Sandbox · build

Justfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set unstable := true
22

33
mod wasm 'src/wasm_sandbox/Justfile'
4-
mod jssandbox 'src/javascript_sandbox/Justfile'
4+
mod js 'src/javascript_sandbox/Justfile'
55
mod nanvix 'src/nanvix_sandbox/Justfile'
66
mod python 'src/sdk/python/Justfile'
77
mod examples_mod 'examples/Justfile'
@@ -13,9 +13,9 @@ clean: wasm::clean python::clean
1313

1414
#### BUILD TARGETS ####
1515

16-
build-all target=default-target: (wasm::build target) (jssandbox::build target) nanvix::build python::build
16+
build-all target=default-target: (wasm::build target) (js::build target) nanvix::build python::build
1717

18-
lint: lint-rust wasm::lint jssandbox::lint python::lint
18+
lint: lint-rust wasm::lint js::lint python::lint
1919

2020
lint-rust:
2121
cargo clippy -p hyperlight-sandbox --all-targets --features test-utils -- -D warnings
@@ -41,11 +41,11 @@ test-rust:
4141

4242
benchmark: python::python-sandbox-benchmark
4343

44-
python-dist: (wasm::build "release") (jssandbox::build "release") python::python-dist
44+
python-dist: (wasm::build "release") (js::build "release") python::python-dist
4545

4646
python-wheelhouse-test: python-dist python::python-wheelhouse-test
4747

48-
examples target=default-target: (wasm::examples target) (jssandbox::examples target) python::examples
48+
examples target=default-target: (wasm::examples target) (js::examples target) python::examples
4949

5050
integration-examples target=default-target: (wasm::guest-build target) wasm::js-guest-build python::build examples_mod::integration-examples
5151

@@ -60,6 +60,7 @@ slides:
6060

6161
##### Run GitHub Actions CI locally using act (https://nektosact.com) #######
6262

63+
[unix]
6364
ci job="":
6465
#!/usr/bin/env bash
6566
if ! command -v act &>/dev/null; then

examples/Justfile

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
repo-root := replace(invocation_directory(), "\\", "/")
2-
wit-world := "WIT_WORLD=" + repo-root + "/src/wasm_sandbox/wit/sandbox-world.wasm"
3-
1+
repo-root := invocation_directory_native()
42
integration-copilot-sdk-deps:
53
uv sync --group copilot-sdk --inexact --no-install-package hyperlight-sandbox-backend-wasm --no-install-package hyperlight-sandbox-backend-hyperlight-js
64

@@ -11,15 +9,15 @@ integration-agent-framework-devui-deps:
119
uv sync --group agent-framework-devui
1210

1311
copilot-sdk-example: integration-copilot-sdk-deps
14-
{{ wit-world }} uv run python {{repo-root}}/examples/copilot-sdk/copilot_sdk_tools.py
12+
uv run python {{repo-root}}/examples/copilot-sdk/copilot_sdk_tools.py
1513

1614
agent-framework-example: integration-agent-framework-deps
17-
{{ wit-world }} uv run python {{repo-root}}/examples/agent-framework/copilot_agent.py --no-wait
15+
uv run python {{repo-root}}/examples/agent-framework/copilot_agent.py --no-wait
1816

1917
agent-framework-example-interactive: integration-agent-framework-deps
20-
{{ wit-world }} uv run python {{repo-root}}/examples/agent-framework/copilot_agent.py --interactive
18+
uv run python {{repo-root}}/examples/agent-framework/copilot_agent.py --interactive
2119

2220
agent-framework-example-devui: integration-agent-framework-deps integration-agent-framework-devui-deps
23-
{{ wit-world }} uv run python {{repo-root}}/examples/agent-framework/copilot_agent.py --devui
21+
uv run python {{repo-root}}/examples/agent-framework/copilot_agent.py --devui
2422

2523
integration-examples: copilot-sdk-example agent-framework-example

src/javascript_sandbox/Justfile

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
set windows-shell := ["pwsh", "-NoLogo", "-Command"]
12
default-target := "debug"
2-
repo-root := replace(invocation_directory(), "\\", "/")
3-
wit-world := "WIT_WORLD=" + repo-root + "/src/wasm_sandbox/wit/sandbox-world.wasm"
3+
repo-root := invocation_directory_native()
44

5-
build target=default-target:
5+
# If cargo fingerprints exist but the runtime binary is missing, clean stale state
6+
# to force hyperlight-js's build script to re-run. This can happen when rust-cache
7+
# restores partial artifacts.
8+
[unix]
9+
_clean-stale:
610
#!/usr/bin/env bash
7-
# If cargo fingerprints exist but the runtime binary is missing, clean stale state
8-
# to force hyperlight-js's build script to re-run. This can happen when rust-cache
9-
# restores partial artifacts.
1011
for profile in debug release; do
1112
if compgen -G "{{repo-root}}/target/$profile/build/hyperlight-js-*" > /dev/null && \
1213
[ ! -f "{{repo-root}}/target/hyperlight-js-runtime/x86_64-hyperlight-none/$profile/hyperlight-js-runtime" ]; then
@@ -16,19 +17,38 @@ build target=default-target:
1617
{{repo-root}}/target/$profile/.fingerprint/hyperlight-js-*
1718
fi
1819
done
19-
{{ wit-world }} cargo build --manifest-path {{repo-root}}/src/javascript_sandbox/Cargo.toml --profile={{ if target == "debug" {"dev"} else { target } }}
20+
21+
[windows]
22+
_clean-stale:
23+
foreach ($profile in @('debug', 'release')) { \
24+
$bp = '{{repo-root}}/target/' + $profile + '/build'; \
25+
$rp = '{{repo-root}}/target/hyperlight-js-runtime/x86_64-hyperlight-none/' + $profile + '/hyperlight-js-runtime'; \
26+
if ((Get-ChildItem -Path $bp -Filter 'hyperlight-js-*' -ErrorAction SilentlyContinue) -and \
27+
-not (Test-Path $rp)) { \
28+
Write-Host ('Cleaning stale hyperlight-js ' + $profile + ' build artifacts...'); \
29+
Remove-Item -Recurse -Force '{{repo-root}}/target/hyperlight-js-runtime' -ErrorAction SilentlyContinue; \
30+
Get-ChildItem -Path $bp -Filter 'hyperlight-js-*' | Remove-Item -Recurse -Force; \
31+
$fp = '{{repo-root}}/target/' + $profile + '/.fingerprint'; \
32+
if (Test-Path $fp) { \
33+
Get-ChildItem -Path $fp -Filter 'hyperlight-js-*' | Remove-Item -Recurse -Force \
34+
} \
35+
} \
36+
}
37+
38+
build target=default-target: _clean-stale
39+
cargo build --manifest-path {{repo-root}}/src/javascript_sandbox/Cargo.toml --profile={{ if target == "debug" {"dev"} else { target } }}
2040

2141
#### EXAMPLES ####
2242

2343
examples target=default-target:
24-
{{ wit-world }} cargo run --manifest-path {{repo-root}}/src/javascript_sandbox/Cargo.toml --profile={{ if target == "debug" {"dev"} else { target } }} --example basics
25-
{{ wit-world }} cargo run --manifest-path {{repo-root}}/src/javascript_sandbox/Cargo.toml --profile={{ if target == "debug" {"dev"} else { target } }} --example network_demo
26-
{{ wit-world }} cargo run --manifest-path {{repo-root}}/src/javascript_sandbox/Cargo.toml --profile={{ if target == "debug" {"dev"} else { target } }} --example filesystem_demo
44+
cargo run --manifest-path {{repo-root}}/src/javascript_sandbox/Cargo.toml --profile={{ if target == "debug" {"dev"} else { target } }} --example basics
45+
cargo run --manifest-path {{repo-root}}/src/javascript_sandbox/Cargo.toml --profile={{ if target == "debug" {"dev"} else { target } }} --example network_demo
46+
cargo run --manifest-path {{repo-root}}/src/javascript_sandbox/Cargo.toml --profile={{ if target == "debug" {"dev"} else { target } }} --example filesystem_demo
2747

2848
#### TESTS ####
2949

3050
lint:
31-
{{ wit-world }} cargo clippy -p hyperlight-javascript-sandbox --all-targets -- -D warnings
51+
cargo clippy -p hyperlight-javascript-sandbox --all-targets -- -D warnings
3252

3353
test:
34-
{{ wit-world }} cargo test -p hyperlight-javascript-sandbox
54+
cargo test -p hyperlight-javascript-sandbox

src/nanvix_sandbox/Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
repo-root := replace(invocation_directory(), "\\", "/")
1+
repo-root := invocation_directory_native()
22
nanvix-rev := "f4bc205a40ed072cbb5f26b141498477985782f7"
33
skip-msg := "echo 'Skipping nanvix (not supported on Windows)'"
44

0 commit comments

Comments
 (0)