diff --git a/.travis.yml b/.travis.yml index 4da32b9d..31c58032 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ matrix: - rust: nightly before_install: rustup component add rustfmt-preview --toolchain nightly script: (cd crates/webidl && cargo test) - env: RUST_BACKTRACE=1 + env: RUST_BACKTRACE=1 RUST_LOG=wasm_bindgen_webidl # Dist linux binary - env: TARGET=x86_64-unknown-linux-musl DEPLOY=1 diff --git a/crates/webidl/Cargo.toml b/crates/webidl/Cargo.toml index 51544224..8b586ecb 100644 --- a/crates/webidl/Cargo.toml +++ b/crates/webidl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-bindgen-webidl" -version = "0.1.0" +version = "0.2.11" authors = ["Nick Fitzgerald "] [[test]] @@ -12,12 +12,14 @@ name = "webidl-expected" path = "tests/expected/lib.rs" [dev-dependencies] +diff = "0.1.11" +env_logger = "0.5.10" wasm-bindgen = { version = "=0.2.11", path = "../..", default-features = false } wasm-bindgen-backend = { version = "=0.2.11", path = "../backend", features = ["extra-traits"] } -diff = "0.1.11" [dependencies] failure = "0.1" +log = "0.4.1" proc-macro2 = "0.4" quote = '0.6' syn = { version = '0.14', features = ['full'] } diff --git a/crates/webidl/src/lib.rs b/crates/webidl/src/lib.rs index a4039a42..377ce86e 100755 --- a/crates/webidl/src/lib.rs +++ b/crates/webidl/src/lib.rs @@ -9,6 +9,8 @@ emitted for the types and methods described in the WebIDL. #![deny(missing_debug_implementations)] extern crate failure; +#[macro_use] +extern crate log; extern crate proc_macro2; extern crate quote; extern crate syn; @@ -99,7 +101,10 @@ impl<'a> WebidlParse<'a> for webidl::ast::Definition { | webidl::ast::Definition::Includes(..) | webidl::ast::Definition::Mixin(..) | webidl::ast::Definition::Namespace(..) - | webidl::ast::Definition::Typedef(..) => Ok(()), + | webidl::ast::Definition::Typedef(..) => { + warn!("Unsupported WebIDL definition: {:?}", self); + Ok(()) + } } } } @@ -113,7 +118,10 @@ impl<'a> WebidlParse<'a> for webidl::ast::Interface { interface.webidl_parse(program, ()) } // TODO - webidl::ast::Interface::Callback(..) | webidl::ast::Interface::Partial(..) => Ok(()), + webidl::ast::Interface::Callback(..) | webidl::ast::Interface::Partial(..) => { + warn!("Unsupported WebIDL interface: {:?}", self); + Ok(()) + } } } } @@ -153,7 +161,10 @@ impl<'a> WebidlParse<'a> for webidl::ast::InterfaceMember { | webidl::ast::InterfaceMember::Const(_) | webidl::ast::InterfaceMember::Iterable(_) | webidl::ast::InterfaceMember::Maplike(_) - | webidl::ast::InterfaceMember::Setlike(_) => Ok(()), + | webidl::ast::InterfaceMember::Setlike(_) => { + warn!("Unsupported WebIDL interface member: {:?}", self); + Ok(()) + } } } } @@ -167,7 +178,10 @@ impl<'a> WebidlParse<'a> for webidl::ast::Operation { // TODO webidl::ast::Operation::Special(_) | webidl::ast::Operation::Static(_) - | webidl::ast::Operation::Stringifier(_) => Ok(()), + | webidl::ast::Operation::Stringifier(_) => { + warn!("Unsupported WebIDL operation: {:?}", self); + Ok(()) + } } } } @@ -276,14 +290,26 @@ impl<'a> WebidlParse<'a> for webidl::ast::RegularOperation { fn webidl_parse(&self, program: &mut backend::ast::Program, self_name: &'a str) -> Result<()> { let fn_name = match self.name { - None => return Ok(()), + None => { + warn!( + "Operations without a name are unsupported. Skipping {:?}", + self + ); + return Ok(()); + } Some(ref name) => Ident::new(name, proc_macro2::Span::call_site()), }; let (output, ret) = match self.return_type { webidl::ast::ReturnType::Void => (syn::ReturnType::Default, None), webidl::ast::ReturnType::NonVoid(ref ty) => match webidl_ty_to_syn_ty(ty) { - None => return Ok(()), + None => { + warn!( + "Operation's return type is not yet supported: {:?}. Skipping bindings for {:?}", + ty, self + ); + return Ok(()); + } Some(ty) => ( syn::ReturnType::Type(Default::default(), Box::new(ty.clone())), Some(ty), @@ -303,14 +329,30 @@ impl<'a> WebidlParse<'a> for webidl::ast::RegularOperation { arguments.push(self_ref_ty); for arg in &self.arguments { - if arg.optional || arg.variadic { - // We don't support optional or variadic functions yet; skip - // bindings for this this whole function. + if arg.optional { + warn!( + "Optional arguments are not supported yet. Skipping bindings for {:?}", + self + ); + return Ok(()); + } + + if arg.variadic { + warn!( + "Variadic arguments are not supported yet. Skipping bindings for {:?}", + self + ); return Ok(()); } match webidl_ty_to_syn_ty(&arg.type_) { - None => return Ok(()), + None => { + warn!( + "Argument's type is not yet supported: {:?}. Skipping bindings for {:?}", + arg.type_, self + ); + return Ok(()); + } Some(ty) => { inputs.push(simple_fn_arg( proc_macro2::Ident::new(&arg.name, proc_macro2::Span::call_site()), diff --git a/crates/webidl/tests/all/lib.rs b/crates/webidl/tests/all/lib.rs index 3e95915d..19d08cec 100644 --- a/crates/webidl/tests/all/lib.rs +++ b/crates/webidl/tests/all/lib.rs @@ -1,4 +1,5 @@ extern crate diff; +extern crate env_logger; extern crate proc_macro2; extern crate syn; extern crate wasm_bindgen_backend as backend; diff --git a/crates/webidl/tests/all/util.rs b/crates/webidl/tests/all/util.rs index 40befff8..76dd531a 100644 --- a/crates/webidl/tests/all/util.rs +++ b/crates/webidl/tests/all/util.rs @@ -1,4 +1,5 @@ use diff; +use env_logger; use std::io::{self, Write}; use std::process; use std::sync::{Once, ONCE_INIT}; @@ -90,6 +91,11 @@ fn strip_wasm_bindgen_generated(source: String) -> String { } pub fn assert_compile(webidl: &str, expected: &str) { + static INIT_ENV_LOGGER: Once = ONCE_INIT; + INIT_ENV_LOGGER.call_once(|| { + env_logger::init(); + }); + let actual = wb_webidl::compile(webidl).expect("should compile the webidl source OK"); let (actual, actual_stderr) = rustfmt(actual);