From 5daef5d086b16a02fcff5873898c42249ecd5d33 Mon Sep 17 00:00:00 2001
From: PG Herveou <pgherveou@gmail.com>
Date: Mon, 8 Jan 2024 14:11:31 +0100
Subject: [PATCH] Contracts rename riscv-experimental and enable ci tests
 (#2879)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- Keep feature name short s/riscv-experimental/riscv
- Add to feature to CI build

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
---
 .gitlab/pipeline/test.yml                     |  2 +-
 substrate/frame/contracts/fixtures/Cargo.toml |  5 ++---
 substrate/frame/contracts/fixtures/build.rs   | 10 +++++-----
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/.gitlab/pipeline/test.yml b/.gitlab/pipeline/test.yml
index 359d5b4dbcd..00d2b22c810 100644
--- a/.gitlab/pipeline/test.yml
+++ b/.gitlab/pipeline/test.yml
@@ -29,7 +29,7 @@ test-linux-stable:
         --locked \
         --release \
         --no-fail-fast \
-        --features try-runtime,experimental,ci-only-tests \
+        --features try-runtime,experimental,riscv,ci-only-tests \
         --partition count:${CI_NODE_INDEX}/${CI_NODE_TOTAL}
     # Upload tests results to Elasticsearch
     - echo "Upload test results to Elasticsearch"
diff --git a/substrate/frame/contracts/fixtures/Cargo.toml b/substrate/frame/contracts/fixtures/Cargo.toml
index 58f20f0b8f5..36bc3974f5e 100644
--- a/substrate/frame/contracts/fixtures/Cargo.toml
+++ b/substrate/frame/contracts/fixtures/Cargo.toml
@@ -21,9 +21,8 @@ parity-wasm = "0.45.0"
 tempfile = "3.8.1"
 toml = "0.8.2"
 twox-hash = "1.6.3"
-polkavm-linker = "0.3.0"
+polkavm-linker = { version = "0.3.0", optional = true }
 anyhow = "1.0.0"
 
 [features]
-# Enable experimental RISCV fixtures build
-riscv-experimental = []
+riscv = ["polkavm-linker"]
diff --git a/substrate/frame/contracts/fixtures/build.rs b/substrate/frame/contracts/fixtures/build.rs
index 34e44c5db11..125ee7f3722 100644
--- a/substrate/frame/contracts/fixtures/build.rs
+++ b/substrate/frame/contracts/fixtures/build.rs
@@ -91,7 +91,7 @@ impl Entry {
 	}
 
 	/// Return the name of the RISC-V polkavm file.
-	#[cfg(feature = "riscv-experimental")]
+	#[cfg(feature = "riscv")]
 	fn out_riscv_filename(&self) -> String {
 		format!("{}.polkavm", self.name())
 	}
@@ -232,7 +232,7 @@ fn post_process_wasm(input_path: &Path, output_path: &Path) -> Result<()> {
 }
 
 /// Build contracts for RISC-V.
-#[cfg(feature = "riscv-experimental")]
+#[cfg(feature = "riscv")]
 fn invoke_riscv_build(current_dir: &Path) -> Result<()> {
 	let encoded_rustflags =
 		["-Crelocation-model=pie", "-Clink-arg=--emit-relocs", "-Clink-arg=-Tmemory.ld"]
@@ -267,7 +267,7 @@ fn invoke_riscv_build(current_dir: &Path) -> Result<()> {
 	bail!("Failed to build contracts");
 }
 /// Post-process the compiled wasm contracts.
-#[cfg(feature = "riscv-experimental")]
+#[cfg(feature = "riscv")]
 fn post_process_riscv(input_path: &Path, output_path: &Path) -> Result<()> {
 	let mut config = polkavm_linker::Config::default();
 	config.set_strip(true);
@@ -286,7 +286,7 @@ fn write_output(build_dir: &Path, out_dir: &Path, entries: Vec<Entry>) -> Result
 			&out_dir.join(&wasm_output),
 		)?;
 
-		#[cfg(feature = "riscv-experimental")]
+		#[cfg(feature = "riscv")]
 		post_process_riscv(
 			&build_dir.join("target/riscv32em-unknown-none-elf/release").join(entry.name()),
 			&out_dir.join(entry.out_riscv_filename()),
@@ -340,7 +340,7 @@ fn main() -> Result<()> {
 
 	invoke_wasm_build(tmp_dir_path)?;
 
-	#[cfg(feature = "riscv-experimental")]
+	#[cfg(feature = "riscv")]
 	invoke_riscv_build(tmp_dir_path)?;
 
 	write_output(tmp_dir_path, &out_dir, entries)?;
-- 
GitLab