From dae6f70cbdabb897c3fc676eae26678ac179896c Mon Sep 17 00:00:00 2001 From: mooori Date: Tue, 18 Oct 2022 20:40:14 +0200 Subject: [PATCH] Re-export crate to avoid dependency in contract (#24) --- Cargo.toml | 1 + near-plugins-derive/src/access_control_role.rs | 4 +++- near-plugins/Cargo.toml | 1 + near-plugins/src/lib.rs | 12 ++++++++++++ .../tests/contracts/access_controllable/Cargo.toml | 1 - 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index acb3996..da1d968 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ homepage = "https://github.com/aurora-is-near/near-plugins" keywords = ["near", "smart contract", "plugin"] [workspace.dependencies] +bitflags = "1.3" near-sdk = "4.0.0" near-plugins-derive = { path = "near-plugins-derive" } serde = "1" diff --git a/near-plugins-derive/src/access_control_role.rs b/near-plugins-derive/src/access_control_role.rs index 4ec63ce..07f566c 100644 --- a/near-plugins-derive/src/access_control_role.rs +++ b/near-plugins-derive/src/access_control_role.rs @@ -39,6 +39,7 @@ //! The last property aims to facilitate migrations which add or remove enum //! variants. +use crate::utils::cratename; use proc_macro::TokenStream; use proc_macro2::{Ident, Span}; use quote::quote; @@ -51,6 +52,7 @@ const DEFAULT_BOUNDCHECKER_TYPE_NAME: &str = "__AclBoundchecker"; pub fn derive_access_control_role(input: TokenStream) -> TokenStream { // This derive doesn't take attributes, so no need to use `darling`. + let cratename = cratename(); let input: ItemEnum = parse_macro_input!(input); let ItemEnum { ident, variants, .. @@ -175,7 +177,7 @@ pub fn derive_access_control_role(input: TokenStream) -> TokenStream { } } - ::bitflags::bitflags! { + ::#cratename::bitflags::bitflags! { /// Encodes permissions for roles and admins. #[derive(BorshDeserialize, BorshSerialize, Default)] struct #bitflags_type_ident: u128 { diff --git a/near-plugins/Cargo.toml b/near-plugins/Cargo.toml index 16a0126..fec73c0 100644 --- a/near-plugins/Cargo.toml +++ b/near-plugins/Cargo.toml @@ -9,6 +9,7 @@ version.workspace = true crate-type = ["cdylib", "rlib"] [dependencies] +bitflags.workspace = true near-sdk.workspace = true near-plugins-derive.workspace = true serde.workspace = true diff --git a/near-plugins/src/lib.rs b/near-plugins/src/lib.rs index 46eda8d..cf12c5c 100644 --- a/near-plugins/src/lib.rs +++ b/near-plugins/src/lib.rs @@ -18,3 +18,15 @@ pub use near_plugins_derive::{ pub use ownable::Ownable; pub use pausable::Pausable; pub use upgradable::Upgradable; + +// Re-exporting these dependencies avoids requiring contracts to depend on them. +// For example, without re-exporting `bitflags` a contract using the access +// control plugin would require: +// +// ```toml +// # Cargo.toml +// [dependencies] +// bitflags = "x.y" +// ``` +#[doc(hidden)] +pub use bitflags; diff --git a/near-plugins/tests/contracts/access_controllable/Cargo.toml b/near-plugins/tests/contracts/access_controllable/Cargo.toml index af234fb..133101f 100644 --- a/near-plugins/tests/contracts/access_controllable/Cargo.toml +++ b/near-plugins/tests/contracts/access_controllable/Cargo.toml @@ -7,7 +7,6 @@ edition = "2018" crate-type = ["cdylib", "rlib"] [dependencies] -bitflags = "1.3" near-plugins = { path = "../../../../near-plugins" } near-sdk = "4.0.0"