diff --git a/Cargo.lock b/Cargo.lock index 2444d51..fee7d6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,62 +8,6 @@ version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" -[[package]] -name = "cargo-component-bindings" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "545e48ba821e07f93c97aea897bee6d407de4d58947f914160131f3d78b2c704" -dependencies = [ - "cargo-component-macro", - "wit-bindgen", -] - -[[package]] -name = "cargo-component-macro" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e198ee0b668e902b43b5e7d2e9620a3891d2632429b3ba66e1ceea455053cbf5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "proc-macro2" -version = "1.0.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "syn" -version = "2.0.48" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - [[package]] name = "unicode-math-class" version = "0.1.0" @@ -72,10 +16,10 @@ checksum = "7d246cf599d5fae3c8d56e04b20eb519adb89a8af8d0b0fbcded369aa3647d65" [[package]] name = "unicode-math-class-wasm" -version = "2.0.0+0.1.0" +version = "3.0.0+0.1.0" dependencies = [ - "cargo-component-bindings", "unicode-math-class", + "wit-bindgen", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 4cbf209..3165f65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,13 @@ [package] name = "unicode-math-class-wasm" -version = "2.0.0+0.1.0" +version = "3.0.0+0.1.0" edition = "2021" publish = false [dependencies] -cargo-component-bindings = "0.6.0" +wit-bindgen = { version = "0.16.0", default-features = false, features = [ + "realloc", +] } unicode-math-class = "=0.1.0" [lib] diff --git a/src/bindings.rs b/src/bindings.rs new file mode 100644 index 0000000..c54fc8a --- /dev/null +++ b/src/bindings.rs @@ -0,0 +1,208 @@ +// Generated by `wit-bindgen` 0.16.0. DO NOT EDIT! +pub mod exports { + pub mod typst_community { + pub mod unicode_math_class { + + #[allow(clippy::all)] + pub mod types { + #[used] + #[doc(hidden)] + #[cfg(target_arch = "wasm32")] + static __FORCE_SECTION_REF: fn() = super::super::super::super::__link_section; + /// + #[repr(u8)] + #[derive(Clone, Copy, Eq, PartialEq)] + pub enum MathClass { + Normal, + Alphabetic, + Binary, + Closing, + Diacritic, + Fence, + GlyphPart, + Large, + Opening, + Punctuation, + Relation, + Space, + Unary, + Vary, + Special, + } + impl ::core::fmt::Debug for MathClass { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + match self { + MathClass::Normal => { + f.debug_tuple("MathClass::Normal").finish() + } + MathClass::Alphabetic => { + f.debug_tuple("MathClass::Alphabetic").finish() + } + MathClass::Binary => { + f.debug_tuple("MathClass::Binary").finish() + } + MathClass::Closing => { + f.debug_tuple("MathClass::Closing").finish() + } + MathClass::Diacritic => { + f.debug_tuple("MathClass::Diacritic").finish() + } + MathClass::Fence => { + f.debug_tuple("MathClass::Fence").finish() + } + MathClass::GlyphPart => { + f.debug_tuple("MathClass::GlyphPart").finish() + } + MathClass::Large => { + f.debug_tuple("MathClass::Large").finish() + } + MathClass::Opening => { + f.debug_tuple("MathClass::Opening").finish() + } + MathClass::Punctuation => { + f.debug_tuple("MathClass::Punctuation").finish() + } + MathClass::Relation => { + f.debug_tuple("MathClass::Relation").finish() + } + MathClass::Space => { + f.debug_tuple("MathClass::Space").finish() + } + MathClass::Unary => { + f.debug_tuple("MathClass::Unary").finish() + } + MathClass::Vary => { + f.debug_tuple("MathClass::Vary").finish() + } + MathClass::Special => { + f.debug_tuple("MathClass::Special").finish() + } + } + } + } + + impl MathClass{ + pub(crate) unsafe fn _lift(val: u8) -> MathClass{ + if !cfg!(debug_assertions) { + return ::core::mem::transmute(val); + } + + match val { + 0 => MathClass::Normal, + 1 => MathClass::Alphabetic, + 2 => MathClass::Binary, + 3 => MathClass::Closing, + 4 => MathClass::Diacritic, + 5 => MathClass::Fence, + 6 => MathClass::GlyphPart, + 7 => MathClass::Large, + 8 => MathClass::Opening, + 9 => MathClass::Punctuation, + 10 => MathClass::Relation, + 11 => MathClass::Space, + 12 => MathClass::Unary, + 13 => MathClass::Vary, + 14 => MathClass::Special, + + _ => panic!("invalid enum discriminant"), + } + } + } + + const _: () = { + + #[doc(hidden)] + #[export_name = "typst-community:unicode-math-class/types@3.0.0#revision"] + #[allow(non_snake_case)] + unsafe extern "C" fn __export_revision() -> i32 { + #[allow(unused_imports)] + use wit_bindgen::rt::{alloc, vec::Vec, string::String}; + + // Before executing any other code, use this function to run all static + // constructors, if they have not yet been run. This is a hack required + // to work around wasi-libc ctors calling import functions to initialize + // the environment. + // + // This functionality will be removed once rust 1.69.0 is stable, at which + // point wasi-libc will no longer have this behavior. + // + // See + // https://github.com/bytecodealliance/preview2-prototyping/issues/99 + // for more details. + #[cfg(target_arch="wasm32")] + wit_bindgen::rt::run_ctors_once(); + + let result0 = <_GuestImpl as Guest>::revision(); + wit_bindgen::rt::as_i32(result0) + } + }; + const _: () = { + + #[doc(hidden)] + #[export_name = "typst-community:unicode-math-class/types@3.0.0#class"] + #[allow(non_snake_case)] + unsafe extern "C" fn __export_class(arg0: i32,arg1: i32,) -> i32 { + #[allow(unused_imports)] + use wit_bindgen::rt::{alloc, vec::Vec, string::String}; + + // Before executing any other code, use this function to run all static + // constructors, if they have not yet been run. This is a hack required + // to work around wasi-libc ctors calling import functions to initialize + // the environment. + // + // This functionality will be removed once rust 1.69.0 is stable, at which + // point wasi-libc will no longer have this behavior. + // + // See + // https://github.com/bytecodealliance/preview2-prototyping/issues/99 + // for more details. + #[cfg(target_arch="wasm32")] + wit_bindgen::rt::run_ctors_once(); + + let len0 = arg1 as usize; + let bytes0 = Vec::from_raw_parts(arg0 as *mut _, len0, len0); + let result1 = <_GuestImpl as Guest>::class(wit_bindgen::rt::string_lift(bytes0)); + let ptr2 = _RET_AREA.0.as_mut_ptr() as i32; + match result1 { + Some(e) => { + *((ptr2 + 0) as *mut u8) = (1i32) as u8; + *((ptr2 + 1) as *mut u8) = (e.clone() as i32) as u8; + }, + None => { + { + *((ptr2 + 0) as *mut u8) = (0i32) as u8; + } + }, + };ptr2 + } + }; + use super::super::super::super::super::Component as _GuestImpl; + pub trait Guest { + /// + fn revision() -> u8; + /// + fn class(c: wit_bindgen::rt::string::String,) -> Option; + } + + #[allow(unused_imports)] + use wit_bindgen::rt::{alloc, vec::Vec, string::String}; + + #[repr(align(1))] + struct _RetArea([u8; 2]); + static mut _RET_AREA: _RetArea = _RetArea([0; 2]); + + } + + } + } +} + +#[cfg(target_arch = "wasm32")] +#[link_section = "component-type:unicode-math-class"] +#[doc(hidden)] +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1142] = [3, 0, 18, 117, 110, 105, 99, 111, 100, 101, 45, 109, 97, 116, 104, 45, 99, 108, 97, 115, 115, 0, 97, 115, 109, 13, 0, 1, 0, 7, 235, 1, 1, 65, 2, 1, 66, 7, 1, 109, 15, 6, 110, 111, 114, 109, 97, 108, 10, 97, 108, 112, 104, 97, 98, 101, 116, 105, 99, 6, 98, 105, 110, 97, 114, 121, 7, 99, 108, 111, 115, 105, 110, 103, 9, 100, 105, 97, 99, 114, 105, 116, 105, 99, 5, 102, 101, 110, 99, 101, 10, 103, 108, 121, 112, 104, 45, 112, 97, 114, 116, 5, 108, 97, 114, 103, 101, 7, 111, 112, 101, 110, 105, 110, 103, 11, 112, 117, 110, 99, 116, 117, 97, 116, 105, 111, 110, 8, 114, 101, 108, 97, 116, 105, 111, 110, 5, 115, 112, 97, 99, 101, 5, 117, 110, 97, 114, 121, 4, 118, 97, 114, 121, 7, 115, 112, 101, 99, 105, 97, 108, 4, 0, 10, 109, 97, 116, 104, 45, 99, 108, 97, 115, 115, 3, 0, 0, 1, 64, 0, 0, 125, 4, 0, 8, 114, 101, 118, 105, 115, 105, 111, 110, 1, 2, 1, 107, 1, 1, 64, 1, 1, 99, 115, 0, 3, 4, 0, 5, 99, 108, 97, 115, 115, 1, 4, 4, 1, 46, 116, 121, 112, 115, 116, 45, 99, 111, 109, 109, 117, 110, 105, 116, 121, 58, 117, 110, 105, 99, 111, 100, 101, 45, 109, 97, 116, 104, 45, 99, 108, 97, 115, 115, 47, 116, 121, 112, 101, 115, 64, 51, 46, 48, 46, 48, 5, 0, 11, 11, 1, 0, 5, 116, 121, 112, 101, 115, 3, 0, 0, 7, 174, 2, 1, 65, 2, 1, 65, 2, 1, 66, 7, 1, 109, 15, 6, 110, 111, 114, 109, 97, 108, 10, 97, 108, 112, 104, 97, 98, 101, 116, 105, 99, 6, 98, 105, 110, 97, 114, 121, 7, 99, 108, 111, 115, 105, 110, 103, 9, 100, 105, 97, 99, 114, 105, 116, 105, 99, 5, 102, 101, 110, 99, 101, 10, 103, 108, 121, 112, 104, 45, 112, 97, 114, 116, 5, 108, 97, 114, 103, 101, 7, 111, 112, 101, 110, 105, 110, 103, 11, 112, 117, 110, 99, 116, 117, 97, 116, 105, 111, 110, 8, 114, 101, 108, 97, 116, 105, 111, 110, 5, 115, 112, 97, 99, 101, 5, 117, 110, 97, 114, 121, 4, 118, 97, 114, 121, 7, 115, 112, 101, 99, 105, 97, 108, 4, 0, 10, 109, 97, 116, 104, 45, 99, 108, 97, 115, 115, 3, 0, 0, 1, 64, 0, 0, 125, 4, 0, 8, 114, 101, 118, 105, 115, 105, 111, 110, 1, 2, 1, 107, 1, 1, 64, 1, 1, 99, 115, 0, 3, 4, 0, 5, 99, 108, 97, 115, 115, 1, 4, 4, 1, 46, 116, 121, 112, 115, 116, 45, 99, 111, 109, 109, 117, 110, 105, 116, 121, 58, 117, 110, 105, 99, 111, 100, 101, 45, 109, 97, 116, 104, 45, 99, 108, 97, 115, 115, 47, 116, 121, 112, 101, 115, 64, 51, 46, 48, 46, 48, 5, 0, 4, 1, 59, 116, 121, 112, 115, 116, 45, 99, 111, 109, 109, 117, 110, 105, 116, 121, 58, 117, 110, 105, 99, 111, 100, 101, 45, 109, 97, 116, 104, 45, 99, 108, 97, 115, 115, 47, 117, 110, 105, 99, 111, 100, 101, 45, 109, 97, 116, 104, 45, 99, 108, 97, 115, 115, 64, 51, 46, 48, 46, 48, 4, 0, 11, 24, 1, 0, 18, 117, 110, 105, 99, 111, 100, 101, 45, 109, 97, 116, 104, 45, 99, 108, 97, 115, 115, 3, 2, 0, 0, 200, 3, 12, 112, 97, 99, 107, 97, 103, 101, 45, 100, 111, 99, 115, 0, 123, 34, 119, 111, 114, 108, 100, 115, 34, 58, 123, 34, 117, 110, 105, 99, 111, 100, 101, 45, 109, 97, 116, 104, 45, 99, 108, 97, 115, 115, 34, 58, 123, 34, 100, 111, 99, 115, 34, 58, 34, 60, 104, 116, 116, 112, 115, 58, 47, 47, 100, 111, 99, 115, 46, 114, 115, 47, 117, 110, 105, 99, 111, 100, 101, 45, 109, 97, 116, 104, 45, 99, 108, 97, 115, 115, 47, 48, 46, 49, 46, 48, 47, 117, 110, 105, 99, 111, 100, 101, 95, 109, 97, 116, 104, 95, 99, 108, 97, 115, 115, 47, 62, 34, 125, 125, 44, 34, 105, 110, 116, 101, 114, 102, 97, 99, 101, 115, 34, 58, 123, 34, 116, 121, 112, 101, 115, 34, 58, 123, 34, 102, 117, 110, 99, 115, 34, 58, 123, 34, 114, 101, 118, 105, 115, 105, 111, 110, 34, 58, 34, 60, 104, 116, 116, 112, 115, 58, 47, 47, 100, 111, 99, 115, 46, 114, 115, 47, 117, 110, 105, 99, 111, 100, 101, 45, 109, 97, 116, 104, 45, 99, 108, 97, 115, 115, 47, 48, 46, 49, 46, 48, 47, 117, 110, 105, 99, 111, 100, 101, 95, 109, 97, 116, 104, 95, 99, 108, 97, 115, 115, 47, 99, 111, 110, 115, 116, 97, 110, 116, 46, 82, 69, 86, 73, 83, 73, 79, 78, 46, 104, 116, 109, 108, 62, 34, 44, 34, 99, 108, 97, 115, 115, 34, 58, 34, 60, 104, 116, 116, 112, 115, 58, 47, 47, 100, 111, 99, 115, 46, 114, 115, 47, 117, 110, 105, 99, 111, 100, 101, 45, 109, 97, 116, 104, 45, 99, 108, 97, 115, 115, 47, 48, 46, 49, 46, 48, 47, 117, 110, 105, 99, 111, 100, 101, 95, 109, 97, 116, 104, 95, 99, 108, 97, 115, 115, 47, 102, 110, 46, 99, 108, 97, 115, 115, 46, 104, 116, 109, 108, 62, 34, 125, 44, 34, 116, 121, 112, 101, 115, 34, 58, 123, 34, 109, 97, 116, 104, 45, 99, 108, 97, 115, 115, 34, 58, 123, 34, 100, 111, 99, 115, 34, 58, 34, 60, 104, 116, 116, 112, 115, 58, 47, 47, 100, 111, 99, 115, 46, 114, 115, 47, 117, 110, 105, 99, 111, 100, 101, 45, 109, 97, 116, 104, 45, 99, 108, 97, 115, 115, 47, 48, 46, 49, 46, 48, 47, 117, 110, 105, 99, 111, 100, 101, 95, 109, 97, 116, 104, 95, 99, 108, 97, 115, 115, 47, 101, 110, 117, 109, 46, 77, 97, 116, 104, 67, 108, 97, 115, 115, 46, 104, 116, 109, 108, 62, 34, 125, 125, 125, 125, 125, 0, 70, 9, 112, 114, 111, 100, 117, 99, 101, 114, 115, 1, 12, 112, 114, 111, 99, 101, 115, 115, 101, 100, 45, 98, 121, 2, 13, 119, 105, 116, 45, 99, 111, 109, 112, 111, 110, 101, 110, 116, 6, 48, 46, 49, 56, 46, 50, 16, 119, 105, 116, 45, 98, 105, 110, 100, 103, 101, 110, 45, 114, 117, 115, 116, 6, 48, 46, 49, 54, 46, 48]; + +#[inline(never)] +#[doc(hidden)] +#[cfg(target_arch = "wasm32")] +pub fn __link_section() {} diff --git a/src/lib.rs b/src/lib.rs index cfc7dc0..e94a313 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,21 +1,23 @@ +mod bindings; mod my_macros; -cargo_component_bindings::generate!(); use my_macros::rs_wit_parallel_enum; use unicode_math_class; pub struct Component; -impl bindings::Guest for Component { +impl bindings::exports::typst_community::unicode_math_class::types::Guest for Component { fn revision() -> u8 { unicode_math_class::REVISION } - fn class(c: String) -> Option { + fn class( + c: String, + ) -> Option { let c = c.chars().next().expect("non-empty string"); unicode_math_class::class(c).map(|x| x.into()) } } -rs_wit_parallel_enum!(unicode_math_class::MathClass, bindings::MathClass, { +rs_wit_parallel_enum!(unicode_math_class::MathClass, bindings::exports::typst_community::unicode_math_class::types::MathClass, { Normal, Alphabetic, Binary, diff --git a/wit/world.wit b/wit/world.wit index cdabaab..3306a95 100644 --- a/wit/world.wit +++ b/wit/world.wit @@ -1,4 +1,4 @@ -package typst-community:unicode-math-class@2.0.0+0.1.0; +package typst-community:unicode-math-class@3.0.0+0.1.0; interface types { /// @@ -19,16 +19,17 @@ interface types { vary, special, } + + /// + revision: func() -> u8; + + /// + class: func(c: string) -> option; } /// world unicode-math-class { export types; - use types.{math-class}; - /// - export revision: func() -> u8; - - /// - export class: func(c: string) -> option; + // https://github.com/bytecodealliance/wit-bindgen/issues/822 }