Skip to content

Commit

Permalink
feat: Enable by default release mode, embedded ABIs with doc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
frol committed Feb 3, 2024
1 parent a487c29 commit 22a7cf8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
8 changes: 4 additions & 4 deletions cargo-near/src/commands/build_command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ pub fn run(args: super::BuildCommand) -> color_eyre::eyre::Result<util::Compilat

let mut build_env = vec![("RUSTFLAGS", "-C link-arg=-s")];
let mut cargo_args = vec!["--target", COMPILATION_TARGET];
if args.release {
if !args.no_release {
cargo_args.push("--release");
}

let mut abi = None;
let mut min_abi_path = None;
if !args.no_abi {
let mut contract_abi = abi::generate_abi(&crate_metadata, args.doc, true, color.clone())?;
let mut contract_abi = abi::generate_abi(&crate_metadata, !args.no_doc, true, color.clone())?;
contract_abi.metadata.build = Some(BuildInfo {
compiler: format!("rustc {}", rustc_version::version()?),
builder: format!("cargo-near {}", env!("CARGO_PKG_VERSION")),
image: None,
});
if args.embed_abi {
if !args.no_embed_abi {
let path = util::handle_step("Compressing ABI to be embedded..", || {
let AbiResult { path } = abi::write_to_file(
&contract_abi,
Expand All @@ -72,7 +72,7 @@ pub fn run(args: super::BuildCommand) -> color_eyre::eyre::Result<util::Compilat
abi = Some(contract_abi);
}

if let (true, Some(abi_path)) = (args.embed_abi, &min_abi_path) {
if let (false, Some(abi_path)) = (args.no_embed_abi, &min_abi_path) {
cargo_args.extend(&["--features", "near-sdk/__abi-embed"]);
build_env.push(("CARGO_NEAR_ABI_PATH", abi_path.as_str()));
}
Expand Down
24 changes: 12 additions & 12 deletions cargo-near/src/commands/build_command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ pub mod build;
#[interactive_clap(input_context = near_cli_rs::GlobalContext)]
#[interactive_clap(output_context = BuildCommandlContext)]
pub struct BuildCommand {
/// Build contract in release mode, with optimizations
/// Build contract in debug mode, without optimizations and bigger is size
#[interactive_clap(long)]
pub release: bool,
/// Embed the ABI in the contract binary
#[interactive_clap(long)]
pub embed_abi: bool,
/// Include rustdocs in the embedded ABI
#[interactive_clap(long)]
pub doc: bool,
pub no_release: bool,
/// Do not generate ABI for the contract
#[interactive_clap(long, conflicts_with_all = &["doc", "embed_abi"])]
#[interactive_clap(long)]
pub no_abi: bool,
/// Do not embed the ABI in the contract binary
#[interactive_clap(long)]
pub no_embed_abi: bool,
/// Do not include rustdocs in the embedded ABI
#[interactive_clap(long)]
pub no_doc: bool,
/// Copy final artifacts to this directory
#[interactive_clap(long)]
#[interactive_clap(skip_interactive_input)]
Expand All @@ -40,10 +40,10 @@ impl BuildCommandlContext {
scope: &<BuildCommand as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
let args = BuildCommand {
release: scope.release,
embed_abi: scope.embed_abi,
doc: scope.doc,
no_release: scope.no_release,
no_abi: scope.no_abi,
no_embed_abi: scope.no_embed_abi,
no_doc: scope.no_doc,
out_dir: scope.out_dir.clone(),
manifest_path: scope.manifest_path.clone(),
color: scope.color.clone(),
Expand Down
6 changes: 3 additions & 3 deletions cargo-near/src/commands/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ impl interactive_clap::FromCli for Contract {
let build_command_args =
if let Some(cli_build_command_args) = &clap_variant.build_command_args {
build_command::BuildCommand {
release: cli_build_command_args.release,
embed_abi: cli_build_command_args.embed_abi,
doc: cli_build_command_args.doc,
no_release: cli_build_command_args.no_release,
no_abi: cli_build_command_args.no_abi,
no_embed_abi: cli_build_command_args.no_embed_abi,
no_doc: cli_build_command_args.no_doc,
out_dir: cli_build_command_args.out_dir.clone(),
manifest_path: cli_build_command_args.manifest_path.clone(),
color: cli_build_command_args.color.clone(),
Expand Down
13 changes: 6 additions & 7 deletions cargo-near/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@ pub enum NearCommand {
/// Initializes a new project to create a contract
New(self::new::New),
#[strum_discriminants(strum(
message = "build - Build a NEAR contract and optionally embed ABI"
message = "build - Build a NEAR contract with embed ABI (opt out by passing `--no-embed-abi`)"
))]
/// Build a NEAR contract and optionally embed ABI
/// Build a NEAR contract with embed ABI (opt out by passing `--no-embed-abi`)
Build(self::build_command::BuildCommand),
#[strum_discriminants(strum(
message = "abi - Generates ABI for the contract"
))]
/// Generates ABI for the contract
Abi(self::abi_command::AbiCommand),
#[strum_discriminants(strum(
message = "create-dev-account - Create a development account using the faucet service sponsor to cover
the cost of creating an account (testnet only for now).
To create an account on another network, you need to use \"near-cli-rs\":
https://github.com/near/near-cli-rs"
message = "create-dev-account - Create a development account using a faucet service sponsor to receive some NEAR tokens (testnet only).
To create an account on a different network, use NEAR CLI [https://near.cli.rs]"
))]
/// Create a development account using the faucet service sponsor to cover the cost of creating an account (testnet only for now)
/// Create a development account using the faucet service sponsor to receive some NEAR tokens (testnet only)
/// To create an account on a different network, use NEAR CLI [https://near.cli.rs]
CreateDevAccount(self::create_dev_account::CreateAccount),
#[strum_discriminants(strum(message = "deploy - Add a new contract code"))]
/// Add a new contract code
Expand Down

0 comments on commit 22a7cf8

Please sign in to comment.