Skip to content

Commit 4d17fb3

Browse files
committed
CI fix: move download web3signer binary out of build script (#4163)
## Issue Addressed Attempt to fix #3812 ## Proposed Changes Move web3signer binary download script out of build script to avoid downloading unless necessary. If this works, it should also reduce the build time for all jobs that runs compilation.
1 parent 8630ddf commit 4d17fb3

File tree

4 files changed

+38
-22
lines changed

4 files changed

+38
-22
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/web3signer_tests/Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ name = "web3signer_tests"
33
version = "0.1.0"
44
edition = "2021"
55

6-
build = "build.rs"
7-
86
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
97

108
[dependencies]
@@ -27,9 +25,7 @@ serde = "1.0.116"
2725
serde_derive = "1.0.116"
2826
serde_yaml = "0.8.13"
2927
eth2_network_config = { path = "../../common/eth2_network_config" }
30-
31-
[build-dependencies]
32-
tokio = { version = "1.14.0", features = ["rt-multi-thread", "macros"] }
33-
reqwest = { version = "0.11.0", features = ["json","stream"] }
3428
serde_json = "1.0.58"
3529
zip = "0.5.13"
30+
lazy_static = "1.4.0"
31+
parking_lot = "0.12.0"

testing/web3signer_tests/build.rs renamed to testing/web3signer_tests/src/get_web3signer.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@ use zip::ZipArchive;
1515
/// Use `Some("21.8.1")` to download a specific version.
1616
const FIXED_VERSION_STRING: Option<&str> = None;
1717

18-
#[tokio::main]
19-
async fn main() {
20-
let out_dir = env::var("OUT_DIR").unwrap();
21-
22-
// Read a Github API token from the environment. This is intended to prevent rate-limits on CI.
23-
// We use a name that is unlikely to accidentally collide with anything the user has configured.
24-
let github_token = env::var("LIGHTHOUSE_GITHUB_TOKEN");
25-
26-
download_binary(out_dir.into(), github_token.as_deref().unwrap_or("")).await;
27-
}
28-
2918
pub async fn download_binary(dest_dir: PathBuf, github_token: &str) {
3019
let version_file = dest_dir.join("version");
3120

testing/web3signer_tests/src/lib.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@
99
//! - Lighthouse can issue valid requests to Web3Signer.
1010
//! - The signatures generated by Web3Signer are identical to those which Lighthouse generates.
1111
//!
12-
//! There is a build script in this crate which obtains the latest version of Web3Signer and makes
13-
//! it available via the `OUT_DIR`.
12+
//! There is a `download_binary` function in the `get_web3signer` module which obtains the latest version of Web3Signer and makes
13+
//! it available via the `TEMP_DIR`.
14+
#![cfg(all(test, unix, not(debug_assertions)))]
15+
16+
mod get_web3signer;
1417

15-
#[cfg(all(test, unix, not(debug_assertions)))]
1618
mod tests {
19+
use crate::get_web3signer::download_binary;
1720
use account_utils::validator_definitions::{
1821
SigningDefinition, ValidatorDefinition, ValidatorDefinitions, Web3SignerDefinition,
1922
};
2023
use eth2_keystore::KeystoreBuilder;
2124
use eth2_network_config::Eth2NetworkConfig;
25+
use lazy_static::lazy_static;
26+
use parking_lot::Mutex;
2227
use reqwest::Client;
2328
use serde::Serialize;
2429
use slot_clock::{SlotClock, TestingSlotClock};
@@ -31,7 +36,8 @@ mod tests {
3136
use std::sync::Arc;
3237
use std::time::{Duration, Instant};
3338
use task_executor::TaskExecutor;
34-
use tempfile::TempDir;
39+
use tempfile::{tempdir, TempDir};
40+
use tokio::sync::OnceCell;
3541
use tokio::time::sleep;
3642
use types::*;
3743
use url::Url;
@@ -51,6 +57,13 @@ mod tests {
5157
/// debugging.
5258
const SUPPRESS_WEB3SIGNER_LOGS: bool = true;
5359

60+
lazy_static! {
61+
static ref TEMP_DIR: Arc<Mutex<TempDir>> = Arc::new(Mutex::new(
62+
tempdir().expect("Failed to create temporary directory")
63+
));
64+
static ref GET_WEB3SIGNER_BIN: OnceCell<()> = OnceCell::new();
65+
}
66+
5467
type E = MainnetEthSpec;
5568

5669
/// This marker trait is implemented for objects that we wish to compare to ensure Web3Signer
@@ -99,7 +112,10 @@ mod tests {
99112

100113
/// The location of the Web3Signer binary generated by the build script.
101114
fn web3signer_binary() -> PathBuf {
102-
PathBuf::from(env::var("OUT_DIR").unwrap())
115+
TEMP_DIR
116+
.lock()
117+
.path()
118+
.to_path_buf()
103119
.join("web3signer")
104120
.join("bin")
105121
.join("web3signer")
@@ -143,6 +159,19 @@ mod tests {
143159

144160
impl Web3SignerRig {
145161
pub async fn new(network: &str, listen_address: &str, listen_port: u16) -> Self {
162+
GET_WEB3SIGNER_BIN
163+
.get_or_init(|| async {
164+
// Read a Github API token from the environment. This is intended to prevent rate-limits on CI.
165+
// We use a name that is unlikely to accidentally collide with anything the user has configured.
166+
let github_token = env::var("LIGHTHOUSE_GITHUB_TOKEN");
167+
download_binary(
168+
TEMP_DIR.lock().path().to_path_buf(),
169+
github_token.as_deref().unwrap_or(""),
170+
)
171+
.await;
172+
})
173+
.await;
174+
146175
let keystore_dir = TempDir::new().unwrap();
147176
let keypair = testing_keypair();
148177
let keystore =

0 commit comments

Comments
 (0)