Skip to content

Commit

Permalink
Continue EVM backend development (FuelLabs#3932)
Browse files Browse the repository at this point in the history
This contains the next batch of changes for EVM backend. After some
discussion with @mohammadfawaz I've decided to split some IR changes for
inline assembly support to another PR since it may require some further
discussion and review.

- Extends the test runner with support for multiple build targets.
- Adds new E2E EVM tests job to CI
- Implements initial Solidity ABI support
- Implements initial function code generation support
- Adds EVM assembly printing so `--print-finalized-asm` flag works
  • Loading branch information
tritao authored Jan 31, 2023
1 parent baa2fc2 commit 678415a
Show file tree
Hide file tree
Showing 18 changed files with 648 additions and 104 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,27 @@ jobs:
profile: minimal
toolchain: stable
- uses: Swatinem/rust-cache@v1
- name: Cargo Run E2E Tests
- name: Cargo Run E2E Tests (Fuel VM)
uses: actions-rs/cargo@v1
with:
command: run
args: --locked --release --bin test -- --locked

cargo-run-e2e-test-evm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- uses: Swatinem/rust-cache@v1
- name: Cargo Run E2E Tests (EVM)
uses: actions-rs/cargo@v1
with:
command: run
args: --locked --release --bin test -- --target evm --locked

# TODO: Remove this upon merging std tests with the rest of the E2E tests.
cargo-test-lib-std:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -353,6 +368,7 @@ jobs:
cargo-clippy,
cargo-fmt-check,
cargo-run-e2e-test,
cargo-run-e2e-test-evm,
cargo-test-lib-std,
cargo-test-workspace,
cargo-unused-deps-check,
Expand Down Expand Up @@ -384,6 +400,7 @@ jobs:
cargo-clippy,
cargo-fmt-check,
cargo-run-e2e-test,
cargo-run-e2e-test-evm,
cargo-test-lib-std,
cargo-test-workspace,
cargo-unused-deps-check,
Expand Down Expand Up @@ -454,6 +471,7 @@ jobs:
cargo-clippy,
cargo-fmt-check,
cargo-run-e2e-test,
cargo-run-e2e-test-evm,
cargo-test-lib-std,
cargo-test-workspace,
cargo-unused-deps-check,
Expand Down
138 changes: 122 additions & 16 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion forc-pkg/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
sync::Arc,
};

use sway_core::{fuel_prelude::fuel_tx, language::parsed::TreeType, parse_tree_type};
use sway_core::{fuel_prelude::fuel_tx, language::parsed::TreeType, parse_tree_type, BuildTarget};
pub use sway_types::ConfigTimeConstant;
use sway_utils::constants;

Expand Down Expand Up @@ -143,6 +143,7 @@ pub struct PackageManifest {
pub patch: Option<BTreeMap<String, PatchMap>>,
/// A list of [configuration-time constants](https://github.com/FuelLabs/sway/issues/1498).
pub constants: Option<BTreeMap<String, ConfigTimeConstant>>,
pub build_target: Option<BTreeMap<String, BuildTarget>>,
build_profile: Option<BTreeMap<String, BuildProfile>>,
pub contract_dependencies: Option<BTreeMap<String, ContractDependency>>,
}
Expand Down
28 changes: 22 additions & 6 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::{
str::FromStr,
};
use sway_core::{
abi_generation::generate_json_abi_program,
abi_generation::{evm_json_abi, fuel_json_abi},
asm_generation::ProgramABI,
decl_engine::{DeclEngine, DeclId},
fuel_prelude::{
Expand Down Expand Up @@ -2524,13 +2524,29 @@ pub fn compile(
let mut types = vec![];
ProgramABI::Fuel(time_expr!(
"generate JSON ABI program",
generate_json_abi_program(typed_program, engines.te(), &mut types)
fuel_json_abi::generate_json_abi_program(typed_program, engines.te(), &mut types)
))
}
BuildTarget::EVM => match &asm_res.value {
Some(ref v) => v.0.abi.as_ref().unwrap().clone(),
None => todo!(),
},
BuildTarget::EVM => {
// Merge the ABI output of ASM gen with ABI gen to handle internal constructors
// generated by the ASM backend.
let mut ops = match &asm_res.value {
Some(ref asm) => match &asm.0.abi {
Some(ProgramABI::Evm(ops)) => ops.clone(),
_ => vec![],
},
_ => vec![],
};

let abi = time_expr!(
"generate JSON ABI program",
evm_json_abi::generate_json_abi_program(typed_program, engines.te())
);

ops.extend(abi.into_iter());

ProgramABI::Evm(ops)
}
};

let entries = asm_res
Expand Down
8 changes: 6 additions & 2 deletions sway-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ clap = { version = "3.1", features = ["derive"] }
derivative = "2.2.0"
dirs = "3.0"
either = "1.6"
etk-asm = { version = "0.2.1", features = ["backtraces"] }
ethabi = { package = "fuel-ethabi", version = "18.0.0" }
etk-asm = { package = "fuel-etk-asm", version = "0.3.0-dev", features = ["backtraces"] }
etk-dasm = { package = "fuel-etk-dasm", version = "0.3.0-dev" }
etk-ops = { package = "fuel-etk-ops", version = "0.3.0-dev" }
fuel-abi-types = "0.1"
fuel-ethabi = { version = "18.0.0" }
fuel-vm = { version = "0.22", features = ["serde"] }
hashbrown = "0.13.1"
hex = { version = "0.4", optional = true }
im = "15.0"
itertools = "0.10"
lazy_static = "1.4"
pest = "2.1.3"
pest_derive = "2.1"
petgraph = "0.6"
rustc-hash = "1.1.0"
serde = { version = "1.0", features = ["derive"] }
Expand Down
Loading

0 comments on commit 678415a

Please sign in to comment.