diff --git a/crates/swc_plugin/src/context.rs b/crates/swc_plugin/src/context.rs index 49ff4f5882d..78d8667d586 100644 --- a/crates/swc_plugin/src/context.rs +++ b/crates/swc_plugin/src/context.rs @@ -1,5 +1,6 @@ use swc_common::plugin::Serialized; +#[cfg(target_arch = "wasm32")] // Allow testing extern "C" { fn __emit_diagnostics(bytes_ptr: i32, bytes_ptr_len: i32); fn __free(bytes_ptr: i32, size: i32) -> i32; @@ -13,14 +14,16 @@ extern "C" { pub struct PluginDiagnosticsEmitter {} impl swc_common::errors::Emitter for PluginDiagnosticsEmitter { + #[cfg_attr(not(target_arch = "wasm32"), allow(unused))] fn emit(&mut self, db: &swc_common::errors::DiagnosticBuilder<'_>) { let diag = Serialized::serialize(&*db.diagnostic).expect("Should able to serialize Diagnostic"); let diag_ref = diag.as_ref(); - let ptr = diag_ref.as_ptr() as _; + let ptr = diag_ref.as_ptr() as i32; let len = diag_ref.len() as i32; + #[cfg(target_arch = "wasm32")] // Allow testing unsafe { __emit_diagnostics(ptr, len); } diff --git a/crates/swc_plugin_macro/src/lib.rs b/crates/swc_plugin_macro/src/lib.rs index 217aceaf02e..0bcdf19c17b 100644 --- a/crates/swc_plugin_macro/src/lib.rs +++ b/crates/swc_plugin_macro/src/lib.rs @@ -26,6 +26,7 @@ fn handle_func(func: ItemFn) -> TokenStream { // Declaration for imported function from swc host. // Refer swc_plugin_runner for the actual implementation. + #[cfg(target_arch = "wasm32")] // Allow testing extern "C" { fn __set_transform_result(bytes_ptr: i32, bytes_ptr_len: i32); fn __free(bytes_ptr: i32, size: i32) -> i32; @@ -36,6 +37,7 @@ fn handle_func(func: ItemFn) -> TokenStream { /// When guest calls __set_transform_result host should've completed read guest's memory and allocates its byte /// into host's enviroment so guest can free its memory later. fn set_transform_result_volatile(bytes_ptr: i32, bytes_ptr_len: i32) { + #[cfg(target_arch = "wasm32")] // Allow testing unsafe { __set_transform_result(bytes_ptr, bytes_ptr_len); __free(bytes_ptr, bytes_ptr_len);