From 5e28d5370c6257866c111d9cb2fe8a849e046274 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Tue, 17 Oct 2023 22:41:34 +0700 Subject: [PATCH 01/21] feat: initial rust earthly builders commit --- earthly/rust/Earthfile | 73 ++++++++++++++++++++++++ earthly/rust/Readme.md | 25 ++++++++ earthly/rust/example/rust-toolchain.toml | 4 ++ 3 files changed, 102 insertions(+) create mode 100644 earthly/rust/Earthfile create mode 100644 earthly/rust/Readme.md create mode 100644 earthly/rust/example/rust-toolchain.toml diff --git a/earthly/rust/Earthfile b/earthly/rust/Earthfile new file mode 100644 index 000000000..4b1d34ea2 --- /dev/null +++ b/earthly/rust/Earthfile @@ -0,0 +1,73 @@ +# Common Rust UDCs and Builders. +VERSION 0.7 + +# Base Rustup build container. +rustup: + # Base it on Debian bookworm-slim + FROM debian:bookworm-slim + + WORKDIR /root + + # Install necessary packages + # Expand this list as needed, rather than adding more tools in later containers. + RUN apt-get update && \ + apt-get install --no-install-recommends -y \ + ca-certificates \ + curl \ + file \ + build-essential \ + autoconf \ + automake \ + autotools-dev \ + libtool \ + xutils-dev \ + mold \ + python3 \ + python3-pip \ + musl-tools && \ + rm -rf /var/lib/apt/lists/* + + # Install OpenSSL here but ONLY if we can't avoid using it. + + # Install rustup. + RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain none -y -v + + # Set necessary env vars from this setup. + ENV PATH=/root/.cargo/bin:$PATH + +# Common Rust setup +# Parameters: +# * toolchain : The `rust-toolchain` toml file. +RUST_SETUP: + COMMAND + ARG toolchain + + # Poetry Installation directory. + # Gives poetry and our poetry project a reliable location. + WORKDIR /build + + # Copy our toolchain dependency. + COPY $toolchain ./rust-toolchain.toml + ENV default_rust_channel=$(grep -oP 'channel\s*=\s*"\K[^"]+' rust-toolchain.toml) + + # Install pinned Rustup from `rust-toolchain.toml` + # Plus nightly latest so we can use it for docs, lints, etc. + RUN rustup show && \ + rustup default $default_rust_channel && \ + rustup toolchain install nightly --component miri --component rust-src && \ + cargo --version && \ + cargo +nightly --version + + # Install tools we use commonly with `cargo`. + RUN cargo install cargo-nextest --locked && \ + cargo install cargo-chef --locked && \ + cargo install kani-verifier --locked && \ + cargo kani setup && \ + cargo install refinery_cli --locked + + +# Test rust build container +rust-builder: + FROM +rustup + + DO +RUST_SETUP --toolchain=example/rust-toolchain.toml diff --git a/earthly/rust/Readme.md b/earthly/rust/Readme.md new file mode 100644 index 000000000..c5b2585e0 --- /dev/null +++ b/earthly/rust/Readme.md @@ -0,0 +1,25 @@ +# Rust Earthly Build Containers and UDCs + +This repo defines common rust targets and UDCs for use with rust. + +## User Defined Commands + +### RUST_SETUP + +This UDC sets up a rust build environment. + +Rust build environments are locked to the `rust-toolchain.toml` file in the repo. +This ensures that the version of the toolchain used is locked with the dependencies. + +#### Invocation + +In an `Earthfile` in your source repository add: + +```Earthfile +example_rust_builder: + FROM +rustup + + DO +RUST_SETUP --toolchain=./rust-toolchain.toml +``` + +This builder can then be used to build the projects source. diff --git a/earthly/rust/example/rust-toolchain.toml b/earthly/rust/example/rust-toolchain.toml new file mode 100644 index 000000000..f166657fd --- /dev/null +++ b/earthly/rust/example/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "1.71.0" +profile = "default" +components = [ ] From 4fb44aeb70fc5a8f5ca74afcbdc040205b9334e5 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Tue, 17 Oct 2023 22:52:36 +0700 Subject: [PATCH 02/21] docs(rust): fix spelling issues --- earthly/rust/Earthfile | 2 ++ earthly/rust/Readme.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/earthly/rust/Earthfile b/earthly/rust/Earthfile index 4b1d34ea2..4afcbd062 100644 --- a/earthly/rust/Earthfile +++ b/earthly/rust/Earthfile @@ -1,6 +1,8 @@ # Common Rust UDCs and Builders. VERSION 0.7 +# cspell: words rustup automake autotools xutils miri nextest kani + # Base Rustup build container. rustup: # Base it on Debian bookworm-slim diff --git a/earthly/rust/Readme.md b/earthly/rust/Readme.md index c5b2585e0..61c1a3e0b 100644 --- a/earthly/rust/Readme.md +++ b/earthly/rust/Readme.md @@ -1,5 +1,7 @@ # Rust Earthly Build Containers and UDCs + + This repo defines common rust targets and UDCs for use with rust. ## User Defined Commands From 714b8122d9c7e784a48e99903690b82c94fc4216 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Wed, 18 Oct 2023 14:20:04 +0700 Subject: [PATCH 03/21] ci(rust): Enhance rust container build self check and default to mold for linking. --- earthly/rust/Earthfile | 36 ++++++++++++++++++++++++++++++++---- earthly/rust/config.toml | 28 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 earthly/rust/config.toml diff --git a/earthly/rust/Earthfile b/earthly/rust/Earthfile index 4afcbd062..0a561115f 100644 --- a/earthly/rust/Earthfile +++ b/earthly/rust/Earthfile @@ -10,6 +10,17 @@ rustup: WORKDIR /root + # Set necessary env vars from this setup. + ENV RUSTUP_HOME=/usr/local/rustup + ENV CARGO_HOME=/usr/local/cargo + ENV CARGO_HOME_BIN=$CARGO_HOME/bin + ENV PATH=$CARGO_HOME_BIN:$PATH + + # Ensure correct directory permissions on the install locations. + RUN mkdir -p $RUSTUP_HOME && \ + mkdir -p $CARGO_HOME_BIN && \ + chmod -R a+w $RUSTUP_HOME $CARGO_HOME + # Install necessary packages # Expand this list as needed, rather than adding more tools in later containers. RUN apt-get update && \ @@ -26,7 +37,8 @@ rustup: mold \ python3 \ python3-pip \ - musl-tools && \ + musl-tools \ + clang && \ rm -rf /var/lib/apt/lists/* # Install OpenSSL here but ONLY if we can't avoid using it. @@ -34,8 +46,8 @@ rustup: # Install rustup. RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain none -y -v - # Set necessary env vars from this setup. - ENV PATH=/root/.cargo/bin:$PATH + # Install the default cargo config. + COPY config.toml $CARGO_HOME/config.toml # Common Rust setup # Parameters: @@ -69,7 +81,23 @@ RUST_SETUP: # Test rust build container -rust-builder: +check: FROM +rustup DO +RUST_SETUP --toolchain=example/rust-toolchain.toml + + # Check all the expected tooling is isntalled and works for both the stable and nighlty versions. + RUN rustc --version && \ + rustc +nightly --version && \ + cargo --version && \ + cargo +nightly --version && \ + cargo clippy --version && \ + cargo +nightly clippy --version && \ + cargo nextest --version && \ + cargo chef --version && \ + cargo kani --version && \ + refinery --version && \ + mold --version + + + diff --git a/earthly/rust/config.toml b/earthly/rust/config.toml new file mode 100644 index 000000000..92e97f513 --- /dev/null +++ b/earthly/rust/config.toml @@ -0,0 +1,28 @@ +# Use MOLD linker where possible. +[target.x86_64-unknown-linux-gnu] +linker = "clang" +rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] + +[target.x86_64-unknown-linux-musl] +linker = "clang" +rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] + +[target.aarch64-unknown-linux-gnu] +linker = "clang" +rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] + +[target.aarch64-unknown-linux-musl] +linker = "clang" +rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] + +[target.armv7-unknown-linux-gnueabihf] +linker = "clang" +rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] + +[target.x86_64-pc-windows-gnu] +linker = "clang" +rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] + +[target.x86_64-pc-windows-msvc] +linker = "clang" +rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] From 9a1f2071fa87bfe6a4bd57f4a5a3194bcd0950eb Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Wed, 18 Oct 2023 15:44:24 +0700 Subject: [PATCH 04/21] ci(rust): Default the toolchain option in the RUST_SETUP UDC --- earthly/rust/Earthfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/earthly/rust/Earthfile b/earthly/rust/Earthfile index 0a561115f..be37248fe 100644 --- a/earthly/rust/Earthfile +++ b/earthly/rust/Earthfile @@ -54,7 +54,7 @@ rustup: # * toolchain : The `rust-toolchain` toml file. RUST_SETUP: COMMAND - ARG toolchain + ARG toolchain=./rust-toolchain.toml # Poetry Installation directory. # Gives poetry and our poetry project a reliable location. From 7f812b6137bdfd85bd4c19439bce3e9846349ff8 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Wed, 18 Oct 2023 15:48:24 +0700 Subject: [PATCH 05/21] docs(rust): fix spelling --- earthly/rust/Earthfile | 4 ++-- earthly/rust/config.toml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/earthly/rust/Earthfile b/earthly/rust/Earthfile index be37248fe..90de95e38 100644 --- a/earthly/rust/Earthfile +++ b/earthly/rust/Earthfile @@ -1,7 +1,7 @@ # Common Rust UDCs and Builders. VERSION 0.7 -# cspell: words rustup automake autotools xutils miri nextest kani +# cspell: words rustup rustc automake autotools xutils miri nextest kani # Base Rustup build container. rustup: @@ -86,7 +86,7 @@ check: DO +RUST_SETUP --toolchain=example/rust-toolchain.toml - # Check all the expected tooling is isntalled and works for both the stable and nighlty versions. + # Check all the expected tooling is installed and works for both the stable and nightly versions. RUN rustc --version && \ rustc +nightly --version && \ cargo --version && \ diff --git a/earthly/rust/config.toml b/earthly/rust/config.toml index 92e97f513..c703c21f5 100644 --- a/earthly/rust/config.toml +++ b/earthly/rust/config.toml @@ -1,4 +1,6 @@ # Use MOLD linker where possible. +# cspell: words rustflags armv gnueabihf msvc + [target.x86_64-unknown-linux-gnu] linker = "clang" rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] From c3dfe8d8877765e24fe43af938c8bbf0aa651562 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Thu, 19 Oct 2023 12:45:19 +0700 Subject: [PATCH 06/21] feat(rust): Default to musl on linux for fully static builds --- earthly/rust/Earthfile | 2 ++ earthly/rust/config.toml | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/earthly/rust/Earthfile b/earthly/rust/Earthfile index 90de95e38..e4d5d1eb1 100644 --- a/earthly/rust/Earthfile +++ b/earthly/rust/Earthfile @@ -55,6 +55,7 @@ rustup: RUST_SETUP: COMMAND ARG toolchain=./rust-toolchain.toml + ARG host=x86_64-unknown-linux-musl # Poetry Installation directory. # Gives poetry and our poetry project a reliable location. @@ -67,6 +68,7 @@ RUST_SETUP: # Install pinned Rustup from `rust-toolchain.toml` # Plus nightly latest so we can use it for docs, lints, etc. RUN rustup show && \ + rustup set default-host $host && \ rustup default $default_rust_channel && \ rustup toolchain install nightly --component miri --component rust-src && \ cargo --version && \ diff --git a/earthly/rust/config.toml b/earthly/rust/config.toml index c703c21f5..8f536a3c3 100644 --- a/earthly/rust/config.toml +++ b/earthly/rust/config.toml @@ -1,11 +1,15 @@ # Use MOLD linker where possible. # cspell: words rustflags armv gnueabihf msvc -[target.x86_64-unknown-linux-gnu] +# Should be the default to have fully static rust programs. +[target.x86_64-unknown-linux-musl] linker = "clang" -rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] +rustflags = [ + "-C", "link-arg=-fuse-ld=/usr/bin/mold", + "-C", "target-feature=+crt-static" +] -[target.x86_64-unknown-linux-musl] +[target.x86_64-unknown-linux-gnu] linker = "clang" rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] From 3b09401008aeb72d9026ceb8be51bef4a2f26185 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Thu, 19 Oct 2023 12:57:34 +0700 Subject: [PATCH 07/21] fix(rust): revert should not install a non native host. rust can x-compile. --- earthly/rust/Earthfile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/earthly/rust/Earthfile b/earthly/rust/Earthfile index e4d5d1eb1..354b18f43 100644 --- a/earthly/rust/Earthfile +++ b/earthly/rust/Earthfile @@ -55,7 +55,6 @@ rustup: RUST_SETUP: COMMAND ARG toolchain=./rust-toolchain.toml - ARG host=x86_64-unknown-linux-musl # Poetry Installation directory. # Gives poetry and our poetry project a reliable location. @@ -67,9 +66,8 @@ RUST_SETUP: # Install pinned Rustup from `rust-toolchain.toml` # Plus nightly latest so we can use it for docs, lints, etc. - RUN rustup show && \ - rustup set default-host $host && \ - rustup default $default_rust_channel && \ + RUN rustup default $default_rust_channel && \ + rustup show && \ rustup toolchain install nightly --component miri --component rust-src && \ cargo --version && \ cargo +nightly --version From 150cbb00f8b26322a957a4a12d0ea0e177c974bc Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Thu, 19 Oct 2023 15:28:47 +0700 Subject: [PATCH 08/21] fix(rust): make sure all targets try to build static --- earthly/rust/config.toml | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/earthly/rust/config.toml b/earthly/rust/config.toml index 8f536a3c3..c90336324 100644 --- a/earthly/rust/config.toml +++ b/earthly/rust/config.toml @@ -11,24 +11,42 @@ rustflags = [ [target.x86_64-unknown-linux-gnu] linker = "clang" -rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] +rustflags = [ + "-C", "link-arg=-fuse-ld=/usr/bin/mold", + "-C", "target-feature=+crt-static" +] [target.aarch64-unknown-linux-gnu] linker = "clang" -rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] +rustflags = [ + "-C", "link-arg=-fuse-ld=/usr/bin/mold", + "-C", "target-feature=+crt-static" +] [target.aarch64-unknown-linux-musl] linker = "clang" -rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] +rustflags = [ + "-C", "link-arg=-fuse-ld=/usr/bin/mold", + "-C", "target-feature=+crt-static" +] [target.armv7-unknown-linux-gnueabihf] linker = "clang" -rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] +rustflags = [ + "-C", "link-arg=-fuse-ld=/usr/bin/mold", + "-C", "target-feature=+crt-static" +] [target.x86_64-pc-windows-gnu] linker = "clang" -rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] +rustflags = [ + "-C", "link-arg=-fuse-ld=/usr/bin/mold", + "-C", "target-feature=+crt-static" +] [target.x86_64-pc-windows-msvc] linker = "clang" -rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] +rustflags = [ + "-C", "link-arg=-fuse-ld=/usr/bin/mold", + "-C", "target-feature=+crt-static" +] From a96a0b7809a5a7a6b185d0370c6c05fa6ad27847 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 20 Oct 2023 18:34:30 +0700 Subject: [PATCH 09/21] ci(rust): add cargo-machete for use in CI checks. --- earthly/rust/Earthfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/earthly/rust/Earthfile b/earthly/rust/Earthfile index 354b18f43..ed1f0af7f 100644 --- a/earthly/rust/Earthfile +++ b/earthly/rust/Earthfile @@ -77,8 +77,8 @@ RUST_SETUP: cargo install cargo-chef --locked && \ cargo install kani-verifier --locked && \ cargo kani setup && \ - cargo install refinery_cli --locked - + cargo install refinery_cli --locked && \ + cargo install cargo-machete --locked # Test rust build container check: From 0a759ce517c2af511d73233858b22a9cb01df5a9 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 20 Oct 2023 18:37:40 +0700 Subject: [PATCH 10/21] feat(rust): Update test toolchain to latest rust stable version --- earthly/rust/example/rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/earthly/rust/example/rust-toolchain.toml b/earthly/rust/example/rust-toolchain.toml index f166657fd..c17e06b4c 100644 --- a/earthly/rust/example/rust-toolchain.toml +++ b/earthly/rust/example/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.71.0" +channel = "1.73.0" profile = "default" components = [ ] From 7a27ffe501f9b72e147aab5465abd8083e1bd6bd Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 20 Oct 2023 18:46:28 +0700 Subject: [PATCH 11/21] fix(rust): Disable static builds for `linux-gnu` as it breaks `nextest` --- earthly/rust/config.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/earthly/rust/config.toml b/earthly/rust/config.toml index c90336324..74ba04a18 100644 --- a/earthly/rust/config.toml +++ b/earthly/rust/config.toml @@ -13,7 +13,7 @@ rustflags = [ linker = "clang" rustflags = [ "-C", "link-arg=-fuse-ld=/usr/bin/mold", - "-C", "target-feature=+crt-static" + # "-C", "target-feature=+crt-static" - Doesn't work for nextest. ] [target.aarch64-unknown-linux-gnu] From 17f9a4191981a8cd5d930356045532f5cbd18831 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 20 Oct 2023 18:54:04 +0700 Subject: [PATCH 12/21] docs(rust): fix spelling lint error --- earthly/rust/config.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/earthly/rust/config.toml b/earthly/rust/config.toml index 74ba04a18..bc0cacbd0 100644 --- a/earthly/rust/config.toml +++ b/earthly/rust/config.toml @@ -1,5 +1,5 @@ # Use MOLD linker where possible. -# cspell: words rustflags armv gnueabihf msvc +# cspell: words rustflags armv gnueabihf msvc nextest # Should be the default to have fully static rust programs. [target.x86_64-unknown-linux-musl] From 539c77a600030a43048035c619977dccd5d84419 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Wed, 25 Oct 2023 20:18:43 +0700 Subject: [PATCH 13/21] feat(rust): add standard targets --- earthly/rust/example/rust-toolchain.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/earthly/rust/example/rust-toolchain.toml b/earthly/rust/example/rust-toolchain.toml index c17e06b4c..dca770e1b 100644 --- a/earthly/rust/example/rust-toolchain.toml +++ b/earthly/rust/example/rust-toolchain.toml @@ -2,3 +2,4 @@ channel = "1.73.0" profile = "default" components = [ ] +targets = ["x86_64-unknown-linux-musl", "aarch64-unknown-linux-musl", "aarch64-apple-darwin"] \ No newline at end of file From 0eb3ab0142dfa6aa9dc65755b636c2673bc38c57 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 27 Oct 2023 16:08:29 +0700 Subject: [PATCH 14/21] feat(rust): Rework rust builders to handle hosts with differeing cpu architectures. --- .gitignore | 3 + earthly/rust/.cargo/README.md | 20 + earthly/rust/.cargo/config.toml | 109 ++ earthly/rust/Earthfile | 242 ++- earthly/rust/config.toml | 52 - earthly/rust/example/Cargo.lock | 1534 +++++++++++++++++ earthly/rust/example/Cargo.toml | 69 + earthly/rust/example/LICENSE | 21 + earthly/rust/example/README.md | 7 + earthly/rust/example/cli/Cargo.toml | 19 + earthly/rust/example/cli/src/lib.rs | 118 ++ earthly/rust/example/core/Cargo.toml | 12 + .../rust/example/core/benches/01_default.rs | 15 + earthly/rust/example/core/src/commands.rs | 37 + earthly/rust/example/core/src/error.rs | 12 + earthly/rust/example/core/src/hazard.rs | 6 + earthly/rust/example/core/src/lib.rs | 14 + earthly/rust/example/rustfmt.toml | 68 + earthly/rust/example/src/main.rs | 37 + .../example/src/resources/default_config.toml | 5 + earthly/rust/example/tests/test_cli.rs | 35 + earthly/rust/example/utils/Cargo.toml | 29 + earthly/rust/example/utils/src/app_config.rs | 111 ++ earthly/rust/example/utils/src/error.rs | 111 ++ earthly/rust/example/utils/src/lib.rs | 6 + earthly/rust/example/utils/src/logger.rs | 68 + earthly/rust/example/utils/src/types.rs | 31 + .../utils/tests/resources/test_config.toml | 4 + .../rust/example/utils/tests/test_config.rs | 45 + earthly/rust/rustfmt.toml | 68 + earthly/rust/scripts/README.md | 6 + earthly/rust/scripts/colors.sh | 11 + earthly/rust/scripts/std_checks.sh | 63 + earthly/rust/scripts/verify_toolchain.sh | 13 + 34 files changed, 2892 insertions(+), 109 deletions(-) create mode 100644 earthly/rust/.cargo/README.md create mode 100644 earthly/rust/.cargo/config.toml delete mode 100644 earthly/rust/config.toml create mode 100644 earthly/rust/example/Cargo.lock create mode 100644 earthly/rust/example/Cargo.toml create mode 100644 earthly/rust/example/LICENSE create mode 100644 earthly/rust/example/README.md create mode 100644 earthly/rust/example/cli/Cargo.toml create mode 100644 earthly/rust/example/cli/src/lib.rs create mode 100644 earthly/rust/example/core/Cargo.toml create mode 100644 earthly/rust/example/core/benches/01_default.rs create mode 100644 earthly/rust/example/core/src/commands.rs create mode 100644 earthly/rust/example/core/src/error.rs create mode 100644 earthly/rust/example/core/src/hazard.rs create mode 100644 earthly/rust/example/core/src/lib.rs create mode 100644 earthly/rust/example/rustfmt.toml create mode 100644 earthly/rust/example/src/main.rs create mode 100644 earthly/rust/example/src/resources/default_config.toml create mode 100644 earthly/rust/example/tests/test_cli.rs create mode 100644 earthly/rust/example/utils/Cargo.toml create mode 100644 earthly/rust/example/utils/src/app_config.rs create mode 100644 earthly/rust/example/utils/src/error.rs create mode 100644 earthly/rust/example/utils/src/lib.rs create mode 100644 earthly/rust/example/utils/src/logger.rs create mode 100644 earthly/rust/example/utils/src/types.rs create mode 100644 earthly/rust/example/utils/tests/resources/test_config.toml create mode 100644 earthly/rust/example/utils/tests/test_config.rs create mode 100644 earthly/rust/rustfmt.toml create mode 100644 earthly/rust/scripts/README.md create mode 100644 earthly/rust/scripts/colors.sh create mode 100755 earthly/rust/scripts/std_checks.sh create mode 100755 earthly/rust/scripts/verify_toolchain.sh diff --git a/.gitignore b/.gitignore index c9613dfcc..66f8abf70 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ node_modules # Built docs /earthly/docs/site /earthly/docs/local + +# Local Build Artefacts +target/ \ No newline at end of file diff --git a/earthly/rust/.cargo/README.md b/earthly/rust/.cargo/README.md new file mode 100644 index 000000000..faae38060 --- /dev/null +++ b/earthly/rust/.cargo/README.md @@ -0,0 +1,20 @@ +# Rust Cargo Configuration + +We define RUST Global Cargo Configurations here. +It is applied globaly to all Rust Code built by Project Catalyst. + +Each Project Catalyst Repo that has Rust code must include this file in: + +```path +/.cargo/config.toml +``` + +This config exists here so that it can be used locally during development, as well as during CI builds. + +It will be checked during CI that it has not been altered from the enforced standard. +The enforced standard can be referenced here: [Catalyst-CI Global Cargo Config](todo) + +If this file needs to be updated, please update it in the standard location first, have the PR +approved, and then update this file to match. + +Differences between these files and the enforced standards will prevent CI from accepting your PR. diff --git a/earthly/rust/.cargo/config.toml b/earthly/rust/.cargo/config.toml new file mode 100644 index 000000000..003b6526b --- /dev/null +++ b/earthly/rust/.cargo/config.toml @@ -0,0 +1,109 @@ +# Use MOLD linker where possible, but ONLY in CI applicable targets. +# cspell: words rustflags armv gnueabihf msvc nextest idents rustdocflags rustdoc lintfix lintrestrict testfast testdocs + +# Configure how Docker container targets build. + +# If you want to customize these targets for a local build, then customize them in you: +# $CARGO_HOME/config.toml +# NOT in the project itself. +# These targets are ONLY the targets used by CI and inside docker builds. + +# DO NOT remove `"-C", "target-feature=+crt-static"` from the rustflags for these targets. + +# Should be the default to have fully static rust programs in CI +[target.x86_64-unknown-linux-musl] +linker = "clang" +rustflags = [ + "-C", "link-arg=-fuse-ld=/usr/bin/mold", + "-C", "target-feature=+crt-static" +] + +# Should be the default to have fully static rust programs in CI +[target.aarch64-unknown-linux-musl] +linker = "clang" +rustflags = [ + "-C", "link-arg=-fuse-ld=/usr/bin/mold", + "-C", "target-feature=+crt-static" +] + + +[build] + +rustflags = [ + "-D", + "warnings", + "-D", + "missing_docs", + "-D", + "let_underscore_drop", + "-D", + "non_ascii_idents", + "-D", + "single_use_lifetimes", + "-D", + "trivial_casts", + "-D", + "trivial_numeric_casts", +] + +rustdocflags = [ + "-D", + "warnings", + "-D", + "missing_docs", + "-D", + "rustdoc::broken_intra_doc_links", + "-D", + "rustdoc::invalid_codeblock_attributes", + "-D", + "rustdoc::invalid_html_tags", + "-D", + "rustdoc::invalid_rust_codeblocks", + "-D", + "rustdoc::bare_urls", + "-D", + "rustdoc::unescaped_backticks", +] + +[profile.dev] +opt-level = 1 +debug = true +debug-assertions = true +overflow-checks = true +lto = false +panic = 'unwind' +incremental = true +codegen-units = 256 + +[profile.release] +opt-level = 3 +debug = false +debug-assertions = false +overflow-checks = false +lto = true +panic = 'unwind' +incremental = false +codegen-units = 16 + +[alias] +lint = "clippy -- -D warnings -D clippy::pedantic -D clippy::unwrap_used -D clippy::expect_used -D clippy::exit -D clippy::get_unwrap -D clippy::index_refutable_slice -D clippy::indexing_slicing -D clippy::match_on_vec_items -D clippy::match_wild_err_arm -D clippy::missing_panics_doc -D clippy::panic -D clippy::string_slice -D clippy::unchecked_duration_subtraction -D clippy::unreachable -D clippy::missing_docs_in_private_items" +lintfix = "clippy -- -D warnings -D clippy::pedantic -D clippy::unwrap_used -D clippy::expect_used -D clippy::exit -D clippy::get_unwrap -D clippy::index_refutable_slice -D clippy::indexing_slicing -D clippy::match_on_vec_items -D clippy::match_wild_err_arm -D clippy::missing_panics_doc -D clippy::panic -D clippy::string_slice -D clippy::unchecked_duration_subtraction -D clippy::unreachable" +lintrestrict = "clippy -- -D warnings -D clippy::pedantic -D clippy::restriction -D clippy::missing_docs_in_private_items" +lint-vscode = "clippy --workspace --message-format=json-diagnostic-rendered-ansi --all-targets -- -D warnings -D clippy::pedantic -D clippy::unwrap_used -D clippy::expect_used -D clippy::exit -D clippy::get_unwrap -D clippy::index_refutable_slice -D clippy::indexing_slicing -D clippy::match_on_vec_items -D clippy::match_wild_err_arm -D clippy::missing_panics_doc -D clippy::panic -D clippy::string_slice -D clippy::unchecked_duration_subtraction -D clippy::unreachable -D clippy::missing_docs_in_private_items" + +docs = "doc --workspace -r --all-features --no-deps --bins --document-private-items --examples --locked" +# nightly docs build broken... when they are'nt we can enable these docs... --unit-graph --timings=html,json -Z unstable-options" +testfast = "nextest run --release --workspace --locked" +testci = "nextest run --release --workspace --locked -P ci" +testdocs = "test --doc --release --workspace --locked --doc" + +# Rust formatting, MUST be run with +nightly +fmtchk = "fmt -- --check -v --color=always" +fmtfix = "fmt -- -v" + +[term] +quiet = false # whether cargo output is quiet +verbose = true # whether cargo provides verbose output +color = 'always' # whether cargo colorizes output use `CARGO_TERM_COLOR="off"` to disable. +progress.when = 'auto' # whether cargo shows progress bar +progress.width = 80 # width of progress bar diff --git a/earthly/rust/Earthfile b/earthly/rust/Earthfile index 41ed39390..2adaec2f8 100644 --- a/earthly/rust/Earthfile +++ b/earthly/rust/Earthfile @@ -4,55 +4,83 @@ VERSION 0.7 # cspell: words rustup rustc automake autotools xutils miri nextest kani # Base Rustup build container. -rustup: - # Base it on Debian bookworm-slim - FROM debian:bookworm-slim +rust-base: + ARG TARGETPLATFORM + ARG TARGETOS + ARG TARGETARCH + ARG TARGETVARIANT + ARG USERPLATFORM + ARG USEROS + ARG USERARCH + ARG USERVARIANT + + + # This is our base Host toolset, and rustup. + # The ACTUAL version of rust that will be used, and available targets + # is controlled by a `rust-toolchain.toml` file when the RUST_SETUP UDC is run. + # HOWEVER, It is enforced that the rust version in `rust-toolchain.toml` MUST match this version. + FROM rust:1.73-alpine3.18 + + RUN echo "TARGETPLATFORM = $TARGETPLATFORM"; \ + echo "TARGETOS = $TARGETOS"; \ + echo "TARGETARCH = $TARGETARCH"; \ + echo "TARGETVARIANT = $TARGETVARIANT"; \ + echo "USERPLATFORM = $USERPLATFORM"; \ + echo "USEROS = $USEROS"; \ + echo "USERARCH = $USERARCH"; \ + echo "USERVARIANT = $USERVARIANT"; - WORKDIR /root - - # Set necessary env vars from this setup. - ENV RUSTUP_HOME=/usr/local/rustup - ENV CARGO_HOME=/usr/local/cargo - ENV CARGO_HOME_BIN=$CARGO_HOME/bin - ENV PATH=$CARGO_HOME_BIN:$PATH - # Ensure correct directory permissions on the install locations. - RUN mkdir -p $RUSTUP_HOME && \ - mkdir -p $CARGO_HOME_BIN && \ - chmod -R a+w $RUSTUP_HOME $CARGO_HOME + WORKDIR /root # Install necessary packages # Expand this list as needed, rather than adding more tools in later containers. - RUN apt-get update && \ - apt-get install --no-install-recommends -y \ - ca-certificates \ - curl \ - file \ - build-essential \ - autoconf \ - automake \ - autotools-dev \ - libtool \ - xutils-dev \ + RUN apk add --no-cache \ + musl-dev \ mold \ - python3 \ - python3-pip \ - musl-tools \ - clang && \ - rm -rf /var/lib/apt/lists/* - - # Install OpenSSL here but ONLY if we can't avoid using it. + clang \ + ripgrep \ + bash \ + colordiff \ + graphviz - # Install rustup. - RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain none -y -v + # Install a nightly toolchain which matches. + RUN rustup toolchain install nightly --component miri --component rust-src --component rustfmt # Install the default cargo config. - COPY config.toml $CARGO_HOME/config.toml + COPY .cargo/config.toml $CARGO_HOME/config.toml + + # Install rust based tooling + # Install tools we use commonly with `cargo`. + # Note, we disable static compiles for tools, specifically, as its not required. + # These tools are not artefacts and we do not use them in production. + RUN export RUSTFLAGS="-C target-feature=-crt-static" && \ + cargo install cargo-nextest --version=0.9.59 && \ + cargo install cargo-machete --version=0.6.0 && \ + cargo install refinery_cli --version=0.8.11 + + + # Universal build scripts we will always need and are not target dependent. + COPY --dir scripts /scripts + RUN ls -al /scripts + + # Standardized Rust configs. + # Build will refuse to proceed if the projects rust configs do not match these. + # This is to enforce consistent compiler and tool configuration on local setup and CI builds. + COPY rustfmt.toml /stdcfgs/ + +# Builds all the rust-base targets for each supported DOCKER architecture. +# Currently only used for multi-platform cross build testing. +# This will ONLY work if you have `qemu` properly setup on linux and `rosetta` for +# docker enabled on Mac. +# Again, this is just a test target, and not for general use. +rust-base-all-hosts: + BUILD --platform=linux/amd64 --platform=linux/arm64 +rust-base # Common Rust setup # Parameters: # * toolchain : The `rust-toolchain` toml file. -RUST_SETUP: +SETUP: COMMAND ARG toolchain=./rust-toolchain.toml @@ -62,35 +90,135 @@ RUST_SETUP: # Copy our toolchain dependency. COPY $toolchain ./rust-toolchain.toml - ENV default_rust_channel=$(grep -oP 'channel\s*=\s*"\K[^"]+' rust-toolchain.toml) + ENV default_rust_channel=$(rg -oP 'channel\s*=\s*"\K[^"]+' rust-toolchain.toml) + + # Check that `default_rust_channel` and $RUST_VERSION from the rust-base container are exactly the same. + # This ensures CI Rust version and local rust version are properly aligned and prevents version skew. + RUN /scripts/verify_toolchain.sh $default_rust_channel $RUST_VERSION # Install pinned Rustup from `rust-toolchain.toml` # Plus nightly latest so we can use it for docs, lints, etc. RUN rustup default $default_rust_channel && \ rustup show && \ - rustup toolchain install nightly --component miri --component rust-src && \ cargo --version && \ cargo +nightly --version - # Install tools we use commonly with `cargo`. - RUN cargo install cargo-nextest --locked && \ - cargo install refinery_cli --locked && \ - cargo install cargo-machete --locked -# Test rust build container -check: - FROM +rustup +CP_SRC: + # Copy the build src using this. + COMMAND + # This can be one directory like `"src/*"` or multiple src seperated by `","`: + # eg, "example/Cargo.toml, example/Cargo.lock, example/src" + ARG src="" - DO +RUST_SETUP --toolchain=example/rust-toolchain.toml + # ONLY copy whats needed to build. Not everything. + # Note: rust-toolchain.toml was already copied when rust was setup. + # Minimizing whats copied reduces needless cache misses. + FOR --sep=", " file IN $src + COPY --dir $file . + END - # Check all the expected tooling is installed and works for both the stable and nightly versions. - RUN rustc --version && \ - rustc +nightly --version && \ - cargo --version && \ - cargo +nightly --version && \ - cargo clippy --version && \ - cargo +nightly clippy --version && \ - cargo nextest --version && \ - cargo machete --version \ - refinery --version && \ - mold --version + RUN ls -al + + +# Steps we do during the `check` CI phase for all Rust programs +CHECK: + COMMAND + + # This is set up so that ALL checks are run and it will fail if any fail. + # This imporvies visibility into all issues that need to be corrected for `check` + # to pass without needing to iterate excessively. + RUN /scripts/std_checks.sh + + #diff .cargo/config.toml .stdconfig/.cargo/config.toml; \ + # cargo_config_chk_failed=$?; \ + # if [ "$cargo_config_chk_failed" -ne 0 ]; then \ + # echo ".cargo/config.toml has diverged from standard verstion."; \ + # fi; \ + # \ + # cargo +nightly fmtchk; \ + # fmt_chk_failed=$?; \ + # if [ "$fmt_chk_failed" -ne 0 ]; then \ + # echo "cargo fmt: failed"; \ + # fi; \ + # \ + # cargo machete; \ + # unused_crate_dependency_check_failed=$?; \ + # \ + # cargo modules generate --help; \ + # \ + # if [ "$unused_crate_dependency_check_failed" -ne 0 ]; then echo "cargo machete: failed"; fi; \ + # exit $(($fmt_chk_failed || $unused_crate_dependency_check_failed)) + +# Set up our target toolchains, and copy our files. +builder: + FROM +rust-base + + DO +SETUP --toolchain=example/rust-toolchain.toml + + DO +CP_SRC --src="example/cli example/core example/src example/tests example/utils example/Cargo.* rustfmt.toml .cargo" + +# Test rust build container - Use best architecture host tools. +check-hosted: + FROM +builder + + DO +CHECK + +# Run check using the most efficient host tooling +# CI Automated Entry point. +check: + FROM busybox + # This is necessary to pick the correct architecture build to suit the native machine. + # It primarily ensures that Darwin/Arm builds work as expected without needing x86 emulation. + # All target implementation of this should follow this pattern. + ARG USERARCH + + IF [ "$USERARCH" == "arm64" ] + BUILD --platform=linux/arm64 +check-hosted + ELSE + BUILD --platform=linux/amd64 +check-hosted + END + +# Test which runs check with all supported host tooling. Needs qemu or rosetta to run. +# Only used to validate tooling is working across host toolsets. +check-all-hosts: + BUILD --platform=linux/amd64 --platform=linux/arm64 +check-hosted + + +build: + # Build the service + FROM +rust-base + + DO +SETUP --toolchain=example/rust-toolchain.toml + + DO +CP_SRC --src="example/cli example/core example/src example/tests example/utils example/Cargo.* rustfmt.toml .cargo" + + DO +COPY_SRC + + RUN cargo build --release --workspace --locked; \ + build_failed=$?; \ + cargo lint; \ + lint_failed=$?; \ + cargo docs; \ + docs_failed=$?; \ + exit $(($build_failed || $lint_failed || $docs_failed)) + + # Run rust tests. + FROM +build + + COPY --dir .config . + + # Cargo nextest creates a test artifact. TODO: Work out how to publish it (even if test run fails). + RUN cargo testci; \ + testci_failed=$?; \ + cargo testdocs; \ + testdocs_failed=$?; \ + exit $(($testci_failed || $testdocs_failed)) + + + RUN ldd target/x86_64-unknown-linux-musl/release/cat-gateway + RUN readelf -p .comment target/x86_64-unknown-linux-musl/release/cat-gateway + RUN strip -v target/x86_64-unknown-linux-musl/release/cat-gateway + + SAVE ARTIFACT target/x86_64-unknown-linux-musl/doc doc + SAVE ARTIFACT target/x86_64-unknown-linux-musl/release/cat-gateway cat-gateway diff --git a/earthly/rust/config.toml b/earthly/rust/config.toml deleted file mode 100644 index 6d6820327..000000000 --- a/earthly/rust/config.toml +++ /dev/null @@ -1,52 +0,0 @@ -# Use MOLD linker where possible. -# cspell: words rustflags armv gnueabihf msvc nextest - -# Should be the default to have fully static rust programs. -[target.x86_64-unknown-linux-musl] -linker = "clang" -rustflags = [ - "-C", "link-arg=-fuse-ld=/usr/bin/mold", - "-C", "target-feature=+crt-static" -] - -[target.x86_64-unknown-linux-gnu] -linker = "clang" -rustflags = [ - "-C", "link-arg=-fuse-ld=/usr/bin/mold", - # "-C", "target-feature=+crt-static" - proc-macro doesn't work with it. `https://github.com/rust-lang/rust/issues/78210` -] - -[target.aarch64-unknown-linux-gnu] -linker = "clang" -rustflags = [ - "-C", "link-arg=-fuse-ld=/usr/bin/mold", - # "-C", "target-feature=+crt-static" - proc-macro doesn't work with it. `https://github.com/rust-lang/rust/issues/78210` -] - -[target.aarch64-unknown-linux-musl] -linker = "clang" -rustflags = [ - "-C", "link-arg=-fuse-ld=/usr/bin/mold", - "-C", "target-feature=+crt-static" -] - -[target.armv7-unknown-linux-gnueabihf] -linker = "clang" -rustflags = [ - "-C", "link-arg=-fuse-ld=/usr/bin/mold", - "-C", "target-feature=+crt-static" -] - -[target.x86_64-pc-windows-gnu] -linker = "clang" -rustflags = [ - "-C", "link-arg=-fuse-ld=/usr/bin/mold", - "-C", "target-feature=+crt-static" -] - -[target.x86_64-pc-windows-msvc] -linker = "clang" -rustflags = [ - "-C", "link-arg=-fuse-ld=/usr/bin/mold", - "-C", "target-feature=+crt-static" -] diff --git a/earthly/rust/example/Cargo.lock b/earthly/rust/example/Cargo.lock new file mode 100644 index 000000000..83c14ca39 --- /dev/null +++ b/earthly/rust/example/Cargo.lock @@ -0,0 +1,1534 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "anstream" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] +name = "anstyle-parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" +dependencies = [ + "anstyle", + "windows-sys 0.48.0", +] + +[[package]] +name = "arc-swap" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" + +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + +[[package]] +name = "assert_cmd" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88903cb14723e4d4003335bb7f8a14f27691649105346a0f0957466c096adfe6" +dependencies = [ + "anstyle", + "bstr", + "doc-comment", + "predicates 3.0.4", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "backtrace" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "better-panic" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fa9e1d11a268684cbd90ed36370d7577afb6c62d912ddff5c15fc34343e5036" +dependencies = [ + "backtrace", + "console", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bstr" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c79ad7fb2dd38f3dabd76b09c6a5a20c038fc0213ef1e9afd30eb777f120f019" +dependencies = [ + "memchr", + "regex-automata", + "serde 1.0.190", +] + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "clap_lex", + "indexmap 1.9.3", + "once_cell", + "strsim", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap_complete" +version = "3.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f7a2e0a962c45ce25afce14220bc24f9dade0a1787f185cecf96bfba7847cd8" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_derive" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "cli" +version = "2.0.0-beta" +dependencies = [ + "assert_cmd", + "clap", + "clap_complete", + "core", + "predicates 2.1.5", + "utils", +] + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "config" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1b9d958c2b1368a663f05538fc1b5975adce1e19f435acceae987aceeeb369" +dependencies = [ + "lazy_static", + "nom", + "rust-ini", + "serde 1.0.190", + "serde-hjson", + "serde_json", + "toml 0.5.11", + "yaml-rust", +] + +[[package]] +name = "console" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "windows-sys 0.45.0", +] + +[[package]] +name = "core" +version = "2.0.0-beta" +dependencies = [ + "log", + "rand", + "utils", +] + +[[package]] +name = "cpufeatures" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fbc60abd742b35f2492f808e1abbb83d45f72db402e14c55057edc9c7b1e9e4" +dependencies = [ + "libc", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crypto-mac" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "deranged" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" + +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "error-chain" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" +dependencies = [ + "version_check", +] + +[[package]] +name = "float-cmp" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" +dependencies = [ + "num-traits 0.2.17", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "gimli" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "hmac" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" +dependencies = [ + "crypto-mac", + "digest", +] + +[[package]] +name = "human-panic" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b82da652938b83f94cfdaaf9ae7aaadb8430d84b0dfda226998416318727eac2" +dependencies = [ + "anstream", + "anstyle", + "backtrace", + "os_info", + "serde 1.0.190", + "serde_derive", + "toml 0.7.8", + "uuid 1.5.0", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" +dependencies = [ + "equivalent", + "hashbrown 0.14.2", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itertools" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lexical-core" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe" +dependencies = [ + "arrayvec", + "bitflags", + "cfg-if", + "ryu", + "static_assertions", +] + +[[package]] +name = "libc" +version = "0.2.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" + +[[package]] +name = "libsystemd" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f4f0b5b062ba67aa075e331de778082c09e66b5ef32970ea5a1e9c37c9555d1" +dependencies = [ + "hmac", + "libc", + "log", + "nix", + "once_cell", + "serde 1.0.190", + "sha2", + "thiserror", + "uuid 0.8.2", +] + +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + +[[package]] +name = "nix" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", + "memoffset", +] + +[[package]] +name = "nom" +version = "5.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08959a387a676302eebf4ddbcbc611da04285579f76f88ee0506c63b1a61dd4b" +dependencies = [ + "lexical-core", + "memchr", + "version_check", +] + +[[package]] +name = "normalize-line-endings" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" + +[[package]] +name = "num-traits" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" +dependencies = [ + "num-traits 0.2.17", +] + +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_threads" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +dependencies = [ + "libc", +] + +[[package]] +name = "object" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "os_info" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "006e42d5b888366f1880eda20371fedde764ed2213dc8496f49622fa0c99cd5e" +dependencies = [ + "log", + "serde 1.0.190", + "winapi", +] + +[[package]] +name = "os_str_bytes" +version = "6.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "predicates" +version = "2.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59230a63c37f3e18569bdb90e4a89cbf5bf8b06fea0b84e65ea10cc4df47addd" +dependencies = [ + "difflib", + "float-cmp", + "itertools 0.10.5", + "normalize-line-endings", + "predicates-core", + "regex", +] + +[[package]] +name = "predicates" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dfc28575c2e3f19cb3c73b93af36460ae898d426eba6fc15b9bd2a5220758a0" +dependencies = [ + "anstyle", + "difflib", + "itertools 0.11.0", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" + +[[package]] +name = "predicates-tree" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" +dependencies = [ + "predicates-core", + "termtree", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom", + "redox_syscall", + "thiserror", +] + +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rust-example" +version = "0.0.1" +dependencies = [ + "assert_cmd", + "better-panic", + "cli", + "human-panic", + "predicates 2.1.5", + "utils", +] + +[[package]] +name = "rust-ini" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2" + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + +[[package]] +name = "serde" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8" + +[[package]] +name = "serde" +version = "1.0.190" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-hjson" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a3a4e0ea8a88553209f6cc6cfe8724ecad22e1acf372793c27d995290fe74f8" +dependencies = [ + "lazy_static", + "num-traits 0.1.43", + "regex", + "serde 0.8.23", +] + +[[package]] +name = "serde_derive" +version = "1.0.190" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + +[[package]] +name = "serde_json" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +dependencies = [ + "itoa", + "ryu", + "serde 1.0.190", +] + +[[package]] +name = "serde_spanned" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80" +dependencies = [ + "serde 1.0.190", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer", + "cfg-if", + "cpufeatures", + "digest", + "opaque-debug", +] + +[[package]] +name = "slog" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8347046d4ebd943127157b94d63abb990fcf729dc4e9978927fdf4ac3c998d06" + +[[package]] +name = "slog-async" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72c8038f898a2c79507940990f05386455b3a317d8f18d4caea7cbc3d5096b84" +dependencies = [ + "crossbeam-channel", + "slog", + "take_mut", + "thread_local", +] + +[[package]] +name = "slog-journald" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83e14eb8c2f5d0c8fc9fbac40e6391095e4dc5cb334f7dce99c75cb1919eb39c" +dependencies = [ + "libsystemd", + "slog", +] + +[[package]] +name = "slog-scope" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f95a4b4c3274cd2869549da82b57ccc930859bdbf5bcea0424bc5f140b3c786" +dependencies = [ + "arc-swap", + "lazy_static", + "slog", +] + +[[package]] +name = "slog-stdlog" +version = "4.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6706b2ace5bbae7291d3f8d2473e2bfab073ccd7d03670946197aec98471fa3e" +dependencies = [ + "log", + "slog", + "slog-scope", +] + +[[package]] +name = "slog-syslog" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28ba6ff50243a331b924a840dc079c2958d3f053f624766ca9311f11a67da548" +dependencies = [ + "slog", + "syslog", +] + +[[package]] +name = "slog-term" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87d29185c55b7b258b4f120eab00f48557d4d9bc814f41713f449d35b0f8977c" +dependencies = [ + "atty", + "slog", + "term", + "thread_local", + "time 0.3.30", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syslog" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a5d8ef1b679c07976f3ee336a436453760c470f54b5e7237556728b8589515d" +dependencies = [ + "error-chain", + "libc", + "log", + "time 0.1.45", +] + +[[package]] +name = "take_mut" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" + +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi", +] + +[[package]] +name = "termcolor" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "termtree" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" + +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + +[[package]] +name = "thiserror" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "time" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + +[[package]] +name = "time" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +dependencies = [ + "deranged", + "itoa", + "libc", + "num_threads", + "powerfmt", + "serde 1.0.190", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" +dependencies = [ + "time-core", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde 1.0.190", +] + +[[package]] +name = "toml" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +dependencies = [ + "serde 1.0.190", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde 1.0.190", +] + +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap 2.0.2", + "serde 1.0.190", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "utils" +version = "2.0.0-beta" +dependencies = [ + "backtrace", + "clap", + "config", + "lazy_static", + "log", + "serde 1.0.190", + "slog", + "slog-async", + "slog-journald", + "slog-scope", + "slog-stdlog", + "slog-syslog", + "slog-term", + "thiserror", +] + +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "serde 1.0.190", +] + +[[package]] +name = "uuid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc" +dependencies = [ + "getrandom", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + +[[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-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[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", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[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_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[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_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[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_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[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_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "winnow" +version = "0.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c" +dependencies = [ + "memchr", +] + +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] diff --git a/earthly/rust/example/Cargo.toml b/earthly/rust/example/Cargo.toml new file mode 100644 index 000000000..4bda6029d --- /dev/null +++ b/earthly/rust/example/Cargo.toml @@ -0,0 +1,69 @@ +[package] +name = "rust-example" +version = "0.0.1" +authors = ["Abid Omar ", "Steven Johnson "] +edition = "2021" +repository = "https://github.com/input-output-hk/catalyst-ci" +readme = "README.md" +license = "MIT" +keywords = ["cli"] +description = """ +Example Rust program to test CI/CD and serve as a working example. +""" + +[workspace] +members = [ + "utils", + "cli", + "core", +] + +[features] +nightly = ["utils/nightly"] +termlog = ["utils/termlog"] +journald = ["utils/journald"] +syslog = ["utils/syslog"] + +[dependencies] +utils = { path = "utils" } +cli = { path = "cli"} +# core = { path = "core" } +human-panic = "1.0.3" +better-panic = "0.3.0" +# log = "0.4.14" + +[dev-dependencies] +assert_cmd = "2.0.4" +predicates = "2.1.1" + +[profile.dev] +opt-level=0 +debug = true +rpath = false +lto = false +debug-assertions = true +codegen-units = 4 + +[profile.release] +opt-level=3 +debug = false +rpath = false +lto = true +debug-assertions = false +codegen-units = 1 + +[profile.test] +opt-level = 1 +debug = true +rpath = false +lto = false +debug-assertions = true +codegen-units = 4 + +[profile.bench] +opt-level = 3 +debug = false +rpath = false +lto = true +debug-assertions = false +codegen-units = 1 diff --git a/earthly/rust/example/LICENSE b/earthly/rust/example/LICENSE new file mode 100644 index 000000000..3562ace0c --- /dev/null +++ b/earthly/rust/example/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Abid Omar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/earthly/rust/example/README.md b/earthly/rust/example/README.md new file mode 100644 index 000000000..2ded8bae7 --- /dev/null +++ b/earthly/rust/example/README.md @@ -0,0 +1,7 @@ +# Example Rust Project + +This is an simple but hopefully full featured example rust project. +It is used to test both our Catalyst-CI Rust building infrastructure and serve as a template for its use. + +This code was originally sourced from: ["rust-starter](https://rust-starter.github.io/). +The code in this repo has been adapted for our needs. diff --git a/earthly/rust/example/cli/Cargo.toml b/earthly/rust/example/cli/Cargo.toml new file mode 100644 index 000000000..fbb512099 --- /dev/null +++ b/earthly/rust/example/cli/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "cli" +version = "2.0.0-beta" +authors = ["Abid Omar "] +description = "CLI interface for rust-starter" +edition = "2021" + +[dependencies] +utils = { path = "../utils" } +core = { path = "../core" } +clap_complete = "3.0" + +[dependencies.clap] +version = "3.0.14" +features = ["cargo", "derive"] + +[dev-dependencies] +assert_cmd = "2.0.4" +predicates = "2.1.1" diff --git a/earthly/rust/example/cli/src/lib.rs b/earthly/rust/example/cli/src/lib.rs new file mode 100644 index 000000000..fa006e88e --- /dev/null +++ b/earthly/rust/example/cli/src/lib.rs @@ -0,0 +1,118 @@ +use core::commands; +use std::{path::PathBuf, str::FromStr}; + +use clap::{AppSettings, IntoApp, Parser, Subcommand}; +use clap_complete::{ + generate, + shells::{Bash, Fish, Zsh}, +}; +use utils::{app_config::AppConfig, error::Result, types::LogLevel}; + +#[derive(Parser, Debug)] +#[clap( + name = "rust-starter", + author, + about, + long_about = "Rust Starter CLI", + version +)] +#[clap(setting = AppSettings::SubcommandRequired)] +#[clap(global_setting(AppSettings::DeriveDisplayOrder))] +pub struct Cli { + /// Set a custom config file + #[clap(short, long, parse(from_os_str), value_name = "FILE")] + pub config: Option, + + /// Set a custom config file + #[clap(name = "debug", short, long = "debug", value_name = "DEBUG")] + pub debug: Option, + + /// Set Log Level + #[clap( + name = "log_level", + short, + long = "log-level", + value_name = "LOG_LEVEL" + )] + pub log_level: Option, + + /// Subcommands + #[clap(subcommand)] + command: Commands, +} + +#[derive(Subcommand, Debug)] +enum Commands { + #[clap( + name = "hazard", + about = "Generate a hazardous occurrence", + long_about = None, + )] + Hazard, + #[clap( + name = "error", + about = "Simulate an error", + long_about = None, + )] + Error, + #[clap( + name = "completion", + about = "Generate completion scripts", + long_about = None, + )] + Completion { + #[clap(subcommand)] + subcommand: CompletionSubcommand, + }, + #[clap( + name = "config", + about = "Show Configuration", + long_about = None, + )] + Config, +} + +#[derive(Subcommand, PartialEq, Debug)] +enum CompletionSubcommand { + #[clap(about = "generate the autocompletion script for bash")] + Bash, + #[clap(about = "generate the autocompletion script for zsh")] + Zsh, + #[clap(about = "generate the autocompletion script for fish")] + Fish, +} + +pub fn cli_match() -> Result<()> { + // Parse the command line arguments + let cli = Cli::parse(); + + // Merge clap config file if the value is set + AppConfig::merge_config(cli.config.as_deref())?; + + let app = Cli::into_app(); + + AppConfig::merge_args(app)?; + + // Execute the subcommand + match &cli.command { + Commands::Hazard => commands::hazard()?, + Commands::Error => commands::simulate_error()?, + Commands::Completion { subcommand } => { + let mut app = Cli::into_app(); + match subcommand { + CompletionSubcommand::Bash => { + generate(Bash, &mut app, "rust-starter", &mut std::io::stdout()); + }, + CompletionSubcommand::Zsh => { + generate(Zsh, &mut app, "rust-starter", &mut std::io::stdout()); + }, + CompletionSubcommand::Fish => { + generate(Fish, &mut app, "rust-starter", &mut std::io::stdout()); + }, + } + }, + Commands::Config => commands::config()?, + } + + Ok(()) +} diff --git a/earthly/rust/example/core/Cargo.toml b/earthly/rust/example/core/Cargo.toml new file mode 100644 index 000000000..d4eddb562 --- /dev/null +++ b/earthly/rust/example/core/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "core" +version = "2.0.0-beta" +authors = ["Abid Omar "] +description = "The application core code" +edition = "2021" + +[dependencies] +utils = { path = "../utils" } + +rand = "0.8.4" +log = "0.4.14" diff --git a/earthly/rust/example/core/benches/01_default.rs b/earthly/rust/example/core/benches/01_default.rs new file mode 100644 index 000000000..f116acc01 --- /dev/null +++ b/earthly/rust/example/core/benches/01_default.rs @@ -0,0 +1,15 @@ +#![feature(test)] + +extern crate core; +extern crate test; + +use core::hazard; + +use test::Bencher; + +#[bench] +fn bench_hazard(b: &mut Bencher) { + b.iter(|| { + hazard::generate_hazard().unwrap(); + }) +} diff --git a/earthly/rust/example/core/src/commands.rs b/earthly/rust/example/core/src/commands.rs new file mode 100644 index 000000000..e59258ed7 --- /dev/null +++ b/earthly/rust/example/core/src/commands.rs @@ -0,0 +1,37 @@ +use utils::{app_config::AppConfig, error::Result}; + +use super::{error, hazard}; + +/// Show the configuration file +pub fn hazard() -> Result<()> { + // Generate, randomly, True or False + let random_hazard: bool = hazard::generate_hazard()?; + + if random_hazard { + println!("You got it right!"); + } else { + println!("You got it wrong!"); + } + + Ok(()) +} + +/// Show the configuration file +pub fn config() -> Result<()> { + let config = AppConfig::fetch()?; + println!("{:#?}", config); + + Ok(()) +} + +/// Simulate an error +pub fn simulate_error() -> Result<()> { + // Log this Error simulation + info!("We are simulating an error"); + + // Simulate an error + error::simulate_error()?; + + // We should never get here... + Ok(()) +} diff --git a/earthly/rust/example/core/src/error.rs b/earthly/rust/example/core/src/error.rs new file mode 100644 index 000000000..5e8fae129 --- /dev/null +++ b/earthly/rust/example/core/src/error.rs @@ -0,0 +1,12 @@ +use std::fs::File; + +use utils::error::Result; + +/// Return, randomly, true or false +pub fn simulate_error() -> Result<()> { + log::error!("Simulating error"); + // Trigger an error + File::open("thisfiledoesnotexist")?; + + Ok(()) +} diff --git a/earthly/rust/example/core/src/hazard.rs b/earthly/rust/example/core/src/hazard.rs new file mode 100644 index 000000000..6d48175cf --- /dev/null +++ b/earthly/rust/example/core/src/hazard.rs @@ -0,0 +1,6 @@ +use utils::error::Result; + +/// Return, randomly, true or false +pub fn generate_hazard() -> Result { + Ok(rand::random()) +} diff --git a/earthly/rust/example/core/src/lib.rs b/earthly/rust/example/core/src/lib.rs new file mode 100644 index 000000000..d68f8c166 --- /dev/null +++ b/earthly/rust/example/core/src/lib.rs @@ -0,0 +1,14 @@ +#[macro_use] +extern crate log; + +pub mod commands; +pub mod error; +pub mod hazard; + +use utils::error::Result; + +pub fn start() -> Result<()> { + // does nothing + + Ok(()) +} diff --git a/earthly/rust/example/rustfmt.toml b/earthly/rust/example/rustfmt.toml new file mode 100644 index 000000000..b0f20832c --- /dev/null +++ b/earthly/rust/example/rustfmt.toml @@ -0,0 +1,68 @@ +# Enable unstable features: +# * imports_indent +# * imports_layout +# * imports_granularity +# * group_imports +# * reorder_impl_items +# * trailing_comma +# * where_single_line +# * wrap_comments +# * comment_width +# * blank_lines_upper_bound +# * condense_wildcard_suffixes +# * force_multiline_blocks +# * format_code_in_doc_comments +# * format_generated_files +# * hex_literal_case +# * inline_attribute_width +# * normalize_comments +# * normalize_doc_attributes +# * overflow_delimited_expr +unstable_features = true + +# Compatibility: +edition = "2021" + +# Tabs & spaces - Defaults, listed for clarity +tab_spaces = 4 +hard_tabs = false + +# Commas. +trailing_comma = "Vertical" +match_block_trailing_comma = true + +# General width constraints. +max_width = 100 + +# Comments: +normalize_comments = true +normalize_doc_attributes = true +wrap_comments = true +comment_width = 90 # small excess is okay but prefer 80 +format_code_in_doc_comments = true +format_generated_files = false + +# Imports. +imports_indent = "Block" +imports_layout = "Mixed" +group_imports = "StdExternalCrate" +reorder_imports = true +imports_granularity = "Crate" + +# Arguments: +use_small_heuristics = "Default" +fn_params_layout = "Compressed" +overflow_delimited_expr = true +where_single_line = true + +# Misc: +inline_attribute_width = 0 +blank_lines_upper_bound = 1 +reorder_impl_items = true +use_field_init_shorthand = true +force_multiline_blocks = true +condense_wildcard_suffixes = true +hex_literal_case = "Upper" + +# Ignored files: +ignore = [] diff --git a/earthly/rust/example/src/main.rs b/earthly/rust/example/src/main.rs new file mode 100644 index 000000000..2466293f4 --- /dev/null +++ b/earthly/rust/example/src/main.rs @@ -0,0 +1,37 @@ +#[cfg(not(debug_assertions))] +use human_panic::setup_panic; + +#[cfg(debug_assertions)] +extern crate better_panic; + +use utils::{app_config::AppConfig, error::Result}; + +/// The main entry point of the application. +fn main() -> Result<()> { + // Human Panic. Only enabled when *not* debugging. + #[cfg(not(debug_assertions))] + { + setup_panic!(); + } + + // Better Panic. Only enabled *when* debugging. + #[cfg(debug_assertions)] + { + better_panic::Settings::debug() + .most_recent_first(false) + .lineno_suffix(true) + .verbosity(better_panic::Verbosity::Full) + .install(); + } + + let _guard = utils::logger::setup_logging()?; + + // Initialize Configuration + let config_contents = include_str!("resources/default_config.toml"); + AppConfig::init(Some(config_contents))?; + + // Match Commands + cli::cli_match()?; + + Ok(()) +} diff --git a/earthly/rust/example/src/resources/default_config.toml b/earthly/rust/example/src/resources/default_config.toml new file mode 100644 index 000000000..2efa81eb8 --- /dev/null +++ b/earthly/rust/example/src/resources/default_config.toml @@ -0,0 +1,5 @@ +debug = false +log_level = "info" + +[database] +url = "custom database url" diff --git a/earthly/rust/example/tests/test_cli.rs b/earthly/rust/example/tests/test_cli.rs new file mode 100644 index 000000000..9bd86d3e4 --- /dev/null +++ b/earthly/rust/example/tests/test_cli.rs @@ -0,0 +1,35 @@ +#[cfg(test)] +extern crate assert_cmd; +extern crate predicates; + +use std::process::Command; + +use assert_cmd::prelude::*; +use predicates::prelude::*; + +#[test] +fn test_cli() { + let mut cmd = Command::cargo_bin("rust-starter").expect("Calling binary failed"); + cmd.assert().failure(); +} + +#[test] +fn test_version() { + let expected_version = "rust-starter 2.0.0-beta\n"; + let mut cmd = Command::cargo_bin("rust-starter").expect("Calling binary failed"); + cmd.arg("--version").assert().stdout(expected_version); +} + +#[test] +fn test_hazard_exit_code() { + let mut cmd = Command::cargo_bin("rust-starter").expect("Calling binary failed"); + cmd.arg("hazard").assert().code(0); +} + +#[test] +fn test_hazard_stdout() { + let hazard_predicate = + predicate::function(|x: &str| x == "You got it right!\n" || x == "You got it wrong!\n"); + let mut cmd = Command::cargo_bin("rust-starter").expect("Calling binary failed"); + cmd.arg("hazard").assert().stdout(hazard_predicate); +} diff --git a/earthly/rust/example/utils/Cargo.toml b/earthly/rust/example/utils/Cargo.toml new file mode 100644 index 000000000..37e351cc8 --- /dev/null +++ b/earthly/rust/example/utils/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "utils" +version = "2.0.0-beta" +authors = ["Abid Omar "] +description = "Various utilities and functionalities" +edition = "2021" + +[features] +nightly = [] +termlog = [] +syslog = [] +journald = [] + +[dependencies] +thiserror = "1.0.30" +backtrace = "0.3.64" +# color-backtrace = "0.5.1" +config = "0.11.0" +lazy_static = "1.4.0" +slog = "2.7.0" +slog-syslog = "0.13.0" +slog-term = "2.8.0" +slog-scope = "4.4.0" +slog-async = "2.7.0" +slog-stdlog = "4.1.0" +slog-journald = "2.2.0" +clap = "3.0.14" +log = "0.4.14" +serde = { version = "1.0.136", features = ["derive"] } diff --git a/earthly/rust/example/utils/src/app_config.rs b/earthly/rust/example/utils/src/app_config.rs new file mode 100644 index 000000000..ce7d1dffb --- /dev/null +++ b/earthly/rust/example/utils/src/app_config.rs @@ -0,0 +1,111 @@ +use std::{path::Path, sync::RwLock}; + +use config::{Config, Environment}; +use lazy_static::{__Deref, lazy_static}; +use serde::{Deserialize, Serialize}; + +use super::error::Result; +use crate::types::LogLevel; + +// CONFIG static variable. It's actually an AppConfig +// inside an RwLock. +lazy_static! { + pub static ref CONFIG: RwLock = RwLock::new(Config::new()); +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct Database { + pub url: String, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct AppConfig { + pub debug: bool, + pub log_level: LogLevel, + pub database: Database, +} + +impl AppConfig { + /// Initialize AppConfig. + pub fn init(default_config: Option<&str>) -> Result<()> { + let mut settings = Config::new(); + + // Embed file into executable + // This macro will embed the configuration file into the + // executable. Check include_str! for more info. + if let Some(config_contents) = default_config { + // let contents = include_str!(config_file_path); + settings.merge(config::File::from_str( + config_contents, + config::FileFormat::Toml, + ))?; + } + + // Merge settings with env variables + settings.merge(Environment::with_prefix("APP"))?; // TODO: Merge settings with Clap Settings Arguments + + // Save Config to RwLoc + { + let mut w = CONFIG.write()?; + *w = settings; + } + + Ok(()) + } + + pub fn merge_args(app: clap::App) -> Result<()> { + let args = app.get_matches(); + + if args.is_present("debug") { + AppConfig::set("debug", args.value_of("debug").unwrap())?; + } + + if args.is_present("log_level") { + AppConfig::set("log_level", args.value_of("log_level").unwrap())?; + } + + Ok(()) + } + + pub fn merge_config(config_file: Option<&Path>) -> Result<()> { + // Merge settings with config file if there is one + if let Some(config_file_path) = config_file { + { + CONFIG + .write()? + .merge(config::File::with_name(config_file_path.to_str().unwrap()))?; + } + } + Ok(()) + } + + // Set CONFIG + pub fn set(key: &str, value: &str) -> Result<()> { + { + // Set Property + CONFIG.write()?.set(key, value)?; + } + + Ok(()) + } + + // Get a single value + pub fn get<'de, T>(key: &'de str) -> Result + where T: serde::Deserialize<'de> { + Ok(CONFIG.read()?.get::(key)?) + } + + // Get CONFIG + // This clones Config (from RwLock) into a new AppConfig object. + // This means you have to fetch this again if you changed the configuration. + pub fn fetch() -> Result { + // Get a Read Lock from RwLock + let r = CONFIG.read()?; + + // Clone the Config object + let config_clone = r.deref().clone(); + + // Coerce Config into AppConfig + Ok(config_clone.try_into()?) + } +} diff --git a/earthly/rust/example/utils/src/error.rs b/earthly/rust/example/utils/src/error.rs new file mode 100644 index 000000000..1e20b33ea --- /dev/null +++ b/earthly/rust/example/utils/src/error.rs @@ -0,0 +1,111 @@ +use std::fmt; + +use thiserror::Error; + +/// Result alias +pub type Result = std::result::Result; + +/// Error type for this library. +#[derive(Error, Debug)] +pub struct Error { + pub msg: String, + #[cfg(feature = "nightly")] + backtrace: std::backtrace::Backtrace, + source: Option>, +} + +// Implement the Display trait for our Error type. +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.msg) + } +} + +// Implement Default for Error +impl Default for Error { + fn default() -> Self { + Error { + msg: "".to_string(), + #[cfg(feature = "nightly")] + backtrace: std::backtrace::Backtrace::capture(), + source: None, + } + } +} + +impl Error { + /// Create a new Error instance. + pub fn new(msg: &str) -> Self { + Error { + msg: msg.to_string(), + #[cfg(feature = "nightly")] + backtrace: std::backtrace::Backtrace::capture(), + source: None, + } + } + + /// Create a new Error instance with a source error. + pub fn with_source(msg: &str, source: Box) -> Self { + Error { + msg: msg.to_string(), + #[cfg(feature = "nightly")] + backtrace: std::backtrace::Backtrace::capture(), + source: Some(source), + } + } +} + +impl From for Error { + fn from(err: config::ConfigError) -> Self { + Error { + msg: String::from("Config Error"), + #[cfg(feature = "nightly")] + backtrace: std::backtrace::Backtrace::capture(), + source: Some(Box::new(err)), + } + } +} + +impl From> for Error { + fn from(_err: std::sync::PoisonError) -> Self { + Error { + msg: String::from("Poison Error"), + #[cfg(feature = "nightly")] + backtrace: std::backtrace::Backtrace::capture(), + source: None, + } + } +} + +impl From for Error { + fn from(err: std::io::Error) -> Self { + Error { + msg: String::from("IO Error"), + #[cfg(feature = "nightly")] + backtrace: std::backtrace::Backtrace::capture(), + source: Some(Box::new(err)), + } + } +} + +impl From for Error { + fn from(err: clap::Error) -> Self { + Error { + msg: String::from("Clap Error"), + #[cfg(feature = "nightly")] + backtrace: std::backtrace::Backtrace::capture(), + source: Some(Box::new(err)), + } + } +} + +impl From for Error { + fn from(err: log::SetLoggerError) -> Self { + Error { + msg: String::from("Logger Error"), + #[cfg(feature = "nightly")] + backtrace: std::backtrace::Backtrace::capture(), + source: Some(Box::new(err)), + } + } +} diff --git a/earthly/rust/example/utils/src/lib.rs b/earthly/rust/example/utils/src/lib.rs new file mode 100644 index 000000000..0436beb4e --- /dev/null +++ b/earthly/rust/example/utils/src/lib.rs @@ -0,0 +1,6 @@ +#![cfg_attr(feature = "nightly", feature(backtrace))] + +pub mod app_config; +pub mod error; +pub mod logger; +pub mod types; diff --git a/earthly/rust/example/utils/src/logger.rs b/earthly/rust/example/utils/src/logger.rs new file mode 100644 index 000000000..84a303714 --- /dev/null +++ b/earthly/rust/example/utils/src/logger.rs @@ -0,0 +1,68 @@ +use slog::{o, Drain}; +use slog_journald::JournaldDrain; +use slog_syslog::Facility; + +use super::error::Result; + +pub fn setup_logging() -> Result { + // Setup Logging + let guard = slog_scope::set_global_logger(default_root_logger()?); + let _log_guard = slog_stdlog::init()?; + + Ok(guard) +} + +pub fn default_root_logger() -> Result { + // Create drains + let drain = slog::Duplicate(default_discard()?, default_discard()?).fuse(); + + // Merge drains + #[cfg(feature = "termlog")] + let drain = slog::Duplicate(default_term_drain().unwrap_or(default_discard()?), drain).fuse(); + #[cfg(feature = "syslog")] + let drain = slog::Duplicate(default_syslog_drain().unwrap_or(default_discard()?), drain).fuse(); + #[cfg(feature = "journald")] + let drain = slog::Duplicate( + default_journald_drain().unwrap_or(default_discard()?), + drain, + ) + .fuse(); + + // Create Logger + let logger = slog::Logger::root(drain, o!("who" => "rust-starter")); + + // Return Logger + Ok(logger) +} + +fn default_discard() -> Result { + let drain = slog_async::Async::default(slog::Discard); + + Ok(drain) +} + +// term drain: Log to Terminal +fn default_term_drain() -> Result { + let plain = slog_term::PlainSyncDecorator::new(std::io::stdout()); + let term = slog_term::FullFormat::new(plain); + + let drain = slog_async::Async::default(term.build().fuse()); + + Ok(drain) +} + +// syslog drain: Log to syslog +fn default_syslog_drain() -> Result { + let syslog = slog_syslog::unix_3164(Facility::LOG_USER)?; + + let drain = slog_async::Async::default(syslog.fuse()); + + Ok(drain) +} + +fn default_journald_drain() -> Result { + let journald = JournaldDrain.ignore_res(); + let drain = slog_async::Async::default(journald); + + Ok(drain) +} diff --git a/earthly/rust/example/utils/src/types.rs b/earthly/rust/example/utils/src/types.rs new file mode 100644 index 000000000..00106576f --- /dev/null +++ b/earthly/rust/example/utils/src/types.rs @@ -0,0 +1,31 @@ +use std::str::FromStr; + +use serde::{Deserialize, Serialize}; + +use crate::error::Result; + +#[derive(Debug, Serialize, Deserialize)] +pub enum LogLevel { + #[serde(rename = "debug")] + Debug, + #[serde(rename = "info")] + Info, + #[serde(rename = "warn")] + Warn, + #[serde(rename = "error")] + Error, +} + +impl FromStr for LogLevel { + type Err = crate::error::Error; + + fn from_str(s: &str) -> Result { + match s { + "debug" => Ok(LogLevel::Debug), + "info" => Ok(LogLevel::Info), + "warn" => Ok(LogLevel::Warn), + "error" => Ok(LogLevel::Error), + _ => Ok(LogLevel::Info), + } + } +} diff --git a/earthly/rust/example/utils/tests/resources/test_config.toml b/earthly/rust/example/utils/tests/resources/test_config.toml new file mode 100644 index 000000000..cc5e99b71 --- /dev/null +++ b/earthly/rust/example/utils/tests/resources/test_config.toml @@ -0,0 +1,4 @@ +debug = false + +[database] +url = "custom database url" diff --git a/earthly/rust/example/utils/tests/test_config.rs b/earthly/rust/example/utils/tests/test_config.rs new file mode 100644 index 000000000..d9c344185 --- /dev/null +++ b/earthly/rust/example/utils/tests/test_config.rs @@ -0,0 +1,45 @@ +use utils::app_config::*; + +#[test] +fn fetch_config() { + // Initialize configuration + let config_contents = include_str!("resources/test_config.toml"); + AppConfig::init(Some(config_contents)).unwrap(); + + // Fetch an instance of Config + let config = AppConfig::fetch().unwrap(); + + // Check the values + assert_eq!(config.debug, false); + assert_eq!(config.database.url, "custom database url"); +} + +#[test] +fn verify_get() { + // Initialize configuration + let config_contents = include_str!("resources/test_config.toml"); + AppConfig::init(Some(config_contents)).unwrap(); + + // Check value with get + assert_eq!(AppConfig::get::("debug").unwrap(), false); + assert_eq!( + AppConfig::get::("database.url").unwrap(), + "custom database url" + ); +} + +#[test] +fn verify_set() { + // Initialize configuration + let config_contents = include_str!("resources/test_config.toml"); + AppConfig::init(Some(config_contents)).unwrap(); + + // Set a field + AppConfig::set("database.url", "new url").unwrap(); + + // Fetch a new instance of Config + let config = AppConfig::fetch().unwrap(); + + // Check value was modified + assert_eq!(config.database.url, "new url"); +} diff --git a/earthly/rust/rustfmt.toml b/earthly/rust/rustfmt.toml new file mode 100644 index 000000000..b0f20832c --- /dev/null +++ b/earthly/rust/rustfmt.toml @@ -0,0 +1,68 @@ +# Enable unstable features: +# * imports_indent +# * imports_layout +# * imports_granularity +# * group_imports +# * reorder_impl_items +# * trailing_comma +# * where_single_line +# * wrap_comments +# * comment_width +# * blank_lines_upper_bound +# * condense_wildcard_suffixes +# * force_multiline_blocks +# * format_code_in_doc_comments +# * format_generated_files +# * hex_literal_case +# * inline_attribute_width +# * normalize_comments +# * normalize_doc_attributes +# * overflow_delimited_expr +unstable_features = true + +# Compatibility: +edition = "2021" + +# Tabs & spaces - Defaults, listed for clarity +tab_spaces = 4 +hard_tabs = false + +# Commas. +trailing_comma = "Vertical" +match_block_trailing_comma = true + +# General width constraints. +max_width = 100 + +# Comments: +normalize_comments = true +normalize_doc_attributes = true +wrap_comments = true +comment_width = 90 # small excess is okay but prefer 80 +format_code_in_doc_comments = true +format_generated_files = false + +# Imports. +imports_indent = "Block" +imports_layout = "Mixed" +group_imports = "StdExternalCrate" +reorder_imports = true +imports_granularity = "Crate" + +# Arguments: +use_small_heuristics = "Default" +fn_params_layout = "Compressed" +overflow_delimited_expr = true +where_single_line = true + +# Misc: +inline_attribute_width = 0 +blank_lines_upper_bound = 1 +reorder_impl_items = true +use_field_init_shorthand = true +force_multiline_blocks = true +condense_wildcard_suffixes = true +hex_literal_case = "Upper" + +# Ignored files: +ignore = [] diff --git a/earthly/rust/scripts/README.md b/earthly/rust/scripts/README.md new file mode 100644 index 000000000..df629cafc --- /dev/null +++ b/earthly/rust/scripts/README.md @@ -0,0 +1,6 @@ +# Standard stage processing scripts + +These script files are used during the CI phases to simplify the Earthfiles and +to improve maintainability. + +They need to be `bash` scripts, and they need to execute on an `alpine` os base. diff --git a/earthly/rust/scripts/colors.sh b/earthly/rust/scripts/colors.sh new file mode 100644 index 000000000..8335730ad --- /dev/null +++ b/earthly/rust/scripts/colors.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +BLACK='\033[0;30m' +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +BLUE='\033[0;34m' +MAGENTA='\033[0;35m' +CYAN='\033[0;36m' +WHITE='\033[0;37m' +NC='\033[0m' # No Color diff --git a/earthly/rust/scripts/std_checks.sh b/earthly/rust/scripts/std_checks.sh new file mode 100755 index 000000000..e62e65f61 --- /dev/null +++ b/earthly/rust/scripts/std_checks.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +# This script is run inside the `check` stage for rust projects to perfom all +# high level non-compilation checks. +# These are the Standard checks which ALL rust targets must pass before they +# will be scheduled to be `buuild`. +# Individual targets can add extra `check` steps, but these checks must always +# pass. + +source "$(dirname "$0")/colors.sh" + +status() { + local rc="$1" + local message="$2" + shift 2 + + # Check if the command returned a bad status + if "$@"; then + # Append green OK to the message + echo -e "${CYAN}${message} : ${GREEN}[OK]${NC}" + else + # Append red ERROR to the message + echo -e "${CYAN}${message} : ${RED}[ERROR]${NC}" + rc=1 + fi + + # Return the current status + return "$rc" +} + +# Checks if two files that should exist DO, and are equal. +# used to enforce consistency between local config files and the expected config locked in CI. +check_vendored_files() { + local rc=$1 + local localfile=$2 + local vendorfile=$3 + + status "$rc" "Checking if Local File '$localfile' == Vendored File '$vendorfile'" \ + colordiff -Naur "$localfile" "$vendorfile" + return $? +} + +# This is set up so that ALL checks are run and it will fail if any fail. +# This imporvies visibility into all issues that need to be corrected for `check` +# to pass without needing to iterate excessively. + +rc=0 + +## Check if .cargo.config.toml has been modified. +check_vendored_files $rc .cargo/config.toml "$CARGO_HOME"/config.toml; rc=$? +check_vendored_files $rc rustfmt.toml /stdcfgs/rustfmt.toml; rc=$? + +# Check if the rust src is properly formatted. +status $rc "Checking Rust Code Format" cargo +nightly fmtchk; rc=$? +if [ $rc -ne 0 ]; then + echo -e " ${YELLOW}You can locally fix format errors by running: \`cargo +nightly fmtfix\`${NC}" +fi + +# Check if we have unused dependencies declared in our Cargo.toml files. +status $rc "Checking for Unused Dependencies" cargo machete; rc=$? + +# Return an error if any of this fails. +exit $rc \ No newline at end of file diff --git a/earthly/rust/scripts/verify_toolchain.sh b/earthly/rust/scripts/verify_toolchain.sh new file mode 100755 index 000000000..5de53599f --- /dev/null +++ b/earthly/rust/scripts/verify_toolchain.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +source "$(dirname "$0")/colors.sh" + +default_rust_channel=$1 +RUST_VERSION=$2 + +if [ "$default_rust_channel" != "$RUST_VERSION" ]; then + echo -e "${YELLOW}Your Rust Toolchain is set to Version : ${RED}$default_rust_channel${NC}" + echo -e "${YELLOW}This Builder requires it to be : ${GREEN}$RUST_VERSION${NC}" + echo -e "${RED}Either use the correct Earthly Rust Builder version from CI, or correct './rust-toolchain.toml' to match.${NC}" + exit 1; +fi From ad1a5b7863427c022c2fc14548b891905f8d7798 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 27 Oct 2023 16:10:29 +0700 Subject: [PATCH 15/21] fix(rust): remove shellcheck warnings --- earthly/rust/scripts/colors.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/earthly/rust/scripts/colors.sh b/earthly/rust/scripts/colors.sh index 8335730ad..dde47abc0 100644 --- a/earthly/rust/scripts/colors.sh +++ b/earthly/rust/scripts/colors.sh @@ -1,5 +1,7 @@ #!/bin/bash +# shellcheck disable=SC2034 # This file is intended to bo sourced. + BLACK='\033[0;30m' RED='\033[0;31m' GREEN='\033[0;32m' From ece713cd25993fec272c21702f0e9a9e57164f6d Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 27 Oct 2023 20:02:37 +0700 Subject: [PATCH 16/21] fix(rust): simplify the example project. WIP for build steps. --- earthly/rust/.cargo/config.toml | 18 + earthly/rust/Earthfile | 76 +- earthly/rust/example/.cargo/config.toml | 127 ++ earthly/rust/example/Cargo.lock | 1462 +---------------- earthly/rust/example/Cargo.toml | 71 +- earthly/rust/example/LICENSE | 21 - earthly/rust/example/README.md | 3 - earthly/rust/example/benches/benchmark.rs | 14 + earthly/rust/example/cli/Cargo.toml | 19 - earthly/rust/example/cli/src/lib.rs | 118 -- earthly/rust/example/core/Cargo.toml | 12 - .../rust/example/core/benches/01_default.rs | 15 - earthly/rust/example/core/src/commands.rs | 37 - earthly/rust/example/core/src/error.rs | 12 - earthly/rust/example/core/src/hazard.rs | 6 - earthly/rust/example/core/src/lib.rs | 14 - earthly/rust/example/src/main.rs | 58 +- .../example/src/resources/default_config.toml | 5 - .../rust/example/tests/integration_test.rs | 10 + earthly/rust/example/tests/test_cli.rs | 35 - earthly/rust/example/utils/Cargo.toml | 29 - earthly/rust/example/utils/src/app_config.rs | 111 -- earthly/rust/example/utils/src/error.rs | 111 -- earthly/rust/example/utils/src/lib.rs | 6 - earthly/rust/example/utils/src/logger.rs | 68 - earthly/rust/example/utils/src/types.rs | 31 - .../utils/tests/resources/test_config.toml | 4 - .../rust/example/utils/tests/test_config.rs | 45 - earthly/rust/scripts/colors.sh | 20 + earthly/rust/scripts/std_build.sh | 42 + earthly/rust/scripts/std_checks.sh | 19 - 31 files changed, 329 insertions(+), 2290 deletions(-) create mode 100644 earthly/rust/example/.cargo/config.toml delete mode 100644 earthly/rust/example/LICENSE create mode 100644 earthly/rust/example/benches/benchmark.rs delete mode 100644 earthly/rust/example/cli/Cargo.toml delete mode 100644 earthly/rust/example/cli/src/lib.rs delete mode 100644 earthly/rust/example/core/Cargo.toml delete mode 100644 earthly/rust/example/core/benches/01_default.rs delete mode 100644 earthly/rust/example/core/src/commands.rs delete mode 100644 earthly/rust/example/core/src/error.rs delete mode 100644 earthly/rust/example/core/src/hazard.rs delete mode 100644 earthly/rust/example/core/src/lib.rs delete mode 100644 earthly/rust/example/src/resources/default_config.toml create mode 100644 earthly/rust/example/tests/integration_test.rs delete mode 100644 earthly/rust/example/tests/test_cli.rs delete mode 100644 earthly/rust/example/utils/Cargo.toml delete mode 100644 earthly/rust/example/utils/src/app_config.rs delete mode 100644 earthly/rust/example/utils/src/error.rs delete mode 100644 earthly/rust/example/utils/src/lib.rs delete mode 100644 earthly/rust/example/utils/src/logger.rs delete mode 100644 earthly/rust/example/utils/src/types.rs delete mode 100644 earthly/rust/example/utils/tests/resources/test_config.toml delete mode 100644 earthly/rust/example/utils/tests/test_config.rs create mode 100755 earthly/rust/scripts/std_build.sh diff --git a/earthly/rust/.cargo/config.toml b/earthly/rust/.cargo/config.toml index 003b6526b..e1c67e409 100644 --- a/earthly/rust/.cargo/config.toml +++ b/earthly/rust/.cargo/config.toml @@ -85,6 +85,24 @@ panic = 'unwind' incremental = false codegen-units = 16 +[profile.test] +opt-level = 3 +debug = true +lto = false +debug-assertions = true +incremental = true +codegen-units = 256 + +[profile.bench] +opt-level = 3 +debug = false +debug-assertions = false +overflow-checks = false +lto = true +incremental = false +codegen-units = 16 + + [alias] lint = "clippy -- -D warnings -D clippy::pedantic -D clippy::unwrap_used -D clippy::expect_used -D clippy::exit -D clippy::get_unwrap -D clippy::index_refutable_slice -D clippy::indexing_slicing -D clippy::match_on_vec_items -D clippy::match_wild_err_arm -D clippy::missing_panics_doc -D clippy::panic -D clippy::string_slice -D clippy::unchecked_duration_subtraction -D clippy::unreachable -D clippy::missing_docs_in_private_items" lintfix = "clippy -- -D warnings -D clippy::pedantic -D clippy::unwrap_used -D clippy::expect_used -D clippy::exit -D clippy::get_unwrap -D clippy::index_refutable_slice -D clippy::indexing_slicing -D clippy::match_on_vec_items -D clippy::match_wild_err_arm -D clippy::missing_panics_doc -D clippy::panic -D clippy::string_slice -D clippy::unchecked_duration_subtraction -D clippy::unreachable" diff --git a/earthly/rust/Earthfile b/earthly/rust/Earthfile index 2adaec2f8..5e56ebd09 100644 --- a/earthly/rust/Earthfile +++ b/earthly/rust/Earthfile @@ -129,26 +129,6 @@ CHECK: # This imporvies visibility into all issues that need to be corrected for `check` # to pass without needing to iterate excessively. RUN /scripts/std_checks.sh - - #diff .cargo/config.toml .stdconfig/.cargo/config.toml; \ - # cargo_config_chk_failed=$?; \ - # if [ "$cargo_config_chk_failed" -ne 0 ]; then \ - # echo ".cargo/config.toml has diverged from standard verstion."; \ - # fi; \ - # \ - # cargo +nightly fmtchk; \ - # fmt_chk_failed=$?; \ - # if [ "$fmt_chk_failed" -ne 0 ]; then \ - # echo "cargo fmt: failed"; \ - # fi; \ - # \ - # cargo machete; \ - # unused_crate_dependency_check_failed=$?; \ - # \ - # cargo modules generate --help; \ - # \ - # if [ "$unused_crate_dependency_check_failed" -ne 0 ]; then echo "cargo machete: failed"; fi; \ - # exit $(($fmt_chk_failed || $unused_crate_dependency_check_failed)) # Set up our target toolchains, and copy our files. builder: @@ -156,7 +136,7 @@ builder: DO +SETUP --toolchain=example/rust-toolchain.toml - DO +CP_SRC --src="example/cli example/core example/src example/tests example/utils example/Cargo.* rustfmt.toml .cargo" + DO +CP_SRC --src="example/src example/tests example/benches example/Cargo.* example/rustfmt.toml example/.cargo" # Test rust build container - Use best architecture host tools. check-hosted: @@ -184,41 +164,37 @@ check: check-all-hosts: BUILD --platform=linux/amd64 --platform=linux/arm64 +check-hosted - -build: +build-hosted: # Build the service - FROM +rust-base + FROM +builder - DO +SETUP --toolchain=example/rust-toolchain.toml - - DO +CP_SRC --src="example/cli example/core example/src example/tests example/utils example/Cargo.* rustfmt.toml .cargo" - - DO +COPY_SRC - - RUN cargo build --release --workspace --locked; \ - build_failed=$?; \ - cargo lint; \ - lint_failed=$?; \ - cargo docs; \ - docs_failed=$?; \ - exit $(($build_failed || $lint_failed || $docs_failed)) - - # Run rust tests. - FROM +build - - COPY --dir .config . - - # Cargo nextest creates a test artifact. TODO: Work out how to publish it (even if test run fails). - RUN cargo testci; \ - testci_failed=$?; \ - cargo testdocs; \ - testdocs_failed=$?; \ - exit $(($testci_failed || $testdocs_failed)) - + RUN /scripts/std_build.sh + # TODO use the correct target arch here. RUN ldd target/x86_64-unknown-linux-musl/release/cat-gateway RUN readelf -p .comment target/x86_64-unknown-linux-musl/release/cat-gateway RUN strip -v target/x86_64-unknown-linux-musl/release/cat-gateway SAVE ARTIFACT target/x86_64-unknown-linux-musl/doc doc SAVE ARTIFACT target/x86_64-unknown-linux-musl/release/cat-gateway cat-gateway + +# Run build using the most efficient host tooling +# CI Automated Entry point. +build: + FROM busybox + # This is necessary to pick the correct architecture build to suit the native machine. + # It primarily ensures that Darwin/Arm builds work as expected without needing x86 emulation. + # All target implementation of this should follow this pattern. + ARG USERARCH + + IF [ "$USERARCH" == "arm64" ] + BUILD --platform=linux/arm64 +build-hosted + ELSE + BUILD --platform=linux/amd64 +build-hosted + END + + +# Test which runs check with all supported host tooling. Needs qemu or rosetta to run. +# Only used to validate tooling is working across host toolsets. +build-all-hosts: + BUILD --platform=linux/amd64 --platform=linux/arm64 +build-hosted diff --git a/earthly/rust/example/.cargo/config.toml b/earthly/rust/example/.cargo/config.toml new file mode 100644 index 000000000..e1c67e409 --- /dev/null +++ b/earthly/rust/example/.cargo/config.toml @@ -0,0 +1,127 @@ +# Use MOLD linker where possible, but ONLY in CI applicable targets. +# cspell: words rustflags armv gnueabihf msvc nextest idents rustdocflags rustdoc lintfix lintrestrict testfast testdocs + +# Configure how Docker container targets build. + +# If you want to customize these targets for a local build, then customize them in you: +# $CARGO_HOME/config.toml +# NOT in the project itself. +# These targets are ONLY the targets used by CI and inside docker builds. + +# DO NOT remove `"-C", "target-feature=+crt-static"` from the rustflags for these targets. + +# Should be the default to have fully static rust programs in CI +[target.x86_64-unknown-linux-musl] +linker = "clang" +rustflags = [ + "-C", "link-arg=-fuse-ld=/usr/bin/mold", + "-C", "target-feature=+crt-static" +] + +# Should be the default to have fully static rust programs in CI +[target.aarch64-unknown-linux-musl] +linker = "clang" +rustflags = [ + "-C", "link-arg=-fuse-ld=/usr/bin/mold", + "-C", "target-feature=+crt-static" +] + + +[build] + +rustflags = [ + "-D", + "warnings", + "-D", + "missing_docs", + "-D", + "let_underscore_drop", + "-D", + "non_ascii_idents", + "-D", + "single_use_lifetimes", + "-D", + "trivial_casts", + "-D", + "trivial_numeric_casts", +] + +rustdocflags = [ + "-D", + "warnings", + "-D", + "missing_docs", + "-D", + "rustdoc::broken_intra_doc_links", + "-D", + "rustdoc::invalid_codeblock_attributes", + "-D", + "rustdoc::invalid_html_tags", + "-D", + "rustdoc::invalid_rust_codeblocks", + "-D", + "rustdoc::bare_urls", + "-D", + "rustdoc::unescaped_backticks", +] + +[profile.dev] +opt-level = 1 +debug = true +debug-assertions = true +overflow-checks = true +lto = false +panic = 'unwind' +incremental = true +codegen-units = 256 + +[profile.release] +opt-level = 3 +debug = false +debug-assertions = false +overflow-checks = false +lto = true +panic = 'unwind' +incremental = false +codegen-units = 16 + +[profile.test] +opt-level = 3 +debug = true +lto = false +debug-assertions = true +incremental = true +codegen-units = 256 + +[profile.bench] +opt-level = 3 +debug = false +debug-assertions = false +overflow-checks = false +lto = true +incremental = false +codegen-units = 16 + + +[alias] +lint = "clippy -- -D warnings -D clippy::pedantic -D clippy::unwrap_used -D clippy::expect_used -D clippy::exit -D clippy::get_unwrap -D clippy::index_refutable_slice -D clippy::indexing_slicing -D clippy::match_on_vec_items -D clippy::match_wild_err_arm -D clippy::missing_panics_doc -D clippy::panic -D clippy::string_slice -D clippy::unchecked_duration_subtraction -D clippy::unreachable -D clippy::missing_docs_in_private_items" +lintfix = "clippy -- -D warnings -D clippy::pedantic -D clippy::unwrap_used -D clippy::expect_used -D clippy::exit -D clippy::get_unwrap -D clippy::index_refutable_slice -D clippy::indexing_slicing -D clippy::match_on_vec_items -D clippy::match_wild_err_arm -D clippy::missing_panics_doc -D clippy::panic -D clippy::string_slice -D clippy::unchecked_duration_subtraction -D clippy::unreachable" +lintrestrict = "clippy -- -D warnings -D clippy::pedantic -D clippy::restriction -D clippy::missing_docs_in_private_items" +lint-vscode = "clippy --workspace --message-format=json-diagnostic-rendered-ansi --all-targets -- -D warnings -D clippy::pedantic -D clippy::unwrap_used -D clippy::expect_used -D clippy::exit -D clippy::get_unwrap -D clippy::index_refutable_slice -D clippy::indexing_slicing -D clippy::match_on_vec_items -D clippy::match_wild_err_arm -D clippy::missing_panics_doc -D clippy::panic -D clippy::string_slice -D clippy::unchecked_duration_subtraction -D clippy::unreachable -D clippy::missing_docs_in_private_items" + +docs = "doc --workspace -r --all-features --no-deps --bins --document-private-items --examples --locked" +# nightly docs build broken... when they are'nt we can enable these docs... --unit-graph --timings=html,json -Z unstable-options" +testfast = "nextest run --release --workspace --locked" +testci = "nextest run --release --workspace --locked -P ci" +testdocs = "test --doc --release --workspace --locked --doc" + +# Rust formatting, MUST be run with +nightly +fmtchk = "fmt -- --check -v --color=always" +fmtfix = "fmt -- -v" + +[term] +quiet = false # whether cargo output is quiet +verbose = true # whether cargo provides verbose output +color = 'always' # whether cargo colorizes output use `CARGO_TERM_COLOR="off"` to disable. +progress.when = 'auto' # whether cargo shows progress bar +progress.width = 80 # width of progress bar diff --git a/earthly/rust/example/Cargo.lock b/earthly/rust/example/Cargo.lock index 83c14ca39..f2f8c892f 100644 --- a/earthly/rust/example/Cargo.lock +++ b/earthly/rust/example/Cargo.lock @@ -2,105 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "aho-corasick" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" -dependencies = [ - "memchr", -] - -[[package]] -name = "anstream" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" - -[[package]] -name = "anstyle-parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" -dependencies = [ - "windows-sys 0.48.0", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" -dependencies = [ - "anstyle", - "windows-sys 0.48.0", -] - -[[package]] -name = "arc-swap" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" - -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - -[[package]] -name = "assert_cmd" -version = "2.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88903cb14723e4d4003335bb7f8a14f27691649105346a0f0957466c096adfe6" -dependencies = [ - "anstyle", - "bstr", - "doc-comment", - "predicates 3.0.4", - "predicates-core", - "predicates-tree", - "wait-timeout", -] - [[package]] name = "atty" version = "0.2.14" @@ -118,72 +19,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "backtrace" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "better-panic" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fa9e1d11a268684cbd90ed36370d7577afb6c62d912ddff5c15fc34343e5036" -dependencies = [ - "backtrace", - "console", -] - [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array", -] - -[[package]] -name = "bstr" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c79ad7fb2dd38f3dabd76b09c6a5a20c038fc0213ef1e9afd30eb777f120f019" -dependencies = [ - "memchr", - "regex-automata", - "serde 1.0.190", -] - -[[package]] -name = "cc" -version = "1.0.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - [[package]] name = "clap" version = "3.2.25" @@ -192,37 +33,13 @@ checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", "bitflags", - "clap_derive", "clap_lex", - "indexmap 1.9.3", - "once_cell", + "indexmap", "strsim", "termcolor", "textwrap", ] -[[package]] -name = "clap_complete" -version = "3.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f7a2e0a962c45ce25afce14220bc24f9dade0a1787f185cecf96bfba7847cd8" -dependencies = [ - "clap", -] - -[[package]] -name = "clap_derive" -version = "3.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "clap_lex" version = "0.2.4" @@ -232,213 +49,6 @@ dependencies = [ "os_str_bytes", ] -[[package]] -name = "cli" -version = "2.0.0-beta" -dependencies = [ - "assert_cmd", - "clap", - "clap_complete", - "core", - "predicates 2.1.5", - "utils", -] - -[[package]] -name = "colorchoice" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" - -[[package]] -name = "config" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1b9d958c2b1368a663f05538fc1b5975adce1e19f435acceae987aceeeb369" -dependencies = [ - "lazy_static", - "nom", - "rust-ini", - "serde 1.0.190", - "serde-hjson", - "serde_json", - "toml 0.5.11", - "yaml-rust", -] - -[[package]] -name = "console" -version = "0.15.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" -dependencies = [ - "encode_unicode", - "lazy_static", - "libc", - "windows-sys 0.45.0", -] - -[[package]] -name = "core" -version = "2.0.0-beta" -dependencies = [ - "log", - "rand", - "utils", -] - -[[package]] -name = "cpufeatures" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fbc60abd742b35f2492f808e1abbb83d45f72db402e14c55057edc9c7b1e9e4" -dependencies = [ - "libc", -] - -[[package]] -name = "crossbeam-channel" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "crypto-mac" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" -dependencies = [ - "generic-array", - "subtle", -] - -[[package]] -name = "deranged" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" -dependencies = [ - "powerfmt", -] - -[[package]] -name = "difflib" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" - -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "dirs-next" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" -dependencies = [ - "cfg-if", - "dirs-sys-next", -] - -[[package]] -name = "dirs-sys-next" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - -[[package]] -name = "doc-comment" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" - -[[package]] -name = "either" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" - -[[package]] -name = "encode_unicode" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "error-chain" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" -dependencies = [ - "version_check", -] - -[[package]] -name = "float-cmp" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" -dependencies = [ - "num-traits 0.2.17", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.11.0+wasi-snapshot-preview1", -] - -[[package]] -name = "gimli" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" - [[package]] name = "hashbrown" version = "0.12.3" @@ -446,16 +56,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] -name = "hashbrown" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +name = "hello_world" +version = "0.1.0" +dependencies = [ + "clap", +] [[package]] name = "hermit-abi" @@ -466,32 +71,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hmac" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" -dependencies = [ - "crypto-mac", - "digest", -] - -[[package]] -name = "human-panic" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b82da652938b83f94cfdaaf9ae7aaadb8430d84b0dfda226998416318727eac2" -dependencies = [ - "anstream", - "anstyle", - "backtrace", - "os_info", - "serde 1.0.190", - "serde_derive", - "toml 0.7.8", - "uuid 1.5.0", -] - [[package]] name = "indexmap" version = "1.9.3" @@ -499,882 +78,65 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", - "hashbrown 0.12.3", + "hashbrown", ] [[package]] -name = "indexmap" -version = "2.0.2" +name = "libc" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown 0.14.2", -] +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] -name = "itertools" -version = "0.10.5" +name = "os_str_bytes" +version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] -name = "itertools" -version = "0.11.0" +name = "strsim" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" -dependencies = [ - "either", -] +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] -name = "itoa" -version = "1.0.9" +name = "termcolor" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" +dependencies = [ + "winapi-util", +] [[package]] -name = "lazy_static" -version = "1.4.0" +name = "textwrap" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] -name = "lexical-core" -version = "0.7.6" +name = "winapi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ - "arrayvec", - "bitflags", - "cfg-if", - "ryu", - "static_assertions", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] -name = "libc" -version = "0.2.149" +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] -name = "libsystemd" -version = "0.4.1" +name = "winapi-util" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f4f0b5b062ba67aa075e331de778082c09e66b5ef32970ea5a1e9c37c9555d1" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ - "hmac", - "libc", - "log", - "nix", - "once_cell", - "serde 1.0.190", - "sha2", - "thiserror", - "uuid 0.8.2", -] - -[[package]] -name = "linked-hash-map" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] - -[[package]] -name = "miniz_oxide" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" -dependencies = [ - "adler", -] - -[[package]] -name = "nix" -version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" -dependencies = [ - "bitflags", - "cc", - "cfg-if", - "libc", - "memoffset", -] - -[[package]] -name = "nom" -version = "5.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08959a387a676302eebf4ddbcbc611da04285579f76f88ee0506c63b1a61dd4b" -dependencies = [ - "lexical-core", - "memchr", - "version_check", -] - -[[package]] -name = "normalize-line-endings" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" - -[[package]] -name = "num-traits" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" -dependencies = [ - "num-traits 0.2.17", -] - -[[package]] -name = "num-traits" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_threads" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" -dependencies = [ - "libc", -] - -[[package]] -name = "object" -version = "0.32.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" -dependencies = [ - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - -[[package]] -name = "os_info" -version = "3.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "006e42d5b888366f1880eda20371fedde764ed2213dc8496f49622fa0c99cd5e" -dependencies = [ - "log", - "serde 1.0.190", - "winapi", -] - -[[package]] -name = "os_str_bytes" -version = "6.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" - -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - -[[package]] -name = "predicates" -version = "2.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59230a63c37f3e18569bdb90e4a89cbf5bf8b06fea0b84e65ea10cc4df47addd" -dependencies = [ - "difflib", - "float-cmp", - "itertools 0.10.5", - "normalize-line-endings", - "predicates-core", - "regex", -] - -[[package]] -name = "predicates" -version = "3.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dfc28575c2e3f19cb3c73b93af36460ae898d426eba6fc15b9bd2a5220758a0" -dependencies = [ - "anstyle", - "difflib", - "itertools 0.11.0", - "predicates-core", -] - -[[package]] -name = "predicates-core" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" - -[[package]] -name = "predicates-tree" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" -dependencies = [ - "predicates-core", - "termtree", -] - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags", -] - -[[package]] -name = "redox_users" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" -dependencies = [ - "getrandom", - "redox_syscall", - "thiserror", -] - -[[package]] -name = "regex" -version = "1.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" - -[[package]] -name = "rust-example" -version = "0.0.1" -dependencies = [ - "assert_cmd", - "better-panic", - "cli", - "human-panic", - "predicates 2.1.5", - "utils", -] - -[[package]] -name = "rust-ini" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2" - -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - -[[package]] -name = "rustversion" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "serde" -version = "0.8.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8" - -[[package]] -name = "serde" -version = "1.0.190" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde-hjson" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a3a4e0ea8a88553209f6cc6cfe8724ecad22e1acf372793c27d995290fe74f8" -dependencies = [ - "lazy_static", - "num-traits 0.1.43", - "regex", - "serde 0.8.23", -] - -[[package]] -name = "serde_derive" -version = "1.0.190" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde 1.0.190", -] - -[[package]] -name = "serde_spanned" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80" -dependencies = [ - "serde 1.0.190", -] - -[[package]] -name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" -dependencies = [ - "block-buffer", - "cfg-if", - "cpufeatures", - "digest", - "opaque-debug", -] - -[[package]] -name = "slog" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8347046d4ebd943127157b94d63abb990fcf729dc4e9978927fdf4ac3c998d06" - -[[package]] -name = "slog-async" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72c8038f898a2c79507940990f05386455b3a317d8f18d4caea7cbc3d5096b84" -dependencies = [ - "crossbeam-channel", - "slog", - "take_mut", - "thread_local", -] - -[[package]] -name = "slog-journald" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83e14eb8c2f5d0c8fc9fbac40e6391095e4dc5cb334f7dce99c75cb1919eb39c" -dependencies = [ - "libsystemd", - "slog", -] - -[[package]] -name = "slog-scope" -version = "4.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f95a4b4c3274cd2869549da82b57ccc930859bdbf5bcea0424bc5f140b3c786" -dependencies = [ - "arc-swap", - "lazy_static", - "slog", -] - -[[package]] -name = "slog-stdlog" -version = "4.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6706b2ace5bbae7291d3f8d2473e2bfab073ccd7d03670946197aec98471fa3e" -dependencies = [ - "log", - "slog", - "slog-scope", -] - -[[package]] -name = "slog-syslog" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28ba6ff50243a331b924a840dc079c2958d3f053f624766ca9311f11a67da548" -dependencies = [ - "slog", - "syslog", -] - -[[package]] -name = "slog-term" -version = "2.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87d29185c55b7b258b4f120eab00f48557d4d9bc814f41713f449d35b0f8977c" -dependencies = [ - "atty", - "slog", - "term", - "thread_local", - "time 0.3.30", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "subtle" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syslog" -version = "5.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a5d8ef1b679c07976f3ee336a436453760c470f54b5e7237556728b8589515d" -dependencies = [ - "error-chain", - "libc", - "log", - "time 0.1.45", -] - -[[package]] -name = "take_mut" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" - -[[package]] -name = "term" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" -dependencies = [ - "dirs-next", - "rustversion", - "winapi", -] - -[[package]] -name = "termcolor" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "termtree" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" - -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - -[[package]] -name = "thiserror" -version = "1.0.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "thread_local" -version = "1.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" -dependencies = [ - "cfg-if", - "once_cell", -] - -[[package]] -name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - -[[package]] -name = "time" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" -dependencies = [ - "deranged", - "itoa", - "libc", - "num_threads", - "powerfmt", - "serde 1.0.190", - "time-core", - "time-macros", -] - -[[package]] -name = "time-core" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" - -[[package]] -name = "time-macros" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" -dependencies = [ - "time-core", -] - -[[package]] -name = "toml" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde 1.0.190", -] - -[[package]] -name = "toml" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" -dependencies = [ - "serde 1.0.190", - "serde_spanned", - "toml_datetime", - "toml_edit", -] - -[[package]] -name = "toml_datetime" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" -dependencies = [ - "serde 1.0.190", -] - -[[package]] -name = "toml_edit" -version = "0.19.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" -dependencies = [ - "indexmap 2.0.2", - "serde 1.0.190", - "serde_spanned", - "toml_datetime", - "winnow", -] - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "utf8parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" - -[[package]] -name = "utils" -version = "2.0.0-beta" -dependencies = [ - "backtrace", - "clap", - "config", - "lazy_static", - "log", - "serde 1.0.190", - "slog", - "slog-async", - "slog-journald", - "slog-scope", - "slog-stdlog", - "slog-syslog", - "slog-term", - "thiserror", -] - -[[package]] -name = "uuid" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" -dependencies = [ - "serde 1.0.190", -] - -[[package]] -name = "uuid" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc" -dependencies = [ - "getrandom", -] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wait-timeout" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" -dependencies = [ - "libc", -] - -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" -dependencies = [ - "winapi", + "winapi", ] [[package]] @@ -1382,153 +144,3 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - -[[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-targets" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - -[[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", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - -[[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_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - -[[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_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - -[[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_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" - -[[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_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "winnow" -version = "0.5.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c" -dependencies = [ - "memchr", -] - -[[package]] -name = "yaml-rust" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" -dependencies = [ - "linked-hash-map", -] diff --git a/earthly/rust/example/Cargo.toml b/earthly/rust/example/Cargo.toml index 4bda6029d..c130e5743 100644 --- a/earthly/rust/example/Cargo.toml +++ b/earthly/rust/example/Cargo.toml @@ -1,69 +1,16 @@ [package] -name = "rust-example" -version = "0.0.1" -authors = ["Abid Omar ", "Steven Johnson "] -edition = "2021" -repository = "https://github.com/input-output-hk/catalyst-ci" -readme = "README.md" -license = "MIT" -keywords = ["cli"] -description = """ -Example Rust program to test CI/CD and serve as a working example. -""" - -[workspace] -members = [ - "utils", - "cli", - "core", -] - -[features] -nightly = ["utils/nightly"] -termlog = ["utils/termlog"] -journald = ["utils/journald"] -syslog = ["utils/syslog"] +name = "hello_world" +version = "0.1.0" +edition = "2018" [dependencies] -utils = { path = "utils" } -cli = { path = "cli"} -# core = { path = "core" } -human-panic = "1.0.3" -better-panic = "0.3.0" -# log = "0.4.14" +clap = "3.0" [dev-dependencies] -assert_cmd = "2.0.4" -predicates = "2.1.1" - -[profile.dev] -opt-level=0 -debug = true -rpath = false -lto = false -debug-assertions = true -codegen-units = 4 - -[profile.release] -opt-level=3 -debug = false -rpath = false -lto = true -debug-assertions = false -codegen-units = 1 -[profile.test] -opt-level = 1 -debug = true -rpath = false -lto = false -debug-assertions = true -codegen-units = 4 +[[test]] +name = "integration_test" +harness = false -[profile.bench] -opt-level = 3 -debug = false -rpath = false -lto = true -debug-assertions = false -codegen-units = 1 +[[bench]] +name = "benchmark" diff --git a/earthly/rust/example/LICENSE b/earthly/rust/example/LICENSE deleted file mode 100644 index 3562ace0c..000000000 --- a/earthly/rust/example/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2019 Abid Omar - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/earthly/rust/example/README.md b/earthly/rust/example/README.md index 2ded8bae7..81a6e9a14 100644 --- a/earthly/rust/example/README.md +++ b/earthly/rust/example/README.md @@ -2,6 +2,3 @@ This is an simple but hopefully full featured example rust project. It is used to test both our Catalyst-CI Rust building infrastructure and serve as a template for its use. - -This code was originally sourced from: ["rust-starter](https://rust-starter.github.io/). -The code in this repo has been adapted for our needs. diff --git a/earthly/rust/example/benches/benchmark.rs b/earthly/rust/example/benches/benchmark.rs new file mode 100644 index 000000000..13af049e6 --- /dev/null +++ b/earthly/rust/example/benches/benchmark.rs @@ -0,0 +1,14 @@ +// benches/benchmark.rs +#[cfg(test)] +mod benches { + use test::Bencher; + + use super::*; + + #[bench] + fn benchmark_hello_world(b: &mut Bencher) { + b.iter(|| { + main(); + }); + } +} diff --git a/earthly/rust/example/cli/Cargo.toml b/earthly/rust/example/cli/Cargo.toml deleted file mode 100644 index fbb512099..000000000 --- a/earthly/rust/example/cli/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "cli" -version = "2.0.0-beta" -authors = ["Abid Omar "] -description = "CLI interface for rust-starter" -edition = "2021" - -[dependencies] -utils = { path = "../utils" } -core = { path = "../core" } -clap_complete = "3.0" - -[dependencies.clap] -version = "3.0.14" -features = ["cargo", "derive"] - -[dev-dependencies] -assert_cmd = "2.0.4" -predicates = "2.1.1" diff --git a/earthly/rust/example/cli/src/lib.rs b/earthly/rust/example/cli/src/lib.rs deleted file mode 100644 index fa006e88e..000000000 --- a/earthly/rust/example/cli/src/lib.rs +++ /dev/null @@ -1,118 +0,0 @@ -use core::commands; -use std::{path::PathBuf, str::FromStr}; - -use clap::{AppSettings, IntoApp, Parser, Subcommand}; -use clap_complete::{ - generate, - shells::{Bash, Fish, Zsh}, -}; -use utils::{app_config::AppConfig, error::Result, types::LogLevel}; - -#[derive(Parser, Debug)] -#[clap( - name = "rust-starter", - author, - about, - long_about = "Rust Starter CLI", - version -)] -#[clap(setting = AppSettings::SubcommandRequired)] -#[clap(global_setting(AppSettings::DeriveDisplayOrder))] -pub struct Cli { - /// Set a custom config file - #[clap(short, long, parse(from_os_str), value_name = "FILE")] - pub config: Option, - - /// Set a custom config file - #[clap(name = "debug", short, long = "debug", value_name = "DEBUG")] - pub debug: Option, - - /// Set Log Level - #[clap( - name = "log_level", - short, - long = "log-level", - value_name = "LOG_LEVEL" - )] - pub log_level: Option, - - /// Subcommands - #[clap(subcommand)] - command: Commands, -} - -#[derive(Subcommand, Debug)] -enum Commands { - #[clap( - name = "hazard", - about = "Generate a hazardous occurrence", - long_about = None, - )] - Hazard, - #[clap( - name = "error", - about = "Simulate an error", - long_about = None, - )] - Error, - #[clap( - name = "completion", - about = "Generate completion scripts", - long_about = None, - )] - Completion { - #[clap(subcommand)] - subcommand: CompletionSubcommand, - }, - #[clap( - name = "config", - about = "Show Configuration", - long_about = None, - )] - Config, -} - -#[derive(Subcommand, PartialEq, Debug)] -enum CompletionSubcommand { - #[clap(about = "generate the autocompletion script for bash")] - Bash, - #[clap(about = "generate the autocompletion script for zsh")] - Zsh, - #[clap(about = "generate the autocompletion script for fish")] - Fish, -} - -pub fn cli_match() -> Result<()> { - // Parse the command line arguments - let cli = Cli::parse(); - - // Merge clap config file if the value is set - AppConfig::merge_config(cli.config.as_deref())?; - - let app = Cli::into_app(); - - AppConfig::merge_args(app)?; - - // Execute the subcommand - match &cli.command { - Commands::Hazard => commands::hazard()?, - Commands::Error => commands::simulate_error()?, - Commands::Completion { subcommand } => { - let mut app = Cli::into_app(); - match subcommand { - CompletionSubcommand::Bash => { - generate(Bash, &mut app, "rust-starter", &mut std::io::stdout()); - }, - CompletionSubcommand::Zsh => { - generate(Zsh, &mut app, "rust-starter", &mut std::io::stdout()); - }, - CompletionSubcommand::Fish => { - generate(Fish, &mut app, "rust-starter", &mut std::io::stdout()); - }, - } - }, - Commands::Config => commands::config()?, - } - - Ok(()) -} diff --git a/earthly/rust/example/core/Cargo.toml b/earthly/rust/example/core/Cargo.toml deleted file mode 100644 index d4eddb562..000000000 --- a/earthly/rust/example/core/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "core" -version = "2.0.0-beta" -authors = ["Abid Omar "] -description = "The application core code" -edition = "2021" - -[dependencies] -utils = { path = "../utils" } - -rand = "0.8.4" -log = "0.4.14" diff --git a/earthly/rust/example/core/benches/01_default.rs b/earthly/rust/example/core/benches/01_default.rs deleted file mode 100644 index f116acc01..000000000 --- a/earthly/rust/example/core/benches/01_default.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![feature(test)] - -extern crate core; -extern crate test; - -use core::hazard; - -use test::Bencher; - -#[bench] -fn bench_hazard(b: &mut Bencher) { - b.iter(|| { - hazard::generate_hazard().unwrap(); - }) -} diff --git a/earthly/rust/example/core/src/commands.rs b/earthly/rust/example/core/src/commands.rs deleted file mode 100644 index e59258ed7..000000000 --- a/earthly/rust/example/core/src/commands.rs +++ /dev/null @@ -1,37 +0,0 @@ -use utils::{app_config::AppConfig, error::Result}; - -use super::{error, hazard}; - -/// Show the configuration file -pub fn hazard() -> Result<()> { - // Generate, randomly, True or False - let random_hazard: bool = hazard::generate_hazard()?; - - if random_hazard { - println!("You got it right!"); - } else { - println!("You got it wrong!"); - } - - Ok(()) -} - -/// Show the configuration file -pub fn config() -> Result<()> { - let config = AppConfig::fetch()?; - println!("{:#?}", config); - - Ok(()) -} - -/// Simulate an error -pub fn simulate_error() -> Result<()> { - // Log this Error simulation - info!("We are simulating an error"); - - // Simulate an error - error::simulate_error()?; - - // We should never get here... - Ok(()) -} diff --git a/earthly/rust/example/core/src/error.rs b/earthly/rust/example/core/src/error.rs deleted file mode 100644 index 5e8fae129..000000000 --- a/earthly/rust/example/core/src/error.rs +++ /dev/null @@ -1,12 +0,0 @@ -use std::fs::File; - -use utils::error::Result; - -/// Return, randomly, true or false -pub fn simulate_error() -> Result<()> { - log::error!("Simulating error"); - // Trigger an error - File::open("thisfiledoesnotexist")?; - - Ok(()) -} diff --git a/earthly/rust/example/core/src/hazard.rs b/earthly/rust/example/core/src/hazard.rs deleted file mode 100644 index 6d48175cf..000000000 --- a/earthly/rust/example/core/src/hazard.rs +++ /dev/null @@ -1,6 +0,0 @@ -use utils::error::Result; - -/// Return, randomly, true or false -pub fn generate_hazard() -> Result { - Ok(rand::random()) -} diff --git a/earthly/rust/example/core/src/lib.rs b/earthly/rust/example/core/src/lib.rs deleted file mode 100644 index d68f8c166..000000000 --- a/earthly/rust/example/core/src/lib.rs +++ /dev/null @@ -1,14 +0,0 @@ -#[macro_use] -extern crate log; - -pub mod commands; -pub mod error; -pub mod hazard; - -use utils::error::Result; - -pub fn start() -> Result<()> { - // does nothing - - Ok(()) -} diff --git a/earthly/rust/example/src/main.rs b/earthly/rust/example/src/main.rs index 2466293f4..b505b53c9 100644 --- a/earthly/rust/example/src/main.rs +++ b/earthly/rust/example/src/main.rs @@ -1,37 +1,31 @@ -#[cfg(not(debug_assertions))] -use human_panic::setup_panic; - -#[cfg(debug_assertions)] -extern crate better_panic; - -use utils::{app_config::AppConfig, error::Result}; - -/// The main entry point of the application. -fn main() -> Result<()> { - // Human Panic. Only enabled when *not* debugging. - #[cfg(not(debug_assertions))] - { - setup_panic!(); - } - - // Better Panic. Only enabled *when* debugging. - #[cfg(debug_assertions)] - { - better_panic::Settings::debug() - .most_recent_first(false) - .lineno_suffix(true) - .verbosity(better_panic::Verbosity::Full) - .install(); +// src/main.rs +use clap::{App, Arg}; + +fn main() { + let matches = App::new("Hello, World!") + .version("1.0") + .arg( + Arg::with_name("version") + .short('v') + .long("version") + .help("Print the program version"), + ) + .get_matches(); + + if matches.is_present("version") { + println!("Hello, World! v1.0"); + return; } - let _guard = utils::logger::setup_logging()?; - - // Initialize Configuration - let config_contents = include_str!("resources/default_config.toml"); - AppConfig::init(Some(config_contents))?; + println!("Hello, World!"); +} - // Match Commands - cli::cli_match()?; +#[cfg(test)] +mod tests { + use super::*; - Ok(()) + #[test] + fn test_hello_world() { + assert_eq!(main(), ()); + } } diff --git a/earthly/rust/example/src/resources/default_config.toml b/earthly/rust/example/src/resources/default_config.toml deleted file mode 100644 index 2efa81eb8..000000000 --- a/earthly/rust/example/src/resources/default_config.toml +++ /dev/null @@ -1,5 +0,0 @@ -debug = false -log_level = "info" - -[database] -url = "custom database url" diff --git a/earthly/rust/example/tests/integration_test.rs b/earthly/rust/example/tests/integration_test.rs new file mode 100644 index 000000000..7d01f8866 --- /dev/null +++ b/earthly/rust/example/tests/integration_test.rs @@ -0,0 +1,10 @@ +// tests/integration_test.rs +#[cfg(test)] +mod integration_tests { + use super::*; + + #[test] + fn test_hello_world() { + assert_eq!(main(), ()); + } +} diff --git a/earthly/rust/example/tests/test_cli.rs b/earthly/rust/example/tests/test_cli.rs deleted file mode 100644 index 9bd86d3e4..000000000 --- a/earthly/rust/example/tests/test_cli.rs +++ /dev/null @@ -1,35 +0,0 @@ -#[cfg(test)] -extern crate assert_cmd; -extern crate predicates; - -use std::process::Command; - -use assert_cmd::prelude::*; -use predicates::prelude::*; - -#[test] -fn test_cli() { - let mut cmd = Command::cargo_bin("rust-starter").expect("Calling binary failed"); - cmd.assert().failure(); -} - -#[test] -fn test_version() { - let expected_version = "rust-starter 2.0.0-beta\n"; - let mut cmd = Command::cargo_bin("rust-starter").expect("Calling binary failed"); - cmd.arg("--version").assert().stdout(expected_version); -} - -#[test] -fn test_hazard_exit_code() { - let mut cmd = Command::cargo_bin("rust-starter").expect("Calling binary failed"); - cmd.arg("hazard").assert().code(0); -} - -#[test] -fn test_hazard_stdout() { - let hazard_predicate = - predicate::function(|x: &str| x == "You got it right!\n" || x == "You got it wrong!\n"); - let mut cmd = Command::cargo_bin("rust-starter").expect("Calling binary failed"); - cmd.arg("hazard").assert().stdout(hazard_predicate); -} diff --git a/earthly/rust/example/utils/Cargo.toml b/earthly/rust/example/utils/Cargo.toml deleted file mode 100644 index 37e351cc8..000000000 --- a/earthly/rust/example/utils/Cargo.toml +++ /dev/null @@ -1,29 +0,0 @@ -[package] -name = "utils" -version = "2.0.0-beta" -authors = ["Abid Omar "] -description = "Various utilities and functionalities" -edition = "2021" - -[features] -nightly = [] -termlog = [] -syslog = [] -journald = [] - -[dependencies] -thiserror = "1.0.30" -backtrace = "0.3.64" -# color-backtrace = "0.5.1" -config = "0.11.0" -lazy_static = "1.4.0" -slog = "2.7.0" -slog-syslog = "0.13.0" -slog-term = "2.8.0" -slog-scope = "4.4.0" -slog-async = "2.7.0" -slog-stdlog = "4.1.0" -slog-journald = "2.2.0" -clap = "3.0.14" -log = "0.4.14" -serde = { version = "1.0.136", features = ["derive"] } diff --git a/earthly/rust/example/utils/src/app_config.rs b/earthly/rust/example/utils/src/app_config.rs deleted file mode 100644 index ce7d1dffb..000000000 --- a/earthly/rust/example/utils/src/app_config.rs +++ /dev/null @@ -1,111 +0,0 @@ -use std::{path::Path, sync::RwLock}; - -use config::{Config, Environment}; -use lazy_static::{__Deref, lazy_static}; -use serde::{Deserialize, Serialize}; - -use super::error::Result; -use crate::types::LogLevel; - -// CONFIG static variable. It's actually an AppConfig -// inside an RwLock. -lazy_static! { - pub static ref CONFIG: RwLock = RwLock::new(Config::new()); -} - -#[derive(Debug, Serialize, Deserialize)] -pub struct Database { - pub url: String, -} - -#[derive(Debug, Serialize, Deserialize)] -pub struct AppConfig { - pub debug: bool, - pub log_level: LogLevel, - pub database: Database, -} - -impl AppConfig { - /// Initialize AppConfig. - pub fn init(default_config: Option<&str>) -> Result<()> { - let mut settings = Config::new(); - - // Embed file into executable - // This macro will embed the configuration file into the - // executable. Check include_str! for more info. - if let Some(config_contents) = default_config { - // let contents = include_str!(config_file_path); - settings.merge(config::File::from_str( - config_contents, - config::FileFormat::Toml, - ))?; - } - - // Merge settings with env variables - settings.merge(Environment::with_prefix("APP"))?; // TODO: Merge settings with Clap Settings Arguments - - // Save Config to RwLoc - { - let mut w = CONFIG.write()?; - *w = settings; - } - - Ok(()) - } - - pub fn merge_args(app: clap::App) -> Result<()> { - let args = app.get_matches(); - - if args.is_present("debug") { - AppConfig::set("debug", args.value_of("debug").unwrap())?; - } - - if args.is_present("log_level") { - AppConfig::set("log_level", args.value_of("log_level").unwrap())?; - } - - Ok(()) - } - - pub fn merge_config(config_file: Option<&Path>) -> Result<()> { - // Merge settings with config file if there is one - if let Some(config_file_path) = config_file { - { - CONFIG - .write()? - .merge(config::File::with_name(config_file_path.to_str().unwrap()))?; - } - } - Ok(()) - } - - // Set CONFIG - pub fn set(key: &str, value: &str) -> Result<()> { - { - // Set Property - CONFIG.write()?.set(key, value)?; - } - - Ok(()) - } - - // Get a single value - pub fn get<'de, T>(key: &'de str) -> Result - where T: serde::Deserialize<'de> { - Ok(CONFIG.read()?.get::(key)?) - } - - // Get CONFIG - // This clones Config (from RwLock) into a new AppConfig object. - // This means you have to fetch this again if you changed the configuration. - pub fn fetch() -> Result { - // Get a Read Lock from RwLock - let r = CONFIG.read()?; - - // Clone the Config object - let config_clone = r.deref().clone(); - - // Coerce Config into AppConfig - Ok(config_clone.try_into()?) - } -} diff --git a/earthly/rust/example/utils/src/error.rs b/earthly/rust/example/utils/src/error.rs deleted file mode 100644 index 1e20b33ea..000000000 --- a/earthly/rust/example/utils/src/error.rs +++ /dev/null @@ -1,111 +0,0 @@ -use std::fmt; - -use thiserror::Error; - -/// Result alias -pub type Result = std::result::Result; - -/// Error type for this library. -#[derive(Error, Debug)] -pub struct Error { - pub msg: String, - #[cfg(feature = "nightly")] - backtrace: std::backtrace::Backtrace, - source: Option>, -} - -// Implement the Display trait for our Error type. -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.msg) - } -} - -// Implement Default for Error -impl Default for Error { - fn default() -> Self { - Error { - msg: "".to_string(), - #[cfg(feature = "nightly")] - backtrace: std::backtrace::Backtrace::capture(), - source: None, - } - } -} - -impl Error { - /// Create a new Error instance. - pub fn new(msg: &str) -> Self { - Error { - msg: msg.to_string(), - #[cfg(feature = "nightly")] - backtrace: std::backtrace::Backtrace::capture(), - source: None, - } - } - - /// Create a new Error instance with a source error. - pub fn with_source(msg: &str, source: Box) -> Self { - Error { - msg: msg.to_string(), - #[cfg(feature = "nightly")] - backtrace: std::backtrace::Backtrace::capture(), - source: Some(source), - } - } -} - -impl From for Error { - fn from(err: config::ConfigError) -> Self { - Error { - msg: String::from("Config Error"), - #[cfg(feature = "nightly")] - backtrace: std::backtrace::Backtrace::capture(), - source: Some(Box::new(err)), - } - } -} - -impl From> for Error { - fn from(_err: std::sync::PoisonError) -> Self { - Error { - msg: String::from("Poison Error"), - #[cfg(feature = "nightly")] - backtrace: std::backtrace::Backtrace::capture(), - source: None, - } - } -} - -impl From for Error { - fn from(err: std::io::Error) -> Self { - Error { - msg: String::from("IO Error"), - #[cfg(feature = "nightly")] - backtrace: std::backtrace::Backtrace::capture(), - source: Some(Box::new(err)), - } - } -} - -impl From for Error { - fn from(err: clap::Error) -> Self { - Error { - msg: String::from("Clap Error"), - #[cfg(feature = "nightly")] - backtrace: std::backtrace::Backtrace::capture(), - source: Some(Box::new(err)), - } - } -} - -impl From for Error { - fn from(err: log::SetLoggerError) -> Self { - Error { - msg: String::from("Logger Error"), - #[cfg(feature = "nightly")] - backtrace: std::backtrace::Backtrace::capture(), - source: Some(Box::new(err)), - } - } -} diff --git a/earthly/rust/example/utils/src/lib.rs b/earthly/rust/example/utils/src/lib.rs deleted file mode 100644 index 0436beb4e..000000000 --- a/earthly/rust/example/utils/src/lib.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![cfg_attr(feature = "nightly", feature(backtrace))] - -pub mod app_config; -pub mod error; -pub mod logger; -pub mod types; diff --git a/earthly/rust/example/utils/src/logger.rs b/earthly/rust/example/utils/src/logger.rs deleted file mode 100644 index 84a303714..000000000 --- a/earthly/rust/example/utils/src/logger.rs +++ /dev/null @@ -1,68 +0,0 @@ -use slog::{o, Drain}; -use slog_journald::JournaldDrain; -use slog_syslog::Facility; - -use super::error::Result; - -pub fn setup_logging() -> Result { - // Setup Logging - let guard = slog_scope::set_global_logger(default_root_logger()?); - let _log_guard = slog_stdlog::init()?; - - Ok(guard) -} - -pub fn default_root_logger() -> Result { - // Create drains - let drain = slog::Duplicate(default_discard()?, default_discard()?).fuse(); - - // Merge drains - #[cfg(feature = "termlog")] - let drain = slog::Duplicate(default_term_drain().unwrap_or(default_discard()?), drain).fuse(); - #[cfg(feature = "syslog")] - let drain = slog::Duplicate(default_syslog_drain().unwrap_or(default_discard()?), drain).fuse(); - #[cfg(feature = "journald")] - let drain = slog::Duplicate( - default_journald_drain().unwrap_or(default_discard()?), - drain, - ) - .fuse(); - - // Create Logger - let logger = slog::Logger::root(drain, o!("who" => "rust-starter")); - - // Return Logger - Ok(logger) -} - -fn default_discard() -> Result { - let drain = slog_async::Async::default(slog::Discard); - - Ok(drain) -} - -// term drain: Log to Terminal -fn default_term_drain() -> Result { - let plain = slog_term::PlainSyncDecorator::new(std::io::stdout()); - let term = slog_term::FullFormat::new(plain); - - let drain = slog_async::Async::default(term.build().fuse()); - - Ok(drain) -} - -// syslog drain: Log to syslog -fn default_syslog_drain() -> Result { - let syslog = slog_syslog::unix_3164(Facility::LOG_USER)?; - - let drain = slog_async::Async::default(syslog.fuse()); - - Ok(drain) -} - -fn default_journald_drain() -> Result { - let journald = JournaldDrain.ignore_res(); - let drain = slog_async::Async::default(journald); - - Ok(drain) -} diff --git a/earthly/rust/example/utils/src/types.rs b/earthly/rust/example/utils/src/types.rs deleted file mode 100644 index 00106576f..000000000 --- a/earthly/rust/example/utils/src/types.rs +++ /dev/null @@ -1,31 +0,0 @@ -use std::str::FromStr; - -use serde::{Deserialize, Serialize}; - -use crate::error::Result; - -#[derive(Debug, Serialize, Deserialize)] -pub enum LogLevel { - #[serde(rename = "debug")] - Debug, - #[serde(rename = "info")] - Info, - #[serde(rename = "warn")] - Warn, - #[serde(rename = "error")] - Error, -} - -impl FromStr for LogLevel { - type Err = crate::error::Error; - - fn from_str(s: &str) -> Result { - match s { - "debug" => Ok(LogLevel::Debug), - "info" => Ok(LogLevel::Info), - "warn" => Ok(LogLevel::Warn), - "error" => Ok(LogLevel::Error), - _ => Ok(LogLevel::Info), - } - } -} diff --git a/earthly/rust/example/utils/tests/resources/test_config.toml b/earthly/rust/example/utils/tests/resources/test_config.toml deleted file mode 100644 index cc5e99b71..000000000 --- a/earthly/rust/example/utils/tests/resources/test_config.toml +++ /dev/null @@ -1,4 +0,0 @@ -debug = false - -[database] -url = "custom database url" diff --git a/earthly/rust/example/utils/tests/test_config.rs b/earthly/rust/example/utils/tests/test_config.rs deleted file mode 100644 index d9c344185..000000000 --- a/earthly/rust/example/utils/tests/test_config.rs +++ /dev/null @@ -1,45 +0,0 @@ -use utils::app_config::*; - -#[test] -fn fetch_config() { - // Initialize configuration - let config_contents = include_str!("resources/test_config.toml"); - AppConfig::init(Some(config_contents)).unwrap(); - - // Fetch an instance of Config - let config = AppConfig::fetch().unwrap(); - - // Check the values - assert_eq!(config.debug, false); - assert_eq!(config.database.url, "custom database url"); -} - -#[test] -fn verify_get() { - // Initialize configuration - let config_contents = include_str!("resources/test_config.toml"); - AppConfig::init(Some(config_contents)).unwrap(); - - // Check value with get - assert_eq!(AppConfig::get::("debug").unwrap(), false); - assert_eq!( - AppConfig::get::("database.url").unwrap(), - "custom database url" - ); -} - -#[test] -fn verify_set() { - // Initialize configuration - let config_contents = include_str!("resources/test_config.toml"); - AppConfig::init(Some(config_contents)).unwrap(); - - // Set a field - AppConfig::set("database.url", "new url").unwrap(); - - // Fetch a new instance of Config - let config = AppConfig::fetch().unwrap(); - - // Check value was modified - assert_eq!(config.database.url, "new url"); -} diff --git a/earthly/rust/scripts/colors.sh b/earthly/rust/scripts/colors.sh index dde47abc0..3d1cbd2be 100644 --- a/earthly/rust/scripts/colors.sh +++ b/earthly/rust/scripts/colors.sh @@ -11,3 +11,23 @@ MAGENTA='\033[0;35m' CYAN='\033[0;36m' WHITE='\033[0;37m' NC='\033[0m' # No Color + + +status() { + local rc="$1" + local message="$2" + shift 2 + + # Check if the command returned a bad status + if "$@"; then + # Append green OK to the message + echo -e "${CYAN}${message} : ${GREEN}[OK]${NC}" + else + # Append red ERROR to the message + echo -e "${CYAN}${message} : ${RED}[ERROR]${NC}" + rc=1 + fi + + # Return the current status + return "$rc" +} diff --git a/earthly/rust/scripts/std_build.sh b/earthly/rust/scripts/std_build.sh new file mode 100755 index 000000000..3439bc6aa --- /dev/null +++ b/earthly/rust/scripts/std_build.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# This script is run inside the `check` stage for rust projects to perfom all +# high level non-compilation checks. +# These are the Standard checks which ALL rust targets must pass before they +# will be scheduled to be `buuild`. +# Individual targets can add extra `check` steps, but these checks must always +# pass. + +source "$(dirname "$0")/colors.sh" + + +# This is set up so that ALL build steps are run and it will fail if any fail. +# This imporvies visibility into all issues that need to be corrected for `build` +# to pass without needing to iterate excessively. + +rc=0 + +## Build the code +status $rc "Building all code in the workspace" \ + cargo build --release --workspace --locked; rc=$? + +## Check the code passes all clippy lint checks. + +## Check we can generate all the documentation + +## Check if all Self contained tests pass (Test that need no external resources). + +## Check if all documentation tests pass. + +## Check if any benchmarks defined run (We don;t validate the results.) + +## Check if there are any circular dependencies in the project. + +## Generate Module Trees for documentation purposes. + +## Generate Module Graphs for documentation purposes. + +## Save all the artifacts so we can use them. + +# Return an error if any of this fails. +exit $rc \ No newline at end of file diff --git a/earthly/rust/scripts/std_checks.sh b/earthly/rust/scripts/std_checks.sh index e62e65f61..4db2db796 100755 --- a/earthly/rust/scripts/std_checks.sh +++ b/earthly/rust/scripts/std_checks.sh @@ -9,25 +9,6 @@ source "$(dirname "$0")/colors.sh" -status() { - local rc="$1" - local message="$2" - shift 2 - - # Check if the command returned a bad status - if "$@"; then - # Append green OK to the message - echo -e "${CYAN}${message} : ${GREEN}[OK]${NC}" - else - # Append red ERROR to the message - echo -e "${CYAN}${message} : ${RED}[ERROR]${NC}" - rc=1 - fi - - # Return the current status - return "$rc" -} - # Checks if two files that should exist DO, and are equal. # used to enforce consistency between local config files and the expected config locked in CI. check_vendored_files() { From e0f8f322c970cae134fce110dd54ae500355fe9d Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 27 Oct 2023 22:00:54 +0700 Subject: [PATCH 17/21] feat(rust): Nwe simple demo builds, still WIP. --- earthly/rust/.cargo/config.toml | 4 +- earthly/rust/Earthfile | 19 ++- earthly/rust/example/.cargo/config.toml | 4 +- earthly/rust/example/Cargo.lock | 217 ++++++++++++++++-------- earthly/rust/example/Cargo.toml | 4 +- earthly/rust/example/src/main.rs | 33 ++-- 6 files changed, 184 insertions(+), 97 deletions(-) diff --git a/earthly/rust/.cargo/config.toml b/earthly/rust/.cargo/config.toml index e1c67e409..6ccbcb725 100644 --- a/earthly/rust/.cargo/config.toml +++ b/earthly/rust/.cargo/config.toml @@ -15,7 +15,7 @@ linker = "clang" rustflags = [ "-C", "link-arg=-fuse-ld=/usr/bin/mold", - "-C", "target-feature=+crt-static" + "-C", "target-feature=-crt-static" ] # Should be the default to have fully static rust programs in CI @@ -23,7 +23,7 @@ rustflags = [ linker = "clang" rustflags = [ "-C", "link-arg=-fuse-ld=/usr/bin/mold", - "-C", "target-feature=+crt-static" + "-C", "target-feature=-crt-static" ] diff --git a/earthly/rust/Earthfile b/earthly/rust/Earthfile index 5e56ebd09..7e14be5fb 100644 --- a/earthly/rust/Earthfile +++ b/earthly/rust/Earthfile @@ -165,18 +165,25 @@ check-all-hosts: BUILD --platform=linux/amd64 --platform=linux/arm64 +check-hosted build-hosted: + ARG TARGETPLATFORM + # Build the service FROM +builder RUN /scripts/std_build.sh - # TODO use the correct target arch here. - RUN ldd target/x86_64-unknown-linux-musl/release/cat-gateway - RUN readelf -p .comment target/x86_64-unknown-linux-musl/release/cat-gateway - RUN strip -v target/x86_64-unknown-linux-musl/release/cat-gateway + RUN ls -al target/$TARGETARCH/release + + RUN ldd target/$TARGETARCH/release/hello_world + RUN readelf -p .comment target/$TARGETARCH/release/hello_world + RUN ls -al target/$TARGETARCH/release/hello_world + RUN strip -v target/$TARGETARCH/release/hello_world + RUN ls -al target/$TARGETARCH/release/hello_world + + RUN target/$TARGETARCH/release/hello_world - SAVE ARTIFACT target/x86_64-unknown-linux-musl/doc doc - SAVE ARTIFACT target/x86_64-unknown-linux-musl/release/cat-gateway cat-gateway + SAVE ARTIFACT target/$TARGETARCH/doc doc + SAVE ARTIFACT target/$TARGETARCH/release/hello_world hello_world # Run build using the most efficient host tooling # CI Automated Entry point. diff --git a/earthly/rust/example/.cargo/config.toml b/earthly/rust/example/.cargo/config.toml index e1c67e409..6ccbcb725 100644 --- a/earthly/rust/example/.cargo/config.toml +++ b/earthly/rust/example/.cargo/config.toml @@ -15,7 +15,7 @@ linker = "clang" rustflags = [ "-C", "link-arg=-fuse-ld=/usr/bin/mold", - "-C", "target-feature=+crt-static" + "-C", "target-feature=-crt-static" ] # Should be the default to have fully static rust programs in CI @@ -23,7 +23,7 @@ rustflags = [ linker = "clang" rustflags = [ "-C", "link-arg=-fuse-ld=/usr/bin/mold", - "-C", "target-feature=+crt-static" + "-C", "target-feature=-crt-static" ] diff --git a/earthly/rust/example/Cargo.lock b/earthly/rust/example/Cargo.lock index f2f8c892f..eeeac8808 100644 --- a/earthly/rust/example/Cargo.lock +++ b/earthly/rust/example/Cargo.lock @@ -3,57 +3,104 @@ version = 3 [[package]] -name = "atty" -version = "0.2.14" +name = "anstream" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" dependencies = [ - "hermit-abi", - "libc", - "winapi", + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", ] [[package]] -name = "autocfg" -version = "1.1.0" +name = "anstyle" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" [[package]] -name = "bitflags" -version = "1.3.2" +name = "anstyle-parse" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" +dependencies = [ + "anstyle", + "windows-sys", +] [[package]] name = "clap" -version = "3.2.25" +version = "4.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663" dependencies = [ - "atty", - "bitflags", + "anstream", + "anstyle", "clap_lex", - "indexmap", "strsim", - "termcolor", - "textwrap", ] [[package]] -name = "clap_lex" -version = "0.2.4" +name = "clap_derive" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" dependencies = [ - "os_str_bytes", + "heck", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "hashbrown" -version = "0.12.3" +name = "clap_lex" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hello_world" @@ -63,84 +110,114 @@ dependencies = [ ] [[package]] -name = "hermit-abi" -version = "0.1.19" +name = "proc-macro2" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ - "libc", + "unicode-ident", ] [[package]] -name = "indexmap" -version = "1.9.3" +name = "quote" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ - "autocfg", - "hashbrown", + "proc-macro2", ] [[package]] -name = "libc" -version = "0.2.149" +name = "strsim" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] -name = "os_str_bytes" -version = "6.6.1" +name = "syn" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] [[package]] -name = "strsim" -version = "0.10.0" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] -name = "termcolor" -version = "1.3.0" +name = "utf8parse" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" -dependencies = [ - "winapi-util", -] +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] -name = "textwrap" -version = "0.16.0" +name = "windows-sys" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] [[package]] -name = "winapi" -version = "0.3.9" +name = "windows-targets" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "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 = "winapi-i686-pc-windows-gnu" -version = "0.4.0" +name = "windows_aarch64_gnullvm" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] -name = "winapi-util" -version = "0.1.6" +name = "windows_aarch64_msvc" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" -dependencies = [ - "winapi", -] +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[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_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[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_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "windows_x86_64_msvc" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/earthly/rust/example/Cargo.toml b/earthly/rust/example/Cargo.toml index c130e5743..7418078b9 100644 --- a/earthly/rust/example/Cargo.toml +++ b/earthly/rust/example/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "hello_world" version = "0.1.0" -edition = "2018" +edition = "2021" [dependencies] -clap = "3.0" +clap = {version= "4.4.7", features = ["derive" ] } [dev-dependencies] diff --git a/earthly/rust/example/src/main.rs b/earthly/rust/example/src/main.rs index b505b53c9..f3e2a1605 100644 --- a/earthly/rust/example/src/main.rs +++ b/earthly/rust/example/src/main.rs @@ -1,23 +1,26 @@ // src/main.rs -use clap::{App, Arg}; + +use clap::Parser; + +/// Simple program to greet a person +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +struct Args { + /// Name of the person to greet + #[arg(short, long)] + name: String, + + /// Number of times to greet + #[arg(short, long, default_value_t = 1)] + count: u8, +} fn main() { - let matches = App::new("Hello, World!") - .version("1.0") - .arg( - Arg::with_name("version") - .short('v') - .long("version") - .help("Print the program version"), - ) - .get_matches(); + let args = Args::parse(); - if matches.is_present("version") { - println!("Hello, World! v1.0"); - return; + for _ in 0..args.count { + println!("Hello {}!", args.name) } - - println!("Hello, World!"); } #[cfg(test)] From 46e300b9d3773f0c8d63163533221055245d2f76 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Mon, 30 Oct 2023 18:59:25 +0700 Subject: [PATCH 18/21] feat(rust): multiarch rust builder seems complete --- earthly/rust/.cargo/README.md | 20 - earthly/rust/Earthfile | 112 ++-- earthly/rust/example/.cargo/config.toml | 2 +- earthly/rust/example/.config/nextest.toml | 49 ++ earthly/rust/example/Cargo.lock | 516 ++++++++++++++++++ earthly/rust/example/Cargo.toml | 11 + earthly/rust/example/benches/benchmark.rs | 25 +- earthly/rust/example/clippy.toml | 1 + earthly/rust/example/deny.toml | 271 +++++++++ earthly/rust/example/src/lib.rs | 34 ++ earthly/rust/example/src/main.rs | 19 +- earthly/rust/example/t | 7 + .../rust/example/tests/integration_test.rs | 17 +- earthly/rust/scripts/std_build.sh | 17 +- earthly/rust/scripts/std_checks.sh | 19 +- earthly/rust/stdcfgs/README.md | 51 ++ .../config.toml => stdcfgs/cargo_config.toml} | 2 +- earthly/rust/stdcfgs/clippy.toml | 1 + earthly/rust/stdcfgs/deny.toml | 271 +++++++++ earthly/rust/stdcfgs/nextest.toml | 49 ++ earthly/rust/{ => stdcfgs}/rustfmt.toml | 0 21 files changed, 1392 insertions(+), 102 deletions(-) delete mode 100644 earthly/rust/.cargo/README.md create mode 100644 earthly/rust/example/.config/nextest.toml create mode 100644 earthly/rust/example/clippy.toml create mode 100644 earthly/rust/example/deny.toml create mode 100644 earthly/rust/example/src/lib.rs create mode 100644 earthly/rust/example/t create mode 100644 earthly/rust/stdcfgs/README.md rename earthly/rust/{.cargo/config.toml => stdcfgs/cargo_config.toml} (98%) create mode 100644 earthly/rust/stdcfgs/clippy.toml create mode 100644 earthly/rust/stdcfgs/deny.toml create mode 100644 earthly/rust/stdcfgs/nextest.toml rename earthly/rust/{ => stdcfgs}/rustfmt.toml (100%) diff --git a/earthly/rust/.cargo/README.md b/earthly/rust/.cargo/README.md deleted file mode 100644 index faae38060..000000000 --- a/earthly/rust/.cargo/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Rust Cargo Configuration - -We define RUST Global Cargo Configurations here. -It is applied globaly to all Rust Code built by Project Catalyst. - -Each Project Catalyst Repo that has Rust code must include this file in: - -```path -/.cargo/config.toml -``` - -This config exists here so that it can be used locally during development, as well as during CI builds. - -It will be checked during CI that it has not been altered from the enforced standard. -The enforced standard can be referenced here: [Catalyst-CI Global Cargo Config](todo) - -If this file needs to be updated, please update it in the standard location first, have the PR -approved, and then update this file to match. - -Differences between these files and the enforced standards will prevent CI from accepting your PR. diff --git a/earthly/rust/Earthfile b/earthly/rust/Earthfile index 7e14be5fb..c211101f8 100644 --- a/earthly/rust/Earthfile +++ b/earthly/rust/Earthfile @@ -44,30 +44,32 @@ rust-base: colordiff \ graphviz + # Make sure we have the clippy linter. + RUN rustup component add clippy + # Install a nightly toolchain which matches. - RUN rustup toolchain install nightly --component miri --component rust-src --component rustfmt + RUN rustup toolchain install nightly --component miri --component rust-src --component rustfmt --component clippy # Install the default cargo config. - COPY .cargo/config.toml $CARGO_HOME/config.toml + COPY stdcfgs/cargo_config.toml $CARGO_HOME/config.toml # Install rust based tooling # Install tools we use commonly with `cargo`. # Note, we disable static compiles for tools, specifically, as its not required. # These tools are not artefacts and we do not use them in production. - RUN export RUSTFLAGS="-C target-feature=-crt-static" && \ - cargo install cargo-nextest --version=0.9.59 && \ - cargo install cargo-machete --version=0.6.0 && \ - cargo install refinery_cli --version=0.8.11 - + RUN cargo install cargo-nextest --version=0.9.59 && \ + cargo install cargo-machete --version=0.6.0 && \ + cargo install refinery_cli --version=0.8.11 && \ + cargo install cargo-deny --version=0.14.3 && \ + cargo install cargo-modules --version=0.10.2 # Universal build scripts we will always need and are not target dependent. COPY --dir scripts /scripts - RUN ls -al /scripts # Standardized Rust configs. # Build will refuse to proceed if the projects rust configs do not match these. # This is to enforce consistent compiler and tool configuration on local setup and CI builds. - COPY rustfmt.toml /stdcfgs/ + COPY --dir stdcfgs /stdcfgs # Builds all the rust-base targets for each supported DOCKER architecture. # Currently only used for multi-platform cross build testing. @@ -130,13 +132,27 @@ CHECK: # to pass without needing to iterate excessively. RUN /scripts/std_checks.sh +# Check if the build executable, isn't a busted mess. +SMOKE_TEST: + COMMAND + ARG TARGETPLATFORM + ARG bin + + RUN ldd target/$TARGETARCH/release/$bin + RUN readelf -p .comment target/$TARGETARCH/release/$bin + RUN strip -v target/$TARGETARCH/release/$bin + + # ALL executables MUST have `--help` as an option. + RUN target/$TARGETARCH/release/$bin --help + + # Set up our target toolchains, and copy our files. builder: FROM +rust-base DO +SETUP --toolchain=example/rust-toolchain.toml - DO +CP_SRC --src="example/src example/tests example/benches example/Cargo.* example/rustfmt.toml example/.cargo" + DO +CP_SRC --src="example/*" # Test rust build container - Use best architecture host tools. check-hosted: @@ -144,21 +160,6 @@ check-hosted: DO +CHECK -# Run check using the most efficient host tooling -# CI Automated Entry point. -check: - FROM busybox - # This is necessary to pick the correct architecture build to suit the native machine. - # It primarily ensures that Darwin/Arm builds work as expected without needing x86 emulation. - # All target implementation of this should follow this pattern. - ARG USERARCH - - IF [ "$USERARCH" == "arm64" ] - BUILD --platform=linux/arm64 +check-hosted - ELSE - BUILD --platform=linux/amd64 +check-hosted - END - # Test which runs check with all supported host tooling. Needs qemu or rosetta to run. # Only used to validate tooling is working across host toolsets. check-all-hosts: @@ -172,19 +173,37 @@ build-hosted: RUN /scripts/std_build.sh - RUN ls -al target/$TARGETARCH/release - - RUN ldd target/$TARGETARCH/release/hello_world - RUN readelf -p .comment target/$TARGETARCH/release/hello_world - RUN ls -al target/$TARGETARCH/release/hello_world - RUN strip -v target/$TARGETARCH/release/hello_world - RUN ls -al target/$TARGETARCH/release/hello_world - - RUN target/$TARGETARCH/release/hello_world + DO +SMOKE_TEST --bin=hello_world SAVE ARTIFACT target/$TARGETARCH/doc doc SAVE ARTIFACT target/$TARGETARCH/release/hello_world hello_world +# Test which runs check with all supported host tooling. Needs qemu or rosetta to run. +# Only used to validate tooling is working across host toolsets. +build-all-hosts: + BUILD --platform=linux/amd64 --platform=linux/arm64 +build-hosted + +## ----------------------------------------------------------------------------- +## +## Standard CI targets. +## +## These targets are discovered and executed automatically by CI. + +# Run check using the most efficient host tooling +# CI Automated Entry point. +check: + FROM busybox + # This is necessary to pick the correct architecture build to suit the native machine. + # It primarily ensures that Darwin/Arm builds work as expected without needing x86 emulation. + # All target implementation of this should follow this pattern. + ARG USERARCH + + IF [ "$USERARCH" == "arm64" ] + BUILD --platform=linux/arm64 +check-hosted + ELSE + BUILD --platform=linux/amd64 +check-hosted + END + # Run build using the most efficient host tooling # CI Automated Entry point. build: @@ -201,7 +220,24 @@ build: END -# Test which runs check with all supported host tooling. Needs qemu or rosetta to run. -# Only used to validate tooling is working across host toolsets. -build-all-hosts: - BUILD --platform=linux/amd64 --platform=linux/arm64 +build-hosted +# This step will build any packages we would intend to publish or integration test. +package: + FROM scratch + +# Run integration tests on all packages built during the `package` step. +integrate: + FROM scratch + +# Publish packlages if all integration tests have passed. (Failure to pass tests will prevent packages being published.) +publish: + FROM scratch + +## ----------------------------------------------------------------------------- + +# This step simulates the full CI run for local purposes only. +local-ci-run: + BUILD +check + BUILD +build + BUILD +package + BUILD +integrate + BUILD +publish \ No newline at end of file diff --git a/earthly/rust/example/.cargo/config.toml b/earthly/rust/example/.cargo/config.toml index 6ccbcb725..fda1dc15a 100644 --- a/earthly/rust/example/.cargo/config.toml +++ b/earthly/rust/example/.cargo/config.toml @@ -113,7 +113,7 @@ docs = "doc --workspace -r --all-features --no-deps --bins --document-private-it # nightly docs build broken... when they are'nt we can enable these docs... --unit-graph --timings=html,json -Z unstable-options" testfast = "nextest run --release --workspace --locked" testci = "nextest run --release --workspace --locked -P ci" -testdocs = "test --doc --release --workspace --locked --doc" +testdocs = "test --doc --release --workspace --locked" # Rust formatting, MUST be run with +nightly fmtchk = "fmt -- --check -v --color=always" diff --git a/earthly/rust/example/.config/nextest.toml b/earthly/rust/example/.config/nextest.toml new file mode 100644 index 000000000..ebc7d7390 --- /dev/null +++ b/earthly/rust/example/.config/nextest.toml @@ -0,0 +1,49 @@ +# cspell: words nextest scrollability testcase +[store] +# The directory under the workspace root at which nextest-related files are +# written. Profile-specific storage is currently written to dir/. +# dir = "target/nextest" + +[profile.default] +# Print out output for failing tests as soon as they fail, and also at the end +# of the run (for easy scrollability). +failure-output = "immediate-final" + +# Do not cancel the test run on the first failure. +fail-fast = true + +status-level = "all" +final-status-level = "all" + +[profile.ci] +# Print out output for failing tests as soon as they fail, and also at the end +# of the run (for easy scrollability). +failure-output = "immediate-final" +# Do not cancel the test run on the first failure. +fail-fast = false + +status-level = "all" +final-status-level = "all" + + +[profile.ci.junit] +# Output a JUnit report into the given file inside 'store.dir/'. +# If unspecified, JUnit is not written out. + +path = "junit.xml" + +# The name of the top-level "report" element in JUnit report. If aggregating +# reports across different test runs, it may be useful to provide separate names +# for each report. +report-name = "cat-gateway" + +# Whether standard output and standard error for passing tests should be stored in the JUnit report. +# Output is stored in the and elements of the element. +store-success-output = true + +# Whether standard output and standard error for failing tests should be stored in the JUnit report. +# Output is stored in the and elements of the element. +# +# Note that if a description can be extracted from the output, it is always stored in the +# element. +store-failure-output = true diff --git a/earthly/rust/example/Cargo.lock b/earthly/rust/example/Cargo.lock index eeeac8808..61dfd6fe2 100644 --- a/earthly/rust/example/Cargo.lock +++ b/earthly/rust/example/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + [[package]] name = "anstream" version = "0.6.4" @@ -50,6 +65,63 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "ciborium" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "effd91f6c78e5a4ace8a5d3c0b6bfaec9e2baaef55f3efc00e45fb2e477ee926" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdf919175532b369853f5d5e20b26b43112613fd6fe7aee757e35f7a44642656" + +[[package]] +name = "ciborium-ll" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defaa24ecc093c77630e6c15e17c51f5e187bf35ee514f4e2d67baaa96dae22b" +dependencies = [ + "ciborium-io", + "half", +] + [[package]] name = "clap" version = "4.4.7" @@ -96,6 +168,97 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "criterion" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" +dependencies = [ + "anes", + "cast", + "ciborium", + "clap", + "criterion-plot", + "is-terminal", + "itertools", + "num-traits", + "once_cell", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" + +[[package]] +name = "errno" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + [[package]] name = "heck" version = "0.4.1" @@ -107,6 +270,130 @@ name = "hello_world" version = "0.1.0" dependencies = [ "clap", + "criterion", +] + +[[package]] +name = "hermit-abi" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" + +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "js-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" + +[[package]] +name = "linux-raw-sys" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "oorandom" +version = "11.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" + +[[package]] +name = "plotters" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" + +[[package]] +name = "plotters-svg" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" +dependencies = [ + "plotters-backend", ] [[package]] @@ -127,6 +414,120 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rayon" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rustix" +version = "0.38.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.190" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.190" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "strsim" version = "0.10.0" @@ -144,6 +545,16 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "unicode-ident" version = "1.0.12" @@ -156,6 +567,111 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "walkdir" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" + +[[package]] +name = "web-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/earthly/rust/example/Cargo.toml b/earthly/rust/example/Cargo.toml index 7418078b9..de0ecb52d 100644 --- a/earthly/rust/example/Cargo.toml +++ b/earthly/rust/example/Cargo.toml @@ -2,11 +2,21 @@ name = "hello_world" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [dependencies] clap = {version= "4.4.7", features = ["derive" ] } [dev-dependencies] +criterion = { version = "0.5.1", features = ["html_reports"] } + +[lib] +name = "hello_world_lib" +path = "src/lib.rs" + +[[bin]] +name = "hello_world" +path = "src/main.rs" [[test]] name = "integration_test" @@ -14,3 +24,4 @@ harness = false [[bench]] name = "benchmark" +harness = false diff --git a/earthly/rust/example/benches/benchmark.rs b/earthly/rust/example/benches/benchmark.rs index 13af049e6..9268cfb6b 100644 --- a/earthly/rust/example/benches/benchmark.rs +++ b/earthly/rust/example/benches/benchmark.rs @@ -1,14 +1,17 @@ -// benches/benchmark.rs -#[cfg(test)] -mod benches { - use test::Bencher; +//! Simple benchmark example +use criterion::{black_box, criterion_group, criterion_main, Criterion}; - use super::*; - - #[bench] - fn benchmark_hello_world(b: &mut Bencher) { - b.iter(|| { - main(); - }); +fn fibonacci(n: u64) -> u64 { + match n { + 0 => 1, + 1 => 1, + n => fibonacci(n - 1) + fibonacci(n - 2), } } + +fn criterion_benchmark(c: &mut Criterion) { + c.bench_function("fib 20", |b| b.iter(|| fibonacci(black_box(20)))); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); diff --git a/earthly/rust/example/clippy.toml b/earthly/rust/example/clippy.toml new file mode 100644 index 000000000..154626ef4 --- /dev/null +++ b/earthly/rust/example/clippy.toml @@ -0,0 +1 @@ +allow-unwrap-in-tests = true diff --git a/earthly/rust/example/deny.toml b/earthly/rust/example/deny.toml new file mode 100644 index 000000000..23760323c --- /dev/null +++ b/earthly/rust/example/deny.toml @@ -0,0 +1,271 @@ +# This template contains all of the possible sections and their default values + +# Note that all fields that take a lint level have these possible values: +# * deny - An error will be produced and the check will fail +# * warn - A warning will be produced, but the check will not fail +# * allow - No warning or error will be produced, though in some cases a note +# will be + +# The values provided in this template are the default values that will be used +# when any section or field is not specified in your own configuration + +# Root options + +# If 1 or more target triples (and optionally, target_features) are specified, +# only the specified targets will be checked when running `cargo deny check`. +# This means, if a particular package is only ever used as a target specific +# dependency, such as, for example, the `nix` crate only being used via the +# `target_family = "unix"` configuration, that only having windows targets in +# this list would mean the nix crate, as well as any of its exclusive +# dependencies not shared by any other crates, would be ignored, as the target +# list here is effectively saying which targets you are building for. +targets = [ + # The triple can be any string, but only the target triples built in to + # rustc (as of 1.40) can be checked against actual config expressions + #{ triple = "x86_64-unknown-linux-musl" }, + # You can also specify which target_features you promise are enabled for a + # particular target. target_features are currently not validated against + # the actual valid features supported by the target architecture. + #{ triple = "wasm32-unknown-unknown", features = ["atomics"] }, +] +# When creating the dependency graph used as the source of truth when checks are +# executed, this field can be used to prune crates from the graph, removing them +# from the view of cargo-deny. This is an extremely heavy hammer, as if a crate +# is pruned from the graph, all of its dependencies will also be pruned unless +# they are connected to another crate in the graph that hasn't been pruned, +# so it should be used with care. The identifiers are [Package ID Specifications] +# (https://doc.rust-lang.org/cargo/reference/pkgid-spec.html) +#exclude = [] +# If true, metadata will be collected with `--all-features`. Note that this can't +# be toggled off if true, if you want to conditionally enable `--all-features` it +# is recommended to pass `--all-features` on the cmd line instead +all-features = false +# If true, metadata will be collected with `--no-default-features`. The same +# caveat with `all-features` applies +no-default-features = false +# If set, these feature will be enabled when collecting metadata. If `--features` +# is specified on the cmd line they will take precedence over this option. +#features = [] +# When outputting inclusion graphs in diagnostics that include features, this +# option can be used to specify the depth at which feature edges will be added. +# This option is included since the graphs can be quite large and the addition +# of features from the crate(s) to all of the graph roots can be far too verbose. +# This option can be overridden via `--feature-depth` on the cmd line +feature-depth = 1 + +# This section is considered when running `cargo deny check advisories` +# More documentation for the advisories section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html +[advisories] +# The path where the advisory database is cloned/fetched into +db-path = "~/.cargo/advisory-db" +# The url(s) of the advisory databases to use +db-urls = ["https://github.com/rustsec/advisory-db"] +# The lint level for security vulnerabilities +vulnerability = "deny" +# The lint level for unmaintained crates +unmaintained = "warn" +# The lint level for crates that have been yanked from their source registry +yanked = "warn" +# The lint level for crates with security notices. +notice = "warn" +# A list of advisory IDs to ignore. Note that ignored advisories will still +# output a note when they are encountered. +ignore = [ + #"RUSTSEC-0000-0000", +] +# Threshold for security vulnerabilities, any vulnerability with a CVSS score +# lower than the range specified will be ignored. Note that ignored advisories +# will still output a note when they are encountered. +# * None - CVSS Score 0.0 +# * Low - CVSS Score 0.1 - 3.9 +# * Medium - CVSS Score 4.0 - 6.9 +# * High - CVSS Score 7.0 - 8.9 +# * Critical - CVSS Score 9.0 - 10.0 +#severity-threshold = + +# If this is true, then cargo deny will use the git executable to fetch advisory database. +# If this is false, then it uses a built-in git library. +# Setting this to true can be helpful if you have special authentication requirements that cargo-deny does not support. +# See Git Authentication for more information about setting up git authentication. +#git-fetch-with-cli = true + +# This section is considered when running `cargo deny check licenses` +# More documentation for the licenses section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/licenses/cfg.html +[licenses] +# The lint level for crates which do not have a detectable license +unlicensed = "deny" +# List of explicitly allowed licenses +# See https://spdx.org/licenses/ for list of possible licenses +# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. +allow = [ + "MIT", + "Apache-2.0", + "Unicode-DFS-2016" +] +# List of explicitly disallowed licenses +# See https://spdx.org/licenses/ for list of possible licenses +# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. +deny = [ + #"Nokia", +] +# Lint level for licenses considered copyleft +copyleft = "deny" + +# Blanket approval or denial for OSI-approved or FSF Free/Libre licenses +# * both - The license will be approved if it is both OSI-approved *AND* FSF +# * either - The license will be approved if it is either OSI-approved *OR* FSF +# * osi - The license will be approved if it is OSI approved +# * fsf - The license will be approved if it is FSF Free +# * osi-only - The license will be approved if it is OSI-approved *AND NOT* FSF +# * fsf-only - The license will be approved if it is FSF *AND NOT* OSI-approved +# * neither - This predicate is ignored and the default lint level is used +allow-osi-fsf-free = "neither" +# Lint level used when no other predicates are matched +# 1. License isn't in the allow or deny lists +# 2. License isn't copyleft +# 3. License isn't OSI/FSF, or allow-osi-fsf-free = "neither" +default = "deny" +# The confidence threshold for detecting a license from license text. +# The higher the value, the more closely the license text must be to the +# canonical license text of a valid SPDX license file. +# [possible values: any between 0.0 and 1.0]. +confidence-threshold = 0.8 +# Allow 1 or more licenses on a per-crate basis, so that particular licenses +# aren't accepted for every possible crate as with the normal allow list +exceptions = [ + # Each entry is the crate and version constraint, and its specific allow + # list + #{ allow = ["Zlib"], name = "adler32", version = "*" }, +] + +# Some crates don't have (easily) machine readable licensing information, +# adding a clarification entry for it allows you to manually specify the +# licensing information +#[[licenses.clarify]] +# The name of the crate the clarification applies to +#name = "ring" +# The optional version constraint for the crate +#version = "*" +# The SPDX expression for the license requirements of the crate +#expression = "MIT AND ISC AND OpenSSL" +# One or more files in the crate's source used as the "source of truth" for +# the license expression. If the contents match, the clarification will be used +# when running the license check, otherwise the clarification will be ignored +# and the crate will be checked normally, which may produce warnings or errors +# depending on the rest of your configuration +#license-files = [ + # Each entry is a crate relative path, and the (opaque) hash of its contents + #{ path = "LICENSE", hash = 0xbd0eed23 } +#] + +[licenses.private] +# If true, ignores workspace crates that aren't published, or are only +# published to private registries. +# To see how to mark a crate as unpublished (to the official registry), +# visit https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field. +ignore = false +# One or more private registries that you might publish crates to, if a crate +# is only published to private registries, and ignore is true, the crate will +# not have its license(s) checked +registries = [ + #"https://sekretz.com/registry +] + +# This section is considered when running `cargo deny check bans`. +# More documentation about the 'bans' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/bans/cfg.html +[bans] +# Lint level for when multiple versions of the same crate are detected +multiple-versions = "warn" +# Lint level for when a crate version requirement is `*` +wildcards = "deny" +# The graph highlighting used when creating dotgraphs for crates +# with multiple versions +# * lowest-version - The path to the lowest versioned duplicate is highlighted +# * simplest-path - The path to the version with the fewest edges is highlighted +# * all - Both lowest-version and simplest-path are used +highlight = "all" +# The default lint level for `default` features for crates that are members of +# the workspace that is being checked. This can be overridden by allowing/denying +# `default` on a crate-by-crate basis if desired. +workspace-default-features = "allow" +# The default lint level for `default` features for external crates that are not +# members of the workspace. This can be overridden by allowing/denying `default` +# on a crate-by-crate basis if desired. +external-default-features = "allow" +# List of crates that are allowed. Use with care! +allow = [ + #{ name = "ansi_term", version = "=0.11.0" }, +] +# List of crates to deny +deny = [ + # Each entry the name of a crate and a version range. If version is + # not specified, all versions will be matched. + #{ name = "ansi_term", version = "=0.11.0" }, + # + # Wrapper crates can optionally be specified to allow the crate when it + # is a direct dependency of the otherwise banned crate + #{ name = "ansi_term", version = "=0.11.0", wrappers = [] }, + { name = "openssl" }, +] + +# List of features to allow/deny +# Each entry the name of a crate and a version range. If version is +# not specified, all versions will be matched. +#[[bans.features]] +#name = "reqwest" +# Features to not allow +#deny = ["json"] +# Features to allow +#allow = [ +# "rustls", +# "__rustls", +# "__tls", +# "hyper-rustls", +# "rustls", +# "rustls-pemfile", +# "rustls-tls-webpki-roots", +# "tokio-rustls", +# "webpki-roots", +#] +# If true, the allowed features must exactly match the enabled feature set. If +# this is set there is no point setting `deny` +#exact = true + +# Certain crates/versions that will be skipped when doing duplicate detection. +skip = [ + #{ name = "ansi_term", version = "=0.11.0" }, +] +# Similarly to `skip` allows you to skip certain crates during duplicate +# detection. Unlike skip, it also includes the entire tree of transitive +# dependencies starting at the specified crate, up to a certain depth, which is +# by default infinite. +skip-tree = [ + #{ name = "ansi_term", version = "=0.11.0", depth = 20 }, +] + +# This section is considered when running `cargo deny check sources`. +# More documentation about the 'sources' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/sources/cfg.html +[sources] +# Lint level for what to happen when a crate from a crate registry that is not +# in the allow list is encountered +unknown-registry = "deny" +# Lint level for what to happen when a crate from a git repository that is not +# in the allow list is encountered +unknown-git = "deny" +# List of URLs for allowed crate registries. Defaults to the crates.io index +# if not specified. If it is specified but empty, no registries are allowed. +allow-registry = ["https://github.com/rust-lang/crates.io-index"] +# List of URLs for allowed Git repositories +allow-git = [] + +[sources.allow-org] +# 1 or more github.com organizations to allow git sources for +#github = [""] +# 1 or more gitlab.com organizations to allow git sources for +#gitlab = [""] +# 1 or more bitbucket.org organizations to allow git sources for +#bitbucket = [""] diff --git a/earthly/rust/example/src/lib.rs b/earthly/rust/example/src/lib.rs new file mode 100644 index 000000000..57b53cf6f --- /dev/null +++ b/earthly/rust/example/src/lib.rs @@ -0,0 +1,34 @@ +//! Our simple library crate. + +/// Format our hello message nicely. +#[must_use] +pub fn fmt_hello(name: &str, count: u8) -> String { + format!("Hello #{count:>3} {name}!") +} + +/// Excessive unit tests for this function. +#[cfg(test)] +mod tests { + use super::*; + + #[test] + /// Prove we can say hello to Dave on a 3 count. + fn test_hello_dave_3() { + let msg = fmt_hello("Dave", 3); + assert_eq!(msg, "Hello # 3 Dave!"); + } + + #[test] + /// Prove we can say hello to Sally on a 67 count. + fn test_hello_sally_67() { + let msg = fmt_hello("Sally", 67); + assert_eq!(msg, "Hello # 67 Sally!"); + } + + #[test] + /// Prove we can say hello to World on a 123 count. + fn test_hello_world_123() { + let msg = fmt_hello("World", 123); + assert_eq!(msg, "Hello #123 World!"); + } +} diff --git a/earthly/rust/example/src/main.rs b/earthly/rust/example/src/main.rs index f3e2a1605..4f4a4bf22 100644 --- a/earthly/rust/example/src/main.rs +++ b/earthly/rust/example/src/main.rs @@ -1,6 +1,8 @@ -// src/main.rs +//! Simple program to greet a person. +//! Used as a test of the Rust CI/CD pipeline. use clap::Parser; +use hello_world_lib::fmt_hello; /// Simple program to greet a person #[derive(Parser, Debug)] @@ -15,20 +17,11 @@ struct Args { count: u8, } +/// The main entrypoint of this program. fn main() { let args = Args::parse(); - for _ in 0..args.count { - println!("Hello {}!", args.name) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_hello_world() { - assert_eq!(main(), ()); + for cnt in 0..args.count { + println!("{}", fmt_hello(&args.name, cnt)); } } diff --git a/earthly/rust/example/t b/earthly/rust/example/t new file mode 100644 index 000000000..0e4a1c75a --- /dev/null +++ b/earthly/rust/example/t @@ -0,0 +1,7 @@ + +crate hello_world_lib +├── fn fmt_hello: pub +└── mod tests: pub(crate) #[cfg(test)] + ├── fn test_hello_dave_3: pub(self) #[test] + ├── fn test_hello_sally_67: pub(self) #[test] + └── fn test_hello_world_123: pub(self) #[test] diff --git a/earthly/rust/example/tests/integration_test.rs b/earthly/rust/example/tests/integration_test.rs index 7d01f8866..9a5311499 100644 --- a/earthly/rust/example/tests/integration_test.rs +++ b/earthly/rust/example/tests/integration_test.rs @@ -1,10 +1,11 @@ -// tests/integration_test.rs -#[cfg(test)] -mod integration_tests { - use super::*; +//! Simple integration tests - #[test] - fn test_hello_world() { - assert_eq!(main(), ()); - } +#[test] +/// Prove we can say hello to Dave on a 99 count. +fn test_hello_dave_99() { + let msg = fmt_hello("Dave", 99); + assert_eq!(msg, "Hello # 99 Dave!"); } + +/// Dummy main needed because we are integration testing a binary package. +fn main() {} diff --git a/earthly/rust/scripts/std_build.sh b/earthly/rust/scripts/std_build.sh index 3439bc6aa..94ec9862d 100755 --- a/earthly/rust/scripts/std_build.sh +++ b/earthly/rust/scripts/std_build.sh @@ -21,22 +21,33 @@ status $rc "Building all code in the workspace" \ cargo build --release --workspace --locked; rc=$? ## Check the code passes all clippy lint checks. +status $rc "Checking all Clippy Lints in the workspace" \ + cargo lint; rc=$? ## Check we can generate all the documentation +status $rc "Checking Documentation can be generated OK" \ + cargo docs; rc=$? ## Check if all Self contained tests pass (Test that need no external resources). +status $rc "Checking Self contained Unit tests all pass" \ + cargo testci; rc=$? ## Check if all documentation tests pass. +status $rc "Checking Documentation tests all pass" \ + cargo testdocs; rc=$? ## Check if any benchmarks defined run (We don;t validate the results.) - -## Check if there are any circular dependencies in the project. +status $rc "Checking Benchmarks all run to completion" \ + cargo bench --all-targets; rc=$? ## Generate Module Trees for documentation purposes. +# cargo modules generate tree --orphans --types --traits --fns --tests --all-features --lib +# cargo modules generate tree --orphans --types --traits --fns --tests --all-features --bin ## Generate Module Graphs for documentation purposes. +# cargo modules generate graph --all-features --types --traits --fns --modules --uses --externs --acyclic --lib +# cargo modules generate graph --all-features --types --traits --fns --modules --uses --externs --acyclic --bin -## Save all the artifacts so we can use them. # Return an error if any of this fails. exit $rc \ No newline at end of file diff --git a/earthly/rust/scripts/std_checks.sh b/earthly/rust/scripts/std_checks.sh index 4db2db796..81fe71eba 100755 --- a/earthly/rust/scripts/std_checks.sh +++ b/earthly/rust/scripts/std_checks.sh @@ -25,20 +25,25 @@ check_vendored_files() { # This imporvies visibility into all issues that need to be corrected for `check` # to pass without needing to iterate excessively. -rc=0 - -## Check if .cargo.config.toml has been modified. -check_vendored_files $rc .cargo/config.toml "$CARGO_HOME"/config.toml; rc=$? -check_vendored_files $rc rustfmt.toml /stdcfgs/rustfmt.toml; rc=$? - # Check if the rust src is properly formatted. -status $rc "Checking Rust Code Format" cargo +nightly fmtchk; rc=$? +# Note, we run this first so we can print help how to fix. +status 0 "Checking Rust Code Format" cargo +nightly fmtchk; rc=$? if [ $rc -ne 0 ]; then echo -e " ${YELLOW}You can locally fix format errors by running: \`cargo +nightly fmtfix\`${NC}" fi +## Check if .cargo.config.toml has been modified. +check_vendored_files $rc .cargo/config.toml "$CARGO_HOME"/config.toml; rc=$? +check_vendored_files $rc rustfmt.toml /stdcfgs/rustfmt.toml; rc=$? +check_vendored_files $rc .config/nextest.toml /stdcfgs/nextest.toml; rc=$? +check_vendored_files $rc clippy.toml /stdcfgs/clippy.toml; rc=$? +check_vendored_files $rc deny.toml /stdcfgs/deny.toml; rc=$? + # Check if we have unused dependencies declared in our Cargo.toml files. status $rc "Checking for Unused Dependencies" cargo machete; rc=$? +# Check if we have any supply chain issues with dependencies. +status $rc "Checking for Supply Chain Issues" cargo deny check; rc=$? + # Return an error if any of this fails. exit $rc \ No newline at end of file diff --git a/earthly/rust/stdcfgs/README.md b/earthly/rust/stdcfgs/README.md new file mode 100644 index 000000000..f80360071 --- /dev/null +++ b/earthly/rust/stdcfgs/README.md @@ -0,0 +1,51 @@ +# Rust Standardized Configuration + + + +We define RUST Global Cargo Configurations here. +It is applied globally to all Rust Code built by Project Catalyst. + +There are many tools in the rust ecosystem, and there is not a single config file which controls them. +This directory contains our standardized configuration for these tools to ensure consistent use. +These files must be consistent with the Rust configs being used to build code in CI. +They are also important to be consistent on a local developers machine to ensure consistent environments. + +All configs exists here so that they can be used locally during development, as well as during CI builds. + +They will be checked during CI to ensure they have not been altered from the enforced standard. +The enforced standard can be referenced here: [Catalyst-CI Global Cargo Config](todo) + +If a file needs to be updated, please update it in the standard location first, have the PR +approved, and then update the equivalent file in the project repo to match it. + +Differences between these files and the enforced standards will prevent CI from accepting your PR. + +## `cargo_config.toml` + +This is the standard `.cargo/config.toml` file. + +Each Project Catalyst Repo that has Rust code must include this file in: + +```path +/.cargo/config.toml +``` + +## `clippy.toml` + +Clippy configuration options. +Goes in the Rust workspace root folder. + +## `nextest.toml` + +Configures the `nextest` test runner. +Goes in `/.config/nextest.toml` + +## `deny.toml` + +Configuration for cargo deny to enforce software supply chain control. +This file goes in `/deny.toml` + +## `rustfmt.toml` + +Configuration for `rustfmt`. +Goes in `/rustfmt.toml` diff --git a/earthly/rust/.cargo/config.toml b/earthly/rust/stdcfgs/cargo_config.toml similarity index 98% rename from earthly/rust/.cargo/config.toml rename to earthly/rust/stdcfgs/cargo_config.toml index 6ccbcb725..fda1dc15a 100644 --- a/earthly/rust/.cargo/config.toml +++ b/earthly/rust/stdcfgs/cargo_config.toml @@ -113,7 +113,7 @@ docs = "doc --workspace -r --all-features --no-deps --bins --document-private-it # nightly docs build broken... when they are'nt we can enable these docs... --unit-graph --timings=html,json -Z unstable-options" testfast = "nextest run --release --workspace --locked" testci = "nextest run --release --workspace --locked -P ci" -testdocs = "test --doc --release --workspace --locked --doc" +testdocs = "test --doc --release --workspace --locked" # Rust formatting, MUST be run with +nightly fmtchk = "fmt -- --check -v --color=always" diff --git a/earthly/rust/stdcfgs/clippy.toml b/earthly/rust/stdcfgs/clippy.toml new file mode 100644 index 000000000..154626ef4 --- /dev/null +++ b/earthly/rust/stdcfgs/clippy.toml @@ -0,0 +1 @@ +allow-unwrap-in-tests = true diff --git a/earthly/rust/stdcfgs/deny.toml b/earthly/rust/stdcfgs/deny.toml new file mode 100644 index 000000000..23760323c --- /dev/null +++ b/earthly/rust/stdcfgs/deny.toml @@ -0,0 +1,271 @@ +# This template contains all of the possible sections and their default values + +# Note that all fields that take a lint level have these possible values: +# * deny - An error will be produced and the check will fail +# * warn - A warning will be produced, but the check will not fail +# * allow - No warning or error will be produced, though in some cases a note +# will be + +# The values provided in this template are the default values that will be used +# when any section or field is not specified in your own configuration + +# Root options + +# If 1 or more target triples (and optionally, target_features) are specified, +# only the specified targets will be checked when running `cargo deny check`. +# This means, if a particular package is only ever used as a target specific +# dependency, such as, for example, the `nix` crate only being used via the +# `target_family = "unix"` configuration, that only having windows targets in +# this list would mean the nix crate, as well as any of its exclusive +# dependencies not shared by any other crates, would be ignored, as the target +# list here is effectively saying which targets you are building for. +targets = [ + # The triple can be any string, but only the target triples built in to + # rustc (as of 1.40) can be checked against actual config expressions + #{ triple = "x86_64-unknown-linux-musl" }, + # You can also specify which target_features you promise are enabled for a + # particular target. target_features are currently not validated against + # the actual valid features supported by the target architecture. + #{ triple = "wasm32-unknown-unknown", features = ["atomics"] }, +] +# When creating the dependency graph used as the source of truth when checks are +# executed, this field can be used to prune crates from the graph, removing them +# from the view of cargo-deny. This is an extremely heavy hammer, as if a crate +# is pruned from the graph, all of its dependencies will also be pruned unless +# they are connected to another crate in the graph that hasn't been pruned, +# so it should be used with care. The identifiers are [Package ID Specifications] +# (https://doc.rust-lang.org/cargo/reference/pkgid-spec.html) +#exclude = [] +# If true, metadata will be collected with `--all-features`. Note that this can't +# be toggled off if true, if you want to conditionally enable `--all-features` it +# is recommended to pass `--all-features` on the cmd line instead +all-features = false +# If true, metadata will be collected with `--no-default-features`. The same +# caveat with `all-features` applies +no-default-features = false +# If set, these feature will be enabled when collecting metadata. If `--features` +# is specified on the cmd line they will take precedence over this option. +#features = [] +# When outputting inclusion graphs in diagnostics that include features, this +# option can be used to specify the depth at which feature edges will be added. +# This option is included since the graphs can be quite large and the addition +# of features from the crate(s) to all of the graph roots can be far too verbose. +# This option can be overridden via `--feature-depth` on the cmd line +feature-depth = 1 + +# This section is considered when running `cargo deny check advisories` +# More documentation for the advisories section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html +[advisories] +# The path where the advisory database is cloned/fetched into +db-path = "~/.cargo/advisory-db" +# The url(s) of the advisory databases to use +db-urls = ["https://github.com/rustsec/advisory-db"] +# The lint level for security vulnerabilities +vulnerability = "deny" +# The lint level for unmaintained crates +unmaintained = "warn" +# The lint level for crates that have been yanked from their source registry +yanked = "warn" +# The lint level for crates with security notices. +notice = "warn" +# A list of advisory IDs to ignore. Note that ignored advisories will still +# output a note when they are encountered. +ignore = [ + #"RUSTSEC-0000-0000", +] +# Threshold for security vulnerabilities, any vulnerability with a CVSS score +# lower than the range specified will be ignored. Note that ignored advisories +# will still output a note when they are encountered. +# * None - CVSS Score 0.0 +# * Low - CVSS Score 0.1 - 3.9 +# * Medium - CVSS Score 4.0 - 6.9 +# * High - CVSS Score 7.0 - 8.9 +# * Critical - CVSS Score 9.0 - 10.0 +#severity-threshold = + +# If this is true, then cargo deny will use the git executable to fetch advisory database. +# If this is false, then it uses a built-in git library. +# Setting this to true can be helpful if you have special authentication requirements that cargo-deny does not support. +# See Git Authentication for more information about setting up git authentication. +#git-fetch-with-cli = true + +# This section is considered when running `cargo deny check licenses` +# More documentation for the licenses section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/licenses/cfg.html +[licenses] +# The lint level for crates which do not have a detectable license +unlicensed = "deny" +# List of explicitly allowed licenses +# See https://spdx.org/licenses/ for list of possible licenses +# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. +allow = [ + "MIT", + "Apache-2.0", + "Unicode-DFS-2016" +] +# List of explicitly disallowed licenses +# See https://spdx.org/licenses/ for list of possible licenses +# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. +deny = [ + #"Nokia", +] +# Lint level for licenses considered copyleft +copyleft = "deny" + +# Blanket approval or denial for OSI-approved or FSF Free/Libre licenses +# * both - The license will be approved if it is both OSI-approved *AND* FSF +# * either - The license will be approved if it is either OSI-approved *OR* FSF +# * osi - The license will be approved if it is OSI approved +# * fsf - The license will be approved if it is FSF Free +# * osi-only - The license will be approved if it is OSI-approved *AND NOT* FSF +# * fsf-only - The license will be approved if it is FSF *AND NOT* OSI-approved +# * neither - This predicate is ignored and the default lint level is used +allow-osi-fsf-free = "neither" +# Lint level used when no other predicates are matched +# 1. License isn't in the allow or deny lists +# 2. License isn't copyleft +# 3. License isn't OSI/FSF, or allow-osi-fsf-free = "neither" +default = "deny" +# The confidence threshold for detecting a license from license text. +# The higher the value, the more closely the license text must be to the +# canonical license text of a valid SPDX license file. +# [possible values: any between 0.0 and 1.0]. +confidence-threshold = 0.8 +# Allow 1 or more licenses on a per-crate basis, so that particular licenses +# aren't accepted for every possible crate as with the normal allow list +exceptions = [ + # Each entry is the crate and version constraint, and its specific allow + # list + #{ allow = ["Zlib"], name = "adler32", version = "*" }, +] + +# Some crates don't have (easily) machine readable licensing information, +# adding a clarification entry for it allows you to manually specify the +# licensing information +#[[licenses.clarify]] +# The name of the crate the clarification applies to +#name = "ring" +# The optional version constraint for the crate +#version = "*" +# The SPDX expression for the license requirements of the crate +#expression = "MIT AND ISC AND OpenSSL" +# One or more files in the crate's source used as the "source of truth" for +# the license expression. If the contents match, the clarification will be used +# when running the license check, otherwise the clarification will be ignored +# and the crate will be checked normally, which may produce warnings or errors +# depending on the rest of your configuration +#license-files = [ + # Each entry is a crate relative path, and the (opaque) hash of its contents + #{ path = "LICENSE", hash = 0xbd0eed23 } +#] + +[licenses.private] +# If true, ignores workspace crates that aren't published, or are only +# published to private registries. +# To see how to mark a crate as unpublished (to the official registry), +# visit https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field. +ignore = false +# One or more private registries that you might publish crates to, if a crate +# is only published to private registries, and ignore is true, the crate will +# not have its license(s) checked +registries = [ + #"https://sekretz.com/registry +] + +# This section is considered when running `cargo deny check bans`. +# More documentation about the 'bans' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/bans/cfg.html +[bans] +# Lint level for when multiple versions of the same crate are detected +multiple-versions = "warn" +# Lint level for when a crate version requirement is `*` +wildcards = "deny" +# The graph highlighting used when creating dotgraphs for crates +# with multiple versions +# * lowest-version - The path to the lowest versioned duplicate is highlighted +# * simplest-path - The path to the version with the fewest edges is highlighted +# * all - Both lowest-version and simplest-path are used +highlight = "all" +# The default lint level for `default` features for crates that are members of +# the workspace that is being checked. This can be overridden by allowing/denying +# `default` on a crate-by-crate basis if desired. +workspace-default-features = "allow" +# The default lint level for `default` features for external crates that are not +# members of the workspace. This can be overridden by allowing/denying `default` +# on a crate-by-crate basis if desired. +external-default-features = "allow" +# List of crates that are allowed. Use with care! +allow = [ + #{ name = "ansi_term", version = "=0.11.0" }, +] +# List of crates to deny +deny = [ + # Each entry the name of a crate and a version range. If version is + # not specified, all versions will be matched. + #{ name = "ansi_term", version = "=0.11.0" }, + # + # Wrapper crates can optionally be specified to allow the crate when it + # is a direct dependency of the otherwise banned crate + #{ name = "ansi_term", version = "=0.11.0", wrappers = [] }, + { name = "openssl" }, +] + +# List of features to allow/deny +# Each entry the name of a crate and a version range. If version is +# not specified, all versions will be matched. +#[[bans.features]] +#name = "reqwest" +# Features to not allow +#deny = ["json"] +# Features to allow +#allow = [ +# "rustls", +# "__rustls", +# "__tls", +# "hyper-rustls", +# "rustls", +# "rustls-pemfile", +# "rustls-tls-webpki-roots", +# "tokio-rustls", +# "webpki-roots", +#] +# If true, the allowed features must exactly match the enabled feature set. If +# this is set there is no point setting `deny` +#exact = true + +# Certain crates/versions that will be skipped when doing duplicate detection. +skip = [ + #{ name = "ansi_term", version = "=0.11.0" }, +] +# Similarly to `skip` allows you to skip certain crates during duplicate +# detection. Unlike skip, it also includes the entire tree of transitive +# dependencies starting at the specified crate, up to a certain depth, which is +# by default infinite. +skip-tree = [ + #{ name = "ansi_term", version = "=0.11.0", depth = 20 }, +] + +# This section is considered when running `cargo deny check sources`. +# More documentation about the 'sources' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/sources/cfg.html +[sources] +# Lint level for what to happen when a crate from a crate registry that is not +# in the allow list is encountered +unknown-registry = "deny" +# Lint level for what to happen when a crate from a git repository that is not +# in the allow list is encountered +unknown-git = "deny" +# List of URLs for allowed crate registries. Defaults to the crates.io index +# if not specified. If it is specified but empty, no registries are allowed. +allow-registry = ["https://github.com/rust-lang/crates.io-index"] +# List of URLs for allowed Git repositories +allow-git = [] + +[sources.allow-org] +# 1 or more github.com organizations to allow git sources for +#github = [""] +# 1 or more gitlab.com organizations to allow git sources for +#gitlab = [""] +# 1 or more bitbucket.org organizations to allow git sources for +#bitbucket = [""] diff --git a/earthly/rust/stdcfgs/nextest.toml b/earthly/rust/stdcfgs/nextest.toml new file mode 100644 index 000000000..ebc7d7390 --- /dev/null +++ b/earthly/rust/stdcfgs/nextest.toml @@ -0,0 +1,49 @@ +# cspell: words nextest scrollability testcase +[store] +# The directory under the workspace root at which nextest-related files are +# written. Profile-specific storage is currently written to dir/. +# dir = "target/nextest" + +[profile.default] +# Print out output for failing tests as soon as they fail, and also at the end +# of the run (for easy scrollability). +failure-output = "immediate-final" + +# Do not cancel the test run on the first failure. +fail-fast = true + +status-level = "all" +final-status-level = "all" + +[profile.ci] +# Print out output for failing tests as soon as they fail, and also at the end +# of the run (for easy scrollability). +failure-output = "immediate-final" +# Do not cancel the test run on the first failure. +fail-fast = false + +status-level = "all" +final-status-level = "all" + + +[profile.ci.junit] +# Output a JUnit report into the given file inside 'store.dir/'. +# If unspecified, JUnit is not written out. + +path = "junit.xml" + +# The name of the top-level "report" element in JUnit report. If aggregating +# reports across different test runs, it may be useful to provide separate names +# for each report. +report-name = "cat-gateway" + +# Whether standard output and standard error for passing tests should be stored in the JUnit report. +# Output is stored in the and elements of the element. +store-success-output = true + +# Whether standard output and standard error for failing tests should be stored in the JUnit report. +# Output is stored in the and elements of the element. +# +# Note that if a description can be extracted from the output, it is always stored in the +# element. +store-failure-output = true diff --git a/earthly/rust/rustfmt.toml b/earthly/rust/stdcfgs/rustfmt.toml similarity index 100% rename from earthly/rust/rustfmt.toml rename to earthly/rust/stdcfgs/rustfmt.toml From 181265ca167b76d2cf38241e6717a5ac3d0d048f Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Mon, 30 Oct 2023 19:46:14 +0700 Subject: [PATCH 19/21] feat(rust): add BSD license to accepted licenses --- earthly/rust/stdcfgs/deny.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/earthly/rust/stdcfgs/deny.toml b/earthly/rust/stdcfgs/deny.toml index 23760323c..640161f30 100644 --- a/earthly/rust/stdcfgs/deny.toml +++ b/earthly/rust/stdcfgs/deny.toml @@ -102,7 +102,8 @@ unlicensed = "deny" allow = [ "MIT", "Apache-2.0", - "Unicode-DFS-2016" + "Unicode-DFS-2016", + "BSD-3-Clause" ] # List of explicitly disallowed licenses # See https://spdx.org/licenses/ for list of possible licenses From 40b6c05c4ece4d96cf9f3b20d21e07ae57a3e155 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Tue, 31 Oct 2023 09:14:12 +0700 Subject: [PATCH 20/21] feat(rust): Enhanced Rust builders to better handle Arm/X86 build machines --- earthly/rust/Earthfile | 12 ++++++++---- earthly/rust/example/.cargo/config.toml | 8 +++++--- earthly/rust/example/deny.toml | 2 ++ earthly/rust/example/t | 7 ------- earthly/rust/scripts/std_build.sh | 8 +++++--- earthly/rust/scripts/std_checks.sh | 9 ++++++--- earthly/rust/stdcfgs/cargo_config.toml | 8 +++++--- earthly/rust/stdcfgs/deny.toml | 5 +++-- 8 files changed, 34 insertions(+), 25 deletions(-) delete mode 100644 earthly/rust/example/t diff --git a/earthly/rust/Earthfile b/earthly/rust/Earthfile index c211101f8..429034dff 100644 --- a/earthly/rust/Earthfile +++ b/earthly/rust/Earthfile @@ -2,6 +2,9 @@ VERSION 0.7 # cspell: words rustup rustc automake autotools xutils miri nextest kani +# cspell: words TARGETPLATFORM TARGETOS TARGETARCH TARGETVARIANT +# cspell: words USERPLATFORM USEROS USERARCH USERVARIANT +# cspell: words ripgrep colordiff rustfmt stdcfgs toolset toolsets readelf # Base Rustup build container. rust-base: @@ -56,7 +59,7 @@ rust-base: # Install rust based tooling # Install tools we use commonly with `cargo`. # Note, we disable static compiles for tools, specifically, as its not required. - # These tools are not artefacts and we do not use them in production. + # These tools are not artifacts and we do not use them in production. RUN cargo install cargo-nextest --version=0.9.59 && \ cargo install cargo-machete --version=0.6.0 && \ cargo install refinery_cli --version=0.8.11 && \ @@ -109,7 +112,7 @@ SETUP: CP_SRC: # Copy the build src using this. COMMAND - # This can be one directory like `"src/*"` or multiple src seperated by `","`: + # This can be one directory like `"src/*"` or multiple src separated by `","`: # eg, "example/Cargo.toml, example/Cargo.lock, example/src" ARG src="" @@ -128,7 +131,7 @@ CHECK: COMMAND # This is set up so that ALL checks are run and it will fail if any fail. - # This imporvies visibility into all issues that need to be corrected for `check` + # This improves visibility into all issues that need to be corrected for `check` # to pass without needing to iterate excessively. RUN /scripts/std_checks.sh @@ -228,7 +231,8 @@ package: integrate: FROM scratch -# Publish packlages if all integration tests have passed. (Failure to pass tests will prevent packages being published.) +# Publish packages if all integration tests have passed. +# (Failure to pass tests will prevent packages being published.) publish: FROM scratch diff --git a/earthly/rust/example/.cargo/config.toml b/earthly/rust/example/.cargo/config.toml index fda1dc15a..e8463c6a5 100644 --- a/earthly/rust/example/.cargo/config.toml +++ b/earthly/rust/example/.cargo/config.toml @@ -1,5 +1,7 @@ # Use MOLD linker where possible, but ONLY in CI applicable targets. -# cspell: words rustflags armv gnueabihf msvc nextest idents rustdocflags rustdoc lintfix lintrestrict testfast testdocs +# cspell: words rustflags armv gnueabihf msvc nextest idents rustdocflags +# cspell: words rustdoc lintfix lintrestrict testfast testdocs codegen testci +# cspell: words fmtchk fmtfix # Configure how Docker container targets build. @@ -80,7 +82,7 @@ opt-level = 3 debug = false debug-assertions = false overflow-checks = false -lto = true +lto = "thin" panic = 'unwind' incremental = false codegen-units = 16 @@ -98,7 +100,7 @@ opt-level = 3 debug = false debug-assertions = false overflow-checks = false -lto = true +lto = "thin" incremental = false codegen-units = 16 diff --git a/earthly/rust/example/deny.toml b/earthly/rust/example/deny.toml index 23760323c..836d0b42d 100644 --- a/earthly/rust/example/deny.toml +++ b/earthly/rust/example/deny.toml @@ -1,5 +1,7 @@ # This template contains all of the possible sections and their default values +# cspell: words rustc RUSTSEC dotgraphs reqwest rustls pemfile webpki + # Note that all fields that take a lint level have these possible values: # * deny - An error will be produced and the check will fail # * warn - A warning will be produced, but the check will not fail diff --git a/earthly/rust/example/t b/earthly/rust/example/t deleted file mode 100644 index 0e4a1c75a..000000000 --- a/earthly/rust/example/t +++ /dev/null @@ -1,7 +0,0 @@ - -crate hello_world_lib -├── fn fmt_hello: pub -└── mod tests: pub(crate) #[cfg(test)] - ├── fn test_hello_dave_3: pub(self) #[test] - ├── fn test_hello_sally_67: pub(self) #[test] - └── fn test_hello_world_123: pub(self) #[test] diff --git a/earthly/rust/scripts/std_build.sh b/earthly/rust/scripts/std_build.sh index 94ec9862d..c74164b3e 100755 --- a/earthly/rust/scripts/std_build.sh +++ b/earthly/rust/scripts/std_build.sh @@ -1,9 +1,11 @@ #!/usr/bin/env bash -# This script is run inside the `check` stage for rust projects to perfom all +# cspell: words testci testdocs + +# This script is run inside the `check` stage for rust projects to perform all # high level non-compilation checks. # These are the Standard checks which ALL rust targets must pass before they -# will be scheduled to be `buuild`. +# will be scheduled to be `build`. # Individual targets can add extra `check` steps, but these checks must always # pass. @@ -11,7 +13,7 @@ source "$(dirname "$0")/colors.sh" # This is set up so that ALL build steps are run and it will fail if any fail. -# This imporvies visibility into all issues that need to be corrected for `build` +# This improves visibility into all issues that need to be corrected for `build` # to pass without needing to iterate excessively. rc=0 diff --git a/earthly/rust/scripts/std_checks.sh b/earthly/rust/scripts/std_checks.sh index 81fe71eba..8138dde73 100755 --- a/earthly/rust/scripts/std_checks.sh +++ b/earthly/rust/scripts/std_checks.sh @@ -1,9 +1,12 @@ #!/usr/bin/env bash -# This script is run inside the `check` stage for rust projects to perfom all +# cspell: words localfile vendorfile colordiff Naur fmtchk fmtfix rustfmt stdcfgs +# cspell: words nextest + +# This script is run inside the `check` stage for rust projects to perform all # high level non-compilation checks. # These are the Standard checks which ALL rust targets must pass before they -# will be scheduled to be `buuild`. +# will be scheduled to be `build`. # Individual targets can add extra `check` steps, but these checks must always # pass. @@ -22,7 +25,7 @@ check_vendored_files() { } # This is set up so that ALL checks are run and it will fail if any fail. -# This imporvies visibility into all issues that need to be corrected for `check` +# This improves visibility into all issues that need to be corrected for `check` # to pass without needing to iterate excessively. # Check if the rust src is properly formatted. diff --git a/earthly/rust/stdcfgs/cargo_config.toml b/earthly/rust/stdcfgs/cargo_config.toml index fda1dc15a..e8463c6a5 100644 --- a/earthly/rust/stdcfgs/cargo_config.toml +++ b/earthly/rust/stdcfgs/cargo_config.toml @@ -1,5 +1,7 @@ # Use MOLD linker where possible, but ONLY in CI applicable targets. -# cspell: words rustflags armv gnueabihf msvc nextest idents rustdocflags rustdoc lintfix lintrestrict testfast testdocs +# cspell: words rustflags armv gnueabihf msvc nextest idents rustdocflags +# cspell: words rustdoc lintfix lintrestrict testfast testdocs codegen testci +# cspell: words fmtchk fmtfix # Configure how Docker container targets build. @@ -80,7 +82,7 @@ opt-level = 3 debug = false debug-assertions = false overflow-checks = false -lto = true +lto = "thin" panic = 'unwind' incremental = false codegen-units = 16 @@ -98,7 +100,7 @@ opt-level = 3 debug = false debug-assertions = false overflow-checks = false -lto = true +lto = "thin" incremental = false codegen-units = 16 diff --git a/earthly/rust/stdcfgs/deny.toml b/earthly/rust/stdcfgs/deny.toml index 640161f30..836d0b42d 100644 --- a/earthly/rust/stdcfgs/deny.toml +++ b/earthly/rust/stdcfgs/deny.toml @@ -1,5 +1,7 @@ # This template contains all of the possible sections and their default values +# cspell: words rustc RUSTSEC dotgraphs reqwest rustls pemfile webpki + # Note that all fields that take a lint level have these possible values: # * deny - An error will be produced and the check will fail # * warn - A warning will be produced, but the check will not fail @@ -102,8 +104,7 @@ unlicensed = "deny" allow = [ "MIT", "Apache-2.0", - "Unicode-DFS-2016", - "BSD-3-Clause" + "Unicode-DFS-2016" ] # List of explicitly disallowed licenses # See https://spdx.org/licenses/ for list of possible licenses From 6b9ee2840826658eedfc31c4713e4471779f3dc7 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Tue, 31 Oct 2023 14:21:35 +0700 Subject: [PATCH 21/21] feat(rust): Allo BSD-3-Clause as a compatible license --- earthly/rust/example/deny.toml | 3 ++- earthly/rust/stdcfgs/deny.toml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/earthly/rust/example/deny.toml b/earthly/rust/example/deny.toml index 836d0b42d..b11e9e887 100644 --- a/earthly/rust/example/deny.toml +++ b/earthly/rust/example/deny.toml @@ -104,7 +104,8 @@ unlicensed = "deny" allow = [ "MIT", "Apache-2.0", - "Unicode-DFS-2016" + "Unicode-DFS-2016", + "BSD-3-Clause" ] # List of explicitly disallowed licenses # See https://spdx.org/licenses/ for list of possible licenses diff --git a/earthly/rust/stdcfgs/deny.toml b/earthly/rust/stdcfgs/deny.toml index 836d0b42d..b11e9e887 100644 --- a/earthly/rust/stdcfgs/deny.toml +++ b/earthly/rust/stdcfgs/deny.toml @@ -104,7 +104,8 @@ unlicensed = "deny" allow = [ "MIT", "Apache-2.0", - "Unicode-DFS-2016" + "Unicode-DFS-2016", + "BSD-3-Clause" ] # List of explicitly disallowed licenses # See https://spdx.org/licenses/ for list of possible licenses