You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a crate that uses proc_macros to generate bindings in either C or WASM. In the WASM case, I import wasm-bindgen and generate a bunch of stuff with the #[wasm_bindgen] attribute. In the C case I generate a bunch of methods with extern "C" fn. Depending on the feature will enable C bindings or WASM bindings.
When compiled with the C feature the crate needs to be a staticlib and when compiled with the WASM feature the crate needs to be a cdylib,rlib. Unfortunately, it does not seem possible to change the crate-type based ona feature flag, as far as I can tell. The solution I found is to pass --crate-type on the cli to cargo rustc. Okie.
Proposed Solution
The underlying call to cargo build could probably just as well use cargo rustc which exposes more flags for the caller. Which appears to be the intent because wasm-pack forwards all extra parameters to cargo build ... so why not forward to the more powerful cargo rustc?
Additional Context
My crate basically takes a CDDL which is used in CBOR to describe data types. I take these datatypes and declare serializer/deserializer for these data types. I export these serializer/deserializers in C for embedded devices and Typescript for the client side.
// Export some wasm stuff#[cfg(feature = "wasm")]#[my_proc_macro(ffi="wasm", cddl="path/to/foo.cddl")]pubmod foo {}// Export some C stuff#[cfg(not(feature = "wasm"))]#[my_proc_macro(ffi="c", cddl="path/to/foo.cddl")]pubmod foo {}
The text was updated successfully, but these errors were encountered:
Motivation
I have a crate that uses proc_macros to generate bindings in either C or WASM. In the WASM case, I import wasm-bindgen and generate a bunch of stuff with the
#[wasm_bindgen]
attribute. In the C case I generate a bunch of methods withextern "C" fn
. Depending on the feature will enable C bindings or WASM bindings.When compiled with the C feature the crate needs to be a staticlib and when compiled with the WASM feature the crate needs to be a cdylib,rlib. Unfortunately, it does not seem possible to change the crate-type based ona feature flag, as far as I can tell. The solution I found is to pass
--crate-type
on the cli tocargo rustc
. Okie.Proposed Solution
The underlying call to
cargo build
could probably just as well usecargo rustc
which exposes more flags for the caller. Which appears to be the intent because wasm-pack forwards all extra parameters tocargo build
... so why not forward to the more powerfulcargo rustc
?Additional Context
My crate basically takes a
CDDL
which is used in CBOR to describe data types. I take these datatypes and declare serializer/deserializer for these data types. I export these serializer/deserializers in C for embedded devices and Typescript for the client side.The text was updated successfully, but these errors were encountered: