Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use build script instead of git submodule #34

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/grevm-ethereum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 1 addition & 5 deletions .github/workflows/grevm-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ rustc-ice-*

# Rust lock file
Cargo.lock

# test submodules
test_data
tests/ethereum/tests
6 changes: 0 additions & 6 deletions .gitmodules

This file was deleted.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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 = []
88 changes: 88 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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", &format!("origin/{}", 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);
}
1 change: 0 additions & 1 deletion test_data
Submodule test_data deleted from 4264bd
1 change: 0 additions & 1 deletion tests/ethereum/tests
Submodule tests deleted from 4f65a0
Loading