I have a project that uses wasm_bindgen, and which uses an extern "C"
block to import code defined in a JS file, like so:
#[wasm_bindgen(module = "../src/foo.js")]
extern "C" {
fn bar(quux: &str, corge: &str) -> String;
fn baz(grault: &str) -> String;
}
Both the rust file that contains the extern "C"
block above, and the foo.js
file live in the $PROJECT_DIR/src
directory i.e. we have $PROJECT_DIR/src/lib.rs
and $PROJECT_DIR/src/foo.js
.
However, I've just updated the dependencies of PROJECT to the most recent wasm_bindgen version (from wasm-bindgen 0.2.29
to wasm-bindgen 0.2.39
as of the time of writing), and suddenly I get a build error claiming that
error: relative module paths aren't supported yet
--> src/lib.rs:40:25
|
40 | #[wasm_bindgen(module = "../src/foo.js")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Consequently, code defined in $PROJECT_DIR/src/foo.js
can't be found anymore, generating additional compile errors. FTR: this did work with wasm-bindgen 0.2.29
.
I have tried replacing the attribute with (in turn, of course)
#[wasm_bindgen(module = "src/foo.js")]
and
#[wasm_bindgen(module = "foo.js")]
Neither of these 2 seems to work.
However, when I hand-hack the generated $PROJECT_DIR/project.js
file (which is generated next to $PROJECT_DIR/project.wasm
) and alter the imports from
const bar = require(String.raw`foo.js`).bar;
const baz = require(String.raw`foo.js`).baz;
to
const bar = require('path').join(__dirname, 'src/foo.js').bar;
const baz = require('path').join(__dirname, 'src/foo.js').baz;
then that works.
Given that relative paths aren't supported anymore (which, from at least the user perspective, is extremely weird in its own right btw), how can I make the Rust compiler understand that I need access to that JS file using the wasm_bindgen
attribute now? Hand-hacking like illustrated above is not sustainable.