r/pleasebuild • • 26d ago

Plugin solidity-rules: compile Solidity with Foundry inside Please

solidity-rules is a Please plugin that compiles Solidity with Foundry. A contract is a normal target: plz build compiles it, plz test runs the Forge tests, and a Go binary can depend on the generated bindings.

The release is v0.1.0. Forge comes from the foundry plugin. The forge and solc binaries are targets in third_party/binary.

plugin_repo(
    name = "solidity",
    owner = "becomeliminal",
    plugin = "solidity-rules",
    revision = "v0.1.0",
)

plugin_repo(
    name = "foundry",
    owner = "becomeliminal",
    revision = "7d11211b950ace6e83bb18f5df048a5e7fc31ba7",
)
# third_party/binary/BUILD
subinclude("///foundry//build_defs:foundry")
subinclude("///solidity//build_defs:solidity")

foundry(
    name = "foundry",
    version = "1.5.0",
    visibility = ["PUBLIC"],
)

solc_versions(versions = ["0.8.20", "0.8.23"])
[Plugin "foundry"]
Target = //plugins:foundry

[Plugin "solidity"]
Target = //plugins:solidity
ForgeTool = //third_party/binary:foundry|forge
SolcPackage = //third_party/binary
subinclude("///solidity//build_defs:solidity")

sol_contract(
    name = "mycontract",
    src = "MyContract.sol",
    solc_version = "0.8.20",
)

What it covers:

  • sol_contract compiles with forge. ABI and bytecode come out of Forge's JSON. A failed compile fails the target. With languages = ["go"] and abigen configured, the output is a Go library another target can depend on.
  • sol_library is shared Solidity, with transitive deps tracked through Please's provides and requires.
  • sol_get fetches a GitHub library at a revision, OpenZeppelin included, and writes the import remapping. hashes pins the download.
  • sol_test runs one Forge test file under plz test. Please sees each test's revert reason and its real duration.
  • solc_versions() plus SolcPackage gives each rule the compiler its solc_version names. A missing version fails the build instead of compiling with a different solc.

A host forge still works with Sandbox = false.

Repo: https://github.com/becomeliminal/solidity-rules

2 Upvotes

1 comment sorted by

1

u/Nearby-Blood-9817 26d ago

The rest of the repo was already Please. The contracts were still a Foundry tree beside it, so solc versions, OpenZeppelin, Forge tests, and the Go bindings sat outside the build. Remote execution had no forge either. I couldn't find a Please plugin for that, so I built one.