Skip to content

Commit

Permalink
add cargo modules docs generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy committed Dec 6, 2023
1 parent 4641928 commit 77b365d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
6 changes: 4 additions & 2 deletions earthly/rust/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
25 changes: 18 additions & 7 deletions earthly/rust/scripts/std_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name>

## 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 <name>

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
2 changes: 1 addition & 1 deletion examples/rust/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 77b365d

Please sign in to comment.