wasmtime icon indicating copy to clipboard operation
wasmtime copied to clipboard

Provide a mechanism for disabling on-by-default config options regardless of the enabled cargo feature flags

Open Stebalien opened this issue 11 months ago • 6 comments

Feature

Provide some mechanism for disabling on-by-default config options without having to enable their associated cargo feature flags.

Benefit

The wasmtime Config has a bunch of options like Config::wasm_reference_types that are enabled by-default if the corresponding cargo feature is enabled. Unfortunately, these config options are gated by the same feature flags making it impossible to turn them off without enabling the underlying cargo feature.

This is fine when building an application, but is a problem for library authors. If a library author wants to configure wasmtime in a specific way, they need to enable features (in cargo) they don't actually want so they can disable them in the config. Unfortunately, there's no way to actually detect if the feature has been enabled.

Implementation

The simplest solution is to provide some form of Config::minimal() constructor (or something like that) that turns off all optional features. New versions of wasmtime may make some of these features mandatory, but, IMO, that's fine. I'm mostly looking for predictability.

Alternatives

Another option is to let users call all config methods even if the associated capabilities are disabled via cargo features:

  1. Remove the #[cfg(feature = ...)] gates on all Config methods and their associated fields in the config.
  2. Return an error from Engine::new if unsupported features are requested.

The main drawback is that we'll lose the compile-time check on whether or not the feature is enabled.

Stebalien avatar Mar 21 '25 18:03 Stebalien

Your motivation definitely makes sense, however I think the alternative you describe is probably the best approach here, mainly because

  1. I think that a Config::minimal() is a little too ambiguous and some people might think it means "good config for embedded use with minimal platform assumptions" while other might think it means "good config for my target platform with minimal wasm features" and I don't think it is worth trying to word-smith our way out of that kind of confusion or whatever and that trying to make everyone happy will make no one happy.

  2. We already do some config validation during engine creation and return errors if incompatible config options are set and things like that.

fitzgen avatar Mar 21 '25 18:03 fitzgen

Agreed yeah, I think it'd be reasonable to un-gate most of the Config methods and have them always available

alexcrichton avatar Mar 21 '25 18:03 alexcrichton

I'm quite happy with either option and I'm happy to take a stab at implementing this.

Stebalien avatar Mar 21 '25 18:03 Stebalien

I'm quite happy with either option and I'm happy to take a stab at implementing this.

Great! Let me know (here or zulip) if you need any pointers or anything like that 👍

fitzgen avatar Mar 21 '25 19:03 fitzgen

Would it make sense to have a method which returns a Config containing exactly the features in the lime1 target (as defined in the tool convensions repo) without any other features enabled?

bjorn3 avatar Mar 21 '25 19:03 bjorn3

I have a PR here (https://github.com/bytecodealliance/wasmtime/pull/10455) but I need a small clarification on the default status of reference types with the "gc" feature disabled.

Stebalien avatar Mar 21 '25 20:03 Stebalien