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

Create wasmtime::Config from toml #9811

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ludfjig
Copy link

@ludfjig ludfjig commented Dec 13, 2024

This PR makes it possible to create a wasmtime::Config from a toml file and is a first step toward resolving #8784. Overall, I think the path forward is as follows:

  1. This PR: Enables loading wasmtime::Config from a toml file, by making CommonOptions derive Deserialize. For example, opt_level is deserialized from values 0, 1, 2, "s" (same as cli flags) instead of "None", "Speed", "SpeedAndSize". Same applies to regalloc_algorithm, compiler and collector. Feedback appreciated on this.
  2. Combine cache-config toml with this new toml.
  3. Have one source of truth for cli flags and config options.

Feedback greatly appreciated, especially regarding how to deal with nn_graph, as well config_var and keyvalue_in_memory_data, which are all marked serde(skip) for now

@ludfjig ludfjig requested a review from a team as a code owner December 13, 2024 00:15
@ludfjig ludfjig requested review from alexcrichton and removed request for a team December 13, 2024 00:15
@ludfjig ludfjig marked this pull request as draft December 13, 2024 00:16
@ludfjig ludfjig force-pushed the ludfjig/fileconfig branch 2 times, most recently from d53fabf to 23b1984 Compare December 13, 2024 00:22
@github-actions github-actions bot added wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:config Issues related to the configuration of Wasmtime labels Dec 13, 2024
Copy link

Label Messager: wasmtime:config

It looks like you are changing Wasmtime's configuration options. Make sure to
complete this check list:

  • If you added a new Config method, you wrote extensive documentation for
    it.

    Our documentation should be of the following form:

    Short, simple summary sentence.
    
    More details. These details can be multiple paragraphs. There should be
    information about not just the method, but its parameters and results as
    well.
    
    Is this method fallible? If so, when can it return an error?
    
    Can this method panic? If so, when does it panic?
    
    # Example
    
    Optional example here.
    
  • If you added a new Config method, or modified an existing one, you
    ensured that this configuration is exercised by the fuzz targets.

    For example, if you expose a new strategy for allocating the next instance
    slot inside the pooling allocator, you should ensure that at least one of our
    fuzz targets exercises that new strategy.

    Often, all that is required of you is to ensure that there is a knob for this
    configuration option in wasmtime_fuzzing::Config (or one
    of its nested structs).

    Rarely, this may require authoring a new fuzz target to specifically test this
    configuration. See our docs on fuzzing for more details.

  • If you are enabling a configuration option by default, make sure that it
    has been fuzzed for at least two weeks before turning it on by default.


To modify this label's message, edit the .github/label-messager/wasmtime-config.md file.

To add new label messages or remove existing label messages, edit the
.github/label-messager.json configuration file.

Learn more.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! I'm liking how this is shaping up pretty cleanly so far. Would you be up for integrating this into a CLI flag itself as well? For example wasmtime --config cfg.toml or something like that

Comment on lines 965 to 977
pub trait FromFile {
fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
where
Self: Sized;
}

impl FromFile for Config {
fn from_file<P: AsRef<Path>>(path: P) -> Result<Self> {
let file_contents = fs::read_to_string(path.as_ref())?;
let mut common_options: CommonOptions = toml::from_str(&file_contents)?;
common_options.config(None)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might perhaps be best as an inherent method on CommonOptions as an alternative constructor? That would still require the caller call .config(...) but that seems like a reasonable tradeoff to me.

Copy link
Author

@ludfjig ludfjig Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, moved to CommonOption::from_file instead. Happy to rename it to something different as well


impl FromFile for Config {
fn from_file<P: AsRef<Path>>(path: P) -> Result<Self> {
let file_contents = fs::read_to_string(path.as_ref())?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind updating the error using .with_context(...) to attach the name of the file here and below?

Copy link
Author

@ludfjig ludfjig Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, addressed!

@ludfjig
Copy link
Author

ludfjig commented Dec 13, 2024

Thanks for this! I'm liking how this is shaping up pretty cleanly so far. Would you be up for integrating this into a CLI flag itself as well? For example wasmtime --config cfg.toml or something like that

Thanks for looking at this. I added a --config flag. Any suggestions on how to best test this?

@alexcrichton
Copy link
Member

For tests I'd recommend tests/all/cli_tests.rs or somewhere around there for making a tempdir with a config file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:config Issues related to the configuration of Wasmtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants