diff --git a/Cargo.lock b/Cargo.lock index f2390d7f2a9..e628a3d69c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1873,7 +1873,7 @@ checksum = "af523c38969b431b33b06a82756659c9a07ea9aa185cb8a770c15fd5c95a0da6" dependencies = [ "proc-macro2", "serde", - "strum_macros", + "strum_macros 0.21.1", ] [[package]] @@ -2229,8 +2229,8 @@ dependencies = [ "regex", "serde", "serde_json", - "strum", - "strum_macros", + "strum 0.21.0", + "strum_macros 0.21.1", "thiserror", "tokio", ] @@ -4966,6 +4966,15 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aaf86bbcfd1fa9670b7a129f64fc0c9fcbbfe4f1bc4210e9e98fe71ffc12cde2" +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +dependencies = [ + "strum_macros 0.24.3", +] + [[package]] name = "strum_macros" version = "0.21.1" @@ -4978,6 +4987,19 @@ dependencies = [ "syn", ] +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + [[package]] name = "substrate-bn" version = "0.6.0" @@ -5036,6 +5058,7 @@ dependencies = [ "serde_json", "sha2 0.9.9", "smallvec", + "strum 0.24.1", "sway-ast", "sway-error", "sway-ir", diff --git a/sway-core/Cargo.toml b/sway-core/Cargo.toml index b2e5ea340d0..f3f6f21cbdf 100644 --- a/sway-core/Cargo.toml +++ b/sway-core/Cargo.toml @@ -33,6 +33,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.91" sha2 = "0.9" smallvec = "1.7" +strum = { version = "0.24.1", features = ["derive"] } sway-ast = { version = "0.35.5", path = "../sway-ast" } sway-error = { version = "0.35.5", path = "../sway-error" } sway-ir = { version = "0.35.5", path = "../sway-ir" } diff --git a/sway-core/src/build_config.rs b/sway-core/src/build_config.rs index 5bb1ee08404..336f5fcd2b5 100644 --- a/sway-core/src/build_config.rs +++ b/sway-core/src/build_config.rs @@ -1,14 +1,34 @@ use std::{path::PathBuf, sync::Arc}; use serde::{Deserialize, Serialize}; +use strum::EnumString; #[derive( - Clone, Copy, Debug, Default, Eq, PartialEq, Hash, Serialize, Deserialize, clap::ValueEnum, + Clone, + Copy, + Debug, + Default, + Eq, + PartialEq, + Hash, + Serialize, + Deserialize, + clap::ValueEnum, + EnumString, )] pub enum BuildTarget { #[default] + #[serde(rename = "fuel")] + #[clap(name = "fuel")] + #[strum(serialize = "fuel")] Fuel, + #[serde(rename = "evm")] + #[clap(name = "evm")] + #[strum(serialize = "evm")] EVM, + #[serde(rename = "midenvm")] + #[clap(name = "midenvm")] + #[strum(serialize = "midenvm")] MidenVM, } diff --git a/test/src/e2e_vm_tests/mod.rs b/test/src/e2e_vm_tests/mod.rs index ea184b149bd..cb20a912b74 100644 --- a/test/src/e2e_vm_tests/mod.rs +++ b/test/src/e2e_vm_tests/mod.rs @@ -16,6 +16,7 @@ use regex::Regex; use std::collections::HashSet; use std::io::stdout; use std::io::Write; +use std::str::FromStr; use std::{ collections::HashMap, path::{Path, PathBuf}, @@ -707,10 +708,8 @@ fn parse_test_toml(path: &Path) -> Result { fn get_test_abi_from_value(value: &toml::Value) -> Result { match value.as_str() { - Some(target) => match target { - "fuel" => Ok(BuildTarget::Fuel), - "evm" => Ok(BuildTarget::EVM), - "miden-vm" | "midenvm" => Ok(BuildTarget::MidenVM), + Some(target) => match BuildTarget::from_str(target) { + Ok(target) => Ok(target), _ => Err(anyhow!(format!("Unknown build target: {target}"))), }, None => Err(anyhow!("Invalid TOML value")), diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/midenvm/midenvm_trivial/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/midenvm/midenvm_trivial/Forc.toml index a09dc0181bc..0302779ba17 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/midenvm/midenvm_trivial/Forc.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/midenvm/midenvm_trivial/Forc.toml @@ -4,5 +4,5 @@ license = "Apache-2.0" name = "midenvm-trivial" entry = "main.sw" implicit-std = false -target = "miden-vm" +target = "midenvm" diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/midenvm/midenvm_trivial/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/midenvm/midenvm_trivial/test.toml index 185e2e2fae5..976e40b12b7 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/midenvm/midenvm_trivial/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/midenvm/midenvm_trivial/test.toml @@ -1,3 +1,3 @@ category = "run" expected_result = { action = "return", value = 42 } -supported_targets = ["miden-vm"] +supported_targets = ["midenvm"] diff --git a/test/src/main.rs b/test/src/main.rs index 75d278feaa6..031c37e6727 100644 --- a/test/src/main.rs +++ b/test/src/main.rs @@ -4,6 +4,7 @@ mod ir_generation; use anyhow::Result; use clap::Parser; use forc_tracing::init_tracing_subscriber; +use std::str::FromStr; use sway_core::BuildTarget; use tracing::Instrument; @@ -78,10 +79,8 @@ async fn main() -> Result<()> { first_only: cli.first_only, }; let build_target = match cli.build_target { - Some(target) => match target.to_lowercase().as_str() { - "fuel" => BuildTarget::Fuel, - "evm" => BuildTarget::EVM, - "miden" | "midenvm" => BuildTarget::MidenVM, + Some(target) => match BuildTarget::from_str(target.as_str()) { + Ok(target) => target, _ => panic!("unexpected build target"), }, None => BuildTarget::default(),