From 49d4a6bac680dc90d0e29b59bbe87eaee6056022 Mon Sep 17 00:00:00 2001 From: nekomoto911 Date: Thu, 28 Nov 2024 23:36:55 +0800 Subject: [PATCH] use build script instead of git submodule --- .github/workflows/grevm-ethereum.yml | 6 +- .github/workflows/grevm-test.yml | 6 +- .gitignore | 4 ++ .gitmodules | 6 -- Cargo.toml | 6 ++ build.rs | 88 ++++++++++++++++++++++++++++ test_data | 1 - tests/ethereum/tests | 1 - 8 files changed, 100 insertions(+), 18 deletions(-) delete mode 100644 .gitmodules create mode 100644 build.rs delete mode 160000 test_data delete mode 160000 tests/ethereum/tests diff --git a/.github/workflows/grevm-ethereum.yml b/.github/workflows/grevm-ethereum.yml index accd967..5c087b4 100644 --- a/.github/workflows/grevm-ethereum.yml +++ b/.github/workflows/grevm-ethereum.yml @@ -16,10 +16,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Initialize ethereum tests - run: | - git submodule update --init tests/ethereum/tests - # install rust tools - name: Set up Rust uses: actions-rs/toolchain@v1 @@ -28,4 +24,4 @@ jobs: override: true - name: Run tests - run: cargo test --test ethereum + run: cargo test --features update-submodule-ethereum-tests --test ethereum diff --git a/.github/workflows/grevm-test.yml b/.github/workflows/grevm-test.yml index 6e3855d..366f25b 100644 --- a/.github/workflows/grevm-test.yml +++ b/.github/workflows/grevm-test.yml @@ -16,10 +16,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Initialize mainnet test_data - run: | - git submodule update --init test_data - # install rust tools - name: Set up Rust uses: actions-rs/toolchain@v1 @@ -28,4 +24,4 @@ jobs: override: true - name: Run tests - run: cargo test -- --skip ethereum + run: cargo test --features update-submodule-test-data -- --skip ethereum diff --git a/.gitignore b/.gitignore index 59c2e57..6a4153d 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,7 @@ rustc-ice-* # Rust lock file Cargo.lock + +# test submodules +test_data +tests/ethereum/tests diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index fd40f74..0000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "test_data"] - path = test_data - url = https://github.com/Galxe/grevm-test-data -[submodule "tests/ethereum/tests"] - path = tests/ethereum/tests - url = https://github.com/ethereum/tests.git diff --git a/Cargo.toml b/Cargo.toml index bf28cd9..e3b262c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ name = "grevm" version = "0.1.0" edition = "2021" description = "Create Parallel EVM" +build = "build.rs" [dependencies] revm = { package = "revm", git = "https://github.com/galxe/revm", rev = "20b5883" } @@ -59,3 +60,8 @@ harness = false codegen-units = 1 panic = "abort" lto = "fat" + +[features] +update-test-submodule = ["update-submodule-test-data", "update-submodule-ethereum-tests"] +update-submodule-test-data = [] +update-submodule-ethereum-tests = [] diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..3765efc --- /dev/null +++ b/build.rs @@ -0,0 +1,88 @@ +//! This crate contains the build script for the grevm project. + +use std::{path::Path, process::Command}; + +struct TestSubmodule { + path: &'static str, + url: &'static str, + branch: &'static str, + commit: Option<&'static str>, +} + +fn git_clone(submodule: &TestSubmodule) -> Command { + let mut command = Command::new("git"); + command.args(&["clone", "-b", submodule.branch, submodule.url, submodule.path]); + command +} + +fn git_fetch(submodule: &TestSubmodule) -> Command { + let mut command = Command::new("git"); + command.args(&["-C", submodule.path, "fetch", "origin", submodule.branch]); + command +} + +fn git_checkout(submodule: &TestSubmodule) -> Command { + let mut command = Command::new("git"); + if let Some(commit) = submodule.commit { + command.args(&["-C", submodule.path, "checkout", commit]); + } else { + command.args(&["-C", submodule.path, "checkout", submodule.branch]); + } + command +} + +fn update_submodule(submodule: &TestSubmodule) { + let test_data = Path::new(submodule.path); + if !test_data.exists() && !git_clone(submodule).status().unwrap().success() { + panic!("Failed to clone submodule {}", submodule.path); + } + + if submodule.commit.is_some() { + if git_checkout(submodule).status().unwrap().success() { + return; + } + } + + if !git_fetch(submodule).status().unwrap().success() { + panic!("Failed to fetch branch {} in submodule {}", submodule.branch, submodule.path); + } + + if !git_checkout(submodule).status().unwrap().success() { + panic!("Failed to checkout {} in submodule {}", submodule.branch, submodule.path); + } +} + +fn update_submodules(submodules: &[TestSubmodule]) { + std::thread::scope(|s| { + for submodule in submodules { + s.spawn(|| { + println!("Updating submodule {}", submodule.path); + update_submodule(submodule); + println!("Updating submodule {} done", submodule.path); + }); + } + }); +} + +fn main() { + #[allow(unused_mut)] + let mut submodules = vec![]; + + #[cfg(feature = "update-submodule-test-data")] + submodules.push(TestSubmodule { + path: "test_data", + url: "https://github.com/Galxe/grevm-test-data", + branch: "main", + commit: Some("4264bdf"), + }); + + #[cfg(feature = "update-submodule-ethereum-tests")] + submodules.push(TestSubmodule { + path: "tests/ethereum/tests", + url: "https://github.com/ethereum/tests", + branch: "develop", + commit: Some("4f65a0a"), + }); + + update_submodules(&submodules); +} diff --git a/test_data b/test_data deleted file mode 160000 index 4264bdf..0000000 --- a/test_data +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4264bdf3e4e14d40a670c12a7108605b324495b2 diff --git a/tests/ethereum/tests b/tests/ethereum/tests deleted file mode 160000 index 4f65a0a..0000000 --- a/tests/ethereum/tests +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4f65a0a7cbecf4442415c226c65e089acaaf6a8b