forked from rust-fuzz/cargo-fuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplates.rs
More file actions
88 lines (82 loc) · 1.84 KB
/
Copy pathtemplates.rs
File metadata and controls
88 lines (82 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
macro_rules! toml_template {
($name:expr, $edition:expr, $fuzz_engine:expr, $fuzzing_workspace:expr) => {
format_args!(
r##"[package]
name = "{name}-fuzz"
version = "0.0.0"
publish = false
{edition}
[package.metadata]
cargo-fuzz = true
[dependencies]
{libfuzzer_sys_dep}
[dependencies.{name}]
path = ".."
{workspace}"##,
name = $name,
edition = if let Some(edition) = &$edition {
format!("edition = \"{}\"\n", edition)
} else {
String::new()
},
libfuzzer_sys_dep = match $fuzz_engine {
crate::options::FuzzEngine::LibFuzzer => r#"libfuzzer-sys = "0.4""#,
crate::options::FuzzEngine::LibAfl => {
r#"libfuzzer-sys = { version = "0.15.3", package = "libafl_libfuzzer" }"#
}
},
workspace = if let Some(true) = $fuzzing_workspace {
r##"
# Use independent workspace for fuzzers
[workspace]
members = ["."]
"##
} else {
""
}
)
};
}
macro_rules! toml_bin_template {
($name: expr) => {
format_args!(
r#"
[[bin]]
name = "{0}"
path = "fuzz_targets/{0}.rs"
test = false
doc = false
bench = false
"#,
$name
)
};
}
macro_rules! gitignore_template {
() => {
format_args!(
r##"target
corpus
artifacts
coverage
"##
)
};
}
macro_rules! target_template {
($edition:expr) => {
format_args!(
r##"#![no_main]
{extern_crate}
use libfuzzer_sys::fuzz_target;
fuzz_target!(|data: &[u8]| {{
// fuzzed code goes here
}});
"##,
extern_crate = match $edition.as_deref() {
None | Some("2015") => "\nextern crate libfuzzer_sys;\n",
Some(_) => "",
},
)
};
}