Skip to content

Commit

Permalink
Re-export crate to avoid dependency in contract (Near-One#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
mooori authored Oct 18, 2022
1 parent e08547d commit dae6f70
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion near-plugins-derive/src/access_control_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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, ..
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions near-plugins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions near-plugins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2018"
crate-type = ["cdylib", "rlib"]

[dependencies]
bitflags = "1.3"
near-plugins = { path = "../../../../near-plugins" }
near-sdk = "4.0.0"

Expand Down

0 comments on commit dae6f70

Please sign in to comment.