Skip to content

Commit 3998de0

Browse files
authored
chore: delay spawning tokio runtime until needed (foundry-rs#8819)
1 parent da28b31 commit 3998de0

File tree

7 files changed

+87
-83
lines changed

7 files changed

+87
-83
lines changed

Cargo.lock

+61-61
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/anvil/src/anvil.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ pub enum AnvilSubcommand {
3333
GenerateFigSpec,
3434
}
3535

36-
#[tokio::main]
37-
async fn main() -> eyre::Result<()> {
36+
fn main() -> eyre::Result<()> {
3837
utils::load_dotenv();
3938

40-
let mut app = Anvil::parse();
41-
app.node.evm_opts.resolve_rpc_alias();
39+
let mut args = Anvil::parse();
40+
args.node.evm_opts.resolve_rpc_alias();
4241

43-
if let Some(ref cmd) = app.cmd {
42+
if let Some(cmd) = &args.cmd {
4443
match cmd {
4544
AnvilSubcommand::Completions { shell } => {
4645
clap_complete::generate(
@@ -61,9 +60,7 @@ async fn main() -> eyre::Result<()> {
6160
}
6261

6362
let _ = fdlimit::raise_fd_limit();
64-
app.node.run().await?;
65-
66-
Ok(())
63+
tokio::runtime::Builder::new_multi_thread().enable_all().build()?.block_on(args.node.run())
6764
}
6865

6966
#[cfg(test)]

crates/cast/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "cast"
2+
name = "foundry-cast"
33
description = "Command-line tool for performing Ethereum RPC calls"
44

55
version.workspace = true
@@ -13,6 +13,9 @@ repository.workspace = true
1313
[lints]
1414
workspace = true
1515

16+
[lib]
17+
name = "cast"
18+
1619
[[bin]]
1720
name = "cast"
1821
path = "bin/main.rs"
File renamed without changes.

crates/cast/bin/cmd/storage.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::opts::parse_slot;
1+
use crate::args::parse_slot;
22
use alloy_network::AnyNetwork;
33
use alloy_primitives::{Address, B256, U256};
44
use alloy_provider::Provider;

crates/cast/bin/main.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,28 @@ use foundry_common::{
2323
use foundry_config::Config;
2424
use std::time::Instant;
2525

26+
pub mod args;
2627
pub mod cmd;
27-
pub mod opts;
2828
pub mod tx;
2929

30-
use opts::{Cast as Opts, CastSubcommand, ToBaseArgs};
30+
use args::{Cast as CastArgs, CastSubcommand, ToBaseArgs};
3131

3232
#[cfg(all(feature = "jemalloc", unix))]
3333
#[global_allocator]
3434
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
3535

36-
#[tokio::main]
37-
async fn main() -> Result<()> {
36+
fn main() -> Result<()> {
3837
handler::install();
3938
utils::load_dotenv();
4039
utils::subscriber();
4140
utils::enable_paint();
41+
let args = CastArgs::parse();
42+
main_args(args)
43+
}
4244

43-
let opts = Opts::parse();
44-
match opts.cmd {
45+
#[tokio::main]
46+
async fn main_args(args: CastArgs) -> Result<()> {
47+
match args.cmd {
4548
// Constants
4649
CastSubcommand::MaxInt { r#type } => {
4750
println!("{}", SimpleCast::max_int(&r#type)?);
@@ -555,11 +558,11 @@ async fn main() -> Result<()> {
555558
}
556559
CastSubcommand::Wallet { command } => command.run().await?,
557560
CastSubcommand::Completions { shell } => {
558-
generate(shell, &mut Opts::command(), "cast", &mut std::io::stdout())
561+
generate(shell, &mut CastArgs::command(), "cast", &mut std::io::stdout())
559562
}
560563
CastSubcommand::GenerateFigSpec => clap_complete::generate(
561564
clap_complete_fig::Fig,
562-
&mut Opts::command(),
565+
&mut CastArgs::command(),
563566
"cast",
564567
&mut std::io::stdout(),
565568
),

crates/chisel/bin/main.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,16 @@ pub enum ChiselSubcommand {
9494
ClearCache,
9595
}
9696

97-
#[tokio::main]
98-
async fn main() -> eyre::Result<()> {
97+
fn main() -> eyre::Result<()> {
9998
handler::install();
10099
utils::subscriber();
101100
utils::load_dotenv();
102-
103-
// Parse command args
104101
let args = Chisel::parse();
102+
main_args(args)
103+
}
105104

105+
#[tokio::main]
106+
async fn main_args(args: Chisel) -> eyre::Result<()> {
106107
// Keeps track of whether or not an interrupt was the last input
107108
let mut interrupt = false;
108109

0 commit comments

Comments
 (0)