Skip to content

Commit bd5a80c

Browse files
authored
https://github.com/bytecodealliance/wit-bindgen/issues/822
1 parent fe20eb0 commit bd5a80c

File tree

5 files changed

+228
-71
lines changed

5 files changed

+228
-71
lines changed

Cargo.lock

Lines changed: 2 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
[package]
22
name = "unicode-math-class-wasm"
3-
version = "2.0.0+0.1.0"
3+
version = "3.0.0+0.1.0"
44
edition = "2021"
55
publish = false
66

77
[dependencies]
8-
cargo-component-bindings = "0.6.0"
8+
wit-bindgen = { version = "0.16.0", default-features = false, features = [
9+
"realloc",
10+
] }
911
unicode-math-class = "=0.1.0"
1012

1113
[lib]

src/bindings.rs

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
// Generated by `wit-bindgen` 0.16.0. DO NOT EDIT!
2+
pub mod exports {
3+
pub mod typst_community {
4+
pub mod unicode_math_class {
5+
6+
#[allow(clippy::all)]
7+
pub mod types {
8+
#[used]
9+
#[doc(hidden)]
10+
#[cfg(target_arch = "wasm32")]
11+
static __FORCE_SECTION_REF: fn() = super::super::super::super::__link_section;
12+
/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/enum.MathClass.html>
13+
#[repr(u8)]
14+
#[derive(Clone, Copy, Eq, PartialEq)]
15+
pub enum MathClass {
16+
Normal,
17+
Alphabetic,
18+
Binary,
19+
Closing,
20+
Diacritic,
21+
Fence,
22+
GlyphPart,
23+
Large,
24+
Opening,
25+
Punctuation,
26+
Relation,
27+
Space,
28+
Unary,
29+
Vary,
30+
Special,
31+
}
32+
impl ::core::fmt::Debug for MathClass {
33+
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
34+
match self {
35+
MathClass::Normal => {
36+
f.debug_tuple("MathClass::Normal").finish()
37+
}
38+
MathClass::Alphabetic => {
39+
f.debug_tuple("MathClass::Alphabetic").finish()
40+
}
41+
MathClass::Binary => {
42+
f.debug_tuple("MathClass::Binary").finish()
43+
}
44+
MathClass::Closing => {
45+
f.debug_tuple("MathClass::Closing").finish()
46+
}
47+
MathClass::Diacritic => {
48+
f.debug_tuple("MathClass::Diacritic").finish()
49+
}
50+
MathClass::Fence => {
51+
f.debug_tuple("MathClass::Fence").finish()
52+
}
53+
MathClass::GlyphPart => {
54+
f.debug_tuple("MathClass::GlyphPart").finish()
55+
}
56+
MathClass::Large => {
57+
f.debug_tuple("MathClass::Large").finish()
58+
}
59+
MathClass::Opening => {
60+
f.debug_tuple("MathClass::Opening").finish()
61+
}
62+
MathClass::Punctuation => {
63+
f.debug_tuple("MathClass::Punctuation").finish()
64+
}
65+
MathClass::Relation => {
66+
f.debug_tuple("MathClass::Relation").finish()
67+
}
68+
MathClass::Space => {
69+
f.debug_tuple("MathClass::Space").finish()
70+
}
71+
MathClass::Unary => {
72+
f.debug_tuple("MathClass::Unary").finish()
73+
}
74+
MathClass::Vary => {
75+
f.debug_tuple("MathClass::Vary").finish()
76+
}
77+
MathClass::Special => {
78+
f.debug_tuple("MathClass::Special").finish()
79+
}
80+
}
81+
}
82+
}
83+
84+
impl MathClass{
85+
pub(crate) unsafe fn _lift(val: u8) -> MathClass{
86+
if !cfg!(debug_assertions) {
87+
return ::core::mem::transmute(val);
88+
}
89+
90+
match val {
91+
0 => MathClass::Normal,
92+
1 => MathClass::Alphabetic,
93+
2 => MathClass::Binary,
94+
3 => MathClass::Closing,
95+
4 => MathClass::Diacritic,
96+
5 => MathClass::Fence,
97+
6 => MathClass::GlyphPart,
98+
7 => MathClass::Large,
99+
8 => MathClass::Opening,
100+
9 => MathClass::Punctuation,
101+
10 => MathClass::Relation,
102+
11 => MathClass::Space,
103+
12 => MathClass::Unary,
104+
13 => MathClass::Vary,
105+
14 => MathClass::Special,
106+
107+
_ => panic!("invalid enum discriminant"),
108+
}
109+
}
110+
}
111+
112+
const _: () = {
113+
114+
#[doc(hidden)]
115+
#[export_name = "typst-community:unicode-math-class/types@3.0.0#revision"]
116+
#[allow(non_snake_case)]
117+
unsafe extern "C" fn __export_revision() -> i32 {
118+
#[allow(unused_imports)]
119+
use wit_bindgen::rt::{alloc, vec::Vec, string::String};
120+
121+
// Before executing any other code, use this function to run all static
122+
// constructors, if they have not yet been run. This is a hack required
123+
// to work around wasi-libc ctors calling import functions to initialize
124+
// the environment.
125+
//
126+
// This functionality will be removed once rust 1.69.0 is stable, at which
127+
// point wasi-libc will no longer have this behavior.
128+
//
129+
// See
130+
// https://github.com/bytecodealliance/preview2-prototyping/issues/99
131+
// for more details.
132+
#[cfg(target_arch="wasm32")]
133+
wit_bindgen::rt::run_ctors_once();
134+
135+
let result0 = <_GuestImpl as Guest>::revision();
136+
wit_bindgen::rt::as_i32(result0)
137+
}
138+
};
139+
const _: () = {
140+
141+
#[doc(hidden)]
142+
#[export_name = "typst-community:unicode-math-class/types@3.0.0#class"]
143+
#[allow(non_snake_case)]
144+
unsafe extern "C" fn __export_class(arg0: i32,arg1: i32,) -> i32 {
145+
#[allow(unused_imports)]
146+
use wit_bindgen::rt::{alloc, vec::Vec, string::String};
147+
148+
// Before executing any other code, use this function to run all static
149+
// constructors, if they have not yet been run. This is a hack required
150+
// to work around wasi-libc ctors calling import functions to initialize
151+
// the environment.
152+
//
153+
// This functionality will be removed once rust 1.69.0 is stable, at which
154+
// point wasi-libc will no longer have this behavior.
155+
//
156+
// See
157+
// https://github.com/bytecodealliance/preview2-prototyping/issues/99
158+
// for more details.
159+
#[cfg(target_arch="wasm32")]
160+
wit_bindgen::rt::run_ctors_once();
161+
162+
let len0 = arg1 as usize;
163+
let bytes0 = Vec::from_raw_parts(arg0 as *mut _, len0, len0);
164+
let result1 = <_GuestImpl as Guest>::class(wit_bindgen::rt::string_lift(bytes0));
165+
let ptr2 = _RET_AREA.0.as_mut_ptr() as i32;
166+
match result1 {
167+
Some(e) => {
168+
*((ptr2 + 0) as *mut u8) = (1i32) as u8;
169+
*((ptr2 + 1) as *mut u8) = (e.clone() as i32) as u8;
170+
},
171+
None => {
172+
{
173+
*((ptr2 + 0) as *mut u8) = (0i32) as u8;
174+
}
175+
},
176+
};ptr2
177+
}
178+
};
179+
use super::super::super::super::super::Component as _GuestImpl;
180+
pub trait Guest {
181+
/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/constant.REVISION.html>
182+
fn revision() -> u8;
183+
/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/fn.class.html>
184+
fn class(c: wit_bindgen::rt::string::String,) -> Option<MathClass>;
185+
}
186+
187+
#[allow(unused_imports)]
188+
use wit_bindgen::rt::{alloc, vec::Vec, string::String};
189+
190+
#[repr(align(1))]
191+
struct _RetArea([u8; 2]);
192+
static mut _RET_AREA: _RetArea = _RetArea([0; 2]);
193+
194+
}
195+
196+
}
197+
}
198+
}
199+
200+
#[cfg(target_arch = "wasm32")]
201+
#[link_section = "component-type:unicode-math-class"]
202+
#[doc(hidden)]
203+
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];
204+
205+
#[inline(never)]
206+
#[doc(hidden)]
207+
#[cfg(target_arch = "wasm32")]
208+
pub fn __link_section() {}

