Skip to content

Commit

Permalink
Merge pull request #17 from magnusuMET/bugfix/crate_name_assumption
Browse files Browse the repository at this point in the history
Fix hdf5 derive name on crate rename
  • Loading branch information
magnusuMET authored Sep 18, 2024
2 parents 41d0221 + 456ee92 commit d2cedee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
## hdf5 unreleased
## hdf5-sys unreleased
## hdf5-src unreleased

## hdf5-derive unreleased
- Fixed crate name assumption

## hdf5-types unreleased


## hdf5-src v0.9.2

Release date: Aug 14, 2024.
Expand Down
1 change: 1 addition & 0 deletions hdf5-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ edition.workspace = true
proc-macro = true

[dependencies]
proc-macro-crate = "3.2.0"
proc-macro-error = { version = "1.0", default-features = false }
proc-macro2 = "1.0"
quote = "1.0"
Expand Down
11 changes: 10 additions & 1 deletion hdf5-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ pub fn derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
let body = impl_trait(&name, &input.data, &input.attrs, &ty_generics);
let dummy = Ident::new(&format!("_IMPL_H5TYPE_FOR_{}", name), Span::call_site());

// Determine name of parent crate, even if renamed using "package"
let crate_name = match proc_macro_crate::crate_name("hdf5-metno").unwrap() {
proc_macro_crate::FoundCrate::Itself => quote!(::hdf5_metno),
proc_macro_crate::FoundCrate::Name(name) => {
let ident = Ident::new(&name, Span::call_site());
quote!( ::#ident )
}
};
let expanded = quote! {
#[allow(dead_code, unused_variables, unused_attributes)]
const #dummy: () = {
use ::hdf5_metno as _h5;
use #crate_name as _h5;

#[automatically_derived]
unsafe impl #impl_generics _h5::types::H5Type for #name #ty_generics #where_clause {
Expand Down

0 comments on commit d2cedee

Please sign in to comment.