Skip to content

Commit 0250b34

Browse files
author
Phil Cummins
committed
formatting
1 parent 5b0f0f0 commit 0250b34

File tree

2 files changed

+55
-22
lines changed

2 files changed

+55
-22
lines changed

src/lib.rs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,53 @@
11
#![deny(warnings)]
22

33
use {
4-
anyhow::{anyhow, bail, ensure, Context, Error, Result}, async_trait::async_trait, bytes::Bytes, component_init::Invoker, futures::future::FutureExt, heck::ToSnakeCase, indexmap::{IndexMap, IndexSet}, prelink::{embedded_helper_utils, embedded_python_standard_library}, serde::Deserialize, std::{
4+
anyhow::{anyhow, bail, ensure, Context, Error, Result},
5+
async_trait::async_trait,
6+
bytes::Bytes,
7+
component_init::Invoker,
8+
futures::future::FutureExt,
9+
heck::ToSnakeCase,
10+
indexmap::{IndexMap, IndexSet},
11+
prelink::{embedded_helper_utils, embedded_python_standard_library},
12+
serde::Deserialize,
13+
std::{
514
collections::{HashMap, HashSet},
615
env, fs,
716
io::Cursor,
817
iter,
918
ops::Deref,
1019
path::{Path, PathBuf},
1120
str,
12-
}, summary::{Escape, Locations, Summary}, wasm_convert::IntoValType, wasm_encoder::{
21+
},
22+
summary::{Escape, Locations, Summary},
23+
wasm_convert::IntoValType,
24+
wasm_encoder::{
1325
CodeSection, ExportKind, ExportSection, Function, FunctionSection, Instruction, Module,
1426
TypeSection,
15-
}, wasmparser::{FuncType, Parser, Payload, TypeRef}, wasmtime::{
27+
},
28+
wasmparser::{FuncType, Parser, Payload, TypeRef},
29+
wasmtime::{
1630
component::{Component, Instance, Linker, ResourceTable, ResourceType},
1731
Config, Engine, Store,
18-
}, wasmtime_wasi::{
32+
},
33+
wasmtime_wasi::{
1934
pipe::{MemoryInputPipe, MemoryOutputPipe},
2035
DirPerms, FilePerms, WasiCtx, WasiCtxBuilder, WasiView,
21-
}, wit_parser::{Resolve, TypeDefKind, UnresolvedPackageGroup, WorldId, WorldItem, WorldKey}
36+
},
37+
wit_parser::{Resolve, TypeDefKind, UnresolvedPackageGroup, WorldId, WorldItem, WorldKey},
2238
};
2339

2440
mod abi;
2541
mod bindgen;
2642
mod bindings;
2743
pub mod command;
44+
mod prelink;
2845
#[cfg(feature = "pyo3")]
2946
mod python;
3047
mod summary;
3148
#[cfg(test)]
3249
mod test;
3350
mod util;
34-
mod prelink;
3551

3652
static NATIVE_EXTENSION_SUFFIX: &str = ".cpython-312-wasm32-wasi.so";
3753

@@ -204,7 +220,8 @@ pub async fn componentize(
204220
// the latter may contain their own WIT files defining their own worlds (in addition to what the caller
205221
// specified as paramters), which we'll try to match up with `module_worlds` in the next step.
206222
let mut raw_configs: Vec<crate::ConfigContext<crate::RawComponentizePyConfig>> = Vec::new();
207-
let mut library_path: Vec<(&str, Vec<std::path::PathBuf>)> = Vec::with_capacity(python_path.len());
223+
let mut library_path: Vec<(&str, Vec<std::path::PathBuf>)> =
224+
Vec::with_capacity(python_path.len());
208225
for path in python_path {
209226
let mut libraries = Vec::new();
210227
search_directory(
@@ -414,8 +431,18 @@ pub async fn componentize(
414431
.env("PYTHONUNBUFFERED", "1")
415432
.env("COMPONENTIZE_PY_APP_NAME", app_name)
416433
.env("PYTHONHOME", "/python")
417-
.preopened_dir(embedded_python_standard_lib.path(), "python", DirPerms::all(), FilePerms::all())?
418-
.preopened_dir(embedded_helper_utils.path(), "bundled", DirPerms::all(), FilePerms::all())?;
434+
.preopened_dir(
435+
embedded_python_standard_lib.path(),
436+
"python",
437+
DirPerms::all(),
438+
FilePerms::all(),
439+
)?
440+
.preopened_dir(
441+
embedded_helper_utils.path(),
442+
"bundled",
443+
DirPerms::all(),
444+
FilePerms::all(),
445+
)?;
419446

420447
// Generate guest mounts for each host directory in `python_path`.
421448
for (index, path) in python_path.iter().enumerate() {

src/prelink.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#![deny(warnings)]
22

3-
use std::{fs, io::{self, Cursor}};
3+
use std::{
4+
fs,
5+
io::{self, Cursor},
6+
};
47

58
use anyhow::Context;
69
use tar::Archive;
@@ -10,16 +13,17 @@ use zstd::Decoder;
1013
use crate::Library;
1114

1215
pub fn embedded_python_standard_library() -> Result<TempDir, io::Error> {
13-
// Untar the embedded copy of the Python standard library into a temporary directory
14-
let stdlib = tempfile::tempdir().expect("could not create temp dirfor python stnadard lib");
16+
// Untar the embedded copy of the Python standard library into a temporary directory
17+
let stdlib = tempfile::tempdir().expect("could not create temp dirfor python stnadard lib");
1518

16-
Archive::new(Decoder::new(Cursor::new(include_bytes!(concat!(
17-
env!("OUT_DIR"),
18-
"/python-lib.tar.zst"
19-
))))?)
20-
.unpack(stdlib.path()).unwrap();
19+
Archive::new(Decoder::new(Cursor::new(include_bytes!(concat!(
20+
env!("OUT_DIR"),
21+
"/python-lib.tar.zst"
22+
))))?)
23+
.unpack(stdlib.path())
24+
.unwrap();
2125

22-
return Ok(stdlib);
26+
return Ok(stdlib);
2327
}
2428

2529
pub fn embedded_helper_utils() -> Result<TempDir, io::Error> {
@@ -30,13 +34,15 @@ pub fn embedded_helper_utils() -> Result<TempDir, io::Error> {
3034
env!("OUT_DIR"),
3135
"/bundled.tar.zst"
3236
))))?)
33-
.unpack(bundled.path()).unwrap();
37+
.unpack(bundled.path())
38+
.unwrap();
3439

3540
return Ok(bundled);
3641
}
3742

38-
pub fn bundle_libraries(library_path: Vec<(&str, Vec<std::path::PathBuf>)>) -> Result<Vec<Library>, io::Error> {
39-
43+
pub fn bundle_libraries(
44+
library_path: Vec<(&str, Vec<std::path::PathBuf>)>,
45+
) -> Result<Vec<Library>, io::Error> {
4046
let mut libraries = vec![
4147
Library {
4248
name: "libcomponentize_py_runtime.so".into(),
@@ -109,7 +115,7 @@ pub fn bundle_libraries(library_path: Vec<(&str, Vec<std::path::PathBuf>)>) -> R
109115
"/libc++abi.so.zst"
110116
))))?,
111117
dl_openable: false,
112-
}
118+
},
113119
];
114120

115121
for (index, (path, libs)) in library_path.iter().enumerate() {

0 commit comments

Comments
 (0)