Skip to content

Commit c5deb00

Browse files
committed
fix regression related to bundled libraries
`componentize-py` tried to read the bundled libraries from the filesystem at runtime rather than actually bundling them. That worked fine as long as the files still existed at the same path when you ran the binary, but stopped working if you deleted them or tried to run the binary on a different machine. Signed-off-by: Joel Dice <[email protected]>
1 parent 881cdb4 commit c5deb00

File tree

9 files changed

+97
-40
lines changed

9 files changed

+97
-40
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "componentize-py"
3-
version = "0.15.1"
3+
version = "0.15.2"
44
edition = "2021"
55
exclude = ["cpython"]
66

examples/cli/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ run a Python-based component targetting the [wasi-cli] `command` world.
1010
## Prerequisites
1111

1212
* `Wasmtime` 26.0.0 or later
13-
* `componentize-py` 0.15.1
13+
* `componentize-py` 0.15.2
1414

1515
Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If
1616
you don't have `cargo`, you can download and install from
1717
https://github.com/bytecodealliance/wasmtime/releases/tag/v26.0.0.
1818

1919
```
2020
cargo install --version 26.0.0 wasmtime-cli
21-
pip install componentize-py==0.15.1
21+
pip install componentize-py==0.15.2
2222
```
2323

2424
## Running the demo

examples/http/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ run a Python-based component targetting the [wasi-http] `proxy` world.
1010
## Prerequisites
1111

1212
* `Wasmtime` 26.0.0 or later
13-
* `componentize-py` 0.15.1
13+
* `componentize-py` 0.15.2
1414

1515
Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If
1616
you don't have `cargo`, you can download and install from
1717
https://github.com/bytecodealliance/wasmtime/releases/tag/v26.0.0.
1818

1919
```
2020
cargo install --version 26.0.0 wasmtime-cli
21-
pip install componentize-py==0.15.1
21+
pip install componentize-py==0.15.2
2222
```
2323

2424
## Running the demo

examples/matrix-math/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ within a guest component.
1111
## Prerequisites
1212

1313
* `wasmtime` 26.0.0 or later
14-
* `componentize-py` 0.15.1
14+
* `componentize-py` 0.15.2
1515
* `NumPy`, built for WASI
1616

1717
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/v26.0.0.
2323

2424
```
2525
cargo install --version 26.0.0 wasmtime-cli
26-
pip install componentize-py==0.15.1
26+
pip install componentize-py==0.15.2
2727
curl -OL https://github.com/dicej/wasi-wheels/releases/download/v0.0.1/numpy-wasi.tar.gz
2828
tar xf numpy-wasi.tar.gz
2929
```

examples/sandbox/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ sandboxed Python code snippets from within a Python app.
88
## Prerequisites
99

1010
* `wasmtime-py` 25.0.0 or later
11-
* `componentize-py` 0.15.1
11+
* `componentize-py` 0.15.2
1212

1313
```
14-
pip install componentize-py==0.15.1 wasmtime==25.0.0
14+
pip install componentize-py==0.15.2 wasmtime==25.0.0
1515
```
1616

1717
## Running the demo

examples/tcp/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ making an outbound TCP request using `wasi-sockets`.
1111
## Prerequisites
1212

1313
* `Wasmtime` 26.0.0 or later
14-
* `componentize-py` 0.15.1
14+
* `componentize-py` 0.15.2
1515

1616
Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If
1717
you don't have `cargo`, you can download and install from
1818
https://github.com/bytecodealliance/wasmtime/releases/tag/v26.0.0.
1919

2020
```
2121
cargo install --version 26.0.0 wasmtime-cli
22-
pip install componentize-py==0.15.1
22+
pip install componentize-py==0.15.2
2323
```
2424

2525
## Running the demo

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ features = ["pyo3/extension-module"]
77

88
[project]
99
name = "componentize-py"
10-
version = "0.15.1"
10+
version = "0.15.2"
1111
description = "Tool to package Python applications as WebAssembly components"
1212
readme = "README.md"
1313
license = { file = "LICENSE" }

src/prelink.rs

Lines changed: 84 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,80 @@ pub fn embedded_helper_utils() -> Result<TempDir, io::Error> {
5151

5252
pub fn bundle_libraries(
5353
library_path: Vec<(&str, Vec<std::path::PathBuf>)>,
54-
) -> Result<Vec<Library>, io::Error> {
54+
) -> Result<Vec<Library>, anyhow::Error> {
5555
let mut libraries = vec![
56-
library_from_so("libcomponentize_py_runtime.so")?,
57-
library_from_so("libpython3.12.so")?,
58-
library_from_so("libc.so")?,
59-
library_from_so("libwasi-emulated-mman.so")?,
60-
library_from_so("libwasi-emulated-process-clocks.so")?,
61-
library_from_so("libwasi-emulated-getpid.so")?,
62-
library_from_so("libwasi-emulated-signal.so")?,
63-
library_from_so("libc++.so")?,
64-
library_from_so("libc++abi.so")?,
56+
Library {
57+
name: "libcomponentize_py_runtime.so".into(),
58+
module: zstd::decode_all(Cursor::new(include_bytes!(concat!(
59+
env!("OUT_DIR"),
60+
"/libcomponentize_py_runtime.so.zst"
61+
))))?,
62+
dl_openable: false,
63+
},
64+
Library {
65+
name: "libpython3.12.so".into(),
66+
module: zstd::decode_all(Cursor::new(include_bytes!(concat!(
67+
env!("OUT_DIR"),
68+
"/libpython3.12.so.zst"
69+
))))?,
70+
dl_openable: false,
71+
},
72+
Library {
73+
name: "libc.so".into(),
74+
module: zstd::decode_all(Cursor::new(include_bytes!(concat!(
75+
env!("OUT_DIR"),
76+
"/libc.so.zst"
77+
))))?,
78+
dl_openable: false,
79+
},
80+
Library {
81+
name: "libwasi-emulated-mman.so".into(),
82+
module: zstd::decode_all(Cursor::new(include_bytes!(concat!(
83+
env!("OUT_DIR"),
84+
"/libwasi-emulated-mman.so.zst"
85+
))))?,
86+
dl_openable: false,
87+
},
88+
Library {
89+
name: "libwasi-emulated-process-clocks.so".into(),
90+
module: zstd::decode_all(Cursor::new(include_bytes!(concat!(
91+
env!("OUT_DIR"),
92+
"/libwasi-emulated-process-clocks.so.zst"
93+
))))?,
94+
dl_openable: false,
95+
},
96+
Library {
97+
name: "libwasi-emulated-getpid.so".into(),
98+
module: zstd::decode_all(Cursor::new(include_bytes!(concat!(
99+
env!("OUT_DIR"),
100+
"/libwasi-emulated-getpid.so.zst"
101+
))))?,
102+
dl_openable: false,
103+
},
104+
Library {
105+
name: "libwasi-emulated-signal.so".into(),
106+
module: zstd::decode_all(Cursor::new(include_bytes!(concat!(
107+
env!("OUT_DIR"),
108+
"/libwasi-emulated-signal.so.zst"
109+
))))?,
110+
dl_openable: false,
111+
},
112+
Library {
113+
name: "libc++.so".into(),
114+
module: zstd::decode_all(Cursor::new(include_bytes!(concat!(
115+
env!("OUT_DIR"),
116+
"/libc++.so.zst"
117+
))))?,
118+
dl_openable: false,
119+
},
120+
Library {
121+
name: "libc++abi.so".into(),
122+
module: zstd::decode_all(Cursor::new(include_bytes!(concat!(
123+
env!("OUT_DIR"),
124+
"/libc++abi.so.zst"
125+
))))?,
126+
dl_openable: false,
127+
},
65128
];
66129

67130
for (index, (path, libs)) in library_path.iter().enumerate() {
@@ -76,7 +139,7 @@ pub fn bundle_libraries(
76139

77140
libraries.push(Library {
78141
name: format!("/{index}/{path}"),
79-
module: fs::read(library).unwrap(),
142+
module: fs::read(library).with_context(|| library.display().to_string())?,
80143
dl_openable: true,
81144
});
82145
}
@@ -85,18 +148,6 @@ pub fn bundle_libraries(
85148
Ok(libraries)
86149
}
87150

88-
fn library_from_so(library_name: &str) -> Result<Library, io::Error> {
89-
let path = env!("OUT_DIR").to_owned();
90-
let filepath = path + "/" + library_name + ".zst";
91-
let bytes = fs::read(filepath)?;
92-
93-
Ok(Library {
94-
name: library_name.into(),
95-
module: zstd::decode_all(Cursor::new(bytes))?,
96-
dl_openable: false,
97-
})
98-
}
99-
100151
pub fn search_for_libraries_and_configs<'a>(
101152
python_path: &'a Vec<&'a str>,
102153
module_worlds: &'a [(&'a str, &'a str)],
@@ -171,15 +222,19 @@ fn search_directory(
171222
modules_seen: &mut HashSet<String>,
172223
) -> Result<(), anyhow::Error> {
173224
if path.is_dir() {
174-
for entry in fs::read_dir(path)? {
225+
for entry in fs::read_dir(path).with_context(|| path.display().to_string())? {
175226
search_directory(root, &entry?.path(), libraries, configs, modules_seen)?;
176227
}
177228
} else if let Some(name) = path.file_name().and_then(|name| name.to_str()) {
178229
if name.ends_with(NATIVE_EXTENSION_SUFFIX) {
179230
libraries.push(path.to_owned());
180231
} else if name == "componentize-py.toml" {
181-
let root = root.canonicalize()?;
182-
let path = path.canonicalize()?;
232+
let root = root
233+
.canonicalize()
234+
.with_context(|| root.display().to_string())?;
235+
let path = path
236+
.canonicalize()
237+
.with_context(|| path.display().to_string())?;
183238

184239
let module = module_name(&root, &path)
185240
.ok_or_else(|| anyhow!("unable to determine module name for {}", path.display()))?;
@@ -224,7 +279,9 @@ fn search_directory(
224279
module,
225280
root: root.to_owned(),
226281
path: path.parent().unwrap().to_owned(),
227-
config: toml::from_str::<RawComponentizePyConfig>(&fs::read_to_string(path)?)?,
282+
config: toml::from_str::<RawComponentizePyConfig>(
283+
&fs::read_to_string(&path).with_context(|| path.display().to_string())?,
284+
)?,
228285
});
229286
}
230287
}

0 commit comments

Comments
 (0)