Skip to content

Commit

Permalink
[fix] #4090 #3858: Fix having to pass IROHA_SKIP_WASM_CHECKS env vari…
Browse files Browse the repository at this point in the history
…able with true (#4096)

* [fix] #4090: Fix having to pass IROHA_SKIP_WASM_CHECKS env variable with true

Signed-off-by: Asem-Abdelhady <[email protected]>

* [fix]: Fix having to pass variable IROHA_SKIP_WASM_CHECKS with checking PORFILE variable to be test

Signed-off-by: Asem-Abdelhady <[email protected]>

* [fix]: delete formating from the src code

Signed-off-by: Asem-Abdelhady <[email protected]>

* [delete] the check needed in building for client and cli

Signed-off-by: Asem-Abdelhady <[email protected]>

* [add] format and checking of smart contracts in CI

Signed-off-by: Asem-Abdelhady <[email protected]>

* [add] check and format in pr for dev

Signed-off-by: Asem-Abdelhady <[email protected]>

* [change] format chekck from dev and dev-pr to dev-pr-static

Signed-off-by: Asem-Abdelhady <[email protected]>

* [revert] paths deletion in dev-pr && [fix] naming issues in dev-pr-static CIs

Signed-off-by: Asem-Abdelhady <[email protected]>

* [change] revert double quotes to single quotes in paths && remove the checking from dev CI

Signed-off-by: Asem-Abdelhady <[email protected]>

* [delete] build script from client && [delete] IROHA_SKIP_WASM_CHECKS from nix

Signed-off-by: Asem-Abdelhady <[email protected]>

* [delete] unecessary print statments and stray comment from cli build.rs

Signed-off-by: Asem-Abdelhady <[email protected]>

---------

Signed-off-by: Asem-Abdelhady <[email protected]>
  • Loading branch information
Asem-Abdelhady authored Dec 11, 2023
1 parent 6f2c04c commit 0fef278
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 100 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/iroha2-dev-pr-static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,25 @@ env:
RUSTUP_TOOLCHAIN: nightly-2023-06-25

jobs:
analysis:
smart_contracts_analysis:
runs-on: ubuntu-latest
container:
image: hyperledger/iroha2-ci:nightly-2023-06-25
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2

- name: Default executor format
run: |
cd ./default_executor
mold --run cargo fmt --all -- --check
- name: Integration tests smart contracts format
run: |
cd ./client/tests/integration/smartcontracts
mold --run cargo fmt --all -- --check
workspace_analysis:
runs-on: ubuntu-latest
container:
image: hyperledger/iroha2-ci:nightly-2023-06-25
Expand Down
21 changes: 1 addition & 20 deletions cli/build.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
//! Build script to extract git hash of iroha build and to check runtime executor
//! Build script to extract git hash of iroha build
use eyre::{eyre, Result, WrapErr};

const DEFAULT_EXECUTOR_PATH: &str = "../default_executor";

fn main() -> Result<()> {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed={DEFAULT_EXECUTOR_PATH}");

extract_git_hash()?;

// HACK: used by Nix, since at the moment
// the checks are a process that's hard to accomodate
// in Nix environment
if std::option_env!("IROHA_SKIP_WASM_CHECKS").is_none() {
check_default_executor()?;
}

Ok(())
}

Expand All @@ -28,10 +16,3 @@ fn extract_git_hash() -> Result<()> {
.map_err(|err| eyre!(Box::new(err)))
.wrap_err("Failed to extract git hash")
}

/// Apply `cargo check` to the smartcontract.
fn check_default_executor() -> Result<()> {
iroha_wasm_builder::Builder::new(DEFAULT_EXECUTOR_PATH)
.format()
.check()
}
29 changes: 0 additions & 29 deletions client/build.rs

This file was deleted.

3 changes: 0 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@
VERGEN_IDEMPOTENT = true;
VERGEN_GIT_SHA = self.rev or "?dirty tree?";

# Temporary workaround
IROHA_SKIP_WASM_CHECKS = true;
};
in rec {
inherit mkIroha;
Expand Down Expand Up @@ -216,7 +214,6 @@
fenix'.rust-analyzer
];

