Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please export --crate-type on the command line #1336

Closed
TomzBench opened this issue Sep 29, 2023 · 1 comment
Closed

Please export --crate-type on the command line #1336

TomzBench opened this issue Sep 29, 2023 · 1 comment

Comments

@TomzBench
Copy link

TomzBench commented Sep 29, 2023

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 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")]
pub mod foo {}

// Export some C stuff
#[cfg(not(feature = "wasm"))]
#[my_proc_macro(ffi="c", cddl="path/to/foo.cddl")]
pub mod foo {}
@TomzBench
Copy link
Author

duplicate #1297

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant