From b89b32e4c515b69cc8fa4581e90a103ac8610f3f Mon Sep 17 00:00:00 2001 From: Ayush Jha Date: Mon, 22 Jan 2024 12:03:17 +0545 Subject: [PATCH 01/10] User defined name for bindings this is a dump (will break it down into separate commits later) --- crates/cli/src/codegen.rs | 14 ++++++++++---- crates/testing/src/autodiscover.rs | 2 +- crates/testing/src/utils.rs | 2 ++ crates/wasm/src/lib.rs | 14 ++++++++++---- crates/wasm/wasmer-pack.exports.wai | 4 ++-- crates/wasmer-pack/src/js/mod.rs | 13 ++++++++----- crates/wasmer-pack/src/lib.rs | 1 + crates/wasmer-pack/src/py/mod.rs | 19 ++++++++++++------- crates/wasmer-pack/src/types.rs | 5 +++++ crates/wasmer-pack/tests/integration_tests.rs | 4 ++-- 10 files changed, 53 insertions(+), 25 deletions(-) diff --git a/crates/cli/src/codegen.rs b/crates/cli/src/codegen.rs index e8e85b1bf7..68acba5686 100644 --- a/crates/cli/src/codegen.rs +++ b/crates/cli/src/codegen.rs @@ -6,6 +6,9 @@ use clap::Parser; #[derive(Debug, Parser)] pub struct Codegen { + /// What to name the generated bindings. + #[clap(short, long)] + pub name: Option, /// Where to save the generated bindings. #[clap(short, long)] pub out_dir: Option, @@ -15,13 +18,16 @@ pub struct Codegen { impl Codegen { pub fn run(self, language: Language) -> Result<(), Error> { - let Codegen { out_dir, input } = self; - + let Codegen { + name, + out_dir, + input, + } = self; let pkg = crate::utils::load(&input)?; let files = match language { - Language::JavaScript => wasmer_pack::generate_javascript(&pkg)?, - Language::Python => wasmer_pack::generate_python(&pkg)?, + Language::JavaScript => wasmer_pack::generate_javascript(&pkg, name)?, + Language::Python => wasmer_pack::generate_python(&pkg, name)?, }; let metadata = pkg.metadata(); diff --git a/crates/testing/src/autodiscover.rs b/crates/testing/src/autodiscover.rs index 46f1151345..1ac296756f 100644 --- a/crates/testing/src/autodiscover.rs +++ b/crates/testing/src/autodiscover.rs @@ -44,7 +44,7 @@ pub fn autodiscover(crate_dir: impl AsRef) -> Result<(), Error> { language = language.name(), "Generating bindings", ); - crate::generate_bindings(&bindings, &wapm_package, language)?; + crate::generate_bindings(&bindings, &wapm_package, language, None)?; match language { Language::JavaScript => { diff --git a/crates/testing/src/utils.rs b/crates/testing/src/utils.rs index 1ec2a88b08..1369fb3761 100644 --- a/crates/testing/src/utils.rs +++ b/crates/testing/src/utils.rs @@ -30,6 +30,7 @@ pub fn generate_bindings( dest: &Path, wapm_dir: &Path, lang: Language, + name: Option, ) -> Result<(), anyhow::Error> { tracing::info!( output_dir=%dest.display(), @@ -38,6 +39,7 @@ pub fn generate_bindings( "Generating bindings", ); let codegen = Codegen { + name: name, out_dir: Some(dest.to_path_buf()), input: wapm_dir.to_path_buf(), }; diff --git a/crates/wasm/src/lib.rs b/crates/wasm/src/lib.rs index ee20413ef4..a2e27cd49c 100644 --- a/crates/wasm/src/lib.rs +++ b/crates/wasm/src/lib.rs @@ -35,13 +35,19 @@ impl crate::wasmer_pack::Package for Package { Ok(Handle::new(Package(pkg))) } - fn generate_javascript(&self) -> Result, wasmer_pack::Error> { - let files = original::generate_javascript(&self.0)?; + fn generate_javascript( + &self, + name: Option, + ) -> Result, wasmer_pack::Error> { + let files = original::generate_javascript(&self.0, name)?; Ok(unwrap_files(files)) } - fn generate_python(&self) -> Result, wasmer_pack::Error> { - let files = original::generate_python(&self.0)?; + fn generate_python( + &self, + name: Option, + ) -> Result, wasmer_pack::Error> { + let files = original::generate_python(&self.0, name)?; Ok(unwrap_files(files)) } } diff --git a/crates/wasm/wasmer-pack.exports.wai b/crates/wasm/wasmer-pack.exports.wai index 08969d97b2..5b4b9c0867 100644 --- a/crates/wasm/wasmer-pack.exports.wai +++ b/crates/wasm/wasmer-pack.exports.wai @@ -11,10 +11,10 @@ resource package { /// Generate a JavaScript project that can be used to access the provided /// package. - generate-javascript: func() -> expected, error> + generate-javascript: func(name: option) -> expected, error> /// Generate a Python project that can be used to access the provided package. - generate-python: func() -> expected, error> + generate-python: func(name: option) -> expected, error> } /// Metadata describing a package. diff --git a/crates/wasmer-pack/src/js/mod.rs b/crates/wasmer-pack/src/js/mod.rs index 49d0b3b821..fe0d8d8fb6 100644 --- a/crates/wasmer-pack/src/js/mod.rs +++ b/crates/wasmer-pack/src/js/mod.rs @@ -41,7 +41,7 @@ static TEMPLATES: Lazy = Lazy::new(|| { }); /// Generate JavaScript bindings for a package. -pub fn generate_javascript(package: &Package) -> Result { +pub fn generate_javascript(package: &Package, name: Option) -> Result { let mut files = Files::new(); let ctx = Context::for_package(package); @@ -53,8 +53,11 @@ pub fn generate_javascript(package: &Package) -> Result { } files.insert_child_directory("src", top_level(&ctx)?); - - let package_json = generate_package_json(package.requires_wasi(), package.metadata()); + let mut metadata = package.metadata().clone(); + if let Some(package_name) = name { + metadata.package_name.set_name(&package_name); + } + let package_json = generate_package_json(package.requires_wasi(), &metadata); files.insert("package.json", package_json); // Note: We need to wrap the generated files in an extra folder because @@ -112,7 +115,7 @@ impl CommandContext { CommandContext { name: cmd.name.clone(), - ident: cmd.name.replace('-', "_"), + ident: cmd.name.to_snake_case(), module_filename: module_filename.display().to_string(), wasm: cmd.wasm.clone(), } @@ -374,7 +377,7 @@ mod tests { }]; let pkg = Package::new(metadata, libraries, commands); - let files = generate_javascript(&pkg).unwrap(); + let files = generate_javascript(&pkg, None).unwrap(); let actual_files: BTreeSet<_> = files.iter().map(|(p, _)| p).collect(); assert_eq!(actual_files, expected); diff --git a/crates/wasmer-pack/src/lib.rs b/crates/wasmer-pack/src/lib.rs index 04ef2a25d7..57fbe001ef 100644 --- a/crates/wasmer-pack/src/lib.rs +++ b/crates/wasmer-pack/src/lib.rs @@ -42,6 +42,7 @@ extern crate pretty_assertions; mod files; mod js; +mod language; mod pirita; mod py; mod types; diff --git a/crates/wasmer-pack/src/py/mod.rs b/crates/wasmer-pack/src/py/mod.rs index 176c15f0db..9757e01992 100644 --- a/crates/wasmer-pack/src/py/mod.rs +++ b/crates/wasmer-pack/src/py/mod.rs @@ -36,9 +36,13 @@ static TEMPLATES: Lazy = Lazy::new(|| { }); /// Generate Python bindings. -pub fn generate_python(package: &Package) -> Result { +pub fn generate_python(package: &Package, name: Option) -> Result { let metadata = package.metadata(); - let package_name = metadata.package_name.python_name(); + let package_name = if let Some(name) = name { + name + } else { + metadata.package_name.name().to_string() + }; let mut files = Files::new(); @@ -167,6 +171,7 @@ impl From for InterfaceContext { #[derive(Debug, serde::Serialize)] struct CommandContext { + name: String, ident: String, module_filename: String, #[serde(skip)] @@ -175,11 +180,11 @@ struct CommandContext { impl From for CommandContext { fn from(cmd: crate::Command) -> CommandContext { - let ident = cmd.name.replace('-', "_"); - let module_filename = format!("{ident}.wasm"); + let module_filename = Path::new(&cmd.name).with_extension("wasm"); CommandContext { - ident, - module_filename, + name: cmd.name.clone(), + ident: cmd.name.to_snake_case(), + module_filename: module_filename.display().to_string(), wasm: cmd.wasm, } } @@ -393,7 +398,7 @@ mod tests { }]; let package = Package::new(metadata, libraries, commands); - let files = generate_python(&package).unwrap(); + let files = generate_python(&package, None).unwrap(); let actual_files: BTreeSet<_> = files.iter().map(|(p, _)| p).collect(); assert_eq!(actual_files, expected); diff --git a/crates/wasmer-pack/src/types.rs b/crates/wasmer-pack/src/types.rs index 5bed928aea..56008afa40 100644 --- a/crates/wasmer-pack/src/types.rs +++ b/crates/wasmer-pack/src/types.rs @@ -93,6 +93,10 @@ impl PackageName { &self.name } + pub fn set_name(&mut self, name: impl Into) { + self.name = name.into(); + } + pub fn namespace(&self) -> &Namespace { &self.namespace } @@ -417,6 +421,7 @@ mod tests { ("_wasmer/package", false), ("wasmer/_package", false), ("लाज/तोब", false), + ("test/package with spaces", false), ("-wasmer/package", false), ("wasmer/-package", false), ("wasmer/-", false), diff --git a/crates/wasmer-pack/tests/integration_tests.rs b/crates/wasmer-pack/tests/integration_tests.rs index cf9be68005..c064c1ac75 100644 --- a/crates/wasmer-pack/tests/integration_tests.rs +++ b/crates/wasmer-pack/tests/integration_tests.rs @@ -14,7 +14,7 @@ fn use_wasi_javascript_bindings() { .join("javascript-wasi"); let _ = std::fs::remove_dir_all(&out_dir); - let js = wasmer_pack::generate_javascript(&pkg).unwrap(); + let js = wasmer_pack::generate_javascript(&pkg, None).unwrap(); js.save_to_disk(&out_dir).unwrap(); let js_dir = Path::new(env!("CARGO_MANIFEST_DIR")) @@ -40,7 +40,7 @@ fn use_wasi_python_bindings() { .join("python-wasi"); let _ = std::fs::remove_dir_all(&out_dir); - let py = wasmer_pack::generate_python(&pkg).unwrap(); + let py = wasmer_pack::generate_python(&pkg, None).unwrap(); py.save_to_disk(&out_dir).unwrap(); let python_dir = Path::new(env!("CARGO_MANIFEST_DIR")) From bc8b59a058678aaad914de1bfc586ce85699e263 Mon Sep 17 00:00:00 2001 From: Ayush Jha Date: Mon, 22 Jan 2024 20:31:26 +0545 Subject: [PATCH 02/10] remove language module dependencies --- crates/wasmer-pack/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/wasmer-pack/src/lib.rs b/crates/wasmer-pack/src/lib.rs index 57fbe001ef..04ef2a25d7 100644 --- a/crates/wasmer-pack/src/lib.rs +++ b/crates/wasmer-pack/src/lib.rs @@ -42,7 +42,6 @@ extern crate pretty_assertions; mod files; mod js; -mod language; mod pirita; mod py; mod types; From bd81d1824722aee835fe4562cdf9acfda8f339f8 Mon Sep 17 00:00:00 2001 From: Ayush Jha Date: Mon, 22 Jan 2024 23:11:21 +0545 Subject: [PATCH 03/10] Making tests pass --- crates/testing/src/utils.rs | 2 +- ...k__bindings__wasmer_pack__bindings.py.snap | 206 ++++++++++-------- crates/wasmer-pack/src/py/mod.rs | 11 +- 3 files changed, 122 insertions(+), 97 deletions(-) diff --git a/crates/testing/src/utils.rs b/crates/testing/src/utils.rs index 1369fb3761..9bf68d25d5 100644 --- a/crates/testing/src/utils.rs +++ b/crates/testing/src/utils.rs @@ -39,7 +39,7 @@ pub fn generate_bindings( "Generating bindings", ); let codegen = Codegen { - name: name, + name, out_dir: Some(dest.to_path_buf()), input: wapm_dir.to_path_buf(), }; diff --git a/crates/wasm/snapshots/Python/wasmer_pack__bindings__wasmer_pack__bindings.py.snap b/crates/wasm/snapshots/Python/wasmer_pack__bindings__wasmer_pack__bindings.py.snap index 45c17b1988..9f4529ff5d 100644 --- a/crates/wasm/snapshots/Python/wasmer_pack__bindings__wasmer_pack__bindings.py.snap +++ b/crates/wasm/snapshots/Python/wasmer_pack__bindings__wasmer_pack__bindings.py.snap @@ -254,129 +254,151 @@ class Package: else: raise TypeError("invalid variant discriminant for expected") return expected - def generate_javascript(self) -> Expected[List['File'], 'Error']: + def generate_javascript(self, name: Optional[str]) -> Expected[List['File'], 'Error']: memory = self._obj._memory; + realloc = self._obj._canonical_abi_realloc free = self._obj._canonical_abi_free obj = self - ret = self._obj._package_generate_javascript(self._obj._resource0_slab.insert(obj.clone())) + if name is None: + variant = 0 + variant2 = 0 + variant3 = 0 + else: + payload0 = name + ptr, len1 = _encode_utf8(payload0, realloc, memory) + variant = 1 + variant2 = ptr + variant3 = len1 + ret = self._obj._package_generate_javascript(self._obj._resource0_slab.insert(obj.clone()), variant, variant2, variant3) assert(isinstance(ret, int)) load = _load(memory.uint8_view, memory, ret, 0) expected: Expected[List['File'], 'Error'] if load == 0: - load0 = _load(memory.int32_view, memory, ret, 4) - load1 = _load(memory.int32_view, memory, ret, 8) - ptr11 = load0 - len12 = load1 + load4 = _load(memory.int32_view, memory, ret, 4) + load5 = _load(memory.int32_view, memory, ret, 8) + ptr16 = load4 + len17 = load5 result: List['File'] = [] - for i13 in range(0, len12): - base2 = ptr11 + i13 * 16 - load3 = _load(memory.int32_view, memory, base2, 0) - load4 = _load(memory.int32_view, memory, base2, 4) - ptr = load3 - len5 = load4 - list = _decode_utf8(memory, ptr, len5) - free(ptr, len5, 1) - load6 = _load(memory.int32_view, memory, base2, 8) - load7 = _load(memory.int32_view, memory, base2, 12) - ptr8 = load6 - len9 = load7 - list10 = cast(bytes, _list_canon_lift(ptr8, len9, 1, memory.uint8_view, memory)) - free(ptr8, len9, 1) - result.append(File(list, list10)) - free(ptr11, len12 * 16, 4) + for i18 in range(0, len17): + base6 = ptr16 + i18 * 16 + load7 = _load(memory.int32_view, memory, base6, 0) + load8 = _load(memory.int32_view, memory, base6, 4) + ptr9 = load7 + len10 = load8 + list = _decode_utf8(memory, ptr9, len10) + free(ptr9, len10, 1) + load11 = _load(memory.int32_view, memory, base6, 8) + load12 = _load(memory.int32_view, memory, base6, 12) + ptr13 = load11 + len14 = load12 + list15 = cast(bytes, _list_canon_lift(ptr13, len14, 1, memory.uint8_view, memory)) + free(ptr13, len14, 1) + result.append(File(list, list15)) + free(ptr16, len17 * 16, 4) expected = Ok(result) elif load == 1: - load14 = _load(memory.int32_view, memory, ret, 4) - load15 = _load(memory.int32_view, memory, ret, 8) - ptr16 = load14 - len17 = load15 - list18 = _decode_utf8(memory, ptr16, len17) - free(ptr16, len17, 1) - load19 = _load(memory.int32_view, memory, ret, 12) - load20 = _load(memory.int32_view, memory, ret, 16) + load19 = _load(memory.int32_view, memory, ret, 4) + load20 = _load(memory.int32_view, memory, ret, 8) ptr21 = load19 len22 = load20 list23 = _decode_utf8(memory, ptr21, len22) free(ptr21, len22, 1) - load24 = _load(memory.int32_view, memory, ret, 20) - load25 = _load(memory.int32_view, memory, ret, 24) - ptr32 = load24 - len33 = load25 - result34: List[str] = [] - for i35 in range(0, len33): - base26 = ptr32 + i35 * 8 - load27 = _load(memory.int32_view, memory, base26, 0) - load28 = _load(memory.int32_view, memory, base26, 4) - ptr29 = load27 - len30 = load28 - list31 = _decode_utf8(memory, ptr29, len30) - free(ptr29, len30, 1) - result34.append(list31) - free(ptr32, len33 * 8, 4) - expected = Err(Error(list18, list23, result34)) + load24 = _load(memory.int32_view, memory, ret, 12) + load25 = _load(memory.int32_view, memory, ret, 16) + ptr26 = load24 + len27 = load25 + list28 = _decode_utf8(memory, ptr26, len27) + free(ptr26, len27, 1) + load29 = _load(memory.int32_view, memory, ret, 20) + load30 = _load(memory.int32_view, memory, ret, 24) + ptr37 = load29 + len38 = load30 + result39: List[str] = [] + for i40 in range(0, len38): + base31 = ptr37 + i40 * 8 + load32 = _load(memory.int32_view, memory, base31, 0) + load33 = _load(memory.int32_view, memory, base31, 4) + ptr34 = load32 + len35 = load33 + list36 = _decode_utf8(memory, ptr34, len35) + free(ptr34, len35, 1) + result39.append(list36) + free(ptr37, len38 * 8, 4) + expected = Err(Error(list23, list28, result39)) else: raise TypeError("invalid variant discriminant for expected") return expected - def generate_python(self) -> Expected[List['File'], 'Error']: + def generate_python(self, name: Optional[str]) -> Expected[List['File'], 'Error']: memory = self._obj._memory; + realloc = self._obj._canonical_abi_realloc free = self._obj._canonical_abi_free obj = self - ret = self._obj._package_generate_python(self._obj._resource0_slab.insert(obj.clone())) + if name is None: + variant = 0 + variant2 = 0 + variant3 = 0 + else: + payload0 = name + ptr, len1 = _encode_utf8(payload0, realloc, memory) + variant = 1 + variant2 = ptr + variant3 = len1 + ret = self._obj._package_generate_python(self._obj._resource0_slab.insert(obj.clone()), variant, variant2, variant3) assert(isinstance(ret, int)) load = _load(memory.uint8_view, memory, ret, 0) expected: Expected[List['File'], 'Error'] if load == 0: - load0 = _load(memory.int32_view, memory, ret, 4) - load1 = _load(memory.int32_view, memory, ret, 8) - ptr11 = load0 - len12 = load1 + load4 = _load(memory.int32_view, memory, ret, 4) + load5 = _load(memory.int32_view, memory, ret, 8) + ptr16 = load4 + len17 = load5 result: List['File'] = [] - for i13 in range(0, len12): - base2 = ptr11 + i13 * 16 - load3 = _load(memory.int32_view, memory, base2, 0) - load4 = _load(memory.int32_view, memory, base2, 4) - ptr = load3 - len5 = load4 - list = _decode_utf8(memory, ptr, len5) - free(ptr, len5, 1) - load6 = _load(memory.int32_view, memory, base2, 8) - load7 = _load(memory.int32_view, memory, base2, 12) - ptr8 = load6 - len9 = load7 - list10 = cast(bytes, _list_canon_lift(ptr8, len9, 1, memory.uint8_view, memory)) - free(ptr8, len9, 1) - result.append(File(list, list10)) - free(ptr11, len12 * 16, 4) + for i18 in range(0, len17): + base6 = ptr16 + i18 * 16 + load7 = _load(memory.int32_view, memory, base6, 0) + load8 = _load(memory.int32_view, memory, base6, 4) + ptr9 = load7 + len10 = load8 + list = _decode_utf8(memory, ptr9, len10) + free(ptr9, len10, 1) + load11 = _load(memory.int32_view, memory, base6, 8) + load12 = _load(memory.int32_view, memory, base6, 12) + ptr13 = load11 + len14 = load12 + list15 = cast(bytes, _list_canon_lift(ptr13, len14, 1, memory.uint8_view, memory)) + free(ptr13, len14, 1) + result.append(File(list, list15)) + free(ptr16, len17 * 16, 4) expected = Ok(result) elif load == 1: - load14 = _load(memory.int32_view, memory, ret, 4) - load15 = _load(memory.int32_view, memory, ret, 8) - ptr16 = load14 - len17 = load15 - list18 = _decode_utf8(memory, ptr16, len17) - free(ptr16, len17, 1) - load19 = _load(memory.int32_view, memory, ret, 12) - load20 = _load(memory.int32_view, memory, ret, 16) + load19 = _load(memory.int32_view, memory, ret, 4) + load20 = _load(memory.int32_view, memory, ret, 8) ptr21 = load19 len22 = load20 list23 = _decode_utf8(memory, ptr21, len22) free(ptr21, len22, 1) - load24 = _load(memory.int32_view, memory, ret, 20) - load25 = _load(memory.int32_view, memory, ret, 24) - ptr32 = load24 - len33 = load25 - result34: List[str] = [] - for i35 in range(0, len33): - base26 = ptr32 + i35 * 8 - load27 = _load(memory.int32_view, memory, base26, 0) - load28 = _load(memory.int32_view, memory, base26, 4) - ptr29 = load27 - len30 = load28 - list31 = _decode_utf8(memory, ptr29, len30) - free(ptr29, len30, 1) - result34.append(list31) - free(ptr32, len33 * 8, 4) - expected = Err(Error(list18, list23, result34)) + load24 = _load(memory.int32_view, memory, ret, 12) + load25 = _load(memory.int32_view, memory, ret, 16) + ptr26 = load24 + len27 = load25 + list28 = _decode_utf8(memory, ptr26, len27) + free(ptr26, len27, 1) + load29 = _load(memory.int32_view, memory, ret, 20) + load30 = _load(memory.int32_view, memory, ret, 24) + ptr37 = load29 + len38 = load30 + result39: List[str] = [] + for i40 in range(0, len38): + base31 = ptr37 + i40 * 8 + load32 = _load(memory.int32_view, memory, base31, 0) + load33 = _load(memory.int32_view, memory, base31, 4) + ptr34 = load32 + len35 = load33 + list36 = _decode_utf8(memory, ptr34, len35) + free(ptr34, len35, 1) + result39.append(list36) + free(ptr37, len38 * 8, 4) + expected = Err(Error(list23, list28, result39)) else: raise TypeError("invalid variant discriminant for expected") return expected diff --git a/crates/wasmer-pack/src/py/mod.rs b/crates/wasmer-pack/src/py/mod.rs index 9757e01992..7c4a686445 100644 --- a/crates/wasmer-pack/src/py/mod.rs +++ b/crates/wasmer-pack/src/py/mod.rs @@ -38,10 +38,12 @@ static TEMPLATES: Lazy = Lazy::new(|| { /// Generate Python bindings. pub fn generate_python(package: &Package, name: Option) -> Result { let metadata = package.metadata(); + + // make sure the name is in snake-case let package_name = if let Some(name) = name { - name + name.to_snake_case() } else { - metadata.package_name.name().to_string() + metadata.package_name.name().to_string().to_snake_case() }; let mut files = Files::new(); @@ -180,10 +182,11 @@ struct CommandContext { impl From for CommandContext { fn from(cmd: crate::Command) -> CommandContext { - let module_filename = Path::new(&cmd.name).with_extension("wasm"); + let ident = cmd.name.to_snake_case(); + let module_filename = Path::new(&ident).with_extension("wasm"); CommandContext { name: cmd.name.clone(), - ident: cmd.name.to_snake_case(), + ident, module_filename: module_filename.display().to_string(), wasm: cmd.wasm, } From c0e1c8543a2eb98b4b3ebffbfe80677f56e2dfa1 Mon Sep 17 00:00:00 2001 From: Ayush Jha Date: Tue, 23 Jan 2024 10:25:21 +0545 Subject: [PATCH 04/10] Use poetry to run python-wasi tests for crate wasmer-pack --- crates/wasmer-pack/tests/integration_tests.rs | 6 +- crates/wasmer-pack/tests/python-wasi/Pipfile | 11 - .../tests/python-wasi/Pipfile.lock | 171 ------------- .../wasmer-pack/tests/python-wasi/poetry.lock | 233 ++++++++++++++++++ .../tests/python-wasi/pyproject.toml | 17 ++ 5 files changed, 253 insertions(+), 185 deletions(-) delete mode 100644 crates/wasmer-pack/tests/python-wasi/Pipfile delete mode 100644 crates/wasmer-pack/tests/python-wasi/Pipfile.lock create mode 100644 crates/wasmer-pack/tests/python-wasi/poetry.lock create mode 100644 crates/wasmer-pack/tests/python-wasi/pyproject.toml diff --git a/crates/wasmer-pack/tests/integration_tests.rs b/crates/wasmer-pack/tests/integration_tests.rs index c064c1ac75..ac780612cb 100644 --- a/crates/wasmer-pack/tests/integration_tests.rs +++ b/crates/wasmer-pack/tests/integration_tests.rs @@ -47,10 +47,10 @@ fn use_wasi_python_bindings() { .join("tests") .join("python-wasi"); - execute("pipenv install", &python_dir); - execute("pipenv run pytest", &python_dir); + execute("poetry install --no-root", &python_dir); + execute("poetry run pytest", &python_dir); execute( - format!("pipenv run mypy {}", out_dir.join("wabt").display()), + format!("poetry run mypy {}", out_dir.join("wabt").display()), &python_dir, ); } diff --git a/crates/wasmer-pack/tests/python-wasi/Pipfile b/crates/wasmer-pack/tests/python-wasi/Pipfile deleted file mode 100644 index c6a5c98053..0000000000 --- a/crates/wasmer-pack/tests/python-wasi/Pipfile +++ /dev/null @@ -1,11 +0,0 @@ -[[source]] -url = "https://pypi.org/simple" -verify_ssl = true -name = "pypi" - -[packages] -wabt = {path = "./../../../../target/tmp/wasmer-pack/python-wasi"} -pytest = "*" -wasmer = "*" -wasmer-compiler-cranelift = "*" -mypy = "*" diff --git a/crates/wasmer-pack/tests/python-wasi/Pipfile.lock b/crates/wasmer-pack/tests/python-wasi/Pipfile.lock deleted file mode 100644 index d997419895..0000000000 --- a/crates/wasmer-pack/tests/python-wasi/Pipfile.lock +++ /dev/null @@ -1,171 +0,0 @@ -{ - "_meta": { - "hash": { - "sha256": "8f51c83bb4916157338161def3fbbbaff3d1650489aa71086daaf0f5dd2798b3" - }, - "pipfile-spec": 6, - "requires": {}, - "sources": [ - { - "name": "pypi", - "url": "https://pypi.org/simple", - "verify_ssl": true - } - ] - }, - "default": { - "attrs": { - "hashes": [ - "sha256:29adc2665447e5191d0e7c568fde78b21f9672d344281d0c6e1ab085429b22b6", - "sha256:86efa402f67bf2df34f51a335487cf46b1ec130d02b8d39fd248abfd30da551c" - ], - "markers": "python_version >= '3.5'", - "version": "==22.1.0" - }, - "exceptiongroup": { - "hashes": [ - "sha256:2ac84b496be68464a2da60da518af3785fff8b7ec0d090a581604bc870bdee41", - "sha256:affbabf13fb6e98988c38d9c5650e701569fe3c1de3233cfb61c5f33774690ad" - ], - "markers": "python_version < '3.11'", - "version": "==1.0.0" - }, - "iniconfig": { - "hashes": [ - "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3", - "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32" - ], - "version": "==1.1.1" - }, - "mypy": { - "hashes": [ - "sha256:1021c241e8b6e1ca5a47e4d52601274ac078a89845cfde66c6d5f769819ffa1d", - "sha256:14d53cdd4cf93765aa747a7399f0961a365bcddf7855d9cef6306fa41de01c24", - "sha256:175f292f649a3af7082fe36620369ffc4661a71005aa9f8297ea473df5772046", - "sha256:26ae64555d480ad4b32a267d10cab7aec92ff44de35a7cd95b2b7cb8e64ebe3e", - "sha256:41fd1cf9bc0e1c19b9af13a6580ccb66c381a5ee2cf63ee5ebab747a4badeba3", - "sha256:5085e6f442003fa915aeb0a46d4da58128da69325d8213b4b35cc7054090aed5", - "sha256:58f27ebafe726a8e5ccb58d896451dd9a662a511a3188ff6a8a6a919142ecc20", - "sha256:6389af3e204975d6658de4fb8ac16f58c14e1bacc6142fee86d1b5b26aa52bda", - "sha256:724d36be56444f569c20a629d1d4ee0cb0ad666078d59bb84f8f887952511ca1", - "sha256:75838c649290d83a2b83a88288c1eb60fe7a05b36d46cbea9d22efc790002146", - "sha256:7b35ce03a289480d6544aac85fa3674f493f323d80ea7226410ed065cd46f206", - "sha256:85f7a343542dc8b1ed0a888cdd34dca56462654ef23aa673907305b260b3d746", - "sha256:86ebe67adf4d021b28c3f547da6aa2cce660b57f0432617af2cca932d4d378a6", - "sha256:8ee8c2472e96beb1045e9081de8e92f295b89ac10c4109afdf3a23ad6e644f3e", - "sha256:91781eff1f3f2607519c8b0e8518aad8498af1419e8442d5d0afb108059881fc", - "sha256:a692a8e7d07abe5f4b2dd32d731812a0175626a90a223d4b58f10f458747dd8a", - "sha256:a705a93670c8b74769496280d2fe6cd59961506c64f329bb179970ff1d24f9f8", - "sha256:c6e564f035d25c99fd2b863e13049744d96bd1947e3d3d2f16f5828864506763", - "sha256:cebca7fd333f90b61b3ef7f217ff75ce2e287482206ef4a8b18f32b49927b1a2", - "sha256:d6af646bd46f10d53834a8e8983e130e47d8ab2d4b7a97363e35b24e1d588947", - "sha256:e7aeaa763c7ab86d5b66ff27f68493d672e44c8099af636d433a7f3fa5596d40", - "sha256:eaa97b9ddd1dd9901a22a879491dbb951b5dec75c3b90032e2baa7336777363b", - "sha256:eb7a068e503be3543c4bd329c994103874fa543c1727ba5288393c21d912d795", - "sha256:f793e3dd95e166b66d50e7b63e69e58e88643d80a3dcc3bcd81368e0478b089c" - ], - "index": "pypi", - "version": "==0.982" - }, - "mypy-extensions": { - "hashes": [ - "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d", - "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8" - ], - "version": "==0.4.3" - }, - "packaging": { - "hashes": [ - "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb", - "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522" - ], - "markers": "python_version >= '3.6'", - "version": "==21.3" - }, - "pluggy": { - "hashes": [ - "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159", - "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3" - ], - "markers": "python_version >= '3.6'", - "version": "==1.0.0" - }, - "pyparsing": { - "hashes": [ - "sha256:2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb", - "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc" - ], - "markers": "python_full_version >= '3.6.8'", - "version": "==3.0.9" - }, - "pytest": { - "hashes": [ - "sha256:892f933d339f068883b6fd5a459f03d85bfcb355e4981e146d2c7616c21fef71", - "sha256:c4014eb40e10f11f355ad4e3c2fb2c6c6d1919c73f3b5a433de4708202cade59" - ], - "index": "pypi", - "version": "==7.2.0" - }, - "tomli": { - "hashes": [ - "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc", - "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f" - ], - "markers": "python_version < '3.11'", - "version": "==2.0.1" - }, - "typing-extensions": { - "hashes": [ - "sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa", - "sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e" - ], - "markers": "python_version >= '3.7'", - "version": "==4.4.0" - }, - "wabt": { - "path": "./../../../../target/tmp/wasmer-pack/python-wasi", - "version": "==0.0.0" - }, - "wasmer": { - "hashes": [ - "sha256:1e63d16bd6e2e2272d8721647831de5c537e0bb08002ee6d7abf167ec02d5178", - "sha256:20b5190112e2e94a8947967f2bc683c9685855d0f34130d8434c87a55216a3bd", - "sha256:214d9a3cfb577ea9449eb2b5f13adceae34c55365e4c3d930066beb86a7f67bc", - "sha256:2caf8c67feae9cd4246421551036917811c446da4f27ad4c989521ef42751931", - "sha256:85e6a5bf44853e8e6a12e947ee3412da9e84f7ce49fc165ba5dbd293e9c5c405", - "sha256:a0a4730ec4907a4cb0d9d4a77ea2608c2c814f22a22b73fc80be0f110e014836", - "sha256:a182a6eca9b46d895b4985fc822fab8da3d2f84fab74ca27e55a7430a7fcf336", - "sha256:aa112198b743cff2e391230436813fb4b244a24443e37866522b7197e3a034da", - "sha256:ab1ae980021e5ec0bf0c6cdd3b979b1d15a5f3eb2b8a32da8dcb1156e4a1e484", - "sha256:b9e5605552bd7d2bc6337519b176defe83bc69b98abf3caaaefa4f7ec231d18a", - "sha256:c0b37117f6d3ff51ee96431c7d224d99799b08d174e30fcd0fcd7e2e3cb8140c", - "sha256:c2af4b907ae2dabcac41e316e811d5937c93adf1f8b05c5d49427f8ce0f37630", - "sha256:d0d93aec6215893d33e803ef0a8d37bf948c585dd80ba0e23a83fafee820bc03", - "sha256:ee442f0970f40ec5e32011c92fd753fb2061da0faa13de13fafc730c31be34e3" - ], - "index": "pypi", - "version": "==1.1.0" - }, - "wasmer-compiler-cranelift": { - "hashes": [ - "sha256:157d87cbd1d04adbad55b50cb4bedc28e444caf74797fd96df17390667e58699", - "sha256:200fea80609cfb088457327acf66d5aa61f4c4f66b5a71133ada960b534c7355", - "sha256:2a4349b1ddd727bd46bc5ede741839dcfc5153c52f064a83998c4150d5d4a85c", - "sha256:32fe38614fccc933da77ee4372904a5fa9c12b859209a2e4048a8284c4c371f2", - "sha256:405546ee864ac158a4107f374dfbb1c8d6cfb189829bdcd13050143a4bd98f28", - "sha256:447285402e366a34667a674db70458c491acd6940b797c175c0b0027f48e64bb", - "sha256:55a524985179f6b7b88ac973e8fac5a2574d3b125a966fba75fedd5a2525e484", - "sha256:7d9c782b7721789b16e303b7e70c59df370896dd62b77e2779e3a44b4e1aa20c", - "sha256:9697ae082317a56776df8ff7df8c922eac38488ef38d3478fe5f0ca144c185ab", - "sha256:9869910179f39696a020edc5689f7759257ac1cce569a7a0fcf340c59788baad", - "sha256:bd03db5a916ead51b442c66acad38847dfe127cf90b2019b1680f1920c4f8d06", - "sha256:bdf75af9ef082e6aeb752550f694273340ece970b65099e0746db0f972760d11", - "sha256:ff25fc99ebafa04a6c271d08a90d17b927930e3019a2b333c7cfb48ba32c6f71", - "sha256:ff7dd5bd69030b63521c24583bf0f5457cd2580237340b91ce35370f72a4a1cc" - ], - "index": "pypi", - "version": "==1.1.0" - } - }, - "develop": {} -} diff --git a/crates/wasmer-pack/tests/python-wasi/poetry.lock b/crates/wasmer-pack/tests/python-wasi/poetry.lock new file mode 100644 index 0000000000..4e07a522e0 --- /dev/null +++ b/crates/wasmer-pack/tests/python-wasi/poetry.lock @@ -0,0 +1,233 @@ +# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "exceptiongroup" +version = "1.2.0" +description = "Backport of PEP 654 (exception groups)" +optional = false +python-versions = ">=3.7" +files = [ + {file = "exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"}, + {file = "exceptiongroup-1.2.0.tar.gz", hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"}, +] + +[package.extras] +test = ["pytest (>=6)"] + +[[package]] +name = "iniconfig" +version = "2.0.0" +description = "brain-dead simple config-ini parsing" +optional = false +python-versions = ">=3.7" +files = [ + {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, + {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, +] + +[[package]] +name = "mypy" +version = "1.8.0" +description = "Optional static typing for Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "mypy-1.8.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:485a8942f671120f76afffff70f259e1cd0f0cfe08f81c05d8816d958d4577d3"}, + {file = "mypy-1.8.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:df9824ac11deaf007443e7ed2a4a26bebff98d2bc43c6da21b2b64185da011c4"}, + {file = "mypy-1.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2afecd6354bbfb6e0160f4e4ad9ba6e4e003b767dd80d85516e71f2e955ab50d"}, + {file = "mypy-1.8.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:8963b83d53ee733a6e4196954502b33567ad07dfd74851f32be18eb932fb1cb9"}, + {file = "mypy-1.8.0-cp310-cp310-win_amd64.whl", hash = "sha256:e46f44b54ebddbeedbd3d5b289a893219065ef805d95094d16a0af6630f5d410"}, + {file = "mypy-1.8.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:855fe27b80375e5c5878492f0729540db47b186509c98dae341254c8f45f42ae"}, + {file = "mypy-1.8.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4c886c6cce2d070bd7df4ec4a05a13ee20c0aa60cb587e8d1265b6c03cf91da3"}, + {file = "mypy-1.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d19c413b3c07cbecf1f991e2221746b0d2a9410b59cb3f4fb9557f0365a1a817"}, + {file = "mypy-1.8.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:9261ed810972061388918c83c3f5cd46079d875026ba97380f3e3978a72f503d"}, + {file = "mypy-1.8.0-cp311-cp311-win_amd64.whl", hash = "sha256:51720c776d148bad2372ca21ca29256ed483aa9a4cdefefcef49006dff2a6835"}, + {file = "mypy-1.8.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:52825b01f5c4c1c4eb0db253ec09c7aa17e1a7304d247c48b6f3599ef40db8bd"}, + {file = "mypy-1.8.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:f5ac9a4eeb1ec0f1ccdc6f326bcdb464de5f80eb07fb38b5ddd7b0de6bc61e55"}, + {file = "mypy-1.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:afe3fe972c645b4632c563d3f3eff1cdca2fa058f730df2b93a35e3b0c538218"}, + {file = "mypy-1.8.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:42c6680d256ab35637ef88891c6bd02514ccb7e1122133ac96055ff458f93fc3"}, + {file = "mypy-1.8.0-cp312-cp312-win_amd64.whl", hash = "sha256:720a5ca70e136b675af3af63db533c1c8c9181314d207568bbe79051f122669e"}, + {file = "mypy-1.8.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:028cf9f2cae89e202d7b6593cd98db6759379f17a319b5faf4f9978d7084cdc6"}, + {file = "mypy-1.8.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:4e6d97288757e1ddba10dd9549ac27982e3e74a49d8d0179fc14d4365c7add66"}, + {file = "mypy-1.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7f1478736fcebb90f97e40aff11a5f253af890c845ee0c850fe80aa060a267c6"}, + {file = "mypy-1.8.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:42419861b43e6962a649068a61f4a4839205a3ef525b858377a960b9e2de6e0d"}, + {file = "mypy-1.8.0-cp38-cp38-win_amd64.whl", hash = "sha256:2b5b6c721bd4aabaadead3a5e6fa85c11c6c795e0c81a7215776ef8afc66de02"}, + {file = "mypy-1.8.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:5c1538c38584029352878a0466f03a8ee7547d7bd9f641f57a0f3017a7c905b8"}, + {file = "mypy-1.8.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:4ef4be7baf08a203170f29e89d79064463b7fc7a0908b9d0d5114e8009c3a259"}, + {file = "mypy-1.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7178def594014aa6c35a8ff411cf37d682f428b3b5617ca79029d8ae72f5402b"}, + {file = "mypy-1.8.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:ab3c84fa13c04aeeeabb2a7f67a25ef5d77ac9d6486ff33ded762ef353aa5592"}, + {file = "mypy-1.8.0-cp39-cp39-win_amd64.whl", hash = "sha256:99b00bc72855812a60d253420d8a2eae839b0afa4938f09f4d2aa9bb4654263a"}, + {file = "mypy-1.8.0-py3-none-any.whl", hash = "sha256:538fd81bb5e430cc1381a443971c0475582ff9f434c16cd46d2c66763ce85d9d"}, + {file = "mypy-1.8.0.tar.gz", hash = "sha256:6ff8b244d7085a0b425b56d327b480c3b29cafbd2eff27316a004f9a7391ae07"}, +] + +[package.dependencies] +mypy-extensions = ">=1.0.0" +tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} +typing-extensions = ">=4.1.0" + +[package.extras] +dmypy = ["psutil (>=4.0)"] +install-types = ["pip"] +mypyc = ["setuptools (>=50)"] +reports = ["lxml"] + +[[package]] +name = "mypy-extensions" +version = "1.0.0" +description = "Type system extensions for programs checked with the mypy type checker." +optional = false +python-versions = ">=3.5" +files = [ + {file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"}, + {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, +] + +[[package]] +name = "packaging" +version = "23.2" +description = "Core utilities for Python packages" +optional = false +python-versions = ">=3.7" +files = [ + {file = "packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"}, + {file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"}, +] + +[[package]] +name = "pluggy" +version = "1.3.0" +description = "plugin and hook calling mechanisms for python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pluggy-1.3.0-py3-none-any.whl", hash = "sha256:d89c696a773f8bd377d18e5ecda92b7a3793cbe66c87060a6fb58c7b6e1061f7"}, + {file = "pluggy-1.3.0.tar.gz", hash = "sha256:cf61ae8f126ac6f7c451172cf30e3e43d3ca77615509771b3a984a0730651e12"}, +] + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + +[[package]] +name = "pytest" +version = "7.4.4" +description = "pytest: simple powerful testing with Python" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pytest-7.4.4-py3-none-any.whl", hash = "sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8"}, + {file = "pytest-7.4.4.tar.gz", hash = "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<2.0" +tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} + +[package.extras] +testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] + +[[package]] +name = "tomli" +version = "2.0.1" +description = "A lil' TOML parser" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, + {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, +] + +[[package]] +name = "typing-extensions" +version = "4.9.0" +description = "Backported and Experimental Type Hints for Python 3.8+" +optional = false +python-versions = ">=3.8" +files = [ + {file = "typing_extensions-4.9.0-py3-none-any.whl", hash = "sha256:af72aea155e91adfc61c3ae9e0e342dbc0cba726d6cba4b6c72c1f34e47291cd"}, + {file = "typing_extensions-4.9.0.tar.gz", hash = "sha256:23478f88c37f27d76ac8aee6c905017a143b0b1b886c3c9f66bc2fd94f9f5783"}, +] + +[[package]] +name = "wabt" +version = "0.0.0" +description = "" +optional = false +python-versions = "*" +files = [] +develop = false + +[package.dependencies] +wasmer = "*" +wasmer_compiler_cranelift = "*" + +[package.source] +type = "directory" +url = "../../../../target/tmp/wasmer-pack/python-wasi" + +[[package]] +name = "wasmer" +version = "1.1.0" +description = "Python extension to run WebAssembly binaries" +optional = false +python-versions = "*" +files = [ + {file = "wasmer-1.1.0-cp310-cp310-macosx_10_7_x86_64.whl", hash = "sha256:c2af4b907ae2dabcac41e316e811d5937c93adf1f8b05c5d49427f8ce0f37630"}, + {file = "wasmer-1.1.0-cp310-cp310-manylinux_2_24_x86_64.whl", hash = "sha256:ab1ae980021e5ec0bf0c6cdd3b979b1d15a5f3eb2b8a32da8dcb1156e4a1e484"}, + {file = "wasmer-1.1.0-cp310-none-win_amd64.whl", hash = "sha256:d0d93aec6215893d33e803ef0a8d37bf948c585dd80ba0e23a83fafee820bc03"}, + {file = "wasmer-1.1.0-cp37-cp37m-macosx_10_7_x86_64.whl", hash = "sha256:1e63d16bd6e2e2272d8721647831de5c537e0bb08002ee6d7abf167ec02d5178"}, + {file = "wasmer-1.1.0-cp37-cp37m-manylinux_2_24_x86_64.whl", hash = "sha256:85e6a5bf44853e8e6a12e947ee3412da9e84f7ce49fc165ba5dbd293e9c5c405"}, + {file = "wasmer-1.1.0-cp37-none-win_amd64.whl", hash = "sha256:a182a6eca9b46d895b4985fc822fab8da3d2f84fab74ca27e55a7430a7fcf336"}, + {file = "wasmer-1.1.0-cp38-cp38-macosx_10_7_x86_64.whl", hash = "sha256:214d9a3cfb577ea9449eb2b5f13adceae34c55365e4c3d930066beb86a7f67bc"}, + {file = "wasmer-1.1.0-cp38-cp38-manylinux_2_24_x86_64.whl", hash = "sha256:b9e5605552bd7d2bc6337519b176defe83bc69b98abf3caaaefa4f7ec231d18a"}, + {file = "wasmer-1.1.0-cp38-none-win_amd64.whl", hash = "sha256:20b5190112e2e94a8947967f2bc683c9685855d0f34130d8434c87a55216a3bd"}, + {file = "wasmer-1.1.0-cp39-cp39-macosx_10_7_x86_64.whl", hash = "sha256:ee442f0970f40ec5e32011c92fd753fb2061da0faa13de13fafc730c31be34e3"}, + {file = "wasmer-1.1.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:aa112198b743cff2e391230436813fb4b244a24443e37866522b7197e3a034da"}, + {file = "wasmer-1.1.0-cp39-cp39-manylinux_2_24_x86_64.whl", hash = "sha256:c0b37117f6d3ff51ee96431c7d224d99799b08d174e30fcd0fcd7e2e3cb8140c"}, + {file = "wasmer-1.1.0-cp39-none-win_amd64.whl", hash = "sha256:a0a4730ec4907a4cb0d9d4a77ea2608c2c814f22a22b73fc80be0f110e014836"}, + {file = "wasmer-1.1.0-py3-none-any.whl", hash = "sha256:2caf8c67feae9cd4246421551036917811c446da4f27ad4c989521ef42751931"}, +] + +[[package]] +name = "wasmer-compiler-cranelift" +version = "1.1.0" +description = "The Cranelift compiler for the `wasmer` package (to compile WebAssembly module)" +optional = false +python-versions = "*" +files = [ + {file = "wasmer_compiler_cranelift-1.1.0-cp310-cp310-macosx_10_7_x86_64.whl", hash = "sha256:9869910179f39696a020edc5689f7759257ac1cce569a7a0fcf340c59788baad"}, + {file = "wasmer_compiler_cranelift-1.1.0-cp310-cp310-manylinux_2_24_x86_64.whl", hash = "sha256:405546ee864ac158a4107f374dfbb1c8d6cfb189829bdcd13050143a4bd98f28"}, + {file = "wasmer_compiler_cranelift-1.1.0-cp310-none-win_amd64.whl", hash = "sha256:bdf75af9ef082e6aeb752550f694273340ece970b65099e0746db0f972760d11"}, + {file = "wasmer_compiler_cranelift-1.1.0-cp37-cp37m-macosx_10_7_x86_64.whl", hash = "sha256:7d9c782b7721789b16e303b7e70c59df370896dd62b77e2779e3a44b4e1aa20c"}, + {file = "wasmer_compiler_cranelift-1.1.0-cp37-cp37m-manylinux_2_24_x86_64.whl", hash = "sha256:ff7dd5bd69030b63521c24583bf0f5457cd2580237340b91ce35370f72a4a1cc"}, + {file = "wasmer_compiler_cranelift-1.1.0-cp37-none-win_amd64.whl", hash = "sha256:447285402e366a34667a674db70458c491acd6940b797c175c0b0027f48e64bb"}, + {file = "wasmer_compiler_cranelift-1.1.0-cp38-cp38-macosx_10_7_x86_64.whl", hash = "sha256:55a524985179f6b7b88ac973e8fac5a2574d3b125a966fba75fedd5a2525e484"}, + {file = "wasmer_compiler_cranelift-1.1.0-cp38-cp38-manylinux_2_24_x86_64.whl", hash = "sha256:bd03db5a916ead51b442c66acad38847dfe127cf90b2019b1680f1920c4f8d06"}, + {file = "wasmer_compiler_cranelift-1.1.0-cp38-none-win_amd64.whl", hash = "sha256:157d87cbd1d04adbad55b50cb4bedc28e444caf74797fd96df17390667e58699"}, + {file = "wasmer_compiler_cranelift-1.1.0-cp39-cp39-macosx_10_7_x86_64.whl", hash = "sha256:ff25fc99ebafa04a6c271d08a90d17b927930e3019a2b333c7cfb48ba32c6f71"}, + {file = "wasmer_compiler_cranelift-1.1.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:9697ae082317a56776df8ff7df8c922eac38488ef38d3478fe5f0ca144c185ab"}, + {file = "wasmer_compiler_cranelift-1.1.0-cp39-cp39-manylinux_2_24_x86_64.whl", hash = "sha256:2a4349b1ddd727bd46bc5ede741839dcfc5153c52f064a83998c4150d5d4a85c"}, + {file = "wasmer_compiler_cranelift-1.1.0-cp39-none-win_amd64.whl", hash = "sha256:32fe38614fccc933da77ee4372904a5fa9c12b859209a2e4048a8284c4c371f2"}, + {file = "wasmer_compiler_cranelift-1.1.0-py3-none-any.whl", hash = "sha256:200fea80609cfb088457327acf66d5aa61f4c4f66b5a71133ada960b534c7355"}, +] + +[metadata] +lock-version = "2.0" +python-versions = "^3.8" +content-hash = "59a9f31fcde4a2132a3e0e63fe708f819971b702a2cf5a16048b3a8ab63c3165" diff --git a/crates/wasmer-pack/tests/python-wasi/pyproject.toml b/crates/wasmer-pack/tests/python-wasi/pyproject.toml new file mode 100644 index 0000000000..4ecf2b9672 --- /dev/null +++ b/crates/wasmer-pack/tests/python-wasi/pyproject.toml @@ -0,0 +1,17 @@ +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" + +[tool.poetry] +name = "python-wasi" +version = "0.1.0" +description = "" +authors = ["Ayush Jha "] + +[tool.poetry.dependencies] +python = "^3.8" +wabt = {path = "./../../../../target/tmp/wasmer-pack/python-wasi"} +pytest = "*" +wasmer = "*" +wasmer-compiler-cranelift = "*" +mypy = "*" From f6aef2971b2a6faeefe376de1ad09c0ef7888e59 Mon Sep 17 00:00:00 2001 From: Ayush Jha Date: Tue, 23 Jan 2024 10:25:36 +0545 Subject: [PATCH 05/10] Fix doc tests --- crates/wasmer-pack/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wasmer-pack/src/lib.rs b/crates/wasmer-pack/src/lib.rs index 04ef2a25d7..e5c42ff848 100644 --- a/crates/wasmer-pack/src/lib.rs +++ b/crates/wasmer-pack/src/lib.rs @@ -29,7 +29,7 @@ //! let pkg = Package ::new(metadata, libraries, commands); //! //! // Now we can generate the bindings for our language -//! let js = wasmer_pack::generate_javascript(&pkg)?; +//! let js = wasmer_pack::generate_javascript(&pkg, None)?; //! //! // And finally, save them to disk //! js.save_to_disk("./out")?; From bcd132809360fbc7c79f9d6bcb7301f742d445c3 Mon Sep 17 00:00:00 2001 From: Ayush Jha Date: Tue, 23 Jan 2024 10:33:46 +0545 Subject: [PATCH 06/10] Update changelog --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0e16dc77b..2c0e6aff81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,17 @@ change, where applicable. ## [Unreleased] - ReleaseDate +### Added +- Added ability to pass in a user-specified name for the generated + bindings. This can be done by passing in the `--name` flag in the + CLI or by passing in the `name` options when calling the + `generate_*` functions. + +### Fixed +- Fixed the `python-wasi` test in `wasmer-pack` crate to use poetry + instead of pipenv. This is because poetry is used everywhere else, + except in this one place. + ## [0.7.1] - 2023-06-12 ### Added From 35ec5770c2c93acdb41f299d9e0ae4358479b2fa Mon Sep 17 00:00:00 2001 From: Ayush Jha Date: Tue, 23 Jan 2024 11:39:37 +0545 Subject: [PATCH 07/10] using an options field instead of name --- crates/cli/src/codegen.rs | 9 +- ...ndings__wasmer-pack__wasmer-pack.d.ts.snap | 10 +- ...bindings__wasmer-pack__wasmer-pack.js.snap | 232 +++++++++++------- ...k__bindings__wasmer_pack__bindings.py.snap | 23 +- crates/wasm/src/lib.rs | 12 +- crates/wasm/wasmer-pack.exports.wai | 9 +- crates/wasmer-pack/src/js/mod.rs | 9 +- crates/wasmer-pack/src/lib.rs | 3 +- crates/wasmer-pack/src/py/mod.rs | 8 +- crates/wasmer-pack/src/types.rs | 7 + crates/wasmer-pack/tests/integration_tests.rs | 4 +- 11 files changed, 209 insertions(+), 117 deletions(-) diff --git a/crates/cli/src/codegen.rs b/crates/cli/src/codegen.rs index 68acba5686..fb179a09a8 100644 --- a/crates/cli/src/codegen.rs +++ b/crates/cli/src/codegen.rs @@ -4,6 +4,7 @@ use crate::Error; use anyhow::Context; use clap::Parser; + #[derive(Debug, Parser)] pub struct Codegen { /// What to name the generated bindings. @@ -26,8 +27,12 @@ impl Codegen { let pkg = crate::utils::load(&input)?; let files = match language { - Language::JavaScript => wasmer_pack::generate_javascript(&pkg, name)?, - Language::Python => wasmer_pack::generate_python(&pkg, name)?, + Language::JavaScript => wasmer_pack::generate_javascript(&pkg, wasmer_pack::BindingsOptions { + name, + })?, + Language::Python => wasmer_pack::generate_python(&pkg, wasmer_pack::BindingsOptions { + name, + })?, }; let metadata = pkg.metadata(); diff --git a/crates/wasm/snapshots/JavaScript/package__src__bindings__wasmer-pack__wasmer-pack.d.ts.snap b/crates/wasm/snapshots/JavaScript/package__src__bindings__wasmer-pack__wasmer-pack.d.ts.snap index c63eff5ac7..e7faa7680f 100644 --- a/crates/wasm/snapshots/JavaScript/package__src__bindings__wasmer-pack__wasmer-pack.d.ts.snap +++ b/crates/wasm/snapshots/JavaScript/package__src__bindings__wasmer-pack__wasmer-pack.d.ts.snap @@ -4,6 +4,12 @@ input_file: crates/wasm/generated_bindings/JavaScript/package/src/bindings/wasme --- export type Result = { tag: "ok", val: T } | { tag: "err", val: E }; /** +* Extra options for bindings generation +*/ +export interface BindingsOptions { + name?: string, +} +/** * A WASI executable. */ export interface Command { @@ -192,11 +198,11 @@ export class Package { * Generate a JavaScript project that can be used to access the provided * package. */ - generateJavascript(): Result; + generateJavascript(options: BindingsOptions): Result; /** * Generate a Python project that can be used to access the provided package. */ - generatePython(): Result; + generatePython(options: BindingsOptions): Result; } export class Metadata { diff --git a/crates/wasm/snapshots/JavaScript/package__src__bindings__wasmer-pack__wasmer-pack.js.snap b/crates/wasm/snapshots/JavaScript/package__src__bindings__wasmer-pack__wasmer-pack.js.snap index 72392ced7f..3ce0aeba3a 100644 --- a/crates/wasm/snapshots/JavaScript/package__src__bindings__wasmer-pack__wasmer-pack.js.snap +++ b/crates/wasm/snapshots/JavaScript/package__src__bindings__wasmer-pack__wasmer-pack.js.snap @@ -228,64 +228,90 @@ class Package { } return variant5; } - generateJavascript() { + generateJavascript(arg1) { const memory = this._obj._exports.memory; + const realloc = this._obj._exports["canonical_abi_realloc"]; const free = this._obj._exports["canonical_abi_free"]; const obj0 = this; - const ret = this._obj._exports['package::generate-javascript'](this._obj._resource0_slab.insert(obj0.clone())); + const {name: v1_0 } = arg1; + const variant3 = v1_0; + let variant3_0; + let variant3_1; + let variant3_2; + + switch (variant3) { + case null: { + variant3_0 = 0; + variant3_1 = 0; + variant3_2 = 0; + + break; + } + default: { + const e = variant3; + const ptr2 = utf8_encode(e, realloc, memory); + const len2 = utf8_encoded_len(); + variant3_0 = 1; + variant3_1 = ptr2; + variant3_2 = len2; + + break; + } + } + const ret = this._obj._exports['package::generate-javascript'](this._obj._resource0_slab.insert(obj0.clone()), variant3_0, variant3_1, variant3_2); - let variant8; + let variant11; switch (data_view(memory).getUint8(ret + 0, true)) { case 0: { - const len3 = data_view(memory).getInt32(ret + 8, true); - const base3 = data_view(memory).getInt32(ret + 4, true); - const result3 = []; - for (let i = 0; i < len3; i++) { - const base = base3 + i * 16; - const ptr1 = data_view(memory).getInt32(base + 0, true); - const len1 = data_view(memory).getInt32(base + 4, true); - const list1 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr1, len1)); - free(ptr1, len1, 1); - const ptr2 = data_view(memory).getInt32(base + 8, true); - const len2 = data_view(memory).getInt32(base + 12, true); - const list2 = new Uint8Array(memory.buffer.slice(ptr2, ptr2 + len2 * 1)); - free(ptr2, len2, 1); - result3.push({ - filename: list1, - contents: list2, + const len6 = data_view(memory).getInt32(ret + 8, true); + const base6 = data_view(memory).getInt32(ret + 4, true); + const result6 = []; + for (let i = 0; i < len6; i++) { + const base = base6 + i * 16; + const ptr4 = data_view(memory).getInt32(base + 0, true); + const len4 = data_view(memory).getInt32(base + 4, true); + const list4 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr4, len4)); + free(ptr4, len4, 1); + const ptr5 = data_view(memory).getInt32(base + 8, true); + const len5 = data_view(memory).getInt32(base + 12, true); + const list5 = new Uint8Array(memory.buffer.slice(ptr5, ptr5 + len5 * 1)); + free(ptr5, len5, 1); + result6.push({ + filename: list4, + contents: list5, }); } - free(base3, len3 * 16, 4); + free(base6, len6 * 16, 4); - variant8 = { tag: "ok", val: result3 }; + variant11 = { tag: "ok", val: result6 }; break; } case 1: { - const ptr4 = data_view(memory).getInt32(ret + 4, true); - const len4 = data_view(memory).getInt32(ret + 8, true); - const list4 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr4, len4)); - free(ptr4, len4, 1); - const ptr5 = data_view(memory).getInt32(ret + 12, true); - const len5 = data_view(memory).getInt32(ret + 16, true); - const list5 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr5, len5)); - free(ptr5, len5, 1); - const len7 = data_view(memory).getInt32(ret + 24, true); - const base7 = data_view(memory).getInt32(ret + 20, true); - const result7 = []; - for (let i = 0; i < len7; i++) { - const base = base7 + i * 8; - const ptr6 = data_view(memory).getInt32(base + 0, true); - const len6 = data_view(memory).getInt32(base + 4, true); - const list6 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr6, len6)); - free(ptr6, len6, 1); - result7.push(list6); + const ptr7 = data_view(memory).getInt32(ret + 4, true); + const len7 = data_view(memory).getInt32(ret + 8, true); + const list7 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr7, len7)); + free(ptr7, len7, 1); + const ptr8 = data_view(memory).getInt32(ret + 12, true); + const len8 = data_view(memory).getInt32(ret + 16, true); + const list8 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr8, len8)); + free(ptr8, len8, 1); + const len10 = data_view(memory).getInt32(ret + 24, true); + const base10 = data_view(memory).getInt32(ret + 20, true); + const result10 = []; + for (let i = 0; i < len10; i++) { + const base = base10 + i * 8; + const ptr9 = data_view(memory).getInt32(base + 0, true); + const len9 = data_view(memory).getInt32(base + 4, true); + const list9 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr9, len9)); + free(ptr9, len9, 1); + result10.push(list9); } - free(base7, len7 * 8, 4); + free(base10, len10 * 8, 4); - variant8 = { tag: "err", val: { - message: list4, - verbose: list5, - causes: result7, + variant11 = { tag: "err", val: { + message: list7, + verbose: list8, + causes: result10, } }; break; } @@ -293,66 +319,92 @@ class Package { throw new RangeError("invalid variant discriminant for expected"); } } - return variant8; + return variant11; } - generatePython() { + generatePython(arg1) { const memory = this._obj._exports.memory; + const realloc = this._obj._exports["canonical_abi_realloc"]; const free = this._obj._exports["canonical_abi_free"]; const obj0 = this; - const ret = this._obj._exports['package::generate-python'](this._obj._resource0_slab.insert(obj0.clone())); + const {name: v1_0 } = arg1; + const variant3 = v1_0; + let variant3_0; + let variant3_1; + let variant3_2; + + switch (variant3) { + case null: { + variant3_0 = 0; + variant3_1 = 0; + variant3_2 = 0; + + break; + } + default: { + const e = variant3; + const ptr2 = utf8_encode(e, realloc, memory); + const len2 = utf8_encoded_len(); + variant3_0 = 1; + variant3_1 = ptr2; + variant3_2 = len2; + + break; + } + } + const ret = this._obj._exports['package::generate-python'](this._obj._resource0_slab.insert(obj0.clone()), variant3_0, variant3_1, variant3_2); - let variant8; + let variant11; switch (data_view(memory).getUint8(ret + 0, true)) { case 0: { - const len3 = data_view(memory).getInt32(ret + 8, true); - const base3 = data_view(memory).getInt32(ret + 4, true); - const result3 = []; - for (let i = 0; i < len3; i++) { - const base = base3 + i * 16; - const ptr1 = data_view(memory).getInt32(base + 0, true); - const len1 = data_view(memory).getInt32(base + 4, true); - const list1 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr1, len1)); - free(ptr1, len1, 1); - const ptr2 = data_view(memory).getInt32(base + 8, true); - const len2 = data_view(memory).getInt32(base + 12, true); - const list2 = new Uint8Array(memory.buffer.slice(ptr2, ptr2 + len2 * 1)); - free(ptr2, len2, 1); - result3.push({ - filename: list1, - contents: list2, + const len6 = data_view(memory).getInt32(ret + 8, true); + const base6 = data_view(memory).getInt32(ret + 4, true); + const result6 = []; + for (let i = 0; i < len6; i++) { + const base = base6 + i * 16; + const ptr4 = data_view(memory).getInt32(base + 0, true); + const len4 = data_view(memory).getInt32(base + 4, true); + const list4 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr4, len4)); + free(ptr4, len4, 1); + const ptr5 = data_view(memory).getInt32(base + 8, true); + const len5 = data_view(memory).getInt32(base + 12, true); + const list5 = new Uint8Array(memory.buffer.slice(ptr5, ptr5 + len5 * 1)); + free(ptr5, len5, 1); + result6.push({ + filename: list4, + contents: list5, }); } - free(base3, len3 * 16, 4); + free(base6, len6 * 16, 4); - variant8 = { tag: "ok", val: result3 }; + variant11 = { tag: "ok", val: result6 }; break; } case 1: { - const ptr4 = data_view(memory).getInt32(ret + 4, true); - const len4 = data_view(memory).getInt32(ret + 8, true); - const list4 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr4, len4)); - free(ptr4, len4, 1); - const ptr5 = data_view(memory).getInt32(ret + 12, true); - const len5 = data_view(memory).getInt32(ret + 16, true); - const list5 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr5, len5)); - free(ptr5, len5, 1); - const len7 = data_view(memory).getInt32(ret + 24, true); - const base7 = data_view(memory).getInt32(ret + 20, true); - const result7 = []; - for (let i = 0; i < len7; i++) { - const base = base7 + i * 8; - const ptr6 = data_view(memory).getInt32(base + 0, true); - const len6 = data_view(memory).getInt32(base + 4, true); - const list6 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr6, len6)); - free(ptr6, len6, 1); - result7.push(list6); + const ptr7 = data_view(memory).getInt32(ret + 4, true); + const len7 = data_view(memory).getInt32(ret + 8, true); + const list7 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr7, len7)); + free(ptr7, len7, 1); + const ptr8 = data_view(memory).getInt32(ret + 12, true); + const len8 = data_view(memory).getInt32(ret + 16, true); + const list8 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr8, len8)); + free(ptr8, len8, 1); + const len10 = data_view(memory).getInt32(ret + 24, true); + const base10 = data_view(memory).getInt32(ret + 20, true); + const result10 = []; + for (let i = 0; i < len10; i++) { + const base = base10 + i * 8; + const ptr9 = data_view(memory).getInt32(base + 0, true); + const len9 = data_view(memory).getInt32(base + 4, true); + const list9 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr9, len9)); + free(ptr9, len9, 1); + result10.push(list9); } - free(base7, len7 * 8, 4); + free(base10, len10 * 8, 4); - variant8 = { tag: "err", val: { - message: list4, - verbose: list5, - causes: result7, + variant11 = { tag: "err", val: { + message: list7, + verbose: list8, + causes: result10, } }; break; } @@ -360,7 +412,7 @@ class Package { throw new RangeError("invalid variant discriminant for expected"); } } - return variant8; + return variant11; } } diff --git a/crates/wasm/snapshots/Python/wasmer_pack__bindings__wasmer_pack__bindings.py.snap b/crates/wasm/snapshots/Python/wasmer_pack__bindings__wasmer_pack__bindings.py.snap index 9f4529ff5d..0c5312b04f 100644 --- a/crates/wasm/snapshots/Python/wasmer_pack__bindings__wasmer_pack__bindings.py.snap +++ b/crates/wasm/snapshots/Python/wasmer_pack__bindings__wasmer_pack__bindings.py.snap @@ -254,17 +254,19 @@ class Package: else: raise TypeError("invalid variant discriminant for expected") return expected - def generate_javascript(self, name: Optional[str]) -> Expected[List['File'], 'Error']: + def generate_javascript(self, options: 'BindingsOptions') -> Expected[List['File'], 'Error']: memory = self._obj._memory; realloc = self._obj._canonical_abi_realloc free = self._obj._canonical_abi_free obj = self - if name is None: + record = options + field = record.name + if field is None: variant = 0 variant2 = 0 variant3 = 0 else: - payload0 = name + payload0 = field ptr, len1 = _encode_utf8(payload0, realloc, memory) variant = 1 variant2 = ptr @@ -328,17 +330,19 @@ class Package: else: raise TypeError("invalid variant discriminant for expected") return expected - def generate_python(self, name: Optional[str]) -> Expected[List['File'], 'Error']: + def generate_python(self, options: 'BindingsOptions') -> Expected[List['File'], 'Error']: memory = self._obj._memory; realloc = self._obj._canonical_abi_realloc free = self._obj._canonical_abi_free obj = self - if name is None: + record = options + field = record.name + if field is None: variant = 0 variant2 = 0 variant3 = 0 else: - payload0 = name + payload0 = field ptr, len1 = _encode_utf8(payload0, realloc, memory) variant = 1 variant2 = ptr @@ -603,6 +607,13 @@ class Interface: raise TypeError("invalid variant discriminant for expected") return expected @dataclass +class BindingsOptions: + """ + Extra options for bindings generation + """ + name: Optional[str] + +@dataclass class Command: """ A WASI executable. diff --git a/crates/wasm/src/lib.rs b/crates/wasm/src/lib.rs index a2e27cd49c..6354c98bd6 100644 --- a/crates/wasm/src/lib.rs +++ b/crates/wasm/src/lib.rs @@ -37,17 +37,21 @@ impl crate::wasmer_pack::Package for Package { fn generate_javascript( &self, - name: Option, + options: wasmer_pack::BindingsOptions, ) -> Result, wasmer_pack::Error> { - let files = original::generate_javascript(&self.0, name)?; + let files = original::generate_javascript(&self.0, original::BindingsOptions{ + name: options.name + })?; Ok(unwrap_files(files)) } fn generate_python( &self, - name: Option, + options: wasmer_pack::BindingsOptions, ) -> Result, wasmer_pack::Error> { - let files = original::generate_python(&self.0, name)?; + let files = original::generate_python(&self.0, original::BindingsOptions{ + name: options.name + })?; Ok(unwrap_files(files)) } } diff --git a/crates/wasm/wasmer-pack.exports.wai b/crates/wasm/wasmer-pack.exports.wai index 5b4b9c0867..eb6f2538eb 100644 --- a/crates/wasm/wasmer-pack.exports.wai +++ b/crates/wasm/wasmer-pack.exports.wai @@ -1,3 +1,8 @@ +/// Extra options for bindings generation +record bindings-options { + name: option +} + /// A package to generate bindings for. resource package { /// Construct a new package from its components. @@ -11,10 +16,10 @@ resource package { /// Generate a JavaScript project that can be used to access the provided /// package. - generate-javascript: func(name: option) -> expected, error> + generate-javascript: func(options: bindings-options) -> expected, error> /// Generate a Python project that can be used to access the provided package. - generate-python: func(name: option) -> expected, error> + generate-python: func(options: bindings-options) -> expected, error> } /// Metadata describing a package. diff --git a/crates/wasmer-pack/src/js/mod.rs b/crates/wasmer-pack/src/js/mod.rs index fe0d8d8fb6..7ac127ebb9 100644 --- a/crates/wasmer-pack/src/js/mod.rs +++ b/crates/wasmer-pack/src/js/mod.rs @@ -8,7 +8,7 @@ use wai_bindgen_gen_core::Generator; use wai_bindgen_gen_js::Js; use wai_parser::Interface; -use crate::{types::Command, Files, Library, Metadata, Package, SourceFile}; +use crate::{types::Command, Files, Library, Metadata, Package, SourceFile, types::BindingsOptions}; /// The version of `@wasmer/wasi` pulled in when using a WASI library. /// @@ -41,7 +41,7 @@ static TEMPLATES: Lazy = Lazy::new(|| { }); /// Generate JavaScript bindings for a package. -pub fn generate_javascript(package: &Package, name: Option) -> Result { +pub fn generate_javascript(package: &Package, options: BindingsOptions) -> Result { let mut files = Files::new(); let ctx = Context::for_package(package); @@ -54,7 +54,7 @@ pub fn generate_javascript(package: &Package, name: Option) -> Result = files.iter().map(|(p, _)| p).collect(); assert_eq!(actual_files, expected); diff --git a/crates/wasmer-pack/src/lib.rs b/crates/wasmer-pack/src/lib.rs index e5c42ff848..f470e8f19c 100644 --- a/crates/wasmer-pack/src/lib.rs +++ b/crates/wasmer-pack/src/lib.rs @@ -29,7 +29,7 @@ //! let pkg = Package ::new(metadata, libraries, commands); //! //! // Now we can generate the bindings for our language -//! let js = wasmer_pack::generate_javascript(&pkg, None)?; +//! let js = wasmer_pack::generate_javascript(&pkg, wasmer_pack::BindingsOptions::default())?; //! //! // And finally, save them to disk //! js.save_to_disk("./out")?; @@ -49,6 +49,7 @@ mod versions; pub use crate::{ files::{Files, SourceFile}, + types::BindingsOptions, js::generate_javascript, py::generate_python, types::{Abi, Command, Interface, Library, Metadata, Module, Package, PackageName}, diff --git a/crates/wasmer-pack/src/py/mod.rs b/crates/wasmer-pack/src/py/mod.rs index 7c4a686445..6726dc6b57 100644 --- a/crates/wasmer-pack/src/py/mod.rs +++ b/crates/wasmer-pack/src/py/mod.rs @@ -8,7 +8,7 @@ use wai_bindgen_gen_core::Generator; use wai_bindgen_gen_wasmer_py::WasmerPy; use crate::{ - types::{Interface, Package}, + types::{Interface, Package, BindingsOptions}, Files, Metadata, Module, SourceFile, }; @@ -36,11 +36,11 @@ static TEMPLATES: Lazy = Lazy::new(|| { }); /// Generate Python bindings. -pub fn generate_python(package: &Package, name: Option) -> Result { +pub fn generate_python(package: &Package, options: BindingsOptions) -> Result { let metadata = package.metadata(); // make sure the name is in snake-case - let package_name = if let Some(name) = name { + let package_name = if let Some(name) = options.name { name.to_snake_case() } else { metadata.package_name.name().to_string().to_snake_case() @@ -401,7 +401,7 @@ mod tests { }]; let package = Package::new(metadata, libraries, commands); - let files = generate_python(&package, None).unwrap(); + let files = generate_python(&package, BindingsOptions::default()).unwrap(); let actual_files: BTreeSet<_> = files.iter().map(|(p, _)| p).collect(); assert_eq!(actual_files, expected); diff --git a/crates/wasmer-pack/src/types.rs b/crates/wasmer-pack/src/types.rs index 56008afa40..b1b70d903f 100644 --- a/crates/wasmer-pack/src/types.rs +++ b/crates/wasmer-pack/src/types.rs @@ -401,6 +401,13 @@ impl Command { } } +/// A set of extra options passed to the bindings generator function +#[derive(Default)] +pub struct BindingsOptions { + /// User defined name for the generated bindings + pub name: Option +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/wasmer-pack/tests/integration_tests.rs b/crates/wasmer-pack/tests/integration_tests.rs index ac780612cb..e7d7fe7055 100644 --- a/crates/wasmer-pack/tests/integration_tests.rs +++ b/crates/wasmer-pack/tests/integration_tests.rs @@ -14,7 +14,7 @@ fn use_wasi_javascript_bindings() { .join("javascript-wasi"); let _ = std::fs::remove_dir_all(&out_dir); - let js = wasmer_pack::generate_javascript(&pkg, None).unwrap(); + let js = wasmer_pack::generate_javascript(&pkg, wasmer_pack::BindingsOptions::default()).unwrap(); js.save_to_disk(&out_dir).unwrap(); let js_dir = Path::new(env!("CARGO_MANIFEST_DIR")) @@ -40,7 +40,7 @@ fn use_wasi_python_bindings() { .join("python-wasi"); let _ = std::fs::remove_dir_all(&out_dir); - let py = wasmer_pack::generate_python(&pkg, None).unwrap(); + let py = wasmer_pack::generate_python(&pkg, wasmer_pack::BindingsOptions::default()).unwrap(); py.save_to_disk(&out_dir).unwrap(); let python_dir = Path::new(env!("CARGO_MANIFEST_DIR")) From 7b789a04a3047b0a9da060ad98d7efcdbb22036f Mon Sep 17 00:00:00 2001 From: Ayush Jha Date: Tue, 23 Jan 2024 11:39:51 +0545 Subject: [PATCH 08/10] fix python and js tests by using a validd wasmer-pack version --- crates/wasm/index.test.ts | 4 +++- crates/wasm/test_wasmer_pack.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/wasm/index.test.ts b/crates/wasm/index.test.ts index 7054870241..96c40d6df9 100644 --- a/crates/wasm/index.test.ts +++ b/crates/wasm/index.test.ts @@ -4,9 +4,11 @@ import { Error as WasmerPackError, File, Package, + BindingsOptions, } from "@wasmer/wasmer-pack/src/bindings/wasmer-pack/wasmer-pack.js"; -const WASMER_PACK_WEBC_FILE = "https://registry-cdn.wapm.io/packages/wasmer/wasmer-pack/wasmer-pack-0.6.0-0b5e21ac-86e4-11ed-90e2-c6aeb50490de.webc"; +const WASMER_PACK_WEBC_FILE = "https://cdn.wasmer.io/webcimages/371a21a5a632442570f2d0ffe0125713ab8947b8b1596708e1fcee32be8cf2b7.webc"; + describe("wasmer-pack bindings", () => { it("is self-hosting", async () => { diff --git a/crates/wasm/test_wasmer_pack.py b/crates/wasm/test_wasmer_pack.py index 3e371f9b11..540be7f20a 100644 --- a/crates/wasm/test_wasmer_pack.py +++ b/crates/wasm/test_wasmer_pack.py @@ -5,6 +5,7 @@ import requests from wasmer_pack import bindings from wasmer_pack.bindings.wasmer_pack import ( + BindingsOptions, Err, Error, Ok, @@ -13,7 +14,7 @@ ) -WASMER_PACK_WEBC_FILE = "https://registry-cdn.wapm.io/packages/wasmer/wasmer-pack/wasmer-pack-0.6.0-0b5e21ac-86e4-11ed-90e2-c6aeb50490de.webc" +WASMER_PACK_WEBC_FILE = "https://cdn.wasmer.io/webcimages/371a21a5a632442570f2d0ffe0125713ab8947b8b1596708e1fcee32be8cf2b7.webc" project_root = Path(__file__).parents[4] @@ -34,7 +35,7 @@ def test_generate_bindings_for_wasmer_pack(): pkg = unwrap(Package.from_webc(wasmer_pack, webc)) try: - files = unwrap(pkg.generate_python()) + files = unwrap(pkg.generate_python(options=BindingsOptions(name=None))) expected = { 'MANIFEST.in', From f49a0f610881d3a615a6f8015eab6b62378f3442 Mon Sep 17 00:00:00 2001 From: Ayush Jha Date: Tue, 23 Jan 2024 11:41:53 +0545 Subject: [PATCH 09/10] Updadte changelog: fixed integration tests --- CHANGELOG.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c0e6aff81..d58954e51c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,14 +18,19 @@ change, where applicable. ### Added - Added ability to pass in a user-specified name for the generated bindings. This can be done by passing in the `--name` flag in the - CLI or by passing in the `name` options when calling the - `generate_*` functions. + CLI or by passing the `name` option when calling the `generate_*` + functions. ### Fixed - Fixed the `python-wasi` test in `wasmer-pack` crate to use poetry instead of pipenv. This is because poetry is used everywhere else, except in this one place. +- Fixed flaky integration tests by specifying a valid webc file for + wasmer-pack in both `test_wasmer_pack.py` (pytest) and + `index.test.ts` (jest) + + ## [0.7.1] - 2023-06-12 ### Added From 355079aacd2ac4428da8a5645c07babcd5017161 Mon Sep 17 00:00:00 2001 From: Ayush Jha Date: Tue, 23 Jan 2024 11:49:16 +0545 Subject: [PATCH 10/10] Fix formatting via `cargo fmt` --- crates/cli/src/codegen.rs | 13 ++++++------- crates/wasm/src/lib.rs | 12 ++++++------ crates/wasmer-pack/src/js/mod.rs | 7 ++++--- crates/wasmer-pack/src/lib.rs | 2 +- crates/wasmer-pack/src/py/mod.rs | 2 +- crates/wasmer-pack/src/types.rs | 2 +- crates/wasmer-pack/tests/integration_tests.rs | 3 ++- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/crates/cli/src/codegen.rs b/crates/cli/src/codegen.rs index fb179a09a8..97912fce09 100644 --- a/crates/cli/src/codegen.rs +++ b/crates/cli/src/codegen.rs @@ -4,7 +4,6 @@ use crate::Error; use anyhow::Context; use clap::Parser; - #[derive(Debug, Parser)] pub struct Codegen { /// What to name the generated bindings. @@ -27,12 +26,12 @@ impl Codegen { let pkg = crate::utils::load(&input)?; let files = match language { - Language::JavaScript => wasmer_pack::generate_javascript(&pkg, wasmer_pack::BindingsOptions { - name, - })?, - Language::Python => wasmer_pack::generate_python(&pkg, wasmer_pack::BindingsOptions { - name, - })?, + Language::JavaScript => { + wasmer_pack::generate_javascript(&pkg, wasmer_pack::BindingsOptions { name })? + } + Language::Python => { + wasmer_pack::generate_python(&pkg, wasmer_pack::BindingsOptions { name })? + } }; let metadata = pkg.metadata(); diff --git a/crates/wasm/src/lib.rs b/crates/wasm/src/lib.rs index 6354c98bd6..7a808425ea 100644 --- a/crates/wasm/src/lib.rs +++ b/crates/wasm/src/lib.rs @@ -39,9 +39,10 @@ impl crate::wasmer_pack::Package for Package { &self, options: wasmer_pack::BindingsOptions, ) -> Result, wasmer_pack::Error> { - let files = original::generate_javascript(&self.0, original::BindingsOptions{ - name: options.name - })?; + let files = original::generate_javascript( + &self.0, + original::BindingsOptions { name: options.name }, + )?; Ok(unwrap_files(files)) } @@ -49,9 +50,8 @@ impl crate::wasmer_pack::Package for Package { &self, options: wasmer_pack::BindingsOptions, ) -> Result, wasmer_pack::Error> { - let files = original::generate_python(&self.0, original::BindingsOptions{ - name: options.name - })?; + let files = + original::generate_python(&self.0, original::BindingsOptions { name: options.name })?; Ok(unwrap_files(files)) } } diff --git a/crates/wasmer-pack/src/js/mod.rs b/crates/wasmer-pack/src/js/mod.rs index 7ac127ebb9..f6ee98432e 100644 --- a/crates/wasmer-pack/src/js/mod.rs +++ b/crates/wasmer-pack/src/js/mod.rs @@ -8,7 +8,9 @@ use wai_bindgen_gen_core::Generator; use wai_bindgen_gen_js::Js; use wai_parser::Interface; -use crate::{types::Command, Files, Library, Metadata, Package, SourceFile, types::BindingsOptions}; +use crate::{ + types::BindingsOptions, types::Command, Files, Library, Metadata, Package, SourceFile, +}; /// The version of `@wasmer/wasi` pulled in when using a WASI library. /// @@ -377,8 +379,7 @@ mod tests { }]; let pkg = Package::new(metadata, libraries, commands); - let files = generate_javascript(&pkg, BindingsOptions { - name: None}).unwrap(); + let files = generate_javascript(&pkg, BindingsOptions { name: None }).unwrap(); let actual_files: BTreeSet<_> = files.iter().map(|(p, _)| p).collect(); assert_eq!(actual_files, expected); diff --git a/crates/wasmer-pack/src/lib.rs b/crates/wasmer-pack/src/lib.rs index f470e8f19c..7ac2b59def 100644 --- a/crates/wasmer-pack/src/lib.rs +++ b/crates/wasmer-pack/src/lib.rs @@ -49,9 +49,9 @@ mod versions; pub use crate::{ files::{Files, SourceFile}, - types::BindingsOptions, js::generate_javascript, py::generate_python, + types::BindingsOptions, types::{Abi, Command, Interface, Library, Metadata, Module, Package, PackageName}, versions::WAI_PARSER_VERSION, }; diff --git a/crates/wasmer-pack/src/py/mod.rs b/crates/wasmer-pack/src/py/mod.rs index 6726dc6b57..d7e1ca6697 100644 --- a/crates/wasmer-pack/src/py/mod.rs +++ b/crates/wasmer-pack/src/py/mod.rs @@ -8,7 +8,7 @@ use wai_bindgen_gen_core::Generator; use wai_bindgen_gen_wasmer_py::WasmerPy; use crate::{ - types::{Interface, Package, BindingsOptions}, + types::{BindingsOptions, Interface, Package}, Files, Metadata, Module, SourceFile, }; diff --git a/crates/wasmer-pack/src/types.rs b/crates/wasmer-pack/src/types.rs index b1b70d903f..14b29d4239 100644 --- a/crates/wasmer-pack/src/types.rs +++ b/crates/wasmer-pack/src/types.rs @@ -405,7 +405,7 @@ impl Command { #[derive(Default)] pub struct BindingsOptions { /// User defined name for the generated bindings - pub name: Option + pub name: Option, } #[cfg(test)] diff --git a/crates/wasmer-pack/tests/integration_tests.rs b/crates/wasmer-pack/tests/integration_tests.rs index e7d7fe7055..f6a26d4693 100644 --- a/crates/wasmer-pack/tests/integration_tests.rs +++ b/crates/wasmer-pack/tests/integration_tests.rs @@ -14,7 +14,8 @@ fn use_wasi_javascript_bindings() { .join("javascript-wasi"); let _ = std::fs::remove_dir_all(&out_dir); - let js = wasmer_pack::generate_javascript(&pkg, wasmer_pack::BindingsOptions::default()).unwrap(); + let js = + wasmer_pack::generate_javascript(&pkg, wasmer_pack::BindingsOptions::default()).unwrap(); js.save_to_disk(&out_dir).unwrap(); let js_dir = Path::new(env!("CARGO_MANIFEST_DIR"))