Skip to content

Commit

Permalink
feat: add derive of bon::Builder for build and build_extended Opts
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Oct 3, 2024
1 parent e135aaf commit d9abdcc
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 6 deletions.
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cargo-near-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ near-abi = { version = "0.4.0", features = ["__chunked-entries"] }
zstd = "0.13"
schemars = "0.8"
rustc_version = "0.4"
bon = "2.3.0"
url = { version = "2.5.0", features = ["serde"], optional = true }
serde = { version = "1.0.197", optional = true }
git2 = { version = "0.19", optional = true }
Expand Down
2 changes: 2 additions & 0 deletions cargo-near-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//!
//! 1. [camino] is re-exported, because it is used in [BuildOpts], and [BuildArtifact] as type of some of fields
//! 2. [near_abi] is re-exported, because details of ABI generated depends on specific version of `near-abi` dependency
//! 3. [bon] is re-exported for the convenience of [bon::vec] helper macro
//!
//! ## Sample usage:
//!
Expand Down Expand Up @@ -111,5 +112,6 @@ pub mod docker {
pub use crate::types::near::docker_build::Opts as DockerBuildOpts;
}

pub use bon;
pub use camino;
pub use near_abi;
8 changes: 5 additions & 3 deletions cargo-near-build/src/types/near/build/input/implicit_env.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/// additional argument of [build](crate::build) function, wrapped in an `Option`
#[derive(Debug, Clone)]
#[derive(Debug, Clone, bon::Builder)]
pub struct Opts {
/// override value of [crate::env_keys::nep330::CONTRACT_PATH] environment variable
#[builder(into)]
pub nep330_contract_path: Option<String>,
/// override value of [crate::env_keys::nep330::CARGO_TARGET_DIR] environment variable,
/// override value of [crate::env_keys::CARGO_TARGET_DIR] environment variable,
/// which is required to avoid deadlock <https://github.com/rust-lang/cargo/issues/8938> in context of nested (cargo) build
/// in build-script;
///
/// should best be a subfolder of [crate::env_keys::nep330::CARGO_TARGET_DIR]
/// should best be a subfolder of [crate::env_keys::CARGO_TARGET_DIR]
/// of crate being built to work normally
#[builder(into)]
pub cargo_target_dir: Option<String>,
}
11 changes: 10 additions & 1 deletion cargo-near-build/src/types/near/build/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,43 @@ pub enum BuildContext {
/// - `None` - for `Option`-s
/// - empty vector - for `Vec`
/// - delegates to [impl Default for CliDescription](struct.CliDescription.html#impl-Default-for-CliDescription)
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, bon::Builder)]
pub struct Opts {
/// disable implicit `--locked` flag for all `cargo` commands, enabled by default
#[builder(default)]
pub no_locked: bool,
/// Build contract in debug mode, without optimizations and bigger in size
#[builder(default)]
pub no_release: bool,
/// Do not generate ABI for the contract
#[builder(default)]
pub no_abi: bool,
/// Do not embed the ABI in the contract binary
#[builder(default)]
pub no_embed_abi: bool,
/// Do not include rustdocs in the embedded ABI
#[builder(default)]
pub no_doc: bool,
/// Copy final artifacts to this directory
pub out_dir: Option<camino::Utf8PathBuf>,
/// Path to the `Cargo.toml` of the contract to build
pub manifest_path: Option<camino::Utf8PathBuf>,
/// Set compile-time feature flags.
#[builder(into)]
pub features: Option<String>,
/// Disables default feature flags.
#[builder(default)]
pub no_default_features: bool,
/// Coloring: auto, always, never;
/// assumed to be auto when `None`
pub color: Option<ColorPreference>,
/// description of cli command, where [BuildOpts](crate::BuildOpts) are being used from, either real
/// or emulated
#[builder(default)]
pub cli_description: CliDescription,
/// additional environment key-value pairs, that should be passed to underlying
/// build commands
#[builder(default)]
pub env: Vec<(String, String)>,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
#[derive(Debug, Clone)]
#[derive(Debug, Clone, bon::Builder)]
pub struct Opts {
/// environment variable name to export result `*.wasm` path to with [`cargo::rustc-env=`](https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-env)
/// instruction
#[builder(into)]
pub result_env_key: Option<String>,
/// list of paths for [`cargo::rerun-if-changed=`](https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-changed)
/// instruction
///
/// if relative, it's relative to path of crate, where build.rs is compiled
#[builder(default)]
pub rerun_if_changed_list: Vec<String>,
/// vector of key-value pairs of environment variable name and its value,
/// when compilation should be skipped on a variable's value match;
/// e.g.
/// skipping emitting output `*.wasm` may be helpful when `PROFILE` is equal to `debug`
/// for using `rust-analyzer/flycheck`, `cargo check`, `bacon` and other dev-tools
#[builder(default)]
pub build_skipped_when_env_is: Vec<(String, String)>,
/// path of stub file, where a placeholder empty `wasm` output is emitted to, when
/// build is skipped due to match in [`Self::build_skipped_when_env_is`]
///
/// if this path is relative, then the base is [`crate::extended::BuildOptsExtended::workdir`]
#[builder(into)]
pub stub_path: Option<String>,
}
3 changes: 2 additions & 1 deletion cargo-near-build/src/types/near/build_extended/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use crate::{BuildImplicitEnvOpts, BuildOpts};

pub mod build_script;

#[derive(Debug, Clone)]
#[derive(Debug, Clone, bon::Builder)]
pub struct OptsExtended {
#[builder(into)]
pub workdir: String,
pub build_opts: BuildOpts,
pub build_implicit_env_opts: BuildImplicitEnvOpts,
Expand Down

0 comments on commit d9abdcc

Please sign in to comment.