From 77b365d6895e3aca19c04014de52e3014d9b2e3b Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Wed, 6 Dec 2023 18:46:07 +0200 Subject: [PATCH] add cargo modules docs generation --- earthly/rust/Earthfile | 6 ++++-- earthly/rust/scripts/std_build.sh | 25 ++++++++++++++++++------- examples/rust/Earthfile | 2 +- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/earthly/rust/Earthfile b/earthly/rust/Earthfile index c46976dda..a19e3974a 100644 --- a/earthly/rust/Earthfile +++ b/earthly/rust/Earthfile @@ -60,7 +60,7 @@ rust-base: 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 && \ + cargo install cargo-modules --version=0.12.0 && \ cargo install cargo-depgraph --version=1.5.0 SAVE ARTIFACT $CARGO_HOME/bin/refinery refinery @@ -129,8 +129,10 @@ CHECK: # Step we do during the `build` CI phase for all Rust programs BUILD: COMMAND + ARG --required libs + ARG --required bins - RUN /scripts/std_build.sh + RUN /scripts/std_build.sh $libs $bins # Check if the build executable, isn't a busted mess. SMOKE_TEST: diff --git a/earthly/rust/scripts/std_build.sh b/earthly/rust/scripts/std_build.sh index 98fac133e..56fe3dbf2 100755 --- a/earthly/rust/scripts/std_build.sh +++ b/earthly/rust/scripts/std_build.sh @@ -49,14 +49,25 @@ cargo depgraph --workspace-only --dedup-transitive-deps > target/doc/workspace.d cargo depgraph --dedup-transitive-deps > target/doc/full.dot cargo depgraph --all-deps --dedup-transitive-deps > target/doc/all.dot +export NO_COLOR=1 ## 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 - +for lib in $1; +do + cargo modules generate tree --orphans --types --traits --tests --all-features \ + --package $lib --lib > target/doc/$lib.lib.modules.tree; rc=$? + + cargo modules generate graph --all-features --modules \ + --package $lib --lib > target/doc/$lib.lib.modules.dot; rc=$? +done +for bin in $2; +do + IFS="/" read -r package bin <<< "$bin" + cargo modules generate tree --orphans --types --traits --tests --all-features \ + --package $package --bin $bin > target/doc/$package.$bin.bin.modules.tree; rc=$? + + cargo modules generate graph --all-features --modules \ + --package $package --bin $bin > target/doc/$package.$bin.bin.modules.dot; rc=$? +done # Return an error if any of this fails. exit $rc \ No newline at end of file diff --git a/examples/rust/Earthfile b/examples/rust/Earthfile index 2420f8321..2c364151b 100644 --- a/examples/rust/Earthfile +++ b/examples/rust/Earthfile @@ -28,7 +28,7 @@ check-all-hosts: build-hosted: FROM +builder - DO ./../../earthly/rust+BUILD + DO ./../../earthly/rust+BUILD --libs="hello_world" --bins="hello_world/hello_world" DO ./../../earthly/rust+SMOKE_TEST --bin=hello_world