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

[pallet-revive] fix fixture build path #6174

Merged
merged 9 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
9 changes: 9 additions & 0 deletions prdoc/pr_6174.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: '[pallet-revive] fix fixture build path'
doc:
- audience: Runtime Dev
description: null
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
crates:
- name: pallet-revive-fixtures
bump: patch
- name: pallet-revive
bump: patch
25 changes: 16 additions & 9 deletions substrate/frame/revive/fixtures/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,14 @@ mod build {
pub fn run() -> Result<()> {
let fixtures_dir: PathBuf = env::var("CARGO_MANIFEST_DIR")?.into();
let contracts_dir = fixtures_dir.join("contracts");
let uapi_dir = fixtures_dir.parent().expect("uapi dir exits; qed").join("uapi");
let ws_dir: PathBuf = env::var("CARGO_WORKSPACE_ROOT_DIR")?.into();
let out_dir: PathBuf = ws_dir.join("target").join("pallet-revive-fixtures");

// create out_dir if it does not exist
if !out_dir.exists() {
fs::create_dir_all(&out_dir)?;
}
let out_dir: PathBuf = env::var("OUT_DIR")?.into();

// the fixtures have a dependency on the uapi crate
println!("cargo::rerun-if-changed={}", fixtures_dir.display());
println!("cargo::rerun-if-changed={}", uapi_dir.display());
let uapi_dir = fixtures_dir.parent().expect("parent dir exits; qed").join("uapi");
if uapi_dir.exists() {
println!("cargo::rerun-if-changed={}", uapi_dir.display());
}

let entries = collect_entries(&contracts_dir);
if entries.is_empty() {
Expand All @@ -207,6 +203,17 @@ mod build {
invoke_build(tmp_dir_path)?;

write_output(tmp_dir_path, &out_dir, entries)?;

#[cfg(unix)]
if let Ok(symlink_dir) = env::var("CARGO_WORKSPACE_ROOT_DIR") {
let symlink_dir: PathBuf = symlink_dir.into();
let symlink_dir: PathBuf = symlink_dir.join("target").join("pallet-revive-fixtures");
if symlink_dir.is_symlink() {
fs::remove_file(&symlink_dir)?
}
std::os::unix::fs::symlink(&out_dir, &symlink_dir)?;
}

Ok(())
}
}
Expand Down
23 changes: 12 additions & 11 deletions substrate/frame/revive/fixtures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ extern crate alloc;
/// Load a given wasm module and returns a wasm binary contents along with it's hash.
#[cfg(feature = "std")]
pub fn compile_module(fixture_name: &str) -> anyhow::Result<(Vec<u8>, sp_core::H256)> {
let ws_dir: std::path::PathBuf = env!("CARGO_WORKSPACE_ROOT_DIR").into();
let fixture_path = ws_dir
.join("target")
.join("pallet-revive-fixtures")
.join(format!("{fixture_name}.polkavm"));
let out_dir: std::path::PathBuf = env!("OUT_DIR").into();
let fixture_path = out_dir.join(format!("{fixture_name}.polkavm"));
log::debug!("Loading fixture from {fixture_path:?}");
let binary = std::fs::read(fixture_path)?;
let code_hash = sp_io::hashing::keccak_256(&binary);
Expand All @@ -43,12 +40,7 @@ pub mod bench {
#[cfg(feature = "riscv")]
macro_rules! fixture {
($name: literal) => {
include_bytes!(concat!(
env!("CARGO_WORKSPACE_ROOT_DIR"),
"/target/pallet-revive-fixtures/",
$name,
".polkavm"
))
include_bytes!(concat!(env!("OUT_DIR"), "/", $name, ".polkavm"))
};
}
#[cfg(not(feature = "riscv"))]
Expand All @@ -71,3 +63,12 @@ pub mod bench {
dummy
}
}

#[cfg(test)]
mod test {
#[test]
fn out_dir_should_have_compiled_mocks() {
let out_dir: std::path::PathBuf = env!("OUT_DIR").into();
assert!(out_dir.join("dummy.polkavm").exists());
}
}
1 change: 1 addition & 0 deletions substrate/frame/revive/src/evm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ pub trait EthExtra {
}
}

#[cfg(feature = "riscv")]
#[cfg(test)]
mod test {
use super::*;
Expand Down
Loading