Skip to content

Commit 4e2b1e7

Browse files
committed
refactor(coprocessor): use shared locked solc install util
1 parent 5084314 commit 4e2b1e7

File tree

11 files changed

+78
-47
lines changed

11 files changed

+78
-47
lines changed

coprocessor/fhevm-engine/Cargo.lock

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

coprocessor/fhevm-engine/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
resolver = "2"
33
members = [
4+
"solc-build-utils",
45
"tfhe-worker",
56
"fhevm-engine-common",
67
"host-listener",
@@ -46,6 +47,7 @@ clap = { version = "4.5.38", features = ["derive", "env"] }
4647
daggy = "0.8.1"
4748
foundry-compilers = { version = "0.19.1", features = ["svm-solc"] }
4849
futures-util = "0.3.31"
50+
fs4 = "0.13.1"
4951
hex = "0.4.3"
5052
lru = "0.13.0"
5153
opentelemetry = "0.29.1"

coprocessor/fhevm-engine/build-utils/solc_retry.rs

Lines changed: 0 additions & 35 deletions
This file was deleted.

coprocessor/fhevm-engine/gw-listener/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ fhevm_gateway_bindings = { path = "../../../gateway-contracts/rust_bindings" }
4141
[build-dependencies]
4242
foundry-compilers = { workspace = true }
4343
semver = { workspace = true }
44+
solc-build-utils = { path = "../solc-build-utils" }
4445

4546
[dev-dependencies]
4647
alloy = { workspace = true, features = ["node-bindings"] }

coprocessor/fhevm-engine/gw-listener/build.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ use std::{env, path::Path};
22

33
use foundry_compilers::{multi::MultiCompiler, solc::SolcCompiler, Project, ProjectPathsConfig};
44
use semver::Version;
5-
6-
#[path = "../build-utils/solc_retry.rs"]
7-
mod solc_retry;
5+
use solc_build_utils::find_or_install_solc_locked;
86

97
fn main() {
108
let paths = ProjectPathsConfig::hardhat(Path::new(env!("CARGO_MANIFEST_DIR"))).unwrap();
119
// Use a specific version due to an issue with libc and libstdc++ in the rust Docker image we use to run it.
12-
let solc = solc_retry::find_or_install_solc(&Version::new(0, 8, 28));
10+
let solc = find_or_install_solc_locked(&Version::new(0, 8, 28));
1311
let project = Project::builder()
1412
.paths(paths)
1513
.build(MultiCompiler::new(Some(SolcCompiler::Specific(solc)), None).unwrap())

coprocessor/fhevm-engine/host-listener/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ tracing-test = { workspace = true }
5151
foundry-compilers = { workspace = true }
5252
foundry-compilers-artifacts = "0.13"
5353
semver = { workspace = true }
54+
solc-build-utils = { path = "../solc-build-utils" }

coprocessor/fhevm-engine/host-listener/build.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ use foundry_compilers::{
22
multi::MultiCompiler, solc::SolcCompiler, Project, ProjectPathsConfig,
33
};
44
use semver::Version;
5+
use solc_build_utils::find_or_install_solc_locked;
56
use std::{env, fs, path::Path, process::Command};
67

7-
#[path = "../build-utils/solc_retry.rs"]
8-
mod solc_retry;
9-
108
fn build_contracts() {
119
println!(
1210
"cargo:rerun-if-changed=../../../host-contracts/contracts/ACL.sol"
@@ -83,7 +81,7 @@ fn main() {
8381
.unwrap();
8482
// Use a specific version due to an issue with libc and libstdc++ in the
8583
// rust Docker image we use to run it.
86-
let solc = solc_retry::find_or_install_solc(&Version::new(0, 8, 28));
84+
let solc = find_or_install_solc_locked(&Version::new(0, 8, 28));
8785
let project = Project::builder()
8886
.paths(paths)
8987
.build(
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "solc-build-utils"
3+
version = "0.1.0"
4+
edition.workspace = true
5+
license.workspace = true
6+
7+
[lib]
8+
path = "src/lib.rs"
9+
10+
[dependencies]
11+
foundry-compilers = { workspace = true }
12+
fs4 = { workspace = true }
13+
semver = { workspace = true }
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use foundry_compilers::solc::Solc;
2+
use fs4::fs_std::FileExt;
3+
use semver::Version;
4+
use std::fs::OpenOptions;
5+
6+
const SOLC_INSTALL_LOCK_FILE: &str = "fhevm-solc-install.lock";
7+
8+
pub fn find_or_install_solc_locked(version: &Version) -> Solc {
9+
let lock_path = std::env::temp_dir().join(SOLC_INSTALL_LOCK_FILE);
10+
let lock_file = OpenOptions::new()
11+
.read(true)
12+
.write(true)
13+
.create(true)
14+
.truncate(false)
15+
.open(&lock_path)
16+
.unwrap_or_else(|err| {
17+
panic!(
18+
"Failed to open solc install lock file {}: {err}",
19+
lock_path.display()
20+
);
21+
});
22+
23+
lock_file.lock_exclusive().unwrap_or_else(|err| {
24+
panic!(
25+
"Failed to acquire solc install lock {}: {err}",
26+
lock_path.display()
27+
);
28+
});
29+
30+
Solc::find_or_install(version)
31+
.unwrap_or_else(|err| panic!("Failed to find or install solc {version}: {err:?}"))
32+
}

coprocessor/fhevm-engine/transaction-sender/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ fhevm_gateway_bindings = { path = "../../../gateway-contracts/rust_bindings" }
3939
[build-dependencies]
4040
foundry-compilers = { workspace = true }
4141
semver = { workspace = true }
42+
solc-build-utils = { path = "../solc-build-utils" }
4243

4344
[dev-dependencies]
4445
alloy = { workspace = true, features = ["node-bindings"] }

0 commit comments

Comments
 (0)