Skip to content

Commit d5e547b

Browse files
committed
deps: make ONNX support optional
1 parent 4dd1ec6 commit d5e547b

4 files changed

Lines changed: 46 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ path = "src/lib.rs"
1313
name = "webnn-graph"
1414
path = "src/main.rs"
1515

16+
[features]
17+
default = ["onnx"]
18+
onnx = ["dep:webnn-onnx-utils"]
19+
1620
[dependencies]
1721
anyhow = "1.0"
1822
serde = { version = "1.0", features = ["derive"] }
@@ -25,7 +29,7 @@ pest_derive = "2.7"
2529
clap = { version = "4.5", features = ["derive"] }
2630
base64 = "0.22"
2731
prost = "0.12"
28-
webnn-onnx-utils = { git = "https://github.com/rustnn/webnn-onnx-utils", branch = "main" }
32+
webnn-onnx-utils = { git = "https://github.com/rustnn/webnn-onnx-utils", branch = "main", optional = true }
2933

3034
[dev-dependencies]
3135
tempfile = "3.8"

src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ pub use external_weights::{resolve_external_weights, WeightResolveError};
55

66
pub mod emit_html;
77
pub mod emit_js;
8-
pub mod onnx;
98
pub mod parser;
10-
pub mod protos;
119
pub mod serialize;
1210
pub mod validate;
1311
pub mod weights;
1412
pub mod weights_io;
13+
14+
#[cfg(feature = "onnx")]
15+
pub mod onnx;
16+
#[cfg(feature = "onnx")]
17+
pub mod protos;

src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use clap::{Parser, Subcommand};
22
use std::fs;
3+
#[cfg(feature = "onnx")]
34
use std::path::Path;
45

56
use webnn_graph::ast::GraphJson;
67
use webnn_graph::emit_html::emit_html;
78
use webnn_graph::emit_js::{emit_builder_js, emit_weights_loader_js};
9+
#[cfg(feature = "onnx")]
810
use webnn_graph::onnx::convert::{convert_onnx, ConvertOptions};
911
use webnn_graph::parser::parse_wg_text;
1012
use webnn_graph::serialize::serialize_graph_to_wg_text;
@@ -94,6 +96,7 @@ enum Command {
9496
#[arg(long)]
9597
output: String,
9698
},
99+
#[cfg(feature = "onnx")]
97100
ConvertOnnx {
98101
/// Input ONNX model file (.onnx)
99102
#[arg(long)]
@@ -256,6 +259,7 @@ fn main() -> anyhow::Result<()> {
256259
fs::write(&output, json)?;
257260
eprintln!("Wrote graph with inline weights to: {}", output);
258261
}
262+
#[cfg(feature = "onnx")]
259263
Command::ConvertOnnx {
260264
input,
261265
output,

0 commit comments

Comments
 (0)