1986f9f79SAlex Crichton# Coding guidelines 2986f9f79SAlex Crichton 3986f9f79SAlex CrichtonFor the most part, Wasmtime and Cranelift follow common Rust conventions and 4986f9f79SAlex Crichton[pull request] (PR) workflows, though we do have a few additional things to 5986f9f79SAlex Crichtonbe aware of. 6986f9f79SAlex Crichton 7986f9f79SAlex Crichton[pull request]: https://help.github.com/articles/about-pull-requests/ 8986f9f79SAlex Crichton 947d3c8deSNick Fitzgerald### `rustfmt` 10986f9f79SAlex Crichton 11986f9f79SAlex CrichtonAll PRs must be formatted according to rustfmt, and this is checked in the 12986f9f79SAlex Crichtoncontinuous integration tests. You can format code locally with: 13986f9f79SAlex Crichton 14986f9f79SAlex Crichton```sh 15986f9f79SAlex Crichton$ cargo fmt 16986f9f79SAlex Crichton``` 17986f9f79SAlex Crichton 18986f9f79SAlex Crichtonat the root of the repository. You can find [more information about rustfmt 19986f9f79SAlex Crichtononline](https://github.com/rust-lang/rustfmt) too, such as how to configure 20986f9f79SAlex Crichtonyour editor. 21986f9f79SAlex Crichton 2247d3c8deSNick Fitzgerald### Minimum Supported `rustc` Version 23986f9f79SAlex Crichton 24a04c4930SAlex CrichtonWasmtime and Cranelift support the latest three stable releases of Rust. This 25a04c4930SAlex Crichtonmeans that if the latest version of Rust is 1.72.0 then Wasmtime supports Rust 26a04c4930SAlex Crichton1.70.0, 1.71.0, and 1.72.0. CI will test by default with 1.72.0 and there will 27a04c4930SAlex Crichtonbe one job running the full test suite on Linux x86\_64 on 1.70.0. 28986f9f79SAlex Crichton 29a04c4930SAlex CrichtonSome of the CI jobs depend on nightly Rust, for example to run rustdoc with 30a04c4930SAlex Crichtonnightly features, however these use pinned versions in CI that are updated 31a04c4930SAlex Crichtonperiodically and the general repository does not depend on nightly features. 32986f9f79SAlex Crichton 33a04c4930SAlex CrichtonUpdating Wasmtime's MSRV is done by editing the `rust-version` field in the 34a04c4930SAlex Crichtonworkspace root's `Cargo.toml` 35986f9f79SAlex Crichton 36*5c8bce70SAlex Crichton### Dependencies of Wasmtime 37*5c8bce70SAlex Crichton 38*5c8bce70SAlex CrichtonWasmtime and Cranelift have a higher threshold than default for adding 39*5c8bce70SAlex Crichtondependencies to the project. All dependencies are required to be "vetted" 40*5c8bce70SAlex Crichtonthrough the [`cargo vet` tool](https://mozilla.github.io/cargo-vet/). This is 41*5c8bce70SAlex Crichtonchecked on CI and will run on all modifications to `Cargo.lock`. 42*5c8bce70SAlex Crichton 43*5c8bce70SAlex CrichtonA "vet" for Wasmtime is not a meticulous code review of a dependency for 44*5c8bce70SAlex Crichtoncorrectness but rather it is a statement that the crate does not contain 45*5c8bce70SAlex Crichtonmalicious code and is safe for us to run during development and (optionally) 46*5c8bce70SAlex Crichtonusers to run when they run Wasmtime themselves. Wasmtime's vet entries are used 47*5c8bce70SAlex Crichtonby other organizations which means that this isn't simply for our own personal 48*5c8bce70SAlex Crichtonuse. Wasmtime additionally uses vet entries from other organizations as well 49*5c8bce70SAlex Crichtonwhich means we don't have to vet everything ourselves. 50*5c8bce70SAlex Crichton 51*5c8bce70SAlex CrichtonNew vet entries are required to be made by trusted contributors to Wasmtime. 52*5c8bce70SAlex CrichtonThis is all configured in the `supply-chain` folder of Wasmtime. These files 53*5c8bce70SAlex Crichtongenerally aren't hand-edited though and are instead managed through the `cargo 54*5c8bce70SAlex Crichtonvet` tool itself. Note that our `supply-chain/audits.toml` additionally contains 55*5c8bce70SAlex Crichtonentries which indicates that authors are trusted as opposed to vets of 56*5c8bce70SAlex Crichtonindividual crates. This lowers the burden of updating version of a crate from a 57*5c8bce70SAlex Crichtontrusted author. 58*5c8bce70SAlex Crichton 59*5c8bce70SAlex CrichtonWhen put together this means that contributions to Wasmtime and Cranelift which 60*5c8bce70SAlex Crichtonupdate existing dependencies or add new dependencies will not be mergeable by 61*5c8bce70SAlex Crichtondefault (CI will fail). This is expected from our project's configuration and 62*5c8bce70SAlex Crichtonthis situation will be handled one of a few ways: 63*5c8bce70SAlex Crichton 64*5c8bce70SAlex Crichton* If a new dependency is being added it might be worth trying to slim down 65*5c8bce70SAlex Crichton what's required or avoiding the dependency altogether. Avoiding new 66*5c8bce70SAlex Crichton dependencies is best when reasonable, but it is not always reasonable to do 67*5c8bce70SAlex Crichton so. This is left to the judgement of the author and reviewer. 68*5c8bce70SAlex Crichton 69*5c8bce70SAlex Crichton* When updating dependencies this should be done for a specific purpose relevant 70*5c8bce70SAlex Crichton to the PR-at-hand. For example if the PR implements a new feature then the 71*5c8bce70SAlex Crichton dependency update should be required for the new feature. Otherwise it's best 72*5c8bce70SAlex Crichton to leave dependency updates to their own PRs. It's ok to update dependencies 73*5c8bce70SAlex Crichton "just for the update" but we prefer to have that as separate PRs. 74*5c8bce70SAlex Crichton 75*5c8bce70SAlex Crichton* If a new dependency or dependency update is required, then a trusted 76*5c8bce70SAlex Crichton contributor of Wasmtime will be required to perform a vet of the new 77*5c8bce70SAlex Crichton crate/version. This will be done through a separate PR to Wasmtime so we ask 78*5c8bce70SAlex Crichton contributors to not run `cargo vet` themselves to get CI passing. Reviewers 79*5c8bce70SAlex Crichton understand what `cargo vet` failures are on CI and how it doesn't reflect on 80*5c8bce70SAlex Crichton the quality of the PR itself. Once the reviewer (or another maintainer) merges 81*5c8bce70SAlex Crichton a PR adding the vet entries necessary for the original contribution it can be 82*5c8bce70SAlex Crichton rebased to get CI passing. 83*5c8bce70SAlex Crichton 84*5c8bce70SAlex CrichtonNote that this process is not in place to prevent new dependencies or prevent 85*5c8bce70SAlex Crichtonupdates, but rather it ensures that development of Wasmtime is done with a 86*5c8bce70SAlex Crichtontrusted set of code that has been reviewed by trusted parties. We welcome 87*5c8bce70SAlex Crichtondependency updates and new functionality, so please don't be too alarmed when 88*5c8bce70SAlex Crichtoncontributing and seeing a failure of `cargo vet` on CI! 89