Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ env:

jobs:
test:
name: Test on ${{ matrix.os }}
name: Test (${{ matrix.os }}, minimal=${{ matrix.minimal }})
Copy link
Copy Markdown
Author

@theHamsta theHamsta May 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made separate tags to have on env with and one without protoc (needing protoc in CI env is a pitfall for someone trying to use webnn-graph)

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
minimal: [true, false]
env:
CARGO_FLAGS: ${{ matrix.minimal && '--no-default-features' || '' }}

steps:
- name: Checkout code
Expand All @@ -29,42 +32,42 @@ jobs:
components: rustfmt, clippy

- name: Install protoc (Linux)
if: runner.os == 'Linux'
if: ${{ runner.os == 'Linux' && !matrix.minimal }}
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler

- name: Install protoc (macOS)
if: runner.os == 'macOS'
if: ${{ runner.os == 'macOS' && !matrix.minimal }}
run: brew install protobuf

- name: Install protoc (Windows)
if: runner.os == 'Windows'
if: ${{ runner.os == 'Windows' && !matrix.minimal }}
run: choco install protoc

- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-${{ matrix.minimal }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
${{ runner.os }}-${{ matrix.minimal }}-cargo-registry-

- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-${{ matrix.minimal }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-git-
${{ runner.os }}-${{ matrix.minimal }}-cargo-git-

- name: Cache target directory
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-target-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-${{ matrix.minimal }}-target-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-target-
${{ runner.os }}-${{ matrix.minimal }}-target-

- name: Check formatting
run: make fmt-check
Expand Down
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ path = "src/lib.rs"
name = "webnn-graph"
path = "src/main.rs"

[features]
default = ["onnx"]
onnx = ["dep:webnn-onnx-utils"]

[dependencies]
anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -25,7 +29,7 @@ pest_derive = "2.7"
clap = { version = "4.5", features = ["derive"] }
base64 = "0.22"
prost = "0.12"
webnn-onnx-utils = { git = "https://github.com/rustnn/webnn-onnx-utils", branch = "main" }
webnn-onnx-utils = { git = "https://github.com/rustnn/webnn-onnx-utils", branch = "main", optional = true }

[dev-dependencies]
tempfile = "3.8"
34 changes: 20 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
.PHONY: all build test fmt clean run check lint help parse validate emit-js emit-html coverage
.PHONY: all build test fmt clean run check lint help parse validate emit-js emit-html coverage minimal

CARGO_FLAGS ?=

# Default target
all: build

# Build the project
build:
cargo build
cargo build $(CARGO_FLAGS)

# Build with --no-default-features
minimal:
cargo build --no-default-features

# Build with release optimizations
release:
cargo build --release
cargo build --release $(CARGO_FLAGS)

# Run all tests
test:
cargo test
cargo test $(CARGO_FLAGS)

# Run tests with output
test-verbose:
cargo test -- --nocapture
cargo test $(CARGO_FLAGS) -- --nocapture

# Format code
fmt:
Expand All @@ -29,37 +35,37 @@ fmt-check:

# Run clippy linter
lint:
cargo clippy -- -D warnings
cargo clippy $(CARGO_FLAGS) -- -D warnings

# Quick compile check without building
check:
cargo check
cargo check $(CARGO_FLAGS)

# Clean build artifacts
clean:
cargo clean

# Run the CLI tool (parse example)
run:
cargo run --bin webnn-graph -- parse examples/resnet_head.webnn
cargo run $(CARGO_FLAGS) --bin webnn-graph -- parse examples/resnet_head.webnn

# Parse example graph
parse:
cargo run --bin webnn-graph -- parse examples/resnet_head.webnn
cargo run $(CARGO_FLAGS) --bin webnn-graph -- parse examples/resnet_head.webnn

# Validate example graph
validate:
cargo run --bin webnn-graph -- parse examples/resnet_head.webnn > /tmp/graph.json && \
cargo run --bin webnn-graph -- validate /tmp/graph.json --weights-manifest examples/weights.manifest.json
cargo run $(CARGO_FLAGS) --bin webnn-graph -- parse examples/resnet_head.webnn > /tmp/graph.json && \
cargo run $(CARGO_FLAGS) --bin webnn-graph -- validate /tmp/graph.json --weights-manifest examples/weights.manifest.json

# Emit JavaScript for example graph
emit-js:
cargo run --bin webnn-graph -- parse examples/resnet_head.webnn > /tmp/graph.json && \
cargo run --bin webnn-graph -- emit-js /tmp/graph.json
cargo run $(CARGO_FLAGS) --bin webnn-graph -- parse examples/resnet_head.webnn > /tmp/graph.json && \
cargo run $(CARGO_FLAGS) --bin webnn-graph -- emit-js /tmp/graph.json

# Generate HTML visualizer for example graph
emit-html:
cargo run --bin webnn-graph -- emit-html examples/resnet_head.webnn > /tmp/webnn_viz.html
cargo run $(CARGO_FLAGS) --bin webnn-graph -- emit-html examples/resnet_head.webnn > /tmp/webnn_viz.html
@echo "Visualizer generated: /tmp/webnn_viz.html"
@echo "Open it with: open /tmp/webnn_viz.html"

Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ pub use external_weights::{resolve_external_weights, WeightResolveError};

pub mod emit_html;
pub mod emit_js;
pub mod onnx;
pub mod parser;
pub mod protos;
pub mod serialize;
pub mod validate;
pub mod weights;
pub mod weights_io;

#[cfg(feature = "onnx")]
pub mod onnx;
#[cfg(feature = "onnx")]
pub mod protos;
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use clap::{Parser, Subcommand};
use std::fs;
#[cfg(feature = "onnx")]
use std::path::Path;

use webnn_graph::ast::GraphJson;
use webnn_graph::emit_html::emit_html;
use webnn_graph::emit_js::{emit_builder_js, emit_weights_loader_js};
#[cfg(feature = "onnx")]
use webnn_graph::onnx::convert::{convert_onnx, ConvertOptions};
use webnn_graph::parser::parse_wg_text;
use webnn_graph::serialize::serialize_graph_to_wg_text;
Expand Down Expand Up @@ -94,6 +96,7 @@ enum Command {
#[arg(long)]
output: String,
},
#[cfg(feature = "onnx")]
ConvertOnnx {
/// Input ONNX model file (.onnx)
#[arg(long)]
Expand Down Expand Up @@ -256,6 +259,7 @@ fn main() -> anyhow::Result<()> {
fs::write(&output, json)?;
eprintln!("Wrote graph with inline weights to: {}", output);
}
#[cfg(feature = "onnx")]
Command::ConvertOnnx {
input,
output,
Expand Down
Loading