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

Fix the path used when importing a JavaScript library #115

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions crates/testing/src/autodiscover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ fn setup_python(crate_dir: &Path, generated_bindings: &Path) -> Result<(), Error
cmd.arg("install")
.arg("--sync")
.arg("--no-interaction")
.arg("--quiet")
.arg("--no-root");
tracing::info!(?cmd, "Installing dependencies");
let status = cmd
Expand Down
23 changes: 5 additions & 18 deletions crates/wasmer-pack/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,14 @@ use crate::{types::Command, Files, Library, Metadata, Package, SourceFile};
const WASMER_WASI_VERSION: &str = "^1.2.2";

static TEMPLATES: Lazy<Environment> = Lazy::new(|| {
let mut env = Environment::new();
env.add_template("bindings.index.js", include_str!("bindings.index.js.j2"))
.unwrap();
env.add_template(
compile_templates!(
"bindings.index.js",
"bindings.index.d.ts",
include_str!("bindings.index.d.ts.j2"),
)
.unwrap();
env.add_template("command.d.ts", include_str!("command.d.ts.j2"))
.unwrap();
env.add_template("command.js", include_str!("command.js.j2"))
.unwrap();
env.add_template("top-level.index.js", include_str!("top-level.index.js.j2"))
.unwrap();
env.add_template(
"top-level.index.d.ts",
include_str!("top-level.index.d.ts.j2"),
"command.d.ts",
"command.js",
"top-level.index.js",
)
.unwrap();

env
});

/// Generate JavaScript bindings for a package.
Expand Down
3 changes: 3 additions & 0 deletions crates/wasmer-pack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#[cfg(test)]
extern crate pretty_assertions;

#[macro_use]
mod macros;

mod files;
mod js;
mod py;
Expand Down
15 changes: 15 additions & 0 deletions crates/wasmer-pack/src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
macro_rules! compile_templates {
( $($name:literal),* $(,)?) => {{
let mut env = Environment::new();

$(
env.add_template(
$name,
include_str!(concat!($name, ".j2")),
)
.expect(concat!("Unable to add template, ", $name));
)*

env
}}
}
18 changes: 2 additions & 16 deletions crates/wasmer-pack/src/py/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,12 @@ use crate::{
};

static TEMPLATES: Lazy<Environment> = Lazy::new(|| {
let mut env = Environment::new();
env.add_template(
compile_templates!(
"bindings.__init__.py",
include_str!("bindings.__init__.py.j2"),
)
.unwrap();
env.add_template(
"top_level.__init__.py",
include_str!("top_level.__init__.py.j2"),
)
.unwrap();
env.add_template("MANIFEST.in", include_str!("MANIFEST.in.j2"))
.unwrap();
env.add_template(
"MANIFEST.in",
"commands.__init__.py",
include_str!("commands.__init__.py.j2"),
)
.unwrap();

env
});

/// Generate Python bindings.
Expand Down
3 changes: 2 additions & 1 deletion examples/wasi-executable/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "wasi-executable"
# Note: We use "_" instead of "-" to test https://github.com/wasmerio/wasmer-pack/issues/98
name = "wasi_executable"
version = "0.0.0"
description = "A basic WASI executable."
edition = "2021"
Expand Down