Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/sol-macro-gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ proc-macro2.workspace = true
quote.workspace = true
syn.workspace = true
prettyplease.workspace = true
serde_json.workspace = true

eyre.workspace = true
33 changes: 32 additions & 1 deletion crates/sol-macro-gen/src/sol_macro_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use eyre::{Context, OptionExt, Result};
use foundry_common::fs;
use proc_macro2::{Span, TokenStream};
use std::{
env::temp_dir,
fmt::Write,
path::{Path, PathBuf},
str::FromStr,
Expand Down Expand Up @@ -82,7 +83,37 @@ impl MultiSolMacroGen {
}

fn generate_binding(instance: &mut SolMacroGen, all_derives: bool) -> Result<()> {
let input = instance.get_sol_input()?.normalize_json()?;
// TODO: in `get_sol_input` we currently can't handle unlinked bytecode: <https://github.com/alloy-rs/core/issues/926>
let input = match instance.get_sol_input() {
Ok(input) => input.normalize_json()?,
Err(error) => {
// TODO(mattsse): remove after <https://github.com/alloy-rs/core/issues/926>
if error.to_string().contains("expected bytecode, found unlinked bytecode") {
// we attempt to do a little hack here until we have this properly supported by
// removing the bytecode objects from the json file and using a tmpfile (very
// hacky)
let content = std::fs::read_to_string(&instance.path)?;
let mut value = serde_json::from_str::<serde_json::Value>(&content)?;
let obj = value.as_object_mut().expect("valid abi");

// clear unlinked bytecode
obj.remove("bytecode");
obj.remove("deployedBytecode");

let tmpdir = temp_dir();
let mut tmp_file = tmpdir.join(instance.path.file_name().unwrap());
std::fs::write(&tmp_file, serde_json::to_string(&value)?)?;

// try again
std::mem::swap(&mut tmp_file, &mut instance.path);
let input = instance.get_sol_input()?.normalize_json()?;
std::mem::swap(&mut tmp_file, &mut instance.path);
input.normalize_json()?
} else {
return Err(error)
}
}
};

let SolInput { attrs: _, path: _, kind } = input;

Expand Down