| name: Rust application | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - "crates/nsh-bundler/**" | |
| - "crates/nsh-cli/**" | |
| - "crates/nsh-core/**" | |
| - "crates/nsh-dev/**" | |
| - "crates/nsh-engine/**" | |
| - "crates/nsh-js/**" | |
| - "crates/nsh-macros/**" | |
| - "crates/nsh-base/**" | |
| - "crates/nsh-package/**" | |
| - "crates/nsh-platform-linux/**" | |
| - "crates/nsh-platform-macos/**" | |
| - "crates/nsh-platform-web/**" | |
| - "crates/nsh-platform-windows/**" | |
| - "crates/nsh-testing/**" | |
| - "examples/counter/**" | |
| - "examples/gallery/**" | |
| - "examples/gallery-rs/**" | |
| - "examples/rust-exports/**" | |
| - "Cargo.toml" | |
| - "Cargo.lock" | |
| - ".cargo/**" | |
| - "rust-toolchain.toml" | |
| - ".github/workflows/rust-app.yml" | |
| pull_request: | |
| paths: | |
| - "crates/nsh-bundler/**" | |
| - "crates/nsh-cli/**" | |
| - "crates/nsh-core/**" | |
| - "crates/nsh-dev/**" | |
| - "crates/nsh-engine/**" | |
| - "crates/nsh-js/**" | |
| - "crates/nsh-macros/**" | |
| - "crates/nsh-base/**" | |
| - "crates/nsh-package/**" | |
| - "crates/nsh-platform-linux/**" | |
| - "crates/nsh-platform-macos/**" | |
| - "crates/nsh-platform-web/**" | |
| - "crates/nsh-platform-windows/**" | |
| - "crates/nsh-testing/**" | |
| - "examples/counter/**" | |
| - "examples/gallery/**" | |
| - "examples/gallery-rs/**" | |
| - "examples/rust-exports/**" | |
| - "Cargo.toml" | |
| - "Cargo.lock" | |
| - ".cargo/**" | |
| - "rust-toolchain.toml" | |
| - ".github/workflows/rust-app.yml" | |
| merge_group: | |
| types: [checks_requested] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: rust-app-${{ github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| # CI builds each crate once: no incremental state and no debug info | |
| # (faster builds, smaller caches; panics still name their file and line). | |
| CARGO_INCREMENTAL: "0" | |
| CARGO_PROFILE_DEV_DEBUG: "0" | |
| # The toolchain file's iOS and Android targets are only the release's. | |
| RUSTUP_TOOLCHAIN: stable | |
| jobs: | |
| check: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-24.04, macos-15, windows-latest] | |
| runs-on: ${{ matrix.os }} | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up temporary files | |
| run: | | |
| mkdir -p "$RUNNER_TEMP/nsh-test-tmp" | |
| echo "TMPDIR=$RUNNER_TEMP/nsh-test-tmp" >> "$GITHUB_ENV" | |
| - name: Set up Windows compiler stack | |
| if: runner.os == 'Windows' | |
| run: echo "RUST_MIN_STACK=268435456" >> "$GITHUB_ENV" | |
| - name: Install GTK 4 | |
| if: runner.os == 'Linux' | |
| run: sudo apt-get update && sudo apt-get install -y libgtk-4-dev | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| components: clippy, rustfmt | |
| # Dependencies only: main's runs save it, pull requests restore it. | |
| - name: Cache Cargo | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| save-if: ${{ github.ref == 'refs/heads/main' }} | |
| - name: Clippy | |
| run: cargo clippy -p gallery-native --all-targets --locked -- -D warnings | |
| # The crate's unit tests; the app's tests are TypeScript (`nsh test`, | |
| # the web job). | |
| - name: Test the crate | |
| run: cargo test -p gallery-native --locked | |
| - name: Check the native dependency graph | |
| run: | | |
| cargo tree -p gallery-native --locked -e normal > "$RUNNER_TEMP/rust-app-dependencies.txt" | |
| if grep -E 'nsh-js |rquickjs|quickjs-jit' "$RUNNER_TEMP/rust-app-dependencies.txt"; then | |
| echo "The Rust executable unexpectedly links a JS runtime" | |
| exit 1 | |
| fi | |
| # The same crate compiled into the app's own web runtime: `nsh package | |
| # --target web` builds it for wasm32 and publishes the site. | |
| web: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up temporary files | |
| run: | | |
| mkdir -p "$RUNNER_TEMP/nsh-test-tmp" | |
| echo "TMPDIR=$RUNNER_TEMP/nsh-test-tmp" >> "$GITHUB_ENV" | |
| # QuickJS is C: bindgen needs libclang, its WebAssembly build clang | |
| # and llvm-ar. The describe program links the gallery's crate, | |
| # whose native entry (`cargo run`) uses GTK 4 on Linux. | |
| - name: Install clang, LLVM and GTK 4 | |
| run: sudo apt-get update && sudo apt-get install -y clang llvm libclang-dev libgtk-4-dev | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: wasm32-unknown-unknown | |
| # Dependencies only: main's runs save it, pull requests restore it. | |
| - name: Cache Cargo | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| save-if: ${{ github.ref == 'refs/heads/main' }} | |
| - name: Build the command line | |
| run: cargo build -p nsh-cli --locked | |
| - name: Publish the Rust gallery for the web | |
| run: | | |
| # nsh.json "root": a Rust app, mounted with no QuickJS. | |
| ./target/debug/nsh package examples/gallery-rs --target web -o target/rust-app-web | |
| site="target/rust-app-web/Rust Gallery" | |
| test -f "$site/index.html" | |
| # The app's runtime registers the crate's UI set and root. | |
| grep -q nsh_app_init "$site"/nsh.*.wasm | |
| grep -q nsh_start_rust "$site"/nsh.*.wasm | |
| if ls "$site"/app.*.nshc > /dev/null 2>&1 || grep -aq InternalError "$site"/nsh.*.wasm; then | |
| echo "The Rust app's web runtime unexpectedly carries JS" | |
| exit 1 | |
| fi | |
| - name: Test the Rust app and check that it builds no JS engine or bundler | |
| run: | | |
| # `nsh test` builds the app's programs in `.nsh/rust` and runs its | |
| # TypeScript tests (`examples/gallery-rs/*.test.tsx`) in the test | |
| # runner. `nsh` describes the app's crates with the generated | |
| # `describe` program: it links no QuickJS, nsh-js, bundler, | |
| # rolldown or Oxc. The test runner runs TypeScript tests (QuickJS, | |
| # source maps) on entries `nsh` builds: no bundler or parser. | |
| check() { | |
| cargo tree --manifest-path examples/gallery-rs/.nsh/rust/Cargo.toml \ | |
| -p "nsh-app-gallery-native-$1" -e normal --target all \ | |
| > "$RUNNER_TEMP/$1-dependencies.txt" | |
| if grep -E "$2" "$RUNNER_TEMP/$1-dependencies.txt"; then | |
| echo "The Rust app's $1 program unexpectedly links $3" | |
| exit 1 | |
| fi | |
| } | |
| ./target/debug/nsh test examples/gallery-rs | |
| check describe '(rquickjs|quickjs-jit|nsh-js|nsh-bundler|rolldown|oxc)([ _-]|$)' "a JS engine or the bundler" | |
| check test '(nsh-bundler|rolldown|oxc_parser)([ _-]|$)' "the bundler" | |
| - name: Run the examples' tests | |
| run: | | |
| for app in counter gallery rust-exports; do | |
| ./target/debug/nsh test "examples/$app" | |
| done | |
| # The same tests in the runner's Chrome, headless, with the browser's | |
| # trusted input (`nsh test --target web`): those a real platform runs | |
| # (real time). | |
| - name: Run the examples' tests in Chrome | |
| run: | | |
| ./target/debug/nsh test examples/counter --target web | |
| for file in device dock form gestures hover navigation network photos resizable shortcuts storage timers; do | |
| ./target/debug/nsh test "examples/gallery/tests/$file.test.tsx" --target web | |
| done | |
| ./target/debug/nsh test examples/gallery/tests/environment.test.tsx --target web --filter appearance | |
| # Apps with Rust crates, in their hosts' runtime: a TSX app and a | |
| # Rust app (its root). | |
| ./target/debug/nsh test examples/rust-exports --target web | |
| ./target/debug/nsh test examples/gallery-rs/App.test.tsx --target web | |
| - name: Publish a TSX app with a Rust crate for the web | |
| run: | | |
| # A TSX entry and the app's crate: QuickJS runs App.tsx, the | |
| # crate's set is compiled into the app's runtime. | |
| ./target/debug/nsh package examples/rust-exports --target web -o target/rust-exports-web | |
| site="target/rust-exports-web/Rust Exports" | |
| ls "$site"/app.*.nshc | |
| grep -q rust-exports/native "$site"/nsh.*.wasm |