// Generated by `wit-bindgen` 0.16.0. DO NOT EDIT!
pub type Profile = typst_community::subsetter::types::Profile;
pub type Error = typst_community::subsetter::types::Error;
const _: () = {
#[doc(hidden)]
#[export_name = "subset"]
#[allow(non_snake_case)]
unsafe extern "C" fn __export_subset(arg0: i32,arg1: i32,arg2: i32,arg3: i32,) -> i32 {
#[allow(unused_imports)]
use ::cargo_component_bindings::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")]
::cargo_component_bindings::rt::run_ctors_once();
let len0 = arg1 as usize;
let result1 = <_GuestImpl as Guest>::subset(Vec::from_raw_parts(arg0 as *mut _, len0, len0), arg2 as u32, typst_community::subsetter::types::Profile::from_handle(arg3 as u32));
let ptr2 = _RET_AREA.0.as_mut_ptr() as i32;
match result1 {
Ok(e) => { {
*((ptr2 + 0) as *mut u8) = (0i32) as u8;
let vec3 = (e).into_boxed_slice();
let ptr3 = vec3.as_ptr() as i32;
let len3 = vec3.len() as i32;
::core::mem::forget(vec3);
*((ptr2 + 8) as *mut i32) = len3;
*((ptr2 + 4) as *mut i32) = ptr3;
} },
Err(e) => { {
*((ptr2 + 0) as *mut u8) = (1i32) as u8;
use typst_community::subsetter::types::Error as V6;
match e {
V6::UnknownKind=> {
{
*((ptr2 + 4) as *mut u8) = (0i32) as u8;
}
}
V6::InvalidOffset=> {
{
*((ptr2 + 4) as *mut u8) = (1i32) as u8;
}
}
V6::MissingData=> {
{
*((ptr2 + 4) as *mut u8) = (2i32) as u8;
}
}
V6::InvalidData=> {
{
*((ptr2 + 4) as *mut u8) = (3i32) as u8;
}
}
V6::MissingTable(e) => {
*((ptr2 + 4) as *mut u8) = (4i32) as u8;
let typst_community::subsetter::types::Tag{ tuple0:tuple04, } = e;
let (t5_0, t5_1, t5_2, t5_3, ) = tuple04;
*((ptr2 + 5) as *mut u8) = (::cargo_component_bindings::rt::as_i32(t5_0)) as u8;
*((ptr2 + 6) as *mut u8) = (::cargo_component_bindings::rt::as_i32(t5_1)) as u8;
*((ptr2 + 7) as *mut u8) = (::cargo_component_bindings::rt::as_i32(t5_2)) as u8;
*((ptr2 + 8) as *mut u8) = (::cargo_component_bindings::rt::as_i32(t5_3)) as u8;
},
}
} },
};ptr2
}
const _: () = {
#[doc(hidden)]
#[export_name = "cabi_post_subset"]
#[allow(non_snake_case)]
unsafe extern "C" fn __post_return_subset(arg0: i32,) {
let l0 = i32::from(*((arg0 + 0) as *const u8));
match l0 {
0 => {
let l1 = *((arg0 + 4) as *const i32);
let l2 = *((arg0 + 8) as *const i32);
let base3 = l1;
let len3 = l2;
::cargo_component_bindings::rt::dealloc(base3, (len3 as usize) * 1, 1);
},
_ => (),
}
}
};
};
use super::Component as _GuestImpl;
pub trait Guest {
fn subset(data: ::cargo_component_bindings::rt::vec::Vec::<u8>,index: u32,profile: Profile,) -> Result<::cargo_component_bindings::rt::vec::Vec::<u8>,Error>;
}
#[allow(unused_imports)]
use ::cargo_component_bindings::rt::{alloc, vec::Vec, string::String};
#[repr(align(4))]
struct _RetArea([u8; 12]);
static mut _RET_AREA: _RetArea = _RetArea([0; 12]);
pub mod typst_community {
pub mod subsetter {
#[allow(clippy::all)]
pub mod types {
#[used]
#[doc(hidden)]
#[cfg(target_arch = "wasm32")]
static __FORCE_SECTION_REF: fn() = super::super::super::__link_section;
#[derive(Debug)]
#[repr(transparent)]
pub struct Profile{
handle: ::cargo_component_bindings::rt::Resource<Profile>,
}
impl Profile{
#[doc(hidden)]
pub unsafe fn from_handle(handle: u32) -> Self {
Self {
handle: ::cargo_component_bindings::rt::Resource::from_handle(handle),
}
}
#[doc(hidden)]
pub fn into_handle(self) -> u32 {
::cargo_component_bindings::rt::Resource::into_handle(self.handle)
}
#[doc(hidden)]
pub fn handle(&self) -> u32 {
::cargo_component_bindings::rt::Resource::handle(&self.handle)
}
}
unsafe impl ::cargo_component_bindings::rt::WasmResource for Profile{
#[inline]
unsafe fn drop(_handle: u32) {
#[cfg(not(target_arch = "wasm32"))]
unreachable!();
#[cfg(target_arch = "wasm32")]
{
#[link(wasm_import_module = "typst-community:subsetter/types@1.0.0+0.1.1")]
extern "C" {
#[link_name = "[resource-drop]profile"]
fn drop(_: u32);
}
drop(_handle);
}
}
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct Tag {
pub tuple0: (u8,u8,u8,u8,),
}
impl ::core::fmt::Debug for Tag {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct("Tag").field("tuple0", &self.tuple0).finish()
}
}
#[derive(Clone, Copy)]
pub enum Error{
UnknownKind,
InvalidOffset,
MissingData,
InvalidData,
MissingTable(Tag),
}
impl ::core::fmt::Debug for Error {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
match self {
Error::UnknownKind => {
f.debug_tuple("Error::UnknownKind").finish()
}
Error::InvalidOffset => {
f.debug_tuple("Error::InvalidOffset").finish()
}
Error::MissingData => {
f.debug_tuple("Error::MissingData").finish()
}
Error::InvalidData => {
f.debug_tuple("Error::InvalidData").finish()
}
Error::MissingTable(e) => {
f.debug_tuple("Error::MissingTable").field(e).finish()
}
}
}
}
impl ::core::fmt::Display for Error {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
write!(f, "{:?}", self)
}
}
impl std::error::Error for Error {}
impl Profile {
#[allow(unused_unsafe, clippy::all)]
pub fn pdf(glyphs: &[u16],) -> Profile{
#[allow(unused_imports)]
use ::cargo_component_bindings::rt::{alloc, vec::Vec, string::String};
unsafe {
let vec0 = glyphs;
let ptr0 = vec0.as_ptr() as i32;
let len0 = vec0.len() as i32;
#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "typst-community:subsetter/types@1.0.0+0.1.1")]
extern "C" {
#[link_name = "[static]profile.pdf"]
fn wit_import(_: i32, _: i32, ) -> i32;
}
#[cfg(not(target_arch = "wasm32"))]
fn wit_import(_: i32, _: i32, ) -> i32{ unreachable!() }
let ret = wit_import(ptr0, len0);
Profile::from_handle(ret as u32)
}
}
}
}
}
}
pub mod exports {
pub mod typst_community {
pub mod subsetter {
#[allow(clippy::all)]
pub mod types {
#[used]
#[doc(hidden)]
#[cfg(target_arch = "wasm32")]
static __FORCE_SECTION_REF: fn() = super::super::super::super::__link_section;
pub use super::super::super::super::super::Profile as Profile;
const _: () = {
#[doc(hidden)]
#[export_name = "typst-community:subsetter/types@1.0.0+0.1.1#[dtor]profile"]
#[allow(non_snake_case)]
unsafe extern "C" fn dtor(rep: usize) {
::cargo_component_bindings::rt::Resource::<Profile>::dtor(rep)
}
};
unsafe impl ::cargo_component_bindings::rt::RustResource for Profile{
unsafe fn new(_rep: usize) -> u32 {
#[cfg(not(target_arch = "wasm32"))]
unreachable!();
#[cfg(target_arch = "wasm32")]
{
#[link(wasm_import_module = "[export]typst-community:subsetter/types@1.0.0+0.1.1")]
extern "C" {
#[link_name = "[resource-new]profile"]
fn new(_: usize) -> u32;
}
new(_rep)
}
}
unsafe fn rep(_handle: u32) -> usize {
#[cfg(not(target_arch = "wasm32"))]
unreachable!();
#[cfg(target_arch = "wasm32")]
{
#[link(wasm_import_module = "[export]typst-community:subsetter/types@1.0.0+0.1.1")]
extern "C" {
#[link_name = "[resource-rep]profile"]
fn rep(_: u32) -> usize;
}
rep(_handle)
}
}
}
pub type OwnProfile = ::cargo_component_bindings::rt::Resource<Profile>;
unsafe impl ::cargo_component_bindings::rt::WasmResource for Profile{
#[inline]
unsafe fn drop(_handle: u32) {
#[cfg(not(target_arch = "wasm32"))]
unreachable!();
#[cfg(target_arch = "wasm32")]
{
#[link(wasm_import_module = "[export]typst-community:subsetter/types@1.0.0+0.1.1")]
extern "C" {
#[link_name = "[resource-drop]profile"]
fn drop(_: u32);
}
drop(_handle);
}
}
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct Tag {
pub tuple0: (u8,u8,u8,u8,),
}
impl ::core::fmt::Debug for Tag {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct("Tag").field("tuple0", &self.tuple0).finish()
}
}
#[derive(Clone, Copy)]
pub enum Error{
UnknownKind,
InvalidOffset,
MissingData,
InvalidData,
MissingTable(Tag),
}
impl ::core::fmt::Debug for Error {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
match self {
Error::UnknownKind => {
f.debug_tuple("Error::UnknownKind").finish()
}
Error::InvalidOffset => {
f.debug_tuple("Error::InvalidOffset").finish()
}
Error::MissingData => {
f.debug_tuple("Error::MissingData").finish()
}
Error::InvalidData => {
f.debug_tuple("Error::InvalidData").finish()
}
Error::MissingTable(e) => {
f.debug_tuple("Error::MissingTable").field(e).finish()
}
}
}
}
impl ::core::fmt::Display for Error {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
write!(f, "{:?}", self)
}
}
impl std::error::Error for Error {}
const _: () = {
#[doc(hidden)]
#[export_name = "typst-community:subsetter/types@1.0.0+0.1.1#[static]profile.pdf"]
#[allow(non_snake_case)]
unsafe extern "C" fn __export_static_profile_pdf(arg0: i32,arg1: i32,) -> i32 {
#[allow(unused_imports)]
use ::cargo_component_bindings::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")]
::cargo_component_bindings::rt::run_ctors_once();
let len0 = arg1 as usize;
let result1 = <_ProfileImpl as GuestProfile>::pdf(Vec::from_raw_parts(arg0 as *mut _, len0, len0));
::cargo_component_bindings::rt::Resource::into_handle(result1) as i32
}
};
use super::super::super::super::super::Profile as _ProfileImpl;
pub trait GuestProfile {
fn pdf(glyphs: ::cargo_component_bindings::rt::vec::Vec::<u16>,) -> OwnProfile;
}
}
}
}
}
#[cfg(target_arch = "wasm32")]
#[link_section = "component-type:subsetter"]
#[doc(hidden)]
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 998] = [3, 0, 9, 115, 117, 98, 115, 101, 116, 116, 101, 114, 0, 97, 115, 109, 13, 0, 1, 0, 7, 229, 1, 1, 65, 2, 1, 66, 10, 4, 0, 7, 112, 114, 111, 102, 105, 108, 101, 3, 1, 1, 111, 4, 125, 125, 125, 125, 1, 114, 1, 6, 116, 117, 112, 108, 101, 48, 1, 4, 0, 3, 116, 97, 103, 3, 0, 2, 1, 113, 5, 12, 117, 110, 107, 110, 111, 119, 110, 45, 107, 105, 110, 100, 0, 0, 14, 105, 110, 118, 97, 108, 105, 100, 45, 111, 102, 102, 115, 101, 116, 0, 0, 12, 109, 105, 115, 115, 105, 110, 103, 45, 100, 97, 116, 97, 0, 0, 12, 105, 110, 118, 97, 108, 105, 100, 45, 100, 97, 116, 97, 0, 0, 13, 109, 105, 115, 115, 105, 110, 103, 45, 116, 97, 98, 108, 101, 1, 3, 0, 4, 0, 5, 101, 114, 114, 111, 114, 3, 0, 4, 1, 112, 123, 1, 105, 0, 1, 64, 1, 6, 103, 108, 121, 112, 104, 115, 6, 0, 7, 4, 0, 19, 91, 115, 116, 97, 116, 105, 99, 93, 112, 114, 111, 102, 105, 108, 101, 46, 112, 100, 102, 1, 8, 4, 1, 43, 116, 121, 112, 115, 116, 45, 99, 111, 109, 109, 117, 110, 105, 116, 121, 58, 115, 117, 98, 115, 101, 116, 116, 101, 114, 47, 116, 121, 112, 101, 115, 64, 49, 46, 48, 46, 48, 43, 48, 46, 49, 46, 49, 5, 0, 11, 11, 1, 0, 5, 116, 121, 112, 101, 115, 3, 0, 0, 7, 239, 4, 1, 65, 2, 1, 65, 15, 1, 66, 10, 4, 0, 7, 112, 114, 111, 102, 105, 108, 101, 3, 1, 1, 111, 4, 125, 125, 125, 125, 1, 114, 1, 6, 116, 117, 112, 108, 101, 48, 1, 4, 0, 3, 116, 97, 103, 3, 0, 2, 1, 113, 5, 12, 117, 110, 107, 110, 111, 119, 110, 45, 107, 105, 110, 100, 0, 0, 14, 105, 110, 118, 97, 108, 105, 100, 45, 111, 102, 102, 115, 101, 116, 0, 0, 12, 109, 105, 115, 115, 105, 110, 103, 45, 100, 97, 116, 97, 0, 0, 12, 105, 110, 118, 97, 108, 105, 100, 45, 100, 97, 116, 97, 0, 0, 13, 109, 105, 115, 115, 105, 110, 103, 45, 116, 97, 98, 108, 101, 1, 3, 0, 4, 0, 5, 101, 114, 114, 111, 114, 3, 0, 4, 1, 112, 123, 1, 105, 0, 1, 64, 1, 6, 103, 108, 121, 112, 104, 115, 6, 0, 7, 4, 0, 19, 91, 115, 116, 97, 116, 105, 99, 93, 112, 114, 111, 102, 105, 108, 101, 46, 112, 100, 102, 1, 8, 3, 1, 43, 116, 121, 112, 115, 116, 45, 99, 111, 109, 109, 117, 110, 105, 116, 121, 58, 115, 117, 98, 115, 101, 116, 116, 101, 114, 47, 116, 121, 112, 101, 115, 64, 49, 46, 48, 46, 48, 43, 48, 46, 49, 46, 49, 5, 0, 2, 3, 0, 0, 7, 112, 114, 111, 102, 105, 108, 101, 3, 0, 7, 112, 114, 111, 102, 105, 108, 101, 3, 0, 1, 2, 3, 0, 0, 3, 116, 97, 103, 3, 0, 3, 116, 97, 103, 3, 0, 3, 2, 3, 0, 0, 5, 101, 114, 114, 111, 114, 3, 0, 5, 101, 114, 114, 111, 114, 3, 0, 5, 1, 112, 125, 1, 105, 2, 1, 106, 1, 7, 1, 6, 1, 64, 3, 4, 100, 97, 116, 97, 7, 5, 105, 110, 100, 101, 120, 121, 7, 112, 114, 111, 102, 105, 108, 101, 8, 0, 9, 4, 0, 6, 115, 117, 98, 115, 101, 116, 1, 10, 1, 66, 10, 4, 0, 7, 112, 114, 111, 102, 105, 108, 101, 3, 1, 1, 111, 4, 125, 125, 125, 125, 1, 114, 1, 6, 116, 117, 112, 108, 101, 48, 1, 4, 0, 3, 116, 97, 103, 3, 0, 2, 1, 113, 5, 12, 117, 110, 107, 110, 111, 119, 110, 45, 107, 105, 110, 100, 0, 0, 14, 105, 110, 118, 97, 108, 105, 100, 45, 111, 102, 102, 115, 101, 116, 0, 0, 12, 109, 105, 115, 115, 105, 110, 103, 45, 100, 97, 116, 97, 0, 0, 12, 105, 110, 118, 97, 108, 105, 100, 45, 100, 97, 116, 97, 0, 0, 13, 109, 105, 115, 115, 105, 110, 103, 45, 116, 97, 98, 108, 101, 1, 3, 0, 4, 0, 5, 101, 114, 114, 111, 114, 3, 0, 4, 1, 112, 123, 1, 105, 0, 1, 64, 1, 6, 103, 108, 121, 112, 104, 115, 6, 0, 7, 4, 0, 19, 91, 115, 116, 97, 116, 105, 99, 93, 112, 114, 111, 102, 105, 108, 101, 46, 112, 100, 102, 1, 8, 4, 1, 43, 116, 121, 112, 115, 116, 45, 99, 111, 109, 109, 117, 110, 105, 116, 121, 58, 115, 117, 98, 115, 101, 116, 116, 101, 114, 47, 116, 121, 112, 101, 115, 64, 49, 46, 48, 46, 48, 43, 48, 46, 49, 46, 49, 5, 11, 4, 1, 47, 116, 121, 112, 115, 116, 45, 99, 111, 109, 109, 117, 110, 105, 116, 121, 58, 115, 117, 98, 115, 101, 116, 116, 101, 114, 47, 115, 117, 98, 115, 101, 116, 116, 101, 114, 64, 49, 46, 48, 46, 48, 43, 48, 46, 49, 46, 49, 4, 0, 11, 15, 1, 0, 9, 115, 117, 98, 115, 101, 116, 116, 101, 114, 3, 2, 0, 0, 16, 12, 112, 97, 99, 107, 97, 103, 101, 45, 100, 111, 99, 115, 0, 123, 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() {}
this problem of "phantom imports" from here WebAssembly/component-model#295 (comment) https://github.com/jcbhmr/unicode-math-class.wasm/actions/runs/7631660252
Details
https://github.com/jcbhmr/unicode-math-class.wasm/tree/fe20eb02987a2a41855fcbe4bee78475f4becb07
has happened to me again in a much worse way; cargo-component (which uses wit-bindgen iirc) is using this phantom imported type instead of the locally declared exported type which has the needed data (the
0th tuple item) that i need to use to perform various library operations.here's the wit:
im trying to provide bindings for this https://docs.rs/subsetter/latest/subsetter/ rust crate in wit
and here's the code
and when that compiles (with using the rust code as shown above) it gives some weird wit when using
wasm-tools component witreproduction: https://github.com/jcbhmr/subsetter.wasm/tree/9b1d7c65a48bdb9a92f6d3bf48ee97b8485fbb64
basically what i understand to be happening in error is that the
use types.{...}is somehow importing the things from theinterface types {}? and then when it generates the rust bindings.rs it generates the imported types and then uses those imported types instead of the exported types that i want it to use.the end result is that i cannot get the
profile.0. 🤷♂️idk if im even explaining this right or what. all i know is that the types that i want and the types that i got are mismatched and idk what to do if this is a bug or if this is how WIT is supposed to work or what lol
cc @lukewagner
Details
bindings.rs copy pasted here