aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAbhishek Arya <inferno@chromium.org>2021-06-05 08:44:21 -0700
committerGitHub <noreply@github.com>2021-06-05 08:44:21 -0700
commit5766e32e90783cb674d7333a3db8135a87515bfb (patch)
treea606b2f9cb97ef19b5d31e8b88fd71f07f3e9350 /docs
parent37d02c6ed30535ce98d6e5882b27ddc2f25d0711 (diff)
downloadoss-fuzz-5766e32e90783cb674d7333a3db8135a87515bfb.tar.gz
Update rust_lang.md
Diffstat (limited to 'docs')
-rw-r--r--docs/getting-started/new-project-guide/rust_lang.md90
1 files changed, 44 insertions, 46 deletions
diff --git a/docs/getting-started/new-project-guide/rust_lang.md b/docs/getting-started/new-project-guide/rust_lang.md
index 8a3b59620..7d961ba41 100644
--- a/docs/getting-started/new-project-guide/rust_lang.md
+++ b/docs/getting-started/new-project-guide/rust_lang.md
@@ -27,52 +27,6 @@ fuzz` tool will build code with required compiler flags as well as link to the
correct libFuzzer on OSS-Fuzz itself. Note that using `cargo fuzz` also makes it
quite easy to run the fuzzers locally yourself if you get a failing test case!
-
-### Writing fuzzers using a test-style strategy
-
-In Rust you will often have tests written in a way so they are only
-compiled into the final binary when build in test-mode. This is, achieved by
-wrapping your test code in `cfg(test)`, e.g.
-```rust
-#[cfg(test)]
-mod tests {
- use super::*;
-
- ...
-```
-
-Cargo-fuzz automatically enables the `fuzzing` feature, which means you can
-follow a similar strategy to writing fuzzers as you do when writing tests.
-Specifically, you can create modules wrapped in the `fuzzing` feature:
-```rust
-#[cfg(fuzzing)]
-pub mod fuzz_logic {
- use super::*;
-
- ...
-```
-and then call the logic within `fuzz_logic` from your fuzzer.
-
-Furthermore, within your `.toml` files, you can then specify fuzzing-specific
-depedencies by wrapping them as follows:
-```
-[target.'cfg(fuzzing)'.dependencies]
-```
-similar to how you wrap test-dependencies as follows:
-```
-[dev-dependencies]
-```
-
-Finally, you can also combine the testing logic you have and the fuzz logic. This
-can be achieved simply by using
-```rust
-#[cfg(any(test, fuzzing))]
-```
-
-A project that follows this structure is Linkerd2-proxy and the project files can be
-seen [here](https://github.com/google/oss-fuzz/tree/master/projects/linkerd2-proxy).
-
-
## Project files
First you'll want to follow the [setup instructions for `cargo fuzz`
@@ -146,3 +100,47 @@ do
cp $FUZZ_TARGET_OUTPUT_DIR/$FUZZ_TARGET_NAME $OUT/
done
```
+
+## Writing fuzzers using a test-style strategy
+
+In Rust you will often have tests written in a way so they are only
+compiled into the final binary when build in test-mode. This is, achieved by
+wrapping your test code in `cfg(test)`, e.g.
+```rust
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ ...
+```
+
+Cargo-fuzz automatically enables the `fuzzing` feature, which means you can
+follow a similar strategy to writing fuzzers as you do when writing tests.
+Specifically, you can create modules wrapped in the `fuzzing` feature:
+```rust
+#[cfg(fuzzing)]
+pub mod fuzz_logic {
+ use super::*;
+
+ ...
+```
+and then call the logic within `fuzz_logic` from your fuzzer.
+
+Furthermore, within your `.toml` files, you can then specify fuzzing-specific
+depedencies by wrapping them as follows:
+```
+[target.'cfg(fuzzing)'.dependencies]
+```
+similar to how you wrap test-dependencies as follows:
+```
+[dev-dependencies]
+```
+
+Finally, you can also combine the testing logic you have and the fuzz logic. This
+can be achieved simply by using
+```rust
+#[cfg(any(test, fuzzing))]
+```
+
+A project that follows this structure is Linkerd2-proxy and the project files can be
+seen [here](https://github.com/google/oss-fuzz/tree/master/projects/linkerd2-proxy).