diff --git a/prdoc/pr_6174.prdoc b/prdoc/pr_6174.prdoc new file mode 100644 index 000000000000..8aa1c25012b1 --- /dev/null +++ b/prdoc/pr_6174.prdoc @@ -0,0 +1,9 @@ +title: '[pallet-revive] fix fixture build path' +doc: +- audience: Runtime Dev + description: "Fix fixture build path" +crates: +- name: pallet-revive-fixtures + bump: patch +- name: pallet-revive + bump: patch diff --git a/substrate/frame/revive/fixtures/build.rs b/substrate/frame/revive/fixtures/build.rs index cb4b76408141..ee7db4203cc9 100644 --- a/substrate/frame/revive/fixtures/build.rs +++ b/substrate/frame/revive/fixtures/build.rs @@ -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() { @@ -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(()) } } diff --git a/substrate/frame/revive/fixtures/src/lib.rs b/substrate/frame/revive/fixtures/src/lib.rs index eacd63b97e57..5548dca66d07 100644 --- a/substrate/frame/revive/fixtures/src/lib.rs +++ b/substrate/frame/revive/fixtures/src/lib.rs @@ -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, 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); @@ -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"))] @@ -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()); + } +} diff --git a/substrate/frame/revive/src/evm/runtime.rs b/substrate/frame/revive/src/evm/runtime.rs index 58110bcf186f..e4340b27a187 100644 --- a/substrate/frame/revive/src/evm/runtime.rs +++ b/substrate/frame/revive/src/evm/runtime.rs @@ -387,6 +387,7 @@ pub trait EthExtra { } } +#[cfg(feature = "riscv")] #[cfg(test)] mod test { use super::*;