Comments (2)
Adding in my use case here. I have a need to make a library that wraps some wasi:http
functionality for use in multiple (Rust) components. Specifically I need to implement a replacement http-connector for an SDK I would like to use that is not by default not functoinal in wasm/wasi. At the moment I can't see any way of doing that beyond making my library a kind of no-op component. It would be ideal if I could somehow import the wasi:http
functions into my library without having to jump through the build hoops of having a stubbed component for it.
from cargo-component.
I have a use case which I think is hitting this same problem. I would like to implement the same component from several crates but share utility code between them. Having the bindings redefined in each crate makes the types impossible to share (I think) so I need them in a separate crate that all the others can import.
For what it's worth I was able to make that work with a bit of hand tweaking:
I created a shared_bindings crate in my workspace using cargo component new --lib shared_bindings
, setup the correct .wit file and generated the bindings with cargo component build
then modified the lib.rs to simply export the bindings:
#[allow(warnings)]
mod bindings;
pub use bindings::*;
And modified bindings.rs to make the export!
macro public as well as change the Cargo.toml file to make the crate a regular rlib. I was then able to create my implementation crates with cargo component new --lib
as usual but instead of declaring the bindings module from the local bindings.rs I imported the shared_bindings crate and used those definitions. cargo component --build
works and creates usable wasm files, at least in my fairly simple test case.
Not particularly ergonomic as is but it seems to indicate that the changes to the tooling needed to support this are pretty minimal.
from cargo-component.
Related Issues (20)
- Error building when using cargo-component `bindings` instead of `wit-bindgen` HOT 1
- `cargo component check --workspace` should not generate bindings for workspace members without `[package.metadata.component]` set HOT 2
- `cargo-component` is not acquring a file lock for componentization
- Document the schema of the cargo-component Cargo.toml configuration HOT 1
- Hello world example fails when project name contains underscore HOT 1
- Add a `cargo component serve` subcommand that uses a default runner of `wasmtime serve`
- wit pubilsh --init fails to register the WIT package to wa.dev, while it successfully create a pacakge on the registry HOT 4
- Build fails with 'failed to create a target world for package ...' HOT 2
- Use something like nightly.link or a non-re-published release to avoid excess notifications
- Build error: `error: string size out of bounds (at offset {offset})` HOT 10
- Additional `import`s in generated component HOT 2
- Resource Static Methods Cause Build Failure When Imported HOT 5
- Wit package name/version validated against registry publishes
- Some wasi imports added per default into wit HOT 2
- cargo install cargo-component error HOT 5
- Compile error when installing cargo component HOT 7
- Minimum Supported Rust Version (MSRV)
- Bindings are sometimes incorrectly generated type + `Borrow` suffix vs `&` type HOT 2
- `cargo component add` not producing runnable/usable binaries
- Cargo Component install give error in RPI 4 (ARM CORTEX-A72) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cargo-component.