Skip to content

Commit 693968a

Browse files
authored
chore(sol_macro_gen): remove unlinked bytecode workaround (#11613)
1 parent b8b3cb9 commit 693968a

File tree

5 files changed

+30
-35
lines changed

5 files changed

+30
-35
lines changed

Cargo.lock

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

crates/forge/tests/cli/bind.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// <https://github.com/foundry-rs/foundry/issues/9482>
2+
forgetest_init!(bind_unlinked_bytecode, |prj, cmd| {
3+
prj.wipe();
4+
prj.add_source(
5+
"SomeLibContract.sol",
6+
r#"
7+
library SomeLib {
8+
function add(uint256 a, uint256 b) external pure returns (uint256) {
9+
return a + b;
10+
}
11+
}
12+
13+
contract SomeLibContract {
14+
function add(uint256 a, uint256 b) public pure returns (uint256) {
15+
return SomeLib.add(a, b);
16+
}
17+
}
18+
"#,
19+
);
20+
cmd.args(["bind", "--select", "SomeLibContract"]).assert_success().stdout_eq(str![[r#"
21+
[COMPILING_FILES] with [SOLC_VERSION]
22+
[SOLC_VERSION] [ELAPSED]
23+
Compiler run successful!
24+
Generating bindings for 1 contracts
25+
Bindings have been generated to [..]
26+
"#]]);
27+
});

crates/forge/tests/cli/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extern crate foundry_test_utils;
44
pub mod constants;
55
pub mod utils;
66

7+
mod bind;
78
mod bind_json;
89
mod build;
910
mod cache;

crates/sol-macro-gen/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ proc-macro2.workspace = true
2323
quote.workspace = true
2424
syn.workspace = true
2525
prettyplease.workspace = true
26-
serde_json.workspace = true
2726

2827
eyre.workspace = true
2928

crates/sol-macro-gen/src/sol_macro_gen.rs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use eyre::{Context, OptionExt, Result};
1515
use foundry_common::fs;
1616
use proc_macro2::{Span, TokenStream};
1717
use std::{
18-
env::temp_dir,
1918
fmt::Write,
2019
path::{Path, PathBuf},
2120
str::FromStr,
@@ -38,6 +37,7 @@ impl SolMacroGen {
3837
let path = self.path.to_string_lossy().into_owned();
3938
let name = proc_macro2::Ident::new(&self.name, Span::call_site());
4039
let tokens = quote::quote! {
40+
#[sol(ignore_unlinked)]
4141
#name,
4242
#path
4343
};
@@ -85,38 +85,7 @@ impl MultiSolMacroGen {
8585
}
8686

8787
fn generate_binding(instance: &mut SolMacroGen, all_derives: bool) -> Result<()> {
88-
// TODO: in `get_sol_input` we currently can't handle unlinked bytecode: <https://github.com/alloy-rs/core/issues/926>
89-
let input = match instance.get_sol_input() {
90-
Ok(input) => input.normalize_json()?,
91-
Err(error) => {
92-
// TODO(mattsse): remove after <https://github.com/alloy-rs/core/issues/926>
93-
if error.to_string().contains("expected bytecode, found unlinked bytecode") {
94-
// we attempt to do a little hack here until we have this properly supported by
95-
// removing the bytecode objects from the json file and using a tmpfile (very
96-
// hacky)
97-
let content = std::fs::read_to_string(&instance.path)?;
98-
let mut value = serde_json::from_str::<serde_json::Value>(&content)?;
99-
let obj = value.as_object_mut().expect("valid abi");
100-
101-
// clear unlinked bytecode
102-
obj.remove("bytecode");
103-
obj.remove("deployedBytecode");
104-
105-
let tmpdir = temp_dir();
106-
let mut tmp_file = tmpdir.join(instance.path.file_name().unwrap());
107-
std::fs::write(&tmp_file, serde_json::to_string(&value)?)?;
108-
109-
// try again
110-
std::mem::swap(&mut tmp_file, &mut instance.path);
111-
let input = instance.get_sol_input()?.normalize_json()?;
112-
std::mem::swap(&mut tmp_file, &mut instance.path);
113-
input.normalize_json()?
114-
} else {
115-
return Err(error);
116-
}
117-
}
118-
};
119-
88+
let input = instance.get_sol_input()?.normalize_json()?;
12089
let SolInput { attrs: _, path: _, kind } = input;
12190

12291
let tokens = match kind {

0 commit comments

Comments
 (0)