From bd9ddacf85875f13ac40a06dd6f763617b83e4e1 Mon Sep 17 00:00:00 2001 From: achimcc Date: Mon, 8 Nov 2021 13:28:28 +0100 Subject: [PATCH 1/6] add offline flag to build mode --- src/cmd/build.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index eadd5706..8a340ffe 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -70,6 +70,9 @@ pub struct BuildCommand { /// Then no debug functionality is compiled into the contract. #[structopt(long = "--release")] build_release: bool, + /// Build offline + #[structopt(long = "--offline")] + build_offline: bool, /// Which build artifacts to generate. /// /// - `all`: Generate the Wasm, the metadata and a bundled `.contract` file. -- GitLab From 63dd59c831105be3dab8ab8c77d15b0c9d9c101a Mon Sep 17 00:00:00 2001 From: achimcc Date: Mon, 8 Nov 2021 13:56:29 +0100 Subject: [PATCH 2/6] add network enum and interpret --offline flag --- src/cmd/build.rs | 17 ++++++++++++++++- src/main.rs | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 8a340ffe..7524dad5 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -18,7 +18,7 @@ use crate::{ crate_metadata::CrateMetadata, maybe_println, util, validate_wasm, workspace::{Manifest, ManifestPath, Profile, Workspace}, - BuildArtifacts, BuildMode, BuildResult, OptimizationPasses, OptimizationResult, OutputType, + BuildArtifacts, BuildMode, Network, BuildResult, OptimizationPasses, OptimizationResult, OutputType, UnstableFlags, UnstableOptions, Verbosity, VerbosityFlags, }; use anyhow::{Context, Result}; @@ -46,6 +46,7 @@ pub(crate) struct ExecuteArgs { pub(crate) manifest_path: ManifestPath, verbosity: Verbosity, build_mode: BuildMode, + network: Network, build_artifact: BuildArtifacts, unstable_flags: UnstableFlags, optimization_passes: OptimizationPasses, @@ -152,6 +153,11 @@ impl BuildCommand { false => BuildMode::Debug, }; + let network = match self.build_offline { + true => Network::Offline, + false => Network::Online, + }; + let output_type = match self.output_json { true => OutputType::Json, false => OutputType::HumanReadable, @@ -166,6 +172,7 @@ impl BuildCommand { manifest_path, verbosity, build_mode, + network, build_artifact: self.build_artifact, unstable_flags, optimization_passes, @@ -200,6 +207,7 @@ impl CheckCommand { manifest_path, verbosity, build_mode: BuildMode::Debug, + network: Network::default(), build_artifact: BuildArtifacts::CheckOnly, unstable_flags, optimization_passes: OptimizationPasses::Zero, @@ -231,6 +239,7 @@ fn exec_cargo_for_wasm_target( crate_metadata: &CrateMetadata, command: &str, build_mode: BuildMode, + network: Network, verbosity: Verbosity, unstable_flags: &UnstableFlags, ) -> Result<()> { @@ -253,6 +262,9 @@ fn exec_cargo_for_wasm_target( "--release", &target_dir, ]; + if network == Network::Offline { + args.push("--offline"); + } if build_mode == BuildMode::Debug { args.push("--features=ink_env/ink-debug"); } else { @@ -628,6 +640,7 @@ pub(crate) fn execute(args: ExecuteArgs) -> Result { manifest_path, verbosity, build_mode, + network, build_artifact, unstable_flags, optimization_passes, @@ -653,6 +666,7 @@ pub(crate) fn execute(args: ExecuteArgs) -> Result { &crate_metadata, "build", build_mode, + network, verbosity, &unstable_flags, )?; @@ -683,6 +697,7 @@ pub(crate) fn execute(args: ExecuteArgs) -> Result { &crate_metadata, "check", BuildMode::Release, + network, verbosity, &unstable_flags, )?; diff --git a/src/main.rs b/src/main.rs index b7fb083b..94fa0fea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -306,6 +306,30 @@ impl Display for BuildMode { } } +/// USe network to build contracts or cached dependencies only. +#[derive(Eq, PartialEq, Copy, Clone, Debug, serde::Serialize)] +pub enum Network { + /// Use network + Online, + /// Use cached dependencies. + Offline, +} + +impl Default for Network { + fn default() -> Network { + Network::Online + } +} + +impl Display for Network { + fn fmt(&self, f: &mut Formatter<'_>) -> DisplayResult { + match self { + Self::Online => write!(f, ""), + Self::Offline => write!(f, "offline"), + } + } +} + /// The type of output to display at the end of a build. pub enum OutputType { /// Output build results in a human readable format. -- GitLab From 7608845d40ceea7723041ddb38df633d75d5be3d Mon Sep 17 00:00:00 2001 From: achimcc Date: Mon, 8 Nov 2021 14:26:06 +0100 Subject: [PATCH 3/6] support offline flag for metadata generation --- src/cmd/build.rs | 1 + src/cmd/metadata.rs | 4 +++- src/main.rs | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 7524dad5..742a6a52 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -713,6 +713,7 @@ pub(crate) fn execute(args: ExecuteArgs) -> Result { let metadata_result = super::metadata::execute( &crate_metadata, optimization_result.dest_wasm.as_path(), + network, verbosity, build_artifact.steps(), &unstable_flags, diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index 92bb3c3b..ff9d0510 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -18,7 +18,7 @@ use crate::{ crate_metadata::CrateMetadata, maybe_println, util, workspace::{ManifestPath, Workspace}, - UnstableFlags, Verbosity, + UnstableFlags, Verbosity, Network }; use anyhow::Result; @@ -59,6 +59,7 @@ struct ExtendedMetadataResult { pub(crate) fn execute( crate_metadata: &CrateMetadata, final_contract_wasm: &Path, + network: Network, verbosity: Verbosity, total_steps: usize, unstable_options: &UnstableFlags, @@ -95,6 +96,7 @@ pub(crate) fn execute( &manifest_path.cargo_arg(), &target_dir_arg, "--release", + &network.to_string() ], crate_metadata.manifest_path.directory(), verbosity, diff --git a/src/main.rs b/src/main.rs index 94fa0fea..beb5d09e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -306,7 +306,7 @@ impl Display for BuildMode { } } -/// USe network to build contracts or cached dependencies only. +/// Use network connection to build contracts and generate metadata or use cached dependencies only. #[derive(Eq, PartialEq, Copy, Clone, Debug, serde::Serialize)] pub enum Network { /// Use network @@ -325,7 +325,7 @@ impl Display for Network { fn fmt(&self, f: &mut Formatter<'_>) -> DisplayResult { match self { Self::Online => write!(f, ""), - Self::Offline => write!(f, "offline"), + Self::Offline => write!(f, "--offline"), } } } -- GitLab From 7332ab23e31a96fc9c75b7b74a746a2302d3a3f4 Mon Sep 17 00:00:00 2001 From: achimcc Date: Mon, 8 Nov 2021 14:39:56 +0100 Subject: [PATCH 4/6] cargo fmt --- src/cmd/build.rs | 4 ++-- src/cmd/metadata.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 742a6a52..9086905e 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -18,8 +18,8 @@ use crate::{ crate_metadata::CrateMetadata, maybe_println, util, validate_wasm, workspace::{Manifest, ManifestPath, Profile, Workspace}, - BuildArtifacts, BuildMode, Network, BuildResult, OptimizationPasses, OptimizationResult, OutputType, - UnstableFlags, UnstableOptions, Verbosity, VerbosityFlags, + BuildArtifacts, BuildMode, BuildResult, Network, OptimizationPasses, OptimizationResult, + OutputType, UnstableFlags, UnstableOptions, Verbosity, VerbosityFlags, }; use anyhow::{Context, Result}; use colored::Colorize; diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index ff9d0510..b666cf35 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -18,7 +18,7 @@ use crate::{ crate_metadata::CrateMetadata, maybe_println, util, workspace::{ManifestPath, Workspace}, - UnstableFlags, Verbosity, Network + Network, UnstableFlags, Verbosity, }; use anyhow::Result; @@ -96,7 +96,7 @@ pub(crate) fn execute( &manifest_path.cargo_arg(), &target_dir_arg, "--release", - &network.to_string() + &network.to_string(), ], crate_metadata.manifest_path.directory(), verbosity, -- GitLab From 7f3ed54d03c5dde8aae1274bba1dabfa547a445c Mon Sep 17 00:00:00 2001 From: achimcc Date: Mon, 8 Nov 2021 14:45:44 +0100 Subject: [PATCH 5/6] cargo clippy --- src/cmd/build.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 9086905e..79bb5973 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -451,7 +451,6 @@ fn do_optimization( We use this tool to optimize the size of your contract's Wasm binary.\n\n\ wasm-opt is part of the binaryen package. You can find detailed\n\ installation instructions on https://github.com/WebAssembly/binaryen#tools.\n\n\ - There are ready-to-install packages for many platforms:\n\ * Debian/Ubuntu: apt-get install binaryen\n\ * Homebrew: brew install binaryen\n\ -- GitLab From 787b56771ce14fa757cf0cff4727024e7c884bc7 Mon Sep 17 00:00:00 2001 From: achimcc Date: Mon, 8 Nov 2021 14:58:33 +0100 Subject: [PATCH 6/6] fix tests --- src/cmd/build.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 79bb5973..2a5fdf06 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -876,6 +876,7 @@ mod tests_ci_only { manifest_path: Some(manifest_path.into()), build_artifact: BuildArtifacts::All, build_release: false, + build_offline: false, verbosity: VerbosityFlags::default(), unstable_options: UnstableOptions::default(), @@ -916,6 +917,7 @@ mod tests_ci_only { manifest_path: Some(manifest_path.into()), build_artifact: BuildArtifacts::All, build_release: false, + build_offline: false, verbosity: VerbosityFlags::default(), unstable_options: UnstableOptions::default(), @@ -1083,6 +1085,7 @@ mod tests_ci_only { manifest_path: Some(manifest_path.into()), build_artifact: BuildArtifacts::All, build_release: false, + build_offline: false, verbosity: VerbosityFlags::default(), unstable_options: UnstableOptions::default(), optimization_passes: None, -- GitLab