Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BACKPORT] #4090 #3858: Fix having to pass IROHA_SKIP_WASM_CHECKS env variable with true #4135

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
let builder = if format { builder.format() } else { builder };

let output = {
let mut sp = spinoff::Spinner::new_with_stream(
Expand Down
45 changes: 2 additions & 43 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,
}

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

Expand All @@ -76,19 +72,11 @@ 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
}

/// 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 +85,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 +102,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,
})
}

Expand Down Expand Up @@ -168,13 +154,10 @@ mod internal {
pub struct Builder<'out_dir> {
pub absolute_path: PathBuf,
pub out_dir: Cow<'out_dir, Path>,
pub format: 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 +167,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 +176,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 +191,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
Loading