diff --git a/Cargo.lock b/Cargo.lock index c704367..1f43409 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -478,7 +478,7 @@ dependencies = [ [[package]] name = "componentize-py" -version = "0.19.0" +version = "0.19.1" dependencies = [ "anyhow", "assert_cmd", @@ -508,13 +508,13 @@ dependencies = [ "test-generator", "tokio", "toml 0.8.23", - "wasm-encoder 0.240.0 (git+https://github.com/dicej/wasm-tools?rev=b072b0ca)", - "wasmparser 0.240.0 (git+https://github.com/dicej/wasm-tools?rev=b072b0ca)", + "wasm-encoder 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50)", + "wasmparser 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50)", "wasmtime", "wasmtime-wasi", "wit-component 0.240.0", "wit-dylib", - "wit-parser 0.240.0 (git+https://github.com/dicej/wasm-tools?rev=b072b0ca)", + "wit-parser 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50)", "zstd", ] @@ -3132,19 +3132,19 @@ dependencies = [ [[package]] name = "wasm-encoder" version = "0.240.0" -source = "git+https://github.com/dicej/wasm-tools?rev=b072b0ca#b072b0caa8307779558d96a62bc9522abda6a7fb" +source = "git+https://github.com/bytecodealliance/wasm-tools?rev=b1d8ff59#b1d8ff591bcb8c052b54c3c17495bbbef401897c" dependencies = [ "leb128fmt", - "wasmparser 0.240.0 (git+https://github.com/dicej/wasm-tools?rev=b072b0ca)", + "wasmparser 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=b1d8ff59)", ] [[package]] name = "wasm-encoder" version = "0.240.0" -source = "git+https://github.com/bytecodealliance/wasm-tools?rev=b1d8ff59#b1d8ff591bcb8c052b54c3c17495bbbef401897c" +source = "git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50#fac9fb5065c9d4b3adc057fc83df67f49cf1687f" dependencies = [ "leb128fmt", - "wasmparser 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=b1d8ff59)", + "wasmparser 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50)", ] [[package]] @@ -3166,17 +3166,6 @@ dependencies = [ "wasmparser 0.227.1", ] -[[package]] -name = "wasm-metadata" -version = "0.240.0" -source = "git+https://github.com/dicej/wasm-tools?rev=b072b0ca#b072b0caa8307779558d96a62bc9522abda6a7fb" -dependencies = [ - "anyhow", - "indexmap", - "wasm-encoder 0.240.0 (git+https://github.com/dicej/wasm-tools?rev=b072b0ca)", - "wasmparser 0.240.0 (git+https://github.com/dicej/wasm-tools?rev=b072b0ca)", -] - [[package]] name = "wasm-metadata" version = "0.240.0" @@ -3195,6 +3184,17 @@ dependencies = [ "wasmparser 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=b1d8ff59)", ] +[[package]] +name = "wasm-metadata" +version = "0.240.0" +source = "git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50#fac9fb5065c9d4b3adc057fc83df67f49cf1687f" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50)", + "wasmparser 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50)", +] + [[package]] name = "wasmparser" version = "0.227.1" @@ -3223,7 +3223,7 @@ dependencies = [ [[package]] name = "wasmparser" version = "0.240.0" -source = "git+https://github.com/dicej/wasm-tools?rev=b072b0ca#b072b0caa8307779558d96a62bc9522abda6a7fb" +source = "git+https://github.com/bytecodealliance/wasm-tools?rev=b1d8ff59#b1d8ff591bcb8c052b54c3c17495bbbef401897c" dependencies = [ "bitflags", "hashbrown 0.15.5", @@ -3235,7 +3235,7 @@ dependencies = [ [[package]] name = "wasmparser" version = "0.240.0" -source = "git+https://github.com/bytecodealliance/wasm-tools?rev=b1d8ff59#b1d8ff591bcb8c052b54c3c17495bbbef401897c" +source = "git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50#fac9fb5065c9d4b3adc057fc83df67f49cf1687f" dependencies = [ "bitflags", "hashbrown 0.15.5", @@ -4024,7 +4024,7 @@ dependencies = [ [[package]] name = "wit-component" version = "0.240.0" -source = "git+https://github.com/dicej/wasm-tools?rev=b072b0ca#b072b0caa8307779558d96a62bc9522abda6a7fb" +source = "git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50#fac9fb5065c9d4b3adc057fc83df67f49cf1687f" dependencies = [ "anyhow", "bitflags", @@ -4033,21 +4033,21 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "wasm-encoder 0.240.0 (git+https://github.com/dicej/wasm-tools?rev=b072b0ca)", - "wasm-metadata 0.240.0 (git+https://github.com/dicej/wasm-tools?rev=b072b0ca)", - "wasmparser 0.240.0 (git+https://github.com/dicej/wasm-tools?rev=b072b0ca)", - "wit-parser 0.240.0 (git+https://github.com/dicej/wasm-tools?rev=b072b0ca)", + "wasm-encoder 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50)", + "wasm-metadata 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50)", + "wasmparser 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50)", + "wit-parser 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50)", ] [[package]] name = "wit-dylib" version = "0.240.0" -source = "git+https://github.com/dicej/wasm-tools?rev=b072b0ca#b072b0caa8307779558d96a62bc9522abda6a7fb" +source = "git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50#fac9fb5065c9d4b3adc057fc83df67f49cf1687f" dependencies = [ "anyhow", "indexmap", - "wasm-encoder 0.240.0 (git+https://github.com/dicej/wasm-tools?rev=b072b0ca)", - "wit-parser 0.240.0 (git+https://github.com/dicej/wasm-tools?rev=b072b0ca)", + "wasm-encoder 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50)", + "wit-parser 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50)", ] [[package]] @@ -4094,7 +4094,7 @@ dependencies = [ [[package]] name = "wit-parser" version = "0.240.0" -source = "git+https://github.com/dicej/wasm-tools?rev=b072b0ca#b072b0caa8307779558d96a62bc9522abda6a7fb" +source = "git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50#fac9fb5065c9d4b3adc057fc83df67f49cf1687f" dependencies = [ "anyhow", "id-arena", @@ -4105,7 +4105,7 @@ dependencies = [ "serde_derive", "serde_json", "unicode-xid", - "wasmparser 0.240.0 (git+https://github.com/dicej/wasm-tools?rev=b072b0ca)", + "wasmparser 0.240.0 (git+https://github.com/bytecodealliance/wasm-tools?rev=fac9fb50)", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index bc1561e..12ded49 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "componentize-py" -version = "0.19.0" +version = "0.19.1" edition = "2024" exclude = ["cpython"] @@ -15,11 +15,11 @@ tar = "0.4.42" tempfile = "3.13.0" zstd = "0.13.2" # TODO: switch to wasm-tools release once https://github.com/bytecodealliance/wasm-tools/pull/2367 has been merged and released -wasm-encoder = { git = "https://github.com/dicej/wasm-tools", rev = "b072b0ca" } -wit-dylib = { git = "https://github.com/dicej/wasm-tools", rev = "b072b0ca" } -wit-parser = { git = "https://github.com/dicej/wasm-tools", rev = "b072b0ca" } -wit-component = { git = "https://github.com/dicej/wasm-tools", rev = "b072b0ca" } -wasmparser = { git = "https://github.com/dicej/wasm-tools", rev = "b072b0ca" } +wasm-encoder = { git = "https://github.com/bytecodealliance/wasm-tools", rev = "fac9fb50", features = ["wasmparser"] } +wit-dylib = { git = "https://github.com/bytecodealliance/wasm-tools", rev = "fac9fb50" } +wit-parser = { git = "https://github.com/bytecodealliance/wasm-tools", rev = "fac9fb50" } +wit-component = { git = "https://github.com/bytecodealliance/wasm-tools", rev = "fac9fb50" } +wasmparser = { git = "https://github.com/bytecodealliance/wasm-tools", rev = "fac9fb50" } indexmap = "2.6.0" bincode = "1.3.3" heck = "0.5.0" diff --git a/examples/cli/README.md b/examples/cli/README.md index e2a9144..2aed9a1 100644 --- a/examples/cli/README.md +++ b/examples/cli/README.md @@ -10,7 +10,7 @@ run a Python-based component targetting the [wasi-cli] `command` world. ## Prerequisites * `Wasmtime` 38.0.0 or later -* `componentize-py` 0.19.0 +* `componentize-py` 0.19.1 Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If you don't have `cargo`, you can download and install from @@ -18,7 +18,7 @@ https://github.com/bytecodealliance/wasmtime/releases/tag/v38.0.0. ``` cargo install --version 38.0.0 wasmtime-cli -pip install componentize-py==0.19.0 +pip install componentize-py==0.19.1 ``` ## Running the demo diff --git a/examples/http-p3/README.md b/examples/http-p3/README.md index dabd7f6..e19d9c0 100644 --- a/examples/http-p3/README.md +++ b/examples/http-p3/README.md @@ -11,7 +11,7 @@ run a Python-based component targetting version `0.3.0-rc-2025-09-16` of the ## Prerequisites * `Wasmtime` 38.0.0 or later -* `componentize-py` 0.19.0 +* `componentize-py` 0.19.1 Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If you don't have `cargo`, you can download and install from @@ -19,7 +19,7 @@ https://github.com/bytecodealliance/wasmtime/releases/tag/v38.0.0. ``` cargo install --version 38.0.0 wasmtime-cli -pip install componentize-py==0.19.0 +pip install componentize-py==0.19.1 ``` ## Running the demo diff --git a/examples/http/README.md b/examples/http/README.md index 26895a8..82b753c 100644 --- a/examples/http/README.md +++ b/examples/http/README.md @@ -10,7 +10,7 @@ run a Python-based component targetting the [wasi-http] `proxy` world. ## Prerequisites * `Wasmtime` 38.0.0 or later -* `componentize-py` 0.19.0 +* `componentize-py` 0.19.1 Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If you don't have `cargo`, you can download and install from @@ -18,7 +18,7 @@ https://github.com/bytecodealliance/wasmtime/releases/tag/v38.0.0. ``` cargo install --version 38.0.0 wasmtime-cli -pip install componentize-py==0.19.0 +pip install componentize-py==0.19.1 ``` ## Running the demo diff --git a/examples/matrix-math/README.md b/examples/matrix-math/README.md index b09e4c0..82b8184 100644 --- a/examples/matrix-math/README.md +++ b/examples/matrix-math/README.md @@ -11,7 +11,7 @@ within a guest component. ## Prerequisites * `wasmtime` 38.0.0 or later -* `componentize-py` 0.19.0 +* `componentize-py` 0.19.1 * `NumPy`, built for WASI Note that we use an unofficial build of NumPy since the upstream project does @@ -23,7 +23,7 @@ https://github.com/bytecodealliance/wasmtime/releases/tag/v38.0.0. ``` cargo install --version 38.0.0 wasmtime-cli -pip install componentize-py==0.19.0 +pip install componentize-py==0.19.1 curl -OL https://github.com/dicej/wasi-wheels/releases/download/v0.0.2/numpy-wasi.tar.gz tar xf numpy-wasi.tar.gz ``` diff --git a/examples/sandbox/README.md b/examples/sandbox/README.md index b50a478..813372d 100644 --- a/examples/sandbox/README.md +++ b/examples/sandbox/README.md @@ -8,10 +8,10 @@ sandboxed Python code snippets from within a Python app. ## Prerequisites * `wasmtime-py` 38.0.0 or later -* `componentize-py` 0.19.0 +* `componentize-py` 0.19.1 ``` -pip install componentize-py==0.19.0 wasmtime==38.0.0 +pip install componentize-py==0.19.1 wasmtime==38.0.0 ``` ## Running the demo diff --git a/examples/tcp/README.md b/examples/tcp/README.md index 72ff412..f03a575 100644 --- a/examples/tcp/README.md +++ b/examples/tcp/README.md @@ -11,7 +11,7 @@ making an outbound TCP request using `wasi-sockets`. ## Prerequisites * `Wasmtime` 38.0.0 or later -* `componentize-py` 0.19.0 +* `componentize-py` 0.19.1 Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If you don't have `cargo`, you can download and install from @@ -19,7 +19,7 @@ https://github.com/bytecodealliance/wasmtime/releases/tag/v38.0.0. ``` cargo install --version 38.0.0 wasmtime-cli -pip install componentize-py==0.19.0 +pip install componentize-py==0.19.1 ``` ## Running the demo diff --git a/pyproject.toml b/pyproject.toml index 216ce83..10d3005 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ features = ["pyo3/extension-module"] [project] name = "componentize-py" -version = "0.19.0" +version = "0.19.1" description = "Tool to package Python applications as WebAssembly components" readme = "README.md" license = { file = "LICENSE" } diff --git a/src/lib.rs b/src/lib.rs index 9fd85c7..a25ddbc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,12 +12,15 @@ use { std::{ borrow::Cow, collections::HashMap, - fs, iter, + fs, + io::Cursor, + iter, ops::Deref, path::{Path, PathBuf}, str, }, summary::{Escape, Locations, Summary}, + tar::Archive, wasm_encoder::{CustomSection, Section as _}, wasmtime::{ Config, Engine, Store, @@ -33,6 +36,7 @@ use { CloneMaps, Package, PackageName, Resolve, Stability, TypeDefKind, UnresolvedPackageGroup, World, WorldId, WorldItem, WorldKey, }, + zstd::Decoder, }; pub mod command; @@ -219,6 +223,13 @@ pub fn generate_bindings( true, )?; + Archive::new(Decoder::new(Cursor::new(include_bytes!(concat!( + env!("OUT_DIR"), + "/bundled.tar.zst" + ))))?) + .unpack(output_dir) + .unwrap(); + Ok(()) } diff --git a/tests/bindings.rs b/tests/bindings.rs index f1b6c48..ead51be 100644 --- a/tests/bindings.rs +++ b/tests/bindings.rs @@ -14,7 +14,7 @@ use tar::Archive; fn lint_cli_bindings() -> anyhow::Result<()> { let dir = tempfile::tempdir()?; fs_extra::copy_items( - &["./examples/cli", "./wit", "./bundled"], + &["./examples/cli", "./wit"], dir.path(), &CopyOptions::new(), )?; @@ -24,7 +24,7 @@ fn lint_cli_bindings() -> anyhow::Result<()> { assert!(predicate::path::is_dir().eval(&path.join("wit_world"))); - mypy_check(&path, ["--strict", "."]); + mypy_check(&path, ["--strict", "-m", "app"]); Ok(()) } @@ -33,16 +33,17 @@ fn lint_cli_bindings() -> anyhow::Result<()> { fn lint_http_bindings() -> anyhow::Result<()> { let dir = tempfile::tempdir()?; fs_extra::copy_items( - &["./examples/http", "./wit", "./bundled"], + &["./examples/http", "./wit"], dir.path(), &CopyOptions::new(), )?; - // poll_loop.py has many errors that might not be worth adjusting at the moment, so ignore for now - fs::remove_file(dir.path().join("bundled/poll_loop.py")).unwrap(); let path = dir.path().join("http"); generate_bindings(&path, "wasi:http/proxy@0.2.0")?; + // poll_loop.py has many errors that might not be worth adjusting at the moment, so ignore for now + fs::remove_file(path.join("poll_loop.py")).unwrap(); + assert!(predicate::path::is_dir().eval(&path.join("wit_world"))); mypy_check( @@ -53,8 +54,6 @@ fn lint_http_bindings() -> anyhow::Result<()> { "--ignore-missing-imports", "-m", "app", - "-p", - "wit_world", ], ); @@ -65,7 +64,7 @@ fn lint_http_bindings() -> anyhow::Result<()> { fn lint_http_p3_bindings() -> anyhow::Result<()> { let dir = tempfile::tempdir()?; fs_extra::copy_items( - &["./examples/http-p3", "./wit", "./bundled"], + &["./examples/http-p3", "./wit"], dir.path(), &CopyOptions::new(), )?; @@ -77,7 +76,7 @@ fn lint_http_p3_bindings() -> anyhow::Result<()> { _ = dir.keep(); - mypy_check(&path, ["--strict", "-m", "app", "-p", "wit_world"]); + mypy_check(&path, ["--strict", "-m", "app"]); Ok(()) } @@ -86,7 +85,7 @@ fn lint_http_p3_bindings() -> anyhow::Result<()> { fn lint_matrix_math_bindings() -> anyhow::Result<()> { let dir = tempfile::tempdir()?; fs_extra::copy_items( - &["./examples/matrix-math", "./wit", "./bundled"], + &["./examples/matrix-math", "./wit"], dir.path(), &CopyOptions::new(), )?; @@ -107,8 +106,6 @@ fn lint_matrix_math_bindings() -> anyhow::Result<()> { "silent", "-m", "app", - "-p", - "wit_world", ], ); @@ -118,11 +115,7 @@ fn lint_matrix_math_bindings() -> anyhow::Result<()> { #[test] fn lint_sandbox_bindings() -> anyhow::Result<()> { let dir = tempfile::tempdir()?; - fs_extra::copy_items( - &["./examples/sandbox", "./bundled"], - dir.path(), - &CopyOptions::new(), - )?; + fs_extra::copy_items(&["./examples/sandbox"], dir.path(), &CopyOptions::new())?; let path = dir.path().join("sandbox"); cargo::cargo_bin_cmd!("componentize-py") @@ -133,7 +126,7 @@ fn lint_sandbox_bindings() -> anyhow::Result<()> { assert!(predicate::path::is_dir().eval(&path.join("wit_world"))); - mypy_check(&path, ["--strict", "-m", "guest", "-p", "wit_world"]); + mypy_check(&path, ["--strict", "-m", "guest"]); Ok(()) } @@ -142,7 +135,7 @@ fn lint_sandbox_bindings() -> anyhow::Result<()> { fn lint_tcp_bindings() -> anyhow::Result<()> { let dir = tempfile::tempdir()?; fs_extra::copy_items( - &["./examples/tcp", "./wit", "./bundled"], + &["./examples/tcp", "./wit"], dir.path(), &CopyOptions::new(), )?; @@ -152,7 +145,7 @@ fn lint_tcp_bindings() -> anyhow::Result<()> { assert!(predicate::path::is_dir().eval(&path.join("wit_world"))); - mypy_check(&path, ["--strict", "."]); + mypy_check(&path, ["--strict", "-m", "app"]); Ok(()) } @@ -184,18 +177,10 @@ where Command::new(venv_path(path).join("mypy")) .current_dir(path) - .env( - "MYPYPATH", - ["bundled"] - .into_iter() - .map(|v| path.parent().unwrap().join(v).to_str().unwrap().to_string()) - .collect::>() - .join(":"), - ) .args(args) .assert() .success() - .stdout(predicate::str::is_match("Success: no issues found in \\d+ source files").unwrap()) + .stdout(predicate::str::is_match("Success: no issues found in 1 source file").unwrap()) } fn venv_path(path: &Path) -> PathBuf {