Skip to content

Commit

Permalink
https://github.com/bytecodealliance/wit-bindgen/issues/822
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbhmr authored Jan 29, 2024
1 parent fe20eb0 commit bd5a80c
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 71 deletions.
60 changes: 2 additions & 58 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
208 changes: 208 additions & 0 deletions src/bindings.rs
Original file line number Diff line number Diff line change
@@ -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;
/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/enum.MathClass.html>
#[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/[email protected]#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/[email protected]#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 {
/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/constant.REVISION.html>
fn revision() -> u8;
/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/fn.class.html>
fn class(c: wit_bindgen::rt::string::String,) -> Option<MathClass>;
}

#[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() {}
10 changes: 6 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<bindings::MathClass> {
fn class(
c: String,
) -> Option<bindings::exports::typst_community::unicode_math_class::types::MathClass> {
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,
Expand Down
15 changes: 8 additions & 7 deletions wit/world.wit
Original file line number Diff line number Diff line change
@@ -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 {
/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/enum.MathClass.html>
Expand All @@ -19,16 +19,17 @@ interface types {
vary,
special,
}

/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/constant.REVISION.html>
revision: func() -> u8;

/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/fn.class.html>
class: func(c: string) -> option<math-class>;
}

/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/>
world unicode-math-class {
export types;
use types.{math-class};

/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/constant.REVISION.html>
export revision: func() -> u8;

/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/fn.class.html>
export class: func(c: string) -> option<math-class>;
// https://github.com/bytecodealliance/wit-bindgen/issues/822
}

0 comments on commit bd5a80c

Please sign in to comment.