Skip to content

Commit

Permalink
Make string representations of build targets consistent (FuelLabs#4296)
Browse files Browse the repository at this point in the history
We had two implementations for converting a string to a `BuildTarget`
and they didn't match. (One accepted "miden-vm" or "midenvm" and the
other "miden" or "midenvm".) Now only "midenvm" is accepted and we use
the same codepath everywhere.
  • Loading branch information
AlicanC authored Mar 15, 2023
1 parent ee0a0fd commit 5f452e5
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 14 deletions.
29 changes: 26 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sway-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
22 changes: 21 additions & 1 deletion sway-core/src/build_config.rs
Original file line number Diff line number Diff line change
@@ -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,
}

Expand Down
7 changes: 3 additions & 4 deletions test/src/e2e_vm_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -707,10 +708,8 @@ fn parse_test_toml(path: &Path) -> Result<TestDescription> {

fn get_test_abi_from_value(value: &toml::Value) -> Result<BuildTarget> {
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")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ license = "Apache-2.0"
name = "midenvm-trivial"
entry = "main.sw"
implicit-std = false
target = "miden-vm"
target = "midenvm"

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
category = "run"
expected_result = { action = "return", value = 42 }
supported_targets = ["miden-vm"]
supported_targets = ["midenvm"]
7 changes: 3 additions & 4 deletions test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 5f452e5

Please sign in to comment.