-
Notifications
You must be signed in to change notification settings - Fork 83
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
How to restrict import of unused features required by string type? #433
Comments
Hey @XX so when you build a component in Rust, those imports are needed for the backtrace machinery. There's a discussion on Zulip around exactly why that is. The resulting solutions aren't great (either building for an explicitly non-component target or using nightly rust to remove the default panic machinery), but the discussion should be helpful to you! Unfortunately to run the component as-is in a host embedding, you'll need to link in WASI dependencies. |
@vados-cosmonic So there is no way to restrict a component in using environment variables and other things if it uses a string in interfaces? Because only for integer types in the |
It's been a while since I tried it myself, but have you tried using the wasm32-unknown-unknown target when building?
On Dec 31, 2024 11:20 AM, Alexander Mescheryakov ***@***.***> wrote:
@vados-cosmonic<https://github.com/vados-cosmonic> So there is no way to restrict a component in using environment variables and other things if it uses a string in interfaces? Because only for integer types in the .wit file such imports are not required.
—
Reply to this email directly, view it on GitHub<#433 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAJPQEOPEFF2PSRN2WDX7T32ILN7HAVCNFSM6AAAAABUMFCSICVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNRWGY2DCMRVGI>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
@dicej No, I didn't fully understand what was required. In my case, it was enough to add the necessary interfaces to the linker on the host to make everything work: let mut linker = Linker::<States>::new(&engine);
wasmtime_wasi::add_to_linker_sync(&mut linker)?; The component still won't have access to the stdout, file system etc. until I set up access via context. For example, to access stdout: pub struct States {
table: ResourceTable,
ctx: WasiCtx,
}
impl States {
pub fn new() -> Self {
let table = ResourceTable::new();
let ctx = WasiCtxBuilder::new()
.stdout(wasmtime_wasi::stdout()) // <----- by default stdout is closed, using the host's native stdout
.build();
Self { table, ctx }
}
}
impl WasiView for States {
fn table(&mut self) -> &mut ResourceTable {
&mut self.table
}
fn ctx(&mut self) -> &mut WasiCtx {
&mut self.ctx
}
} But if I still needed to get rid of unnecessary imports, I would take the advice to use the nightly compiler and recompile the |
Hey @XX glad you were able to get the host working (IMO the world is a lot more interesting with the WASI imports :) That said, hopefully you saw the discussion and Joel's specific recommendation (I should have called it out like he did!) -- for super simple components you can use |
@vados-cosmonic Yes, but in my case the component should be able to work with fs, environment variables etc., but only if the user of the host program has granted permissions. |
Ah thanks for clarifying! Glad you were able to get the issue sorted :) |
When I make a simple
.wit
using thestring
type, like this:after building and running I get a request to add a bunch of additional interfaces:
In particular, after running:
But my component should not have the right to get environment variables and do other things. How can I do this?
The text was updated successfully, but these errors were encountered: