forked from NomicFoundation/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate snapshots of the Rust public API (NomicFoundation#1081)
This will make sure any additions/removals impacting users is accounted for.
- Loading branch information
1 parent
43b389e
commit fccfec5
Showing
11 changed files
with
5,162 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
mod manifest; | ||
mod public_api; | ||
mod workspace; | ||
|
||
pub use workspace::*; | ||
pub use public_api::UserFacingCrate; | ||
pub use workspace::{CargoWorkspace, CargoWorkspaceCommands}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use strum_macros::{Display, EnumIter}; | ||
|
||
#[derive(Clone, Copy, Debug, Display, EnumIter)] | ||
#[allow(non_camel_case_types)] | ||
pub enum UserFacingCrate { | ||
// Sorted by dependency order (from dependencies to dependents): | ||
metaslang_cst, | ||
metaslang_graph_builder, | ||
metaslang_bindings, | ||
slang_solidity, | ||
slang_solidity_cli, | ||
} | ||
|
||
#[cfg(test)] | ||
mod public_api_snapshots { | ||
use anyhow::Result; | ||
use rayon::iter::{ParallelBridge, ParallelIterator}; | ||
use strum::IntoEnumIterator; | ||
|
||
use crate::cargo::{CargoWorkspace, UserFacingCrate}; | ||
use crate::codegen::CodegenFileSystem; | ||
|
||
#[test] | ||
fn public_api_snapshots() { | ||
UserFacingCrate::iter() | ||
.filter(|&crate_name| has_library_target(crate_name)) | ||
.par_bridge() | ||
.for_each(|crate_name| generate_public_api(crate_name).unwrap()); | ||
} | ||
|
||
fn generate_public_api(crate_name: UserFacingCrate) -> Result<()> { | ||
let crate_dir = CargoWorkspace::locate_source_crate(crate_name.to_string())?; | ||
|
||
let rustdoc_json = rustdoc_json::Builder::default() | ||
.manifest_path(crate_dir.join("Cargo.toml")) | ||
.all_features(true) | ||
.toolchain(env!("RUST_NIGHTLY_VERSION")) | ||
.build()?; | ||
|
||
let public_api = public_api::Builder::from_rustdoc_json(rustdoc_json).build()?; | ||
|
||
let output_path = crate_dir.join("generated/public_api.txt"); | ||
|
||
let mut fs = CodegenFileSystem::new(&crate_dir)?; | ||
|
||
fs.write_file(output_path, public_api.to_string()) | ||
} | ||
|
||
fn has_library_target(crate_name: UserFacingCrate) -> bool { | ||
match crate_name { | ||
UserFacingCrate::metaslang_cst => true, | ||
UserFacingCrate::metaslang_graph_builder => true, | ||
UserFacingCrate::metaslang_bindings => true, | ||
UserFacingCrate::slang_solidity => true, | ||
UserFacingCrate::slang_solidity_cli => false, | ||
} | ||
} | ||
} |
Oops, something went wrong.