diff --git a/.github/workflows/playground.yml b/.github/workflows/playground.yml index b13631feeb..ce81eb7a23 100644 --- a/.github/workflows/playground.yml +++ b/.github/workflows/playground.yml @@ -1,7 +1,7 @@ name: Build playground on: push: - branches: [main] + branches: [main, test] pull_request: merge_group: diff --git a/playground/.gitignore b/playground/.gitignore index 06af0ad93f..79f14c47fc 100644 --- a/playground/.gitignore +++ b/playground/.gitignore @@ -1,3 +1,4 @@ node_modules/ +src/bindings.rs component-built/ dist/ diff --git a/playground/component/src/bindings.rs b/playground/component/src/bindings.rs deleted file mode 100644 index 30fe002dc6..0000000000 --- a/playground/component/src/bindings.rs +++ /dev/null @@ -1,306 +0,0 @@ -// Generated by `wit-bindgen` 0.25.0. DO NOT EDIT! -// Options used: -#[derive(Clone)] -pub enum PrintPart { - Str(_rt::String), - Name, - Literal, - Keyword, - Type, - Comment, - Reset, -} -impl ::core::fmt::Debug for PrintPart { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - match self { - PrintPart::Str(e) => f.debug_tuple("PrintPart::Str").field(e).finish(), - PrintPart::Name => f.debug_tuple("PrintPart::Name").finish(), - PrintPart::Literal => f.debug_tuple("PrintPart::Literal").finish(), - PrintPart::Keyword => f.debug_tuple("PrintPart::Keyword").finish(), - PrintPart::Type => f.debug_tuple("PrintPart::Type").finish(), - PrintPart::Comment => f.debug_tuple("PrintPart::Comment").finish(), - PrintPart::Reset => f.debug_tuple("PrintPart::Reset").finish(), - } - } -} -#[doc(hidden)] -#[allow(non_snake_case)] -pub unsafe fn _export_parse_cabi(arg0: *mut u8, arg1: usize) -> *mut u8 { - #[cfg(target_arch = "wasm32")] - _rt::run_ctors_once(); - let len0 = arg1; - let bytes0 = _rt::Vec::from_raw_parts(arg0.cast(), len0, len0); - let result1 = T::parse(_rt::string_lift(bytes0)); - let ptr2 = _RET_AREA.0.as_mut_ptr().cast::(); - match result1 { - Ok(e) => { - *ptr2.add(0).cast::() = (0i32) as u8; - let vec3 = (e).into_boxed_slice(); - let ptr3 = vec3.as_ptr().cast::(); - let len3 = vec3.len(); - ::core::mem::forget(vec3); - *ptr2.add(8).cast::() = len3; - *ptr2.add(4).cast::<*mut u8>() = ptr3.cast_mut(); - } - Err(e) => { - *ptr2.add(0).cast::() = (1i32) as u8; - let vec4 = (e.into_bytes()).into_boxed_slice(); - let ptr4 = vec4.as_ptr().cast::(); - let len4 = vec4.len(); - ::core::mem::forget(vec4); - *ptr2.add(8).cast::() = len4; - *ptr2.add(4).cast::<*mut u8>() = ptr4.cast_mut(); - } - }; - ptr2 -} -#[doc(hidden)] -#[allow(non_snake_case)] -pub unsafe fn __post_return_parse(arg0: *mut u8) { - let l0 = i32::from(*arg0.add(0).cast::()); - match l0 { - 0 => { - let l1 = *arg0.add(4).cast::<*mut u8>(); - let l2 = *arg0.add(8).cast::(); - let base3 = l1; - let len3 = l2; - _rt::cabi_dealloc(base3, len3 * 1, 1); - } - _ => { - let l4 = *arg0.add(4).cast::<*mut u8>(); - let l5 = *arg0.add(8).cast::(); - _rt::cabi_dealloc(l4, l5, 1); - } - } -} -#[doc(hidden)] -#[allow(non_snake_case)] -pub unsafe fn _export_print_cabi(arg0: *mut u8, arg1: usize, arg2: i32) -> *mut u8 { - #[cfg(target_arch = "wasm32")] - _rt::run_ctors_once(); - let len0 = arg1; - let result1 = T::print( - _rt::Vec::from_raw_parts(arg0.cast(), len0, len0), - _rt::bool_lift(arg2 as u8), - ); - let ptr2 = _RET_AREA.0.as_mut_ptr().cast::(); - match result1 { - Ok(e) => { - *ptr2.add(0).cast::() = (0i32) as u8; - let vec4 = e; - let len4 = vec4.len(); - let layout4 = _rt::alloc::Layout::from_size_align_unchecked(vec4.len() * 12, 4); - let result4 = if layout4.size() != 0 { - let ptr = _rt::alloc::alloc(layout4).cast::(); - if ptr.is_null() { - _rt::alloc::handle_alloc_error(layout4); - } - ptr - } else { - { - ::core::ptr::null_mut() - } - }; - for (i, e) in vec4.into_iter().enumerate() { - let base = result4.add(i * 12); - { - match e { - PrintPart::Str(e) => { - *base.add(0).cast::() = (0i32) as u8; - let vec3 = (e.into_bytes()).into_boxed_slice(); - let ptr3 = vec3.as_ptr().cast::(); - let len3 = vec3.len(); - ::core::mem::forget(vec3); - *base.add(8).cast::() = len3; - *base.add(4).cast::<*mut u8>() = ptr3.cast_mut(); - } - PrintPart::Name => { - *base.add(0).cast::() = (1i32) as u8; - } - PrintPart::Literal => { - *base.add(0).cast::() = (2i32) as u8; - } - PrintPart::Keyword => { - *base.add(0).cast::() = (3i32) as u8; - } - PrintPart::Type => { - *base.add(0).cast::() = (4i32) as u8; - } - PrintPart::Comment => { - *base.add(0).cast::() = (5i32) as u8; - } - PrintPart::Reset => { - *base.add(0).cast::() = (6i32) as u8; - } - } - } - } - *ptr2.add(8).cast::() = len4; - *ptr2.add(4).cast::<*mut u8>() = result4; - } - Err(e) => { - *ptr2.add(0).cast::() = (1i32) as u8; - let vec5 = (e.into_bytes()).into_boxed_slice(); - let ptr5 = vec5.as_ptr().cast::(); - let len5 = vec5.len(); - ::core::mem::forget(vec5); - *ptr2.add(8).cast::() = len5; - *ptr2.add(4).cast::<*mut u8>() = ptr5.cast_mut(); - } - }; - ptr2 -} -#[doc(hidden)] -#[allow(non_snake_case)] -pub unsafe fn __post_return_print(arg0: *mut u8) { - let l0 = i32::from(*arg0.add(0).cast::()); - match l0 { - 0 => { - let l4 = *arg0.add(4).cast::<*mut u8>(); - let l5 = *arg0.add(8).cast::(); - let base6 = l4; - let len6 = l5; - for i in 0..len6 { - let base = base6.add(i * 12); - { - let l1 = i32::from(*base.add(0).cast::()); - match l1 { - 0 => { - let l2 = *base.add(4).cast::<*mut u8>(); - let l3 = *base.add(8).cast::(); - _rt::cabi_dealloc(l2, l3, 1); - } - 1 => (), - 2 => (), - 3 => (), - 4 => (), - 5 => (), - _ => (), - } - } - } - _rt::cabi_dealloc(base6, len6 * 12, 4); - } - _ => { - let l7 = *arg0.add(4).cast::<*mut u8>(); - let l8 = *arg0.add(8).cast::(); - _rt::cabi_dealloc(l7, l8, 1); - } - } -} -pub trait Guest { - fn parse(contents: _rt::String) -> Result<_rt::Vec, _rt::String>; - fn print(contents: _rt::Vec, skeleton: bool) -> Result<_rt::Vec, _rt::String>; -} -#[doc(hidden)] - -macro_rules! __export_world_wasm_tools_cabi{ - ($ty:ident with_types_in $($path_to_types:tt)*) => (const _: () = { - - #[export_name = "parse"] - unsafe extern "C" fn export_parse(arg0: *mut u8,arg1: usize,) -> *mut u8 { - $($path_to_types)*::_export_parse_cabi::<$ty>(arg0, arg1) - } - #[export_name = "cabi_post_parse"] - unsafe extern "C" fn _post_return_parse(arg0: *mut u8,) { - $($path_to_types)*::__post_return_parse::<$ty>(arg0) - } - #[export_name = "print"] - unsafe extern "C" fn export_print(arg0: *mut u8,arg1: usize,arg2: i32,) -> *mut u8 { - $($path_to_types)*::_export_print_cabi::<$ty>(arg0, arg1, arg2) - } - #[export_name = "cabi_post_print"] - unsafe extern "C" fn _post_return_print(arg0: *mut u8,) { - $($path_to_types)*::__post_return_print::<$ty>(arg0) - } - };); -} -#[doc(hidden)] -pub(crate) use __export_world_wasm_tools_cabi; -#[repr(align(4))] -struct _RetArea([::core::mem::MaybeUninit; 12]); -static mut _RET_AREA: _RetArea = _RetArea([::core::mem::MaybeUninit::uninit(); 12]); -mod _rt { - pub use alloc_crate::string::String; - - #[cfg(target_arch = "wasm32")] - pub fn run_ctors_once() { - wit_bindgen_rt::run_ctors_once(); - } - pub use alloc_crate::vec::Vec; - pub unsafe fn string_lift(bytes: Vec) -> String { - if cfg!(debug_assertions) { - String::from_utf8(bytes).unwrap() - } else { - String::from_utf8_unchecked(bytes) - } - } - pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) { - if size == 0 { - return; - } - let layout = alloc::Layout::from_size_align_unchecked(size, align); - alloc::dealloc(ptr as *mut u8, layout); - } - pub unsafe fn bool_lift(val: u8) -> bool { - if cfg!(debug_assertions) { - match val { - 0 => false, - 1 => true, - _ => panic!("invalid bool discriminant"), - } - } else { - val != 0 - } - } - pub use alloc_crate::alloc; - extern crate alloc as alloc_crate; -} - -/// Generates `#[no_mangle]` functions to export the specified type as the -/// root implementation of all generated traits. -/// -/// For more information see the documentation of `wit_bindgen::generate!`. -/// -/// ```rust -/// # macro_rules! export{ ($($t:tt)*) => (); } -/// # trait Guest {} -/// struct MyType; -/// -/// impl Guest for MyType { -/// // ... -/// } -/// -/// export!(MyType); -/// ``` -#[allow(unused_macros)] -#[doc(hidden)] - -macro_rules! __export_wasm_tools_impl { - ($ty:ident) => (self::export!($ty with_types_in self);); - ($ty:ident with_types_in $($path_to_types_root:tt)*) => ( - $($path_to_types_root)*::__export_world_wasm_tools_cabi!($ty with_types_in $($path_to_types_root)*); - ) -} -#[doc(inline)] -pub(crate) use __export_wasm_tools_impl as export; - -#[cfg(target_arch = "wasm32")] -#[link_section = "component-type:wit-bindgen:0.25.0:wasm-tools:encoded world"] -#[doc(hidden)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 326] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xc5\x01\x01A\x02\x01\ -A\x0a\x01q\x07\x03str\x01s\0\x04name\0\0\x07literal\0\0\x07keyword\0\0\x04type\0\ -\0\x07comment\0\0\x05reset\0\0\x03\0\x0aprint-part\x03\0\0\x01p}\x01j\x01\x02\x01\ -s\x01@\x01\x08contentss\0\x03\x04\0\x05parse\x01\x04\x01p\x01\x01j\x01\x05\x01s\x01\ -@\x02\x08contents\x02\x08skeleton\x7f\0\x06\x04\0\x05print\x01\x07\x04\x01\x1eco\ -mponent:component/wasm-tools\x04\0\x0b\x10\x01\0\x0awasm-tools\x03\0\0\0G\x09pro\ -ducers\x01\x0cprocessed-by\x02\x0dwit-component\x070.208.1\x10wit-bindgen-rust\x06\ -0.25.0"; - -#[inline(never)] -#[doc(hidden)] -#[cfg(target_arch = "wasm32")] -pub fn __link_custom_section_describing_imports() { - wit_bindgen_rt::maybe_link_cabi_realloc(); -}