Debian Codegraph @

CONTRIBUTING.md

raw
1 # Contributing
2
3 This project welcomes contributions for bug fixes, documentation updates, new
4 features, or whatever you might like. Development is done through GitHub pull
5 requests. Feel free to reach out on the [Bytecode Alliance
6 Zulip](https://bytecodealliance.zulipchat.com/) as well if you'd like assistance
7 in contributing or would just like to say hi.
8
9 ### Building From Source
10
11 To create a debug build of this project from source, execute this command at the
12 root of the repository:
13
14 ```
15 $ cargo build
16 ```
17
18 And the resulting binary is located at `./target/debug/wasm-tools` for the
19 current platform.
20
21 An optimized build can be produced with:
22
23 ```
24 $ cargo build --release
25 ```
26
27 ### Testing
28
29 Many crates in this repository (located in `crates/*`) both have unit tests
30 (`#[test]` functions throughout the source) and integration tests
31 (`crates/*/tests/*.rs`). Testing an individual crate can be done with:
32
33 ```
34 $ cargo test -p wasmparser
35 ```
36
37 Running all tests can be done by first ensuring that the spec test suite is
38 checked out:
39
40 ```
41 $ git submodule update --init
42 ```
43
44 and then using Cargo to execute all tests:
45
46 ```
47 $ cargo test --workspace
48 ```
49
50 The majority of all tests is located in `tests/cli/*` and can be run with:
51
52 ```
53 $ cargo test --test cli
54 ```
55
56 Each individual file is a standalone test and documents at the top how to run
57 it. Running individual tests can be done through:
58
59 ```
60 $ cargo test --test cli -- test_name_filter
61 ```
62
63 Or you can use `cargo run` plus the test's arguments to run a single test.
64
65 ```
66 $ cargo run wast tests/cli/empty.wast
67 ```
68
69 Running just the spec test suite can be done with:
70
71 ```
72 $ cargo test --test cli -- spec
73 ```
74
75 and running a single spec test can be done with an argument to this command as a
76 string filter on the filename.
77
78 ```
79 $ cargo test --test cli binary-leb128.wast
80 $ cargo run wast tests/testsuite/binary-leb128.wast --ignore-error-messages
81 ```
82
83 The `tests/cli` tests suite is documented as a self-describing test at
84 `tests/cli/readme.wat`. Each test describes what subcommand of `wasm-tools` is
85 run and the test is itself the input.
86
87 The `tests/testsuite` folder is a git submodule pointing to the [upstream test
88 suite repository](https://github.com/WebAssembly/testsuite/) and is where spec
89 tests come from. The `tests/snapshots` folder contains golden output files
90 which correspond to the `wasmprinter`-printed version of binaries of all tests.
91 These files are used to view the impact of changes to `wasmprinter`.
92
93 Many tests throughout the repository have automatically generated files
94 associated with them which reflect the expected output of an operation. This is
95 done to view, during code review, the impact of changes made. It's not expected
96 that these files need to be edited by hand, but instead setting the environment
97 variable `BLESS=1` when running tests will update all of these test
98 expectations.
99
100 ### Continuous Integration
101
102 All changes to `wasm-tools` are required to pass the CI suite powered by GitHub
103 Actions. Pull requests will automatically have checks performed and can only be
104 merged once all tests are passing. CI checks currently include:
105
106 * Code is all formatted correctly (use `cargo fmt` locally to pass this)
107 * Tests pass on Rust stable, beta, and Nightly.
108 * Tests pass on Linux, macOS, and Windows.
109 * This tool can be compiled to WebAssembly using the `wasm32-wasip1` target.
110 * Fuzzers can be built.
111 * Various miscellaneous checks such as building the tool with various
112 combinations of Cargo features.
113
114 ### Fuzzing
115
116 This repository uses LLVM's libFuzzer through the [`cargo
117 fuzz`](https://github.com/rust-fuzz/cargo-fuzz) tool. Building fuzzers requires
118 a Nightly Rust toolchain which can be acquired with Rustup-based installations
119 of Rust by executing:
120
121 ```
122 $ rustup update nightly
123 ```
124
125 Next the `cargo-fuzz` runner should be installed:
126
127 ```
128 $ cargo install cargo-fuzz
129 ```
130
131 Fuzzers are then built with:
132
133 ```
134 $ cargo +nightly fuzz build
135 ```
136
137 Useful options to this can include:
138
139 * `--dev` - build fuzzers in debug mode instead of release mode (default is
140 release)
141 * `--sanitizer none` - Rust doesn't benefit much from AddressSanitizer for
142 example so disabling sanitizers can improve fuzzing performance and build more
143 quickly too.
144
145 The fuzzing binary for this project is located at
146 `target/$host_target/release/run`. Due to limitations on OSS-Fuzz all fuzzers
147 are combined into a single binary at this time. This binary can be run with:
148
149 ```
150 $ cargo +nightly fuzz run run
151 ```
152
153 The main driver for fuzzing is located at `fuzz/fuzz_targets/run.rs`. This
154 driver dispatches, based on the input, to a number of other fuzzers. Each
155 individual fuzzer lives in `fuzz/src/*.rs`.
156
157 Running a single fuzzer can be done by configuring the `FUZZER` environment
158 variable:
159
160 ```
161 $ FUZZER=roundtrip cargo +nightly fuzz run run
162 ```
163
164 More documentation of `cargo fuzz` can [be found
165 online](https://rust-fuzz.github.io/book/cargo-fuzz.html).
166
167 ### Adding a new Crate
168
169 When a new crate is added to this repository it'll need to be accompanied with a
170 reservation of the crate name on crates.io. That enables this repository to
171 automatically manage publishing of the crate. The steps for adding a new crate
172 are:
173
174 * CI should fail when a new crate is added until the below steps are complete.
175 * Update `ci/publish.rs` with the name of your crate in the array at the top.
176 * A dummy empty crate should be published to crates.io with a small README
177 pointing to this repository and indicating that it's a temporary name
178 reservation until the first version is published from this repository's
179 automation.
180 * A "Trusted Publishing" workflow should be added for the new crate. The
181 workflow filename is `publish.yml` and the environment name is `release`.
182 * The crate should be exclusively owned by the `wasmtime-publish` crates.io
183 user. This will require a `wasm-tools` maintainer to log in, accept the
184 invite, and remove the prior owner.
185
186 After these steps have been completed CI should then pass and the crate will be
187 auto-published from this repository on the next release.
188
189 Note that if you're adding a crate which is not published to crates.io you'll
190 want to add `publish = false` to the manifest.
191
192 # License
193
194 This project is licensed under the Apache 2.0 license with the LLVM exception.
195 See [LICENSE](LICENSE) for more details.
196
197 ### Contribution
198
199 Unless you explicitly state otherwise, any contribution intentionally submitted
200 for inclusion in this project by you, as defined in the Apache-2.0 license,
201 shall be licensed as above, without any additional terms or conditions.