Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc typegen #217

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5e67241
add docgen cmd to crux cli and run cargo doc
StuartHarris Mar 9, 2024
e2b1782
use guppy to slurp workspace structure
StuartHarris Mar 10, 2024
d2fa459
rebase on master conflicts
StuartHarris Mar 16, 2024
9ca8539
clippy
StuartHarris Mar 16, 2024
b48bf18
start discovery
StuartHarris May 29, 2024
438f2b3
first stab at generics
StuartHarris May 31, 2024
d35b035
begin introducing output types WIP
StuartHarris May 31, 2024
1432048
borrow code from cargo-public-api crate WIP
StuartHarris Jun 3, 2024
7814e16
dig into generic type params
StuartHarris Jun 4, 2024
292c9c7
nested generics
StuartHarris Jun 5, 2024
7052f3e
respect serde skip
StuartHarris Jun 6, 2024
389cded
fully qualified names
StuartHarris Jun 6, 2024
78c6d57
sorted items
StuartHarris Jun 6, 2024
9500183
add MIT license
StuartHarris Jun 6, 2024
a013e9c
deps
StuartHarris Jun 7, 2024
e142d15
remove typeshare
StuartHarris Sep 27, 2024
d285c16
public_api mod
StuartHarris Sep 27, 2024
6058e2f
update public_api from origin
StuartHarris Sep 27, 2024
5237e6b
add back tests
StuartHarris Sep 27, 2024
356d9fc
all examples in script, and lockfiles
StuartHarris Sep 27, 2024
b3a540a
build graph wip
StuartHarris Oct 26, 2024
71932c6
ascent wip
StuartHarris Oct 27, 2024
3b7ef60
struct recursion wip
StuartHarris Oct 27, 2024
428fbb8
serde skip
StuartHarris Oct 27, 2024
b99d67a
effect variants
StuartHarris Oct 28, 2024
b4aff89
nested structs
StuartHarris Oct 28, 2024
bbfb454
recursively process generic args
StuartHarris Oct 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
670 changes: 624 additions & 46 deletions Cargo.lock

Large diffs are not rendered by default.

File renamed without changes.
21 changes: 21 additions & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 RedBadger

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.
13 changes: 11 additions & 2 deletions crux_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@ edition.workspace = true
repository.workspace = true
license.workspace = true
keywords.workspace = true
rust-version.workspace = true
rust-version = "1.70"

[[bin]]
name = "crux"
path = "src/main.rs"

[dependencies]
anyhow.workspace = true
clap = { version = "4.3.24", features = ["derive"] }
ascent = "0.7.0"
clap = { version = "4.4.18", features = ["derive"] }
console = "0.15.8"
guppy = "0.17.4"
ignore = "0.4.23"
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.132"
similar = { version = "2.6.0", features = ["inline"] }
tokio = { version = "1.41.0", features = ["full"] }
tokio-fd = "0.3.0"
toml = "0.8.19"
9 changes: 9 additions & 0 deletions crux_cli/codegen.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env fish

cargo build

for d in ../examples/hello_world
pushd $d
../../target/debug/crux codegen --lib shared
popd
end
26 changes: 18 additions & 8 deletions crux_cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ pub(crate) struct Cli {

#[arg(long, short, action = ArgAction::Count)]
pub verbose: u8,
}

#[derive(Subcommand)]
pub(crate) enum Commands {
#[command(visible_alias = "doc")]
Doctor(DoctorArgs),

#[command(visible_alias = "gen")]
Codegen(CodegenArgs),
}

#[derive(Args)]
pub(crate) struct DoctorArgs {
#[arg(long, short)]
pub(crate) fix: Option<PathBuf>,

#[arg(long, short, default_value = "false")]
pub include_source_code: bool,
Expand All @@ -31,16 +46,11 @@ pub(crate) struct Cli {
pub path: Option<PathBuf>,
}

#[derive(Subcommand)]
pub(crate) enum Commands {
#[command(visible_alias = "doc")]
Doctor(DoctorArgs),
}

#[derive(Args)]
pub(crate) struct DoctorArgs {
pub(crate) struct CodegenArgs {
/// name of the library containing your Crux App
#[arg(long, short)]
pub(crate) fix: Option<PathBuf>,
pub lib: String,
}

#[cfg(test)]
Expand Down
44 changes: 44 additions & 0 deletions crux_cli/src/codegen/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
mod parser;

use std::fs::File;

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

use crate::args::CodegenArgs;

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

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

let json_path = rustdoc_json::Builder::default()
.toolchain("nightly")
.manifest_path(lib.manifest_path())
.build()?;
// let json_path = lib
// .manifest_path()
// .parent()
// .unwrap()
// .parent()
// .unwrap()
// .join("target")
// .join("doc")
// .join("shared.json");

let crate_: Crate = spawn_blocking(move || -> Result<Crate> {
let file = File::open(json_path)?;
let crate_ = serde_json::from_reader(file)?;
Ok(crate_)
})
.await??;

parser::parse(&crate_)?;

Ok(())
}
Loading
Loading