Skip to content

Commit

Permalink
[fix] hyperledger-iroha#4090 hyperledger-iroha#3858: Fix having to pa…
Browse files Browse the repository at this point in the history
…ss IROHA_SKIP_WASM_CHECKS env variable with true (hyperledger-iroha#4096)

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

Signed-off-by: Asem-Abdelhady <asemshawkey@gmail.com>

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

Signed-off-by: Asem-Abdelhady <asemshawkey@gmail.com>

* [fix]: delete formating from the src code

Signed-off-by: Asem-Abdelhady <asemshawkey@gmail.com>

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

Signed-off-by: Asem-Abdelhady <asemshawkey@gmail.com>

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

Signed-off-by: Asem-Abdelhady <asemshawkey@gmail.com>

* [add] check and format in pr for dev

Signed-off-by: Asem-Abdelhady <asemshawkey@gmail.com>

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

Signed-off-by: Asem-Abdelhady <asemshawkey@gmail.com>

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

Signed-off-by: Asem-Abdelhady <asemshawkey@gmail.com>

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

Signed-off-by: Asem-Abdelhady <asemshawkey@gmail.com>

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

Signed-off-by: Asem-Abdelhady <asemshawkey@gmail.com>

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

Signed-off-by: Asem-Abdelhady <asemshawkey@gmail.com>

---------

Signed-off-by: Asem-Abdelhady <asemshawkey@gmail.com>
  • Loading branch information
Asem-Abdelhady committed Dec 11, 2023
1 parent 7329e47 commit a7ed2c0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 90 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
14 changes: 0 additions & 14 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ use eyre::{eyre, Result, WrapErr};
fn main() -> Result<()> {
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 @@ -23,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.

1 change: 0 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@
fenix'.rust-analyzer
];

IROHA_SKIP_WASM_CHECKS = true;
};
});
}
8 changes: 1 addition & 7 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);
let builder = if format { builder.format() } else { builder };
let builder = Builder::new(&path).show_output();

let output = {
let mut sp = spinoff::Spinner::new_with_stream(
Expand Down
48 changes: 10 additions & 38 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,8 @@ 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,
}

impl<'path, 'out_dir> Builder<'path, 'out_dir> {
Expand All @@ -59,7 +58,7 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
Self {
path: relative_path.as_ref(),
out_dir: None,
format: false,
show_output: false,
}
}

Expand All @@ -76,19 +75,19 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
self
}

/// Enable smartcontract formatting using `cargo fmt`.
/// Enable showing output of the build process.
///
/// Disabled by default.
pub fn format(mut self) -> Self {
self.format = true;
pub fn show_output(mut self) -> Self {
self.show_output = true;
self
}

/// Apply `cargo check` to the smartcontract.
///
/// # 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 @@ -97,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 @@ -115,7 +113,7 @@ 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 @@ -168,13 +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 @@ -184,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 @@ -195,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 @@ -222,16 +204,6 @@ mod internal {
.into_iter()
}

fn format_smartcontract(&self) -> Result<()> {
let command_output = cargo_command()
.current_dir(&self.absolute_path)
.arg("fmt")
.output()
.wrap_err("Failed to run `cargo fmt`")?;

check_command_output(&command_output, "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 a7ed2c0

Please sign in to comment.