Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

https://github.com/oxidecomputer/typify/compare/v0.6.2\...HEAD[Full list of commits]

* `import_types!` no longer requires consumers to declare `regress` as a direct dependency. The macro now references `regress` through a re-export from `typify`. Users of the macro may drop `regress` from their `Cargo.toml`. The `TypeSpace` builder API is unchanged for `cargo-typify` and `build.rs` callers, who continue to emit `::regress` by default; a new `TypeSpaceSettings::with_regress_crate` setter allows overriding the path.

== 0.6.2 (released 2026-04-24)

https://github.com/oxidecomputer/typify/compare/v0.6.1\...v0.6.2[Full list of commits]
Expand Down
18 changes: 18 additions & 0 deletions typify-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ pub struct TypeSpaceSettings {
patch: BTreeMap<String, TypeSpacePatch>,
replace: BTreeMap<String, TypeSpaceReplace>,
convert: Vec<TypeSpaceConversion>,

regress_crate: Option<String>,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -561,6 +563,22 @@ impl TypeSpaceSettings {
self.map_type = map_type.into();
self
}

/// Override the path used to reference the [`regress`] crate in generated
/// code. The default `::regress` requires consumers to declare `regress`
/// as a direct dependency. The `typify` crate sets this to
/// `::typify::regress` so that consumers of the `import_types!` macro do
/// not need a direct `regress` dependency.
pub fn with_regress_crate<S: ToString>(&mut self, path: S) -> &mut Self {
self.regress_crate = Some(path.to_string());
self
}

/// The configured regress crate path, or the default `::regress`.
pub(crate) fn regress_crate_path(&self) -> syn::Path {
let s = self.regress_crate.as_deref().unwrap_or("::regress");
syn::parse_str(s).expect("regress_crate must parse as a path")
}
}

impl TypeSpacePatch {
Expand Down
5 changes: 3 additions & 2 deletions typify-impl/src/type_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1555,9 +1555,10 @@ impl TypeEntry {

let pat = pattern.as_ref().map(|p| {
let err = format!("doesn't match pattern \"{}\"", p);
let regress = type_space.settings.regress_crate_path();
quote! {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> = ::std::sync::LazyLock::new(|| {
::regress::Regex::new(#p).unwrap()
static PATTERN: ::std::sync::LazyLock<#regress::Regex> = ::std::sync::LazyLock::new(|| {
#regress::Regex::new(#p).unwrap()
});
if PATTERN.find(value).is_none() {
return Err(#err.into());
Expand Down
7 changes: 6 additions & 1 deletion typify-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl From<MacroPatch> for TypeSpacePatch {

fn do_import_types(item: TokenStream) -> Result<TokenStream, syn::Error> {
// Allow the caller to give us either a simple string or a compound object.
let (schema, settings) = if let Ok(ll) = syn::parse::<LitStr>(item.clone()) {
let (schema, mut settings) = if let Ok(ll) = syn::parse::<LitStr>(item.clone()) {
(ll, TypeSpaceSettings::default())
} else {
let MacroSettings {
Expand Down Expand Up @@ -245,6 +245,11 @@ fn do_import_types(item: TokenStream) -> Result<TokenStream, syn::Error> {
(schema.into_inner(), settings)
};

// Macro consumers depend on the `typify` crate, which re-exports `regress`.
// Routing the generated path through the re-export saves callers from
// having to declare `regress` themselves as a peer dependency of `typify`.
settings.with_regress_crate("::typify::regress");

let dir = std::env::var("CARGO_MANIFEST_DIR").map_or_else(
|_| std::env::current_dir().unwrap(),
|s| Path::new(&s).to_path_buf(),
Expand Down
2 changes: 1 addition & 1 deletion typify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ macro = ["typify-macro"]
[dependencies]
typify-macro = { workspace = true, optional = true }
typify-impl = { workspace = true }
regress = { workspace = true }

[dev-dependencies]
chrono = { workspace = true }
env_logger = { workspace = true }
expectorate = { workspace = true }
glob = { workspace = true }
quote = { workspace = true }
regress = { workspace = true }
rustfmt-wrapper = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions typify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@

#![deny(missing_docs)]

#[doc(hidden)]
pub use regress;

pub use typify_impl::accept_as_ident;
pub use typify_impl::CrateVers;
pub use typify_impl::Error;
Expand Down