Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description to generated packages #128

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ change, where applicable.
and not just `wasmer/wasmer-pack`
([#124](https://github.com/wasmerio/wasmer-pack/pull/124))

- Added description field to package.json for javascript packages, and
pyproject.toml for python projects..
([#128](1https://github.com/wasmerio/wasmer-pack/pull/128))

## [0.7.0] - 2023-02-10

### 💥 Breaking Changes 💥
Expand Down
31 changes: 30 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ expression: "format!(\"{meta:#}\")"
}
],
"commands": [],
"description": null,
"description": "The WebAssembly interface to wit-pack.",
"name": "wasmer/wit-pack",
"version": "0.3.0-beta"
}
2 changes: 1 addition & 1 deletion crates/cli/tests/snapshots/known_packages__wabt.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ expression: "format!(\"{meta:#}\")"
"name": "wasm-strip"
}
],
"description": null,
"description": "The WebAssembly Binary Toolkit",
"name": "wasmer/wabt",
"version": "1.0.33"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ expression: "format!(\"{meta:#}\")"
}
],
"commands": [],
"description": null,
"description": "Add two numbers",
"name": "wai/tutorial-01",
"version": "0.1.1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ expression: "format!(\"{meta:#}\")"
}
],
"commands": [],
"description": null,
"description": "The WebAssembly interface to wit-pack.",
"name": "wasmer/wit-pack",
"version": "0.3.0-beta"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ expression: "format!(\"{meta:#}\")"
"name": "wit-pack"
}
],
"description": null,
"description": "A code generator that lets you treat WebAssembly modules like native dependencies.",
"name": "wasmer/wit-pack-cli",
"version": "0.3.0-beta"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ expression: "format!(\"{meta:#}\")"
}
],
"commands": [],
"description": null,
"description": "The WebAssembly interface to wit-pack.",
"name": "wasmer/wit-pack",
"version": "0.3.0-beta"
}
1 change: 1 addition & 0 deletions crates/wasm/snapshots/Python/pyproject.toml.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ input_file: crates/wasm/generated_bindings/Python/pyproject.toml
[project]
name = "wasmer_pack"
version = "x.y.z"
description = "The WebAssembly interface to wasmer-pack."
keywords = []
dependencies = ["wasmer", "wasmer_compiler_cranelift"]

Expand Down
2 changes: 1 addition & 1 deletion crates/wasm/snapshots/Python/wasmer_pack____init__.py.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: crates/testing/src/autodiscover.rs
input_file: crates/wasm/generated_bindings/Python/wasmer_pack/__init__.py
---
'''
Bindings to wasmer/wasmer-pack vX.Y.Z.
The WebAssembly interface to wasmer-pack.
'''

# Generated by wasmer-pack vX.Y.Z.
Expand Down
3 changes: 2 additions & 1 deletion crates/wasmer-pack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ heck = "0.4.0"
minijinja = "0.23.0"
once_cell = "1.14.0"
serde = { version = "1.0.143", features = ["derive"] }
serde_cbor = "0.11.2"
serde_json = "1.0.83"
toml = "0.5.9"
wai-bindgen-gen-core = "0.2.1"
wai-bindgen-gen-js = "0.2.1"
wai-bindgen-gen-wasmer-py = "0.2.1"
wai-parser = "0.2.1"
wasmparser = "0.99.0"
webc = "4.0.0"
webc = "5.0.0-rc.6"

[dev-dependencies]
cargo_metadata = "0.15.0"
Expand Down
5 changes: 4 additions & 1 deletion crates/wasmer-pack/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,17 @@ fn generate_package_json(needs_wasi: bool, metadata: &Metadata) -> SourceFile {
serde_json::json!({})
};

