Build and test from source
You build Tadoru with cargo, and you test it with three commands. This page has the build, the tests, the lints and
the fuzz targets. The crates says what each crate holds.
What you need
Section titled “What you need”Tadoru builds with Rust 1.100.0. rust-toolchain.toml at the root of the repository names that version, so rustup
installs it and cargo uses it in the repository. SQLite is built in. The system C library is the only other library.
If your shell sets RUSTUP_TOOLCHAIN, that variable wins over the file. Unset it in the repository, or set it to
1.100.0.
Fuzzing needs a nightly toolchain and the cargo-fuzz tool. Nothing else needs nightly.
Run every command on this page at the root of the repository, unless the page says otherwise. The web console lives in
the console/ directory of the same repository. It has its own tools and its own build, which
Building and Testing the Console from Its Source describes.
git clone https://github.com/bitcldr/tadoru.gitcd tadorucargo build --releaseThe binary lands in target/release/tadoru. cargo build with no flag makes a debug build in target/debug/tadoru. It
is slower, and it builds faster while you change the code.
Three environment variables change what the build records. TADORU_COMMIT names the commit, which tadoru --version
and GET /api/info show. It takes 7 to 40 lower-case hexadecimal digits, and any other text stops the build.
SOURCE_DATE_EPOCH gives the time of the commit. The server treats a clock earlier than that time as wrong. The build
runs no git, so you set both yourself. TADORU_RELEASE_VERSION names the version, in place of the version in
Cargo.toml. The release workflow sets it, and a build by hand leaves it out. It must be the version in Cargo.toml,
or that version with -dev.N after it, such as 0.1.0-dev.42. After a pre-release, such as 3.0.0-alpha.2, it is
.dev.N. Any other value stops the build. While the variable is set, build metadata after + in the version in
Cargo.toml stops the build too. Without the variable, such a version builds as before. The image build takes
TADORU_COMMIT and SOURCE_DATE_EPOCH as build arguments of packaging/Dockerfile:
TADORU_COMMIT=$(git rev-parse --short HEAD) SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) cargo build --releasedocker build -f packaging/Dockerfile -t tadoru:local \ --build-arg TADORU_COMMIT=$(git rev-parse --short HEAD) \ --build-arg SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) .To run the binary, read Install and run.
Build with the web console
Section titled “Build with the web console”A plain build holds no web console. The feature console puts the pages of the console in console/ into the binary,
so console_listen can serve them. Build the console first, then the server with the feature:
just build-alljust build-all runs just build-console, which installs the packages of the console and builds it into console/out/, and then
cargo build --release -p tadoru --features console. The console needs Node and pnpm, at the versions of mise.toml at
the root of the repository. Run mise install there first. You can run the two steps yourself:
just build-consolecargo build --release -p tadoru --features consolecargo build never builds the console, and a build without the feature never reads it. A build with the feature
embeds what console/out/ holds at that moment. After a git pull, run just build-console again, or just build-all, or the
server embeds the console of the old checkout.
The build prints one line for the console it embeds: the directory, the count and the size of its files, the first
digits of a digest of the set, and the size of the Content-Security-Policy header. Two builds of the same files print
the same digest. Past 4 KiB, a second line warns that a reverse proxy with a small buffer refuses such a header.
Console and remote API says what to set.
To embed a console that was built somewhere else, name its directory in TADORU_CONSOLE_DIR. The path must be
absolute:
TADORU_CONSOLE_DIR=/srv/tadoru-console/out cargo build --release -p tadoru --features consoleThe build checks each file before it embeds it, and it stops with one line that names the cause. Each line but the
first and the third starts with the console in "<directory>":, so it says which console it is about:
| The build says | What to do |
|---|---|
"…/console/out" holds no console |
Run just build-console, or name a built console in TADORU_CONSOLE_DIR |
the console lacks "csp-hashes.json", which each console build writes |
The build of the console stopped half way. Run just build-console again |
TADORU_CONSOLE_DIR is "out", and it takes an absolute directory |
Name the directory with its full path |
"…" is a link, and the build follows no link |
Name the real directory, or remove the link inside it |
"…" changed while the build read it |
A build of the console ran at the same time. Wait for it, then build again |
"…" is an empty directory, and no console build writes one |
A directory was emptied, or removed while the build read it. Run just build-console again |
csp-hashes.json: "script-src" is not empty, … |
A page holds an inline script, which the policy of the server refuses |
cargo test -p tadoru --features console and cargo test -p front --features console add the tests that need the
console: each style inside a page must have its hash in the policy, the binary must hold the files of the console, and
the door of the console must serve them.
With just
Section titled “With just”The file justfile at the root of the repository holds the commands of the server and of the console. Install
just, Node and pnpm with mise install at the root, then run just for the list:
| Recipe | What it does |
|---|---|
just build-console |
Installs the packages of the console and builds it into console/out/ |
just build-server |
cargo build --release: the server, with no console in it |
just build-all |
Builds the console, then the server with it |
just check-server |
The three checks of the server, as below |
just check-console |
The five checks of the console |
just check-all |
Both |
cargo test # every test in the workspacecargo test -p dns-proto # the tests of one crateTwo tests hold the written pages of this manual to the code. If a setting or a command has no entry on its page, the build fails. The section “What is generated” in The Tadoru Manual says which pages they cover.
Lints and format
Section titled “Lints and format”Three commands must pass before you send a change:
cargo testRUSTFLAGS="-D warnings" cargo clippy --all-targetscargo fmt --all -- --checkThe RUSTFLAGS value turns every warning into an error. The continuous integration (CI) job runs the same three
commands on Rust 1.100.0, the version of rust-toolchain.toml. Another toolchain adds or drops lints, so a warning can
pass on your machine and fail in CI. The file keeps the two on one version.
Two lints are denied in the whole workspace: unsafe_code and clippy::unwrap_used. Do not weaken them.
The parsers that read network input, files and archives are fuzzed with
cargo-fuzz. Each target lives in the crate that owns it. The crate has a
fuzz/ directory with its own workspace.
cd crates/dns-protomkdir -p fuzz/corpus/name_parsecargo +nightly fuzz run name_parse fuzz/seeds/name_parse -- -runs=0 # seeds onlycargo +nightly fuzz run name_parse fuzz/corpus/name_parse fuzz/seeds/name_parse \ fuzz/regressions/name_parse -- -max_total_time=300Name the corpus directory first. The fuzzer writes to the first directory and only reads the others.
These crates carry targets: dns-proto, pipeline, server, blocklist, cache, zone, resolver and acme. The
command cargo fuzz list, run in a crate, names its targets.
Every input that ever crashed a target is kept in fuzz/regressions/. cargo test replays each one, so a fixed bug
cannot come back without a failing test.
Continuous integration
Section titled “Continuous integration”CI runs on every pull request and on every push to main. It runs the three commands above, the checks of the
console and a lint of the workflows. A push to main also builds each fuzz target and runs its seeds and its past
crashes once, and builds the container image from source where a change touches its files. A pull request runs no
fuzz.
The search of the fuzzers runs at night: a minute of each target every night, and 30 minutes of each target once a week. The same night run fetches seven published blocklists and holds the reader to them, and asks the public forwarders of the catalog. So a crash that only a long search finds shows up the next morning, not in the CI of your push.