src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1+
mod bindings;
12
mod my_macros;
23

3-
cargo_component_bindings::generate!();
44
use my_macros::rs_wit_parallel_enum;
55
use unicode_math_class;
66

77
pub struct Component;
8-
impl bindings::Guest for Component {
8+
impl bindings::exports::typst_community::unicode_math_class::types::Guest for Component {
99
fn revision() -> u8 {
1010
unicode_math_class::REVISION
1111
}
12-
fn class(c: String) -> Option<bindings::MathClass> {
12+
fn class(
13+
c: String,
14+
) -> Option<bindings::exports::typst_community::unicode_math_class::types::MathClass> {
1315
let c = c.chars().next().expect("non-empty string");
1416
unicode_math_class::class(c).map(|x| x.into())
1517
}
1618
}
1719

18-
rs_wit_parallel_enum!(unicode_math_class::MathClass, bindings::MathClass, {
20+
rs_wit_parallel_enum!(unicode_math_class::MathClass, bindings::exports::typst_community::unicode_math_class::types::MathClass, {
1921
Normal,
2022
Alphabetic,
2123
Binary,

wit/world.wit

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package typst-community:unicode-math-class@2.0.0+0.1.0;
1+
package typst-community:unicode-math-class@3.0.0+0.1.0;
22

33
interface types {
44
/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/enum.MathClass.html>
@@ -19,16 +19,17 @@ interface types {
1919
vary,
2020
special,
2121
}
22+
23+
/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/constant.REVISION.html>
24+
revision: func() -> u8;
25+
26+
/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/fn.class.html>
27+
class: func(c: string) -> option<math-class>;
2228
}
2329

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

29-
/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/constant.REVISION.html>
30-
export revision: func() -> u8;
31-
32-
/// <https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/fn.class.html>
33-
export class: func(c: string) -> option<math-class>;
34+
// https://github.com/bytecodealliance/wit-bindgen/issues/822
3435
}

0 commit comments

Comments
 (0)