Selaa lähdekoodia

Merge branch 'faster-builds'

Benjamin Sago 4 vuotta sitten
vanhempi
commit
31aca2a45c
12 muutettua tiedostoa jossa 111 lisäystä ja 173 poistoa
  1. 1 0
      .gitignore
  2. 3 19
      Cargo.lock
  3. 9 2
      Cargo.toml
  4. 58 25
      Justfile
  5. 34 11
      build.rs
  6. 1 1
      dns-transport/Cargo.toml
  7. 1 24
      dns-transport/src/auto.rs
  8. 0 23
      dns-transport/src/https.rs
  9. 0 23
      dns-transport/src/tcp.rs
  10. 0 23
      dns-transport/src/tls.rs
  11. 3 21
      dns-transport/src/udp.rs
  12. 1 1
      dns/Cargo.toml

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 /target
 /tarpaulin-report.html
 fuzz-*.log
+/cargo-timing*.html

+ 3 - 19
Cargo.lock

@@ -130,7 +130,7 @@ checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499"
 
 [[package]]
 name = "dns"
-version = "0.1.0"
+version = "0.2.0-pre"
 dependencies = [
  "base64",
  "byteorder",
@@ -142,7 +142,7 @@ dependencies = [
 
 [[package]]
 name = "dns-transport"
-version = "0.1.0"
+version = "0.2.0-pre"
 dependencies = [
  "dns",
  "httparse",
@@ -152,7 +152,7 @@ dependencies = [
 
 [[package]]
 name = "dog"
-version = "0.1.0"
+version = "0.2.0-pre"
 dependencies = [
  "ansi_term",
  "atty",
@@ -164,7 +164,6 @@ dependencies = [
  "log",
  "pretty_assertions",
  "rand",
- "regex",
  "serde",
  "serde_json",
 ]
@@ -510,21 +509,6 @@ dependencies = [
  "bitflags",
 ]
 
-[[package]]
-name = "regex"
-version = "1.4.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19"
-dependencies = [
- "regex-syntax",
-]
-
-[[package]]
-name = "regex-syntax"
-version = "0.6.23"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548"
-
 [[package]]
 name = "remove_dir_all"
 version = "0.5.3"

+ 9 - 2
Cargo.toml

@@ -11,23 +11,31 @@ exclude = [
 ]
 homepage = "https://dns.lookup.dog/"
 license = "EUPL-1.2"
-version = "0.1.0"
+version = "0.2.0-pre"
 
 [[bin]]
 name = "dog"
 path = "src/main.rs"
 
+
 [workspace]
 members = [
   "dns",
   "dns-transport",
 ]
 
+
+# make dev builds faster by excluding debug symbols
+[profile.dev]
+debug = false
+
+# use LTO for smaller binaries (that take longer to build)
 [profile.release]
 lto = true
 overflow-checks = true
 panic = "abort"
 
+
 [dependencies]
 
 # dns stuff
@@ -55,7 +63,6 @@ ipconfig = { version = "0.2" }
 
 [build-dependencies]
 datetime = { version = "0.5.1", default_features = false }
-regex = { version = "1.3", default_features = false, features = ["std"] }
 
 [dev-dependencies]
 pretty_assertions = "0.7"

+ 58 - 25
Justfile

@@ -5,106 +5,139 @@ all-quick: build-quick test-quick xtests-quick
 export DOG_DEBUG := ""
 
 
-# compiles the dog binary
+#----------#
+# building #
+#----------#
+
+# compile the dog binary
 @build:
     cargo build
 
-# compiles the dog binary (in release mode)
+# compile the dog binary (in release mode)
 @build-release:
     cargo build --release --verbose
     strip "${CARGO_TARGET_DIR:-target}/release/dog"
 
-# compiles the dog binary (without some features)
+# produce an HTML chart of compilation timings
+@build-time:
+    cargo +nightly clean
+    cargo +nightly build -Z timings
+
+# compile the dog binary (without some features)
 @build-quick:
     cargo build --no-default-features
 
 
-# runs unit tests
+#---------------#
+# running tests #
+#---------------#
+
+# run unit tests
 @test:
-    cargo test --workspace -- --quiet
+    cargo test --lib --bin dog --workspace -- --quiet
 
-# runs unit tests (in release mode)
+# run unit tests (in release mode)
 @test-release:
-    cargo test --release --workspace --verbose
+    cargo test --lib --bin dog -workspace --release --verbose
 
-# runs unit tests (without some features)
+# run unit tests (without some features)
 @test-quick:
-    cargo test --workspace --no-default-features -- --quiet
+    cargo test --lib --bin dog --workspace --no-default-features -- --quiet
 
-# runs mutation tests
+# run mutation tests
 @test-mutation:
     cargo +nightly test    --package dns --features=dns/with_mutagen -- --quiet
     cargo +nightly mutagen --package dns --features=dns/with_mutagen
 
 
-# runs extended tests
+#------------------------#
+# running extended tests #
+#------------------------#
+
+# run extended tests
 @xtests:
     specsheet xtests/*.toml -O cmd.target.dog="${CARGO_TARGET_DIR:-../target}/debug/dog"
 
-# runs extended tests (in release mode)
+# run extended tests (in release mode)
 @xtests-release:
     specsheet xtests/*.toml -O cmd.target.dog="${CARGO_TARGET_DIR:-../target}/release/dog"
 
-# runs extended tests (omitting certain feature tests)
+# run extended tests (omitting certain feature tests)
 @xtests-quick:
     specsheet xtests/*.toml -O cmd.target.dog="${CARGO_TARGET_DIR:-../target}/debug/dog" --skip-tags=udp,tls,https,json
 
 
-# runs fuzzing on the dns crate
+#---------#
+# fuzzing #
+#---------#
+
+# run fuzzing on the dns crate
 @fuzz:
     cargo +nightly fuzz --version
     cd dns; cargo +nightly fuzz run fuzz_parsing -- -jobs=`nproc` -workers=`nproc` -runs=69105
 
-# prints out the data that caused crashes during fuzzing as hexadecimal
+# print out the data that caused crashes during fuzzing as hexadecimal
 @fuzz-hex:
     for crash in dns/fuzz/artifacts/fuzz_parsing/crash-*; do echo; echo $crash; hexyl $crash; done
 
-# removes fuzz log files
+# remove fuzz log files
 @fuzz-clean:
     rm dns/fuzz/fuzz-*.log
 
 
-# lints the code
+#-----------------------#
+# code quality and misc #
+#-----------------------#
+
+# lint the code
 @clippy:
     touch dns/src/lib.rs
     cargo clippy
 
-# generates a code coverage report using tarpaulin via docker
+# generate a code coverage report using tarpaulin via docker
 @coverage-docker:
     docker run --security-opt seccomp=unconfined -v "${PWD}:/volume" xd009642/tarpaulin cargo tarpaulin --all --out Html
 
-# updates dependency versions, and checks for outdated ones
+# update dependency versions, and check for outdated ones
 @update-deps:
     cargo update
     command -v cargo-outdated >/dev/null || (echo "cargo-outdated not installed" && exit 1)
     cargo outdated
 
-# lists unused dependencies
+# list unused dependencies
 @unused-deps:
     command -v cargo-udeps >/dev/null || (echo "cargo-udeps not installed" && exit 1)
     cargo +nightly udeps
 
-# prints versions of the necessary build tools
+# print versions of the necessary build tools
 @versions:
     rustc --version
     cargo --version
 
 
-# renders the documentation
+#---------------#
+# documentation #
+#---------------#
+
+# render the documentation
 @doc:
     cargo doc --no-deps --workspace
 
-# builds the man pages
+# build the man pages
 @man:
     mkdir -p "${CARGO_TARGET_DIR:-target}/man"
     pandoc --standalone -f markdown -t man man/dog.1.md > "${CARGO_TARGET_DIR:-target}/man/dog.1"
 
-# builds and previews the man page
+# build and preview the man page
 @man-preview: man
     man "${CARGO_TARGET_DIR:-target}/man/dog.1"
 
 
-# creates a distributable package
+#-----------#
+# packaging #
+#-----------#
+
+# create a distributable package
 zip desc exe="dog":
     #!/usr/bin/env perl
     use Archive::Zip;

+ 34 - 11
build.rs

@@ -19,7 +19,6 @@ use std::io::{self, Write};
 use std::path::PathBuf;
 
 use datetime::{LocalDateTime, ISO};
-use regex::Regex;
 
 
 /// The build script entry point.
@@ -30,7 +29,11 @@ fn main() -> io::Result<()> {
     let tagline = "dog \\1;32m●\\0m command-line DNS client";
     let url     = "https://dns.lookup.dog/";
 
-    let ver = if is_development_version() {
+    let ver =
+        if is_debug_build() {
+            format!("{}\nv{} \\1;31m(pre-release debug build!)\\0m\n\\1;4;34m{}\\0m", tagline, cargo_version(), url)
+        }
+        else if is_development_version() {
             format!("{}\nv{} [{}] built on {} \\1;31m(pre-release!)\\0m\n\\1;4;34m{}\\0m", tagline, cargo_version(), git_hash(), build_date(), url)
         }
         else {
@@ -40,28 +43,46 @@ fn main() -> io::Result<()> {
     // We need to create these files in the Cargo output directory.
     let out = PathBuf::from(env::var("OUT_DIR").unwrap());
 
-    // The bits .txt files contain ANSI escape codes, ish.
-    let control_code = Regex::new(r##"\\.+?m"##).unwrap();
-
     // Pretty version text
     let mut f = File::create(&out.join("version.pretty.txt"))?;
-    write!(f, "{}\n", ver.replace("\\", "\x1B["))?;
+    writeln!(f, "{}", convert_codes(&ver))?;
 
     // Bland version text
     let mut f = File::create(&out.join("version.bland.txt"))?;
-    write!(f, "{}\n", control_code.replace_all(&ver, ""))?;
+    writeln!(f, "{}", strip_codes(&ver))?;
 
     // Pretty usage text
     let mut f = File::create(&out.join("usage.pretty.txt"))?;
-    write!(f, "{}\n\n{}", tagline.replace("\\", "\x1B["), usage.replace("\\", "\x1B["))?;
+    writeln!(f, "{}", convert_codes(&tagline))?;
+    writeln!(f)?;
+    write!(f, "{}", convert_codes(&usage))?;
 
     // Bland usage text
     let mut f = File::create(&out.join("usage.bland.txt"))?;
-    write!(f, "{}\n\n{}", control_code.replace_all(tagline, ""), control_code.replace_all(usage, ""))?;
+    writeln!(f, "{}", strip_codes(&tagline))?;
+    writeln!(f)?;
+    write!(f, "{}", strip_codes(&usage))?;
 
     Ok(())
 }
 
+/// Converts the escape codes in ‘usage.txt’ to ANSI escape codes.
+fn convert_codes(input: &str) -> String {
+    input.replace("\\", "\x1B[")
+}
+
+/// Removes escape codes from ‘usage.txt’.
+fn strip_codes(input: &str) -> String {
+    input.replace("\\0m", "")
+         .replace("\\1m", "")
+         .replace("\\4m", "")
+         .replace("\\32m", "")
+         .replace("\\33m", "")
+         .replace("\\1;31m", "")
+         .replace("\\1;32m", "")
+         .replace("\\1;33m", "")
+         .replace("\\1;4;34", "")
+}
 
 /// Retrieve the project’s current Git hash, as a string.
 fn git_hash() -> String {
@@ -74,7 +95,6 @@ fn git_hash() -> String {
             .stdout).trim().to_string()
 }
 
-
 /// Whether we should show pre-release info in the version string.
 ///
 /// Both weekly releases and actual releases are --release releases,
@@ -83,13 +103,16 @@ fn is_development_version() -> bool {
     cargo_version().ends_with("-pre") || env::var("PROFILE").unwrap() == "debug"
 }
 
+/// Whether we are building in debug mode.
+fn is_debug_build() -> bool {
+    env::var("PROFILE").unwrap() == "debug"
+}
 
 /// Retrieves the [package] version in Cargo.toml as a string.
 fn cargo_version() -> String {
     env::var("CARGO_PKG_VERSION").unwrap()
 }
 
-
 /// Formats the current date as an ISO 8601 string.
 fn build_date() -> String {
     let now = LocalDateTime::now();

+ 1 - 1
dns-transport/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "dns-transport"
-version = "0.1.0"
+version = "0.2.0-pre"
 authors = ["Benjamin Sago <[email protected]>"]
 edition = "2018"
 

+ 1 - 24
dns-transport/src/auto.rs

@@ -6,32 +6,9 @@ use super::{Transport, Error, UdpTransport, TcpTransport};
 
 /// The **automatic transport**, which sends DNS wire data using the UDP
 /// transport, then tries using the TCP transport if the first one fails
-/// because the response wouldn't fit in a single UDP packet.
+/// because the response wouldnt fit in a single UDP packet.
 ///
 /// This is the default behaviour for many DNS clients.
-///
-/// # Examples
-///
-/// ```no_run
-/// use dns_transport::{Transport, AutoTransport};
-/// use dns::{Request, Flags, Query, Labels, QClass, qtype, record::NS};
-///
-/// let query = Query {
-///     qname: Labels::encode("dns.lookup.dog").unwrap(),
-///     qclass: QClass::IN,
-///     qtype: qtype!(NS),
-/// };
-///
-/// let request = Request {
-///     transaction_id: 0xABCD,
-///     flags: Flags::query(),
-///     query: query,
-///     additional: None,
-/// };
-///
-/// let transport = AutoTransport::new("8.8.8.8");
-/// transport.send(&request);
-/// ```
 pub struct AutoTransport {
     addr: String,
 }

+ 0 - 23
dns-transport/src/https.rs

@@ -11,29 +11,6 @@ use super::{Transport, Error};
 
 /// The **HTTPS transport**, which sends DNS wire data inside HTTP packets
 /// encrypted with TLS, using TCP.
-///
-/// # Examples
-///
-/// ```no_run
-/// use dns_transport::{Transport, HttpsTransport};
-/// use dns::{Request, Flags, Query, Labels, QClass, qtype, record::A};
-///
-/// let query = Query {
-///     qname: Labels::encode("dns.lookup.dog").unwrap(),
-///     qclass: QClass::IN,
-///     qtype: qtype!(A),
-/// };
-///
-/// let request = Request {
-///     transaction_id: 0xABCD,
-///     flags: Flags::query(),
-///     query: query,
-///     additional: None,
-/// };
-///
-/// let transport = HttpsTransport::new("https://cloudflare-dns.com/dns-query");
-/// transport.send(&request);
-/// ```
 pub struct HttpsTransport {
     url: String,
 }

+ 0 - 23
dns-transport/src/tcp.rs

@@ -10,29 +10,6 @@ use super::{Transport, Error};
 
 /// The **TCP transport**, which sends DNS wire data over a TCP stream.
 ///
-/// # Examples
-///
-/// ```no_run
-/// use dns_transport::{Transport, TcpTransport};
-/// use dns::{Request, Flags, Query, Labels, QClass, qtype, record::MX};
-///
-/// let query = Query {
-///     qname: Labels::encode("dns.lookup.dog").unwrap(),
-///     qclass: QClass::IN,
-///     qtype: qtype!(MX),
-/// };
-///
-/// let request = Request {
-///     transaction_id: 0xABCD,
-///     flags: Flags::query(),
-///     query: query,
-///     additional: None,
-/// };
-///
-/// let transport = TcpTransport::new("8.8.8.8");
-/// transport.send(&request);
-/// ```
-///
 /// # References
 ///
 /// - [RFC 1035 §4.2.2](https://tools.ietf.org/html/rfc1035) — Domain Names,

+ 0 - 23
dns-transport/src/tls.rs

@@ -11,29 +11,6 @@ use super::{Transport, Error, TcpTransport};
 
 /// The **TLS transport**, which sends DNS wire data using TCP through an
 /// encrypted TLS connection.
-///
-/// # Examples
-///
-/// ```no_run
-/// use dns_transport::{Transport, TlsTransport};
-/// use dns::{Request, Flags, Query, Labels, QClass, qtype, record::SRV};
-///
-/// let query = Query {
-///     qname: Labels::encode("dns.lookup.dog").unwrap(),
-///     qclass: QClass::IN,
-///     qtype: qtype!(SRV),
-/// };
-///
-/// let request = Request {
-///     transaction_id: 0xABCD,
-///     flags: Flags::query(),
-///     query: query,
-///     additional: None,
-/// };
-///
-/// let transport = TlsTransport::new("dns.google");
-/// transport.send(&request);
-/// ```
 pub struct TlsTransport {
     addr: String,
 }

+ 3 - 21
dns-transport/src/udp.rs

@@ -8,28 +8,10 @@ use super::{Transport, Error};
 
 /// The **UDP transport**, which sends DNS wire data inside a UDP datagram.
 ///
-/// # Examples
+/// # References
 ///
-/// ```no_run
-/// use dns_transport::{Transport, UdpTransport};
-/// use dns::{Request, Flags, Query, Labels, QClass, qtype, record::NS};
-///
-/// let query = Query {
-///     qname: Labels::encode("dns.lookup.dog").unwrap(),
-///     qclass: QClass::IN,
-///     qtype: qtype!(NS),
-/// };
-///
-/// let request = Request {
-///     transaction_id: 0xABCD,
-///     flags: Flags::query(),
-///     query: query,
-///     additional: None,
-/// };
-///
-/// let transport = UdpTransport::new("8.8.8.8");
-/// transport.send(&request);
-/// ```
+/// - [RFC 1035 §4.2.1](https://tools.ietf.org/html/rfc1035) — Domain Names,
+///   Implementation and Specification (November 1987)
 pub struct UdpTransport {
     addr: String,
 }

+ 1 - 1
dns/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "dns"
-version = "0.1.0"
+version = "0.2.0-pre"
 authors = ["Benjamin Sago <[email protected]>"]
 edition = "2018"