Ver Fonte

Put CPI client behind feature flag

Armani Ferrante há 4 anos atrás
pai
commit
20bd3c2db8

+ 1 - 0
cli/src/template.rs

@@ -24,6 +24,7 @@ name = "{1}"
 
 [features]
 no-entrypoint = []
+cpi = ["no-entrypoint"]
 
 [dependencies]
 borsh = {{ git = "https://github.com/project-serum/borsh", branch = "serum", features = ["serum-program"] }}

+ 4 - 4
docs/src/tutorials/tutorial-3.md

@@ -47,10 +47,10 @@ Things to notice
   account. Think of `CpiAccount` exactly like `ProgramAccount`, except used for accounts *not*
   owned by the current program.
 
-::: details
-When adding another Anchor program to your crate's `Cargo.toml`, make sure to specify the `no-entrypoint`
-feature. If you look at the `Cargo.toml` for this example, you'll see
-`puppet = { path = "../puppet", features = ["no-entrypoint"] }`.
+::: tip
+When using another Anchor program for CPI, make sure to specify the `cpi` feature in your `Cargo.toml`.
+If you look at the `Cargo.toml` for this example, you'll see
+`puppet = { path = "../puppet", features = ["cpi"] }`.
 :::
 
 ## Signer Seeds

+ 5 - 1
examples/sysvars/programs/sysvars/Cargo.toml

@@ -5,9 +5,13 @@ description = "Created with Anchor"
 edition = "2018"
 
 [lib]
-crate-type = ["cdylib"]
+crate-type = ["cdylib", "lib"]
 name = "sysvars"
 
+[features]
+no-entrypoint = []
+cpi = ["no-entrypoint"]
+
 [dependencies]
 borsh = { git = "https://github.com/project-serum/borsh", branch = "serum", features = ["serum-program"] }
 solana-program = "1.4.3"

+ 5 - 1
examples/tutorial/basic-0/programs/basic-0/Cargo.toml

@@ -5,9 +5,13 @@ description = "Created with Anchor"
 edition = "2018"
 
 [lib]
-crate-type = ["cdylib"]
+crate-type = ["cdylib", "lib"]
 name = "basic_0"
 
+[features]
+no-entrypoint = []
+cpi = ["no-entrypoint"]
+
 [dependencies]
 borsh = { git = "https://github.com/project-serum/borsh", branch = "serum", features = ["serum-program"] }
 solana-program = "1.4.3"

+ 5 - 5
examples/tutorial/basic-0/programs/basic-0/src/lib.rs

@@ -4,11 +4,11 @@ use anchor::prelude::*;
 
 #[program]
 mod basic_0 {
-   use super::*;
-   pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
-       Ok(())
-   }
+    use super::*;
+    pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
+        Ok(())
+    }
 }
 
 #[derive(Accounts)]
-pub struct Initialize {}
+pub struct Initialize {}

+ 5 - 1
examples/tutorial/basic-1/programs/basic-1/Cargo.toml

@@ -5,9 +5,13 @@ description = "Created with Anchor"
 edition = "2018"
 
 [lib]
-crate-type = ["cdylib"]
+crate-type = ["cdylib", "lib"]
 name = "basic_1"
 
+[features]
+no-entrypoint = []
+cpi = ["no-entrypoint"]
+
 [dependencies]
 borsh = { git = "https://github.com/project-serum/borsh", branch = "serum", features = ["serum-program"] }
 solana-program = "1.4.3"

+ 5 - 1
examples/tutorial/basic-2/programs/basic-2/Cargo.toml

@@ -5,9 +5,13 @@ description = "Created with Anchor"
 edition = "2018"
 
 [lib]
-crate-type = ["cdylib"]
+crate-type = ["cdylib", "lib"]
 name = "basic_2"
 
+[features]
+no-entrypoint = []
+cpi = ["no-entrypoint"]
+
 [dependencies]
 borsh = { git = "https://github.com/project-serum/borsh", branch = "serum", features = ["serum-program"] }
 solana-program = "1.4.3"

+ 2 - 1
examples/tutorial/basic-3/programs/puppet-master/Cargo.toml

@@ -10,10 +10,11 @@ name = "puppet_master"
 
 [features]
 no-entrypoint = []
+cpi = ["no-entrypoint"]
 
 [dependencies]
 borsh = { git = "https://github.com/project-serum/borsh", branch = "serum", features = ["serum-program"] }
 solana-program = "1.4.3"
 solana-sdk = { version = "1.3.14", default-features = false, features = ["program"] }
 anchor = { git = "https://github.com/project-serum/anchor", features = ["derive"] }
-puppet = { path = "../puppet", features = ["no-entrypoint"] }
+puppet = { path = "../puppet", features = ["cpi"] }

+ 1 - 0
examples/tutorial/basic-3/programs/puppet/Cargo.toml

@@ -10,6 +10,7 @@ name = "puppet"
 
 [features]
 no-entrypoint = []
+cpi = ["no-entrypoint"]
 
 [dependencies]
 borsh = { git = "https://github.com/project-serum/borsh", branch = "serum", features = ["serum-program"] }

+ 1 - 0
syn/src/codegen/program.rs

@@ -177,6 +177,7 @@ fn generate_cpi(program: &Program) -> proc_macro2::TokenStream {
         })
         .collect();
     quote! {
+        #[cfg(feature = "cpi")]
         pub mod cpi {
             use super::*;