Skip to content

Commit

Permalink
Merge pull request #137 from wasmerio/user-defined-name
Browse files Browse the repository at this point in the history
  • Loading branch information
ayys authored Jan 23, 2024
2 parents 8c3b73c + 355079a commit 3044670
Show file tree
Hide file tree
Showing 20 changed files with 631 additions and 399 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ 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 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
Expand Down
18 changes: 14 additions & 4 deletions crates/cli/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// Where to save the generated bindings.
#[clap(short, long)]
pub out_dir: Option<PathBuf>,
Expand All @@ -15,13 +18,20 @@ 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, wasmer_pack::BindingsOptions { name })?
}
Language::Python => {
wasmer_pack::generate_python(&pkg, wasmer_pack::BindingsOptions { name })?
}
};

let metadata = pkg.metadata();
Expand Down
2 changes: 1 addition & 1 deletion crates/testing/src/autodiscover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn autodiscover(crate_dir: impl AsRef<Path>) -> 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 => {
Expand Down
2 changes: 2 additions & 0 deletions crates/testing/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub fn generate_bindings(
dest: &Path,
wapm_dir: &Path,
lang: Language,
name: Option<String>,
) -> Result<(), anyhow::Error> {
tracing::info!(
output_dir=%dest.display(),
Expand All @@ -38,6 +39,7 @@ pub fn generate_bindings(
"Generating bindings",
);
let codegen = Codegen {
name,
out_dir: Some(dest.to_path_buf()),
input: wapm_dir.to_path_buf(),
};
Expand Down
4 changes: 3 additions & 1 deletion crates/wasm/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ input_file: crates/wasm/generated_bindings/JavaScript/package/src/bindings/wasme
---
export type Result<T, E> = { tag: "ok", val: T } | { tag: "err", val: E };
/**
* Extra options for bindings generation
*/
export interface BindingsOptions {
name?: string,
}
/**
* A WASI executable.
*/
export interface Command {
Expand Down Expand Up @@ -192,11 +198,11 @@ export class Package {
* Generate a JavaScript project that can be used to access the provided
* package.
*/
generateJavascript(): Result<File[], Error>;
generateJavascript(options: BindingsOptions): Result<File[], Error>;
/**
* Generate a Python project that can be used to access the provided package.
*/
generatePython(): Result<File[], Error>;
generatePython(options: BindingsOptions): Result<File[], Error>;
}

export class Metadata {
Expand Down
Loading

0 comments on commit 3044670

Please sign in to comment.