let package_json = serde_json::json!({
let mut package_json = serde_json::json!({
"name": metadata.package_name.javascript_package(),
"version": &metadata.version,
"main": format!("src/index.js"),
"types": format!("src/index.d.ts"),
"type": "commonjs",
"dependencies": dependencies,
});
if let Some(description) = &metadata.description {
package_json["description"] = serde_json::Value::String(description.to_string());
}

format!("{package_json:#}").into()
}
Expand Down
30 changes: 18 additions & 12 deletions crates/wasmer-pack/src/pirita.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use std::path::Path;

use anyhow::{Context, Error};
use webc::{DirOrFile, Manifest, ParseOptions, WebC};

use crate::{Abi, Command, Interface, Library, Metadata, Module, Package};
use anyhow::{Context, Error};
pub use serde_cbor::Value;
use std::path::Path;
use webc::metadata::annotations::Wapm;
use webc::metadata::{Binding, BindingsExtended, Manifest};
use webc::v1::{DirOrFile, ParseOptions, WebC};

pub(crate) fn load_webc_binary(raw_webc: &[u8]) -> Result<Package, Error> {
let options = ParseOptions::default();
let webc = WebC::parse(raw_webc, &options)?;

let fully_qualified_package_name = webc.get_package_name();
let metadata = metadata(&fully_qualified_package_name)?;

let metadata = metadata(&webc, &fully_qualified_package_name)?;
let libraries = libraries(&webc, &fully_qualified_package_name)?;
let commands = commands(&webc, &fully_qualified_package_name)?;

Expand Down Expand Up @@ -39,22 +41,26 @@ fn libraries(webc: &WebC<'_>, fully_qualified_package_name: &str) -> Result<Vec<
let Manifest { bindings, .. } = webc.get_metadata();
let libraries = bindings
.iter()
.map(|b| load_library(b, webc, fully_qualified_package_name))
.map(|b| load_library(b.clone(), webc, fully_qualified_package_name))
.collect::<Result<Vec<_>, _>>()?;

Ok(libraries)
}

fn metadata(fully_qualified_package_name: &str) -> Result<Metadata, Error> {
fn metadata(webc: &WebC<'_>, fully_qualified_package_name: &str) -> Result<Metadata, Error> {
let (unversioned_name, version) = fully_qualified_package_name.split_once('@').unwrap();
let package_name = unversioned_name
.parse()
.context("Unable to parse the package name")?;
Ok(Metadata::new(package_name, version))
let mut metadata = Metadata::new(package_name, version);
if let Ok(Some(Wapm { description, .. })) = webc.manifest.package_annotation("wapm") {
metadata = metadata.with_description(description);
}
Ok(metadata)
}

fn load_library(
bindings: &webc::Binding,
bindings: Binding,
webc: &WebC,
fully_qualified_package_name: &str,
) -> Result<Library, Error> {
Expand All @@ -69,8 +75,8 @@ fn load_library(
.context("Unable to load the exports interface")?;

let imports_paths = match &bindings {
webc::BindingsExtended::Wit(_) => &[],
webc::BindingsExtended::Wai(w) => w.imports.as_slice(),
BindingsExtended::Wit(_) => &[],
BindingsExtended::Wai(w) => w.imports.as_slice(),
};
let imports = imports_paths
.iter()
Expand Down
2 changes: 1 addition & 1 deletion examples/calc/snapshots/Python/calc____init__.py.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: crates/testing/src/autodiscover.rs
input_file: examples/calc/generated_bindings/Python/calc/__init__.py
---
'''
Bindings to Michael-F-Bryan/calc v0.0.0.
The simplest possible WebAssembly module
'''

# Generated by wasmer-pack vX.Y.Z.
Expand Down
1 change: 1 addition & 0 deletions examples/calc/snapshots/Python/pyproject.toml.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ input_file: examples/calc/generated_bindings/Python/pyproject.toml
[project]
name = "calc"
version = "x.y.z"
description = "The simplest possible WebAssembly module"
keywords = []
dependencies = ["wasmer", "wasmer_compiler_cranelift"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: crates/testing/src/autodiscover.rs
input_file: examples/hello-wasi/generated_bindings/Python/hello_wasi/__init__.py
---
'''
Bindings to Michael-F-Bryan/hello-wasi v0.1.0.
The simplest possible WASI WebAssembly library.
'''

# Generated by wasmer-pack vX.Y.Z.
Expand Down
1 change: 1 addition & 0 deletions examples/hello-wasi/snapshots/Python/pyproject.toml.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ input_file: examples/hello-wasi/generated_bindings/Python/pyproject.toml
[project]
name = "hello_wasi"
version = "x.y.z"
description = "The simplest possible WASI WebAssembly library."
keywords = []
dependencies = ["wasmer", "wasmer_compiler_cranelift"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: crates/testing/src/autodiscover.rs
input_file: examples/host-imports/generated_bindings/Python/host_imports/__init__.py
---
'''
Bindings to Michael-F-Bryan/host-imports v0.0.0.
A WebAssembly library that imports some functions from its host.
'''

# Generated by wasmer-pack vX.Y.Z.
Expand Down
1 change: 1 addition & 0 deletions examples/host-imports/snapshots/Python/pyproject.toml.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ input_file: examples/host-imports/generated_bindings/Python/pyproject.toml
[project]
name = "host_imports"
version = "x.y.z"
description = "A WebAssembly library that imports some functions from its host."
keywords = []
dependencies = ["wasmer", "wasmer_compiler_cranelift"]

Expand Down