alloy-rs / core

High-performance, well-tested & documented core libraries for Ethereum, in Rust
https://alloy.rs
Apache License 2.0
763 stars 135 forks source link

[Bug] `sol!` only accepts string literal #651

Closed wtdcode closed 3 months ago

wtdcode commented 3 months ago

Component

sol! macro

What version of Alloy are you on?

0.7.4

Operating System

Linux

Describe the bug

sol! seems only to support string literals, i.e., LitStr. For instance:

sol!(T, "[]"); // Works
sol!(T, concat!("[","]")); // Doesn't work
const s: &str = "[]";
sol!(T, s); // Doesn't work either

Is it possible to support a constant &str instead? This would be helpful to support something like concat!(std::env!("OUT_DIR"), ...)

wtdcode commented 3 months ago

Seems not possible as https://github.com/rust-lang/rust/issues/69133

DaniPopes commented 3 months ago

We parse out environment variables with $ENV inside of the literal, but that's about as much as you can do unfortunately

chris13524 commented 2 weeks ago

Bumping this, is there a way to reference environment variables in the latest version of sol!? This doesn't seem to work:

sol!(
    #[allow(missing_docs)]
    #[sol(rpc)]
    SafeProxyFactory,
    "$OUT_DIR/../../../../.foundry/forge/out/SafeProxyFactory.sol/SafeProxyFactory.json"
);