From f1e31b503d19e83ab9a4cbb319d3f3014111fa16 Mon Sep 17 00:00:00 2001 From: Jialun Cai Date: Fri, 30 Aug 2024 21:15:24 +0800 Subject: [PATCH] Replace justfile with xtask (#4) --- .cargo/config.toml | 3 + .github/workflows/ci.yml | 59 +++--- .github/workflows/release.yml | 9 +- Cargo.lock | 123 +++---------- Cargo.toml | 2 +- Dockerfile | 4 +- justfile | 33 ---- rustfmt.toml | 2 + src/http.rs | 8 +- src/main.rs | 26 +++ src/udp.rs | 2 +- xtask/.gitignore | 1 + xtask/Cargo.lock | 330 ++++++++++++++++++++++++++++++++++ xtask/Cargo.toml | 11 ++ xtask/src/main.rs | 123 +++++++++++++ 15 files changed, 562 insertions(+), 174 deletions(-) create mode 100644 .cargo/config.toml delete mode 100644 justfile create mode 100644 rustfmt.toml create mode 100644 xtask/.gitignore create mode 100644 xtask/Cargo.lock create mode 100644 xtask/Cargo.toml create mode 100644 xtask/src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..473d28b --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,3 @@ +[alias] +xtask = "run --manifest-path ./xtask/Cargo.toml --" +x = "run --manifest-path ./xtask/Cargo.toml --" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9596d51..f154e58 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,46 +1,51 @@ -name: "CI" +name: CI on: - workflow_dispatch: - pull_request: push: - branches: - - master + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +env: + CARGO_TERM_COLOR: always jobs: - unit-test: - name: Unit test + lint: + name: Coding style check runs-on: ubuntu-latest - timeout-minutes: 30 + timeout-minutes: 10 steps: - - name: Checkout code + - name: Checkout Code uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@master + - name: Install rust nightly toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly + components: rustfmt + - name: Install rust stable toolchain + uses: dtolnay/rust-toolchain@master with: toolchain: stable components: clippy - - uses: extractions/setup-just@v2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Install cargo-nextest - uses: taiki-e/install-action@nextest - - name: Run unit tests + - name: Run lint run: | - just unit-test + cargo x lint - lint: - name: Lint + unit-test: + name: Unit test runs-on: ubuntu-latest - timeout-minutes: 30 + timeout-minutes: 10 steps: - - name: Checkout code + - name: Checkout Code uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@master + - name: Install rust toolchain + uses: dtolnay/rust-toolchain@master with: toolchain: stable components: clippy - - uses: extractions/setup-just@v2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Run lint - run: just lint + - name: Install required tools + run: | + cargo x install-tools + - name: Run tests + run: | + cargo x test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f4791e2..ec40b43 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,9 +18,10 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - - uses: extractions/setup-just@v2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Install rust stable toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable - name: Log in to the Container registry uses: docker/login-action@v3 with: @@ -31,7 +32,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Build Image run: | - just image ${{ env.IMAGE_TAG }} + cargo x build-docker-image --tag ${{ env.IMAGE_TAG }} - name: Publish image run: | export GHCR_IMAGE=ghcr.io/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} diff --git a/Cargo.lock b/Cargo.lock index 8d78c04..d31d7e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,7 +52,7 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" dependencies = [ - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -62,7 +62,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" dependencies = [ "anstyle", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -297,12 +297,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" -version = "0.2.6" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "http" @@ -441,13 +438,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.11" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ + "hermit-abi", "libc", "wasi", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -460,16 +458,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "num_cpus" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "object" version = "0.32.2" @@ -649,7 +637,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -692,27 +680,26 @@ dependencies = [ [[package]] name = "tokio" -version = "1.37.0" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] name = "tokio-macros" -version = "2.2.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", @@ -869,37 +856,13 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.4", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] @@ -908,93 +871,51 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.4" diff --git a/Cargo.toml b/Cargo.toml index cbb35f2..f5a0549 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,5 +16,5 @@ anyhow = "1.0.82" tracing = "0.1.40" tracing-subscriber = { version = "0.3.18" } tower-http = { version = "0.5.2", features = ["add-extension", "trace", "cors", "timeout"] } -tokio = { version = "1.37.0", features = ["rt-multi-thread", "signal", "macros", "net", "io-util"] } +tokio = { version = "1.40.0", features = ["rt-multi-thread", "signal", "macros", "net", "io-util"] } axum = { version = "0.7.5" } diff --git a/Dockerfile b/Dockerfile index 930ac18..3f6befd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ -FROM rust:1.77-buster AS builder +FROM rust:1.80-bookworm AS builder WORKDIR /workspace COPY . . RUN cargo build --release -FROM debian:buster-slim +FROM debian:bookworm-slim COPY --from=builder /workspace/target/release/echoserver /usr/local/bin/echoserver diff --git a/justfile b/justfile deleted file mode 100644 index 38a734f..0000000 --- a/justfile +++ /dev/null @@ -1,33 +0,0 @@ -default: - just --list - -# Build the project -build: - cargo build - -# Format code with rust -fmt: - cargo fmt - -# Run unit tests against the current platform -unit-test: - cargo nextest run - -# Lint code with clippy -lint: - cargo fmt --all -- --check - cargo clippy --all-targets --all-features - -# Clean workspace -clean: - cargo clean - -image_repo := "ghcr.io/zarvd/echoserver" -# Build docker image -image tag: clean - docker buildx build ./ \ - --output=type=docker \ - --no-cache \ - --force-rm \ - --tag {{ image_repo }}:{{ tag }} \ - --file Dockerfile diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..64d94de --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,2 @@ +group_imports = "StdExternalCrate" +imports_granularity = "Module" diff --git a/src/http.rs b/src/http.rs index 1cebb52..f2bd4a3 100644 --- a/src/http.rs +++ b/src/http.rs @@ -3,11 +3,9 @@ use std::time::Duration; use anyhow::Result; use axum::extract::Request; -use axum::{ - response::{IntoResponse, Response}, - routing::{get, post}, - Router, -}; +use axum::response::{IntoResponse, Response}; +use axum::routing::{get, post}; +use axum::Router; use tokio::net::TcpListener; use tower_http::cors::CorsLayer; use tower_http::timeout::TimeoutLayer; diff --git a/src/main.rs b/src/main.rs index 73f44d4..2b3b8f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,29 @@ +#![deny( + warnings, + rust_2018_idioms, + clippy::branches_sharing_code, + clippy::clear_with_drain, + clippy::clone_on_ref_ptr, + clippy::cognitive_complexity, + clippy::collection_is_never_read, + clippy::dbg_macro, + clippy::debug_assert_with_mut_call, + clippy::enum_glob_use, + clippy::equatable_if_let, + clippy::get_unwrap, + clippy::inefficient_to_string, + clippy::macro_use_imports, + clippy::map_clone, + clippy::map_unwrap_or, + clippy::needless_collect, + clippy::option_if_let_else, + clippy::or_fun_call, + clippy::str_to_string, + clippy::too_many_lines, + clippy::uninlined_format_args, + clippy::wildcard_imports +)] + mod http; mod signal; mod tcp; diff --git a/src/udp.rs b/src/udp.rs index 35fe623..6ea1ee2 100644 --- a/src/udp.rs +++ b/src/udp.rs @@ -28,7 +28,7 @@ pub async fn serve(addr: SocketAddr) -> Result<()> { let mut buf = [0; 2048]; match socket.recv_from(&mut buf).await { Ok((n, remote_addr)) => { - handle(socket.clone(), remote_addr, &buf[0..n]) + handle(Arc::clone(&socket), remote_addr, &buf[0..n]) .await .unwrap_or_else(|e| panic!("failed to echo data from UDP server {addr}: {e}")); } diff --git a/xtask/.gitignore b/xtask/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/xtask/.gitignore @@ -0,0 +1 @@ +/target diff --git a/xtask/Cargo.lock b/xtask/Cargo.lock new file mode 100644 index 0000000..4a3cf1a --- /dev/null +++ b/xtask/Cargo.lock @@ -0,0 +1,330 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "anyhow" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" + +[[package]] +name = "clap" +version = "4.5.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + +[[package]] +name = "console" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "unicode-width", + "windows-sys 0.52.0", +] + +[[package]] +name = "duct" +version = "0.13.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4ab5718d1224b63252cd0c6f74f6480f9ffeb117438a2e0f5cf6d9a4798929c" +dependencies = [ + "libc", + "once_cell", + "os_pipe", + "shared_child", +] + +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "os_pipe" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ffd2b0a5634335b135d5728d84c5e0fd726954b87111f7506a61c502280d982" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "shared_child" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09fa9338aed9a1df411814a5b2252f7cd206c55ae9bf2fa763f8de84603aa60c" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-width" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "xtask" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "console", + "duct", +] diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml new file mode 100644 index 0000000..3a38a98 --- /dev/null +++ b/xtask/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "xtask" +version = "0.1.0" +authors = ["zarvd "] +edition = "2021" + +[dependencies] +anyhow = "1" +console = "0.15" +clap = { version = "4", features = ["derive"] } +duct = "0.13" diff --git a/xtask/src/main.rs b/xtask/src/main.rs new file mode 100644 index 0000000..d3ce3d6 --- /dev/null +++ b/xtask/src/main.rs @@ -0,0 +1,123 @@ +use std::fmt::Debug; + +use anyhow::Result; +use clap::{Parser, Subcommand}; +use console::style; +use duct::cmd; + +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +struct Args { + #[command(subcommand)] + action: Action, +} + +#[derive(Debug, Subcommand)] +enum Action { + /// Run linting tools on the codebase + Lint, + /// Install required development tools + InstallTools, + /// Run benchmarks + Bench, + /// Run tests + Test, + /// Generate documentation + Doc, + /// Format the code + Fmt, + /// Build docker image + BuildDockerImage { + #[arg(long, default_value = "ghcr.io/zarvd/echoserver")] + image: String, + #[arg(long, default_value = "latest")] + tag: String, + }, +} + +fn fmt() -> Result<()> { + println!("{}", style("cargo +nightly fmt").bold()); + cmd!("cargo", "+nightly", "fmt").run()?; + Ok(()) +} + +fn check_fmt() -> Result<()> { + println!("{}", style("cargo +nightly fmt --check").bold()); + cmd!("cargo", "+nightly", "fmt", "--check").run()?; + Ok(()) +} + +fn clippy() -> Result<()> { + println!( + "{}", + style("cargo clippy --all-targets --all-features").bold() + ); + cmd!("cargo", "clippy", "--all-targets", "--all-features").run()?; + Ok(()) +} + +fn unit_test() -> Result<()> { + println!("{}", style("cargo nextest run --all-features").bold()); + cmd!("cargo", "nextest", "run", "--all-features").run()?; + Ok(()) +} + +fn bench() -> Result<()> { + println!("{}", style("cargo bench --all-features").bold()); + cmd!("cargo", "bench", "--all-features").run()?; + Ok(()) +} + +fn doc() -> Result<()> { + println!("{}", style("cargo doc --no-deps --all-features").bold()); + cmd!("cargo", "doc", "--no-deps", "--all-features").run()?; + Ok(()) +} + +fn build_docker_image(image: String, tag: String) -> Result<()> { + cmd!( + "docker", + "buildx", + "build", + "--output=type=docker", + "--no-cache", + "--force-rm", + "--file=Dockerfile", + format!("--tag={image}:{tag}"), + "." + ) + .run()?; + Ok(()) +} + +fn main() -> Result<()> { + let args = Args::parse(); + + match args.action { + Action::InstallTools => { + println!("{}", style("cargo install cargo-nextest").bold()); + cmd!("cargo", "install", "cargo-nextest", "--locked").run()?; + } + Action::Lint => { + check_fmt()?; + clippy()?; + } + Action::Test => { + unit_test()?; + } + Action::Bench => { + bench()?; + } + Action::Doc => { + doc()?; + } + Action::Fmt => { + fmt()?; + } + Action::BuildDockerImage { image, tag } => { + build_docker_image(image, tag)?; + } + } + + Ok(()) +}