IROHA_SKIP_WASM_CHECKS = true;
};
});
}
6 changes: 0 additions & 6 deletions tools/wasm_builder_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ enum Cli {
Build {
#[command(flatten)]
common: CommonArgs,
/// Enable smartcontract formatting using `cargo fmt`.
// TODO: why it is a part of `build` in wasm_builder?
#[arg(long)]
format: bool,
/// Optimize WASM output.
#[arg(long)]
optimize: bool,
Expand All @@ -48,12 +44,10 @@ fn main() -> color_eyre::Result<()> {
}
Cli::Build {
common: CommonArgs { path },
format,
optimize,
outfile,
} => {
let builder = Builder::new(&path).show_output();
let builder = if format { builder.format() } else { builder };

let output = {
// not showing the spinner here, cargo does a progress bar for us
Expand Down
43 changes: 2 additions & 41 deletions wasm_builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const TOOLCHAIN: &str = "+nightly-2023-06-25";
/// fn main() -> Result<()> {
/// let bytes = Builder::new("relative/path/to/smartcontract/")
/// .out_dir("path/to/out/dir") // Optional: Set output directory
/// .format() // Optional: Enable smartcontract formatting
/// .build()? // Run build
/// .optimize()? // Optimize WASM output
/// .into_bytes()?; // Get resulting WASM bytes
Expand All @@ -44,8 +43,6 @@ pub struct Builder<'path, 'out_dir> {
path: &'path Path,
/// Build output directory
out_dir: Option<&'out_dir Path>,
/// Flag to enable smartcontract formatting
format: bool,
/// Flag controlling whether to show output of the build process
show_output: bool,
}
Expand All @@ -61,7 +58,6 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
Self {
path: relative_path.as_ref(),
out_dir: None,
format: false,
show_output: false,
}
}
Expand All @@ -79,14 +75,6 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
self
}

/// Enable smartcontract formatting using `cargo fmt`.
///
/// Disabled by default.
pub fn format(mut self) -> Self {
self.format = true;
self
}

/// Enable showing output of the build process.
///
/// Disabled by default.
Expand All @@ -99,7 +87,7 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
///
/// # Errors
///
/// Can fail due to multiple reasons like invalid path, failed formatting, failed build, etc.
/// Can fail due to multiple reasons like invalid path, failed build, etc.
pub fn check(self) -> Result<()> {
self.into_internal()?.check()
}
Expand All @@ -108,8 +96,7 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
///
/// # Errors
///
/// Can fail due to multiple reasons like invalid path, failed formatting,
/// failed build, etc.
/// Can fail due to multiple reasons like invalid path, failed build, etc.
///
/// Will also return error if ran on workspace and not on the concrete package.
pub fn build(self) -> Result<Output> {
Expand All @@ -126,7 +113,6 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
|| -> Result<_> { Ok(Cow::Owned(Self::default_out_dir()?)) },
|out_dir| Ok(Cow::Borrowed(out_dir)),
)?,
format: self.format,
show_output: self.show_output,
})
}
Expand Down Expand Up @@ -180,14 +166,11 @@ mod internal {
pub struct Builder<'out_dir> {
pub absolute_path: PathBuf,
pub out_dir: Cow<'out_dir, Path>,
pub format: bool,
pub show_output: bool,
}

impl Builder<'_> {
pub fn check(self) -> Result<()> {
self.maybe_format()?;

self.check_smartcontract().wrap_err_with(|| {
format!(
"Failed to check the smartcontract at path: {}",
Expand All @@ -197,8 +180,6 @@ mod internal {
}

pub fn build(self) -> Result<Output> {
self.maybe_format()?;

let absolute_path = self.absolute_path.clone();
self.build_smartcontract().wrap_err_with(|| {
format!(
Expand All @@ -208,18 +189,6 @@ mod internal {
})
}

fn maybe_format(&self) -> Result<()> {
if self.format {
self.format_smartcontract().wrap_err_with(|| {
format!(
"Failed to format the smartcontract at path: {}",
self.absolute_path.display()
)
})?;
}
Ok(())
}

fn build_options() -> impl Iterator<Item = &'static str> {
[
"--release",
Expand All @@ -235,14 +204,6 @@ mod internal {
.into_iter()
}

fn format_smartcontract(&self) -> Result<()> {
check_command(
self.show_output,
cargo_command().current_dir(&self.absolute_path).arg("fmt"),
"cargo fmt",
)
}

fn get_base_command(&self, cmd: &'static str) -> std::process::Command {
let mut command = cargo_command();
command
Expand Down

0 comments on commit 0fef278

Please sign in to comment.