Closed Fuuzetsu closed 9 months ago
After surveying some popular crates, it seems that the general approach is to expose some crate =
attribute that allows specifying the name explicitly: borsh already supports this I believe. Without it, just breaks if rename happens.
Only a few crates use proc-macro-crate
helper that goes via cargo, especially because it makes the macro unpure (goes via filesystem...).
There doesn't seem to be a good solution other than these options...
@Fuuzetsu looking up nix doc https://nixos.org/manual/nixpkgs/stable/#compiling-rust-crates-using-nix-instead-of-cargo, it looks like giving up cargo
completely is a viable option.
#[borsh(crate = "borsh")]
everywhere, effectively disabling proc-macro-crate
checks, isn't too ergonomic.@Fuuzetsu looking up nix doc https://nixos.org/manual/nixpkgs/stable/#compiling-rust-crates-using-nix-instead-of-cargo, it looks like giving up
cargo
completely is a viable option.
Hm? Not sure what you mean by this but right, we already do not use cargo during the build.
272 is one of possible ways to resolve this, if adding
#[borsh(crate = "borsh")]
everywhere, effectively disablingproc-macro-crate
checks, isn't too ergonomic.
Right, making it optional is something I guess. Presumably in cases where one renamed borsh
and has a very large number of derives.
FWIW for now we're just using a fork with the proc-macro-crate
deleted from the repo all together...
@dj8yfo I don't think we need to introduce a breaking change to borsh-rs to accommodate non-standard use of build systems.
@Fuuzetsu Please, consider contributing to proc-macro-crate
so it just supports your build environment.
P.S. I closed this issue to indicate that we don't plan to take any actions on it now as it is outside of the scope of this crate, but if you believe otherwise, please, feel free to comment below
We use a build system where
cargo
is not involved during the build (via https://github.com/NixOS/nixpkgs/)However when building a dependency with
borsh-derive
, we get the below issue. looking atcheck_attrs_get_cratename
I can trace it tocrate_name
from proc_macro, notablyworkspace_manifest_path
which seems to want to use whatever binary inCARGO
env variable to then get the manifest path.It appears the whole point is to get the
borsh
crate name as the user has set it to then generate trait impls likeimpl … #cratename::de::BorshDeserialize for … {
.Probably we should be doing whatever
serde
does that doesn't involvecargo
without having to give up on having a separate derive crate (of course if it was just the same crate, I think just using$crate
would have worked).I might try to cook up a patch today.