From da6dd166b6c79c6169025fd0eea1da666a696dee Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 26 Feb 2019 08:44:04 -0800 Subject: [PATCH] Fix the webidl-tests crate --- .appveyor.yml | 1 + .travis.yml | 1 + crates/cli-support/src/js/mod.rs | 14 +++++++++----- crates/webidl-tests/build.rs | 5 ++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 81fd79b758f..3675d4e7c04 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -28,6 +28,7 @@ test_script: - where chromedriver - set CHROMEDRIVER=C:\Tools\WebDriver\chromedriver.exe - cargo test -p js-sys --target wasm32-unknown-unknown + - set WBINDGEN_I_PROMISE_JS_SYNTAX_WORKS_IN_NODE=1 - cargo test -p webidl-tests --target wasm32-unknown-unknown # Try just a few features for `web-sys`, unfortunately the whole crate blows # system command line limits meaning we can't even spawn rustc to enable all diff --git a/.travis.yml b/.travis.yml index ed2b753daca..55736fcfa1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -166,6 +166,7 @@ matrix: install: *INSTALL_NODE_VIA_NVM script: - cargo test -p wasm-bindgen-webidl + - export WBINDGEN_I_PROMISE_JS_SYNTAX_WORKS_IN_NODE=1 - cargo test -p webidl-tests --target wasm32-unknown-unknown if: branch = master diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index 61fd459032d..b10a215cb1b 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -3,6 +3,7 @@ use crate::descriptor::{Descriptor, VectorKind}; use crate::{Bindgen, EncodeInto, OutputMode}; use failure::{bail, Error, ResultExt}; use std::collections::{HashMap, HashSet}; +use std::env; use walrus::{MemoryId, Module}; use wasm_bindgen_wasm_interpreter::Interpreter; @@ -2792,11 +2793,14 @@ impl<'a, 'b> SubContext<'a, 'b> { // module syntax in the snippet to a CommonJS module, which is in theory // not that hard but is a chunk of work to do. if is_local_snippet && self.cx.config.mode.nodejs() { - bail!( - "local JS snippets are not supported with `--nodejs`; \ - see rustwasm/rfcs#6 for more details, but this restriction \ - will be lifted in the future" - ); + // have a small unergonomic escape hatch for our webidl-tests tests + if env::var("WBINDGEN_I_PROMISE_JS_SYNTAX_WORKS_IN_NODE").is_err() { + bail!( + "local JS snippets are not supported with `--nodejs`; \ + see rustwasm/rfcs#6 for more details, but this restriction \ + will be lifted in the future" + ); + } } // Similar to `--no-modules`, only allow vendor prefixes basically for web diff --git a/crates/webidl-tests/build.rs b/crates/webidl-tests/build.rs index 53c4be12d52..3f4e2fb4c66 100644 --- a/crates/webidl-tests/build.rs +++ b/crates/webidl-tests/build.rs @@ -21,14 +21,13 @@ fn main() { let out_file = out_dir.join(path.file_name().unwrap()).with_extension("rs"); - let js_file = path.with_extension("js").canonicalize().unwrap(); generated_rust.push_str(&format!( r#" pub mod import_script {{ use wasm_bindgen::prelude::*; use wasm_bindgen_test::*; - #[wasm_bindgen(module = r"{}")] + #[wasm_bindgen(module = "/{}.js")] extern "C" {{ fn not_actually_a_function{1}(x: &str); }} @@ -41,7 +40,7 @@ fn main() { }} }} "#, - js_file.display(), + path.file_stem().unwrap().to_str().unwrap(), i ));