1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
use crate::ops::forc_build;
use anyhow::Result;
use clap::Parser;
/// Compile the current or target project.
///
/// The output produced will depend on the project's program type. Building script, predicate and
/// contract projects will produce their bytecode in binary format `<project-name>.bin`. Building
/// contracts and libraries will also produce the public ABI in JSON format
/// `<project-name>-abi.json`.
#[derive(Debug, Default, Parser)]
pub struct Command {
/// Path to the project, if not specified, current working directory will be used.
#[clap(short, long)]
pub path: Option<String>,
/// Whether to compile using the original (pre- IR) pipeline.
#[clap(long, hide = true)]
pub use_orig_asm: bool,
/// Whether to compile to bytecode (false) or to print out the generated ASM (true).
#[clap(long)]
pub print_finalized_asm: bool,
/// Whether to compile to bytecode (false) or to print out the generated ASM (true).
#[clap(long)]
pub print_intermediate_asm: bool,
/// Whether to compile to bytecode (false) or to print out the generated IR (true).
#[clap(long)]
pub print_ir: bool,
/// If set, outputs a binary file representing the script bytes.
#[clap(short = 'o')]
pub binary_outfile: Option<String>,
/// If set, outputs source file mapping in JSON format
#[clap(short = 'g', long)]
pub debug_outfile: Option<String>,
/// Offline mode, prevents Forc from using the network when managing dependencies.
/// Meaning it will only try to use previously downloaded dependencies.
#[clap(long = "offline")]
pub offline_mode: bool,
/// Silent mode. Don't output any warnings or errors to the command line.
#[clap(long = "silent", short = 's')]
pub silent_mode: bool,
/// The directory in which the sway compiler output artifacts are placed.
///
/// By default, this is `<project-root>/out`.
#[clap(long)]
pub output_directory: Option<String>,
/// By default the JSON for ABIs is formatted for human readability. By using this option JSON
/// output will be "minified", i.e. all on one line without whitespace.
#[clap(long)]
pub minify_json_abi: bool,
/// Requires that the Forc.lock file is up-to-date. If the lock file is missing, or it
/// needs to be updated, Forc will exit with an error
#[clap(long)]
pub locked: bool,
}
pub(crate) fn exec(command: Command) -> Result<()> {
forc_build::build(command)?;
Ok(())
}