Skip to content

Commit

Permalink
build graph wip
Browse files Browse the repository at this point in the history
  • Loading branch information
StuartHarris committed Oct 26, 2024
1 parent 356d9fc commit b3a540a
Show file tree
Hide file tree
Showing 17 changed files with 199 additions and 2,538 deletions.
63 changes: 61 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions crux_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ path = "src/main.rs"
anyhow.workspace = true
clap = { version = "4.4.18", features = ["derive"] }
console = "0.15.8"
guppy = "0.17.5"
guppy = "0.17.4"
ignore = "0.4.23"
libc = "0.2.155"
ramhorns = "1.0.0"
rustdoc-types = "0.26.0"
libc = "0.2.161"
petgraph = "0.6.5"
ramhorns = "1.0.1"
rustdoc-json = "0.9.2"
rustdoc-types = "0.32.2"
serde = { workspace = true, features = ["derive"] }
serde_json = "1.0.117"
serde_json = "1.0.132"
similar = { version = "2.6.0", features = ["inline"] }
tokio = { version = "1.38.0", features = ["full"] }
tokio = { version = "1.41.0", features = ["full"] }
tokio-fd = "0.3.0"
toml = "0.8.19"
2 changes: 1 addition & 1 deletion crux_cli/codegen.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

cargo build

for d in ../examples/*
for d in ../examples/hello_world
echo ""
echo "---------------"
echo "Public API for $d"
Expand Down
8 changes: 0 additions & 8 deletions crux_cli/src/codegen/graph.rs

This file was deleted.

46 changes: 14 additions & 32 deletions crux_cli/src/codegen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,26 @@
mod graph;
mod parser;
mod public_api;

use std::{
fs::File,
io::{stdout, IsTerminal},
};
use std::fs::File;

use anyhow::{bail, Result};
use guppy::{graph::PackageGraph, MetadataCommand};
use rustdoc_types::Crate;
use tokio::{process::Command, task::spawn_blocking};
use tokio::task::spawn_blocking;

use crate::{args::CodegenArgs, command_runner};
use crate::args::CodegenArgs;

pub async fn codegen(args: &CodegenArgs) -> Result<()> {
let graph = graph::compute_package_graph()?;
let mut cmd = MetadataCommand::new();
let package_graph = PackageGraph::from_command(&mut cmd)?;

let Ok(lib) = graph.workspace().member_by_path(&args.lib) else {
let Ok(lib) = package_graph.workspace().member_by_path(&args.lib) else {
bail!("Could not find workspace package with path {}", args.lib)
};

let mut cmd = Command::new("cargo");
cmd.env("RUSTC_BOOTSTRAP", "1")
.env(
"RUSTDOCFLAGS",
"-Z unstable-options --output-format=json --cap-lints=allow",
)
.arg("doc")
.arg("--no-deps")
.arg("--manifest-path")
.arg(lib.manifest_path())
.arg("--lib");
if stdout().is_terminal() {
cmd.arg("--color=always");
}

command_runner::run(&mut cmd).await?;

let target_directory = graph.workspace().target_directory().as_std_path();
let json_path = target_directory
.join("doc")
.join(format!("{}.json", lib.name().replace('-', "_")));
let json_path = rustdoc_json::Builder::default()
.toolchain("nightly")
.manifest_path(lib.manifest_path())
.build()?;

let crate_: Crate = spawn_blocking(move || -> Result<Crate> {
let file = File::open(json_path)?;
Expand All @@ -49,7 +29,9 @@ pub async fn codegen(args: &CodegenArgs) -> Result<()> {
})
.await??;

parser::parse(&crate_)?;
println!("Parsing rustdoc JSON, version {}", crate_.format_version);
let out = parser::parse(&crate_)?;
println!("{}", out);

Ok(())
}
Loading

0 comments on commit b3a540a

Please sign in to comment.