hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

feat: add new onSolcCompileComplete hook

Open kanej opened this issue 3 weeks ago • 1 comments

Add a onSolcCompileComplete hook that is called immediately after solc compilation. The hook is invoked on execution of solc as part of the compilation job and passes the solc input, solc output along with the compilation job that they represent.

The hook is invoked whether the compilation is a success or not (i.e. there are compilation errors).

onSolcCompileComplete Hook

/**
 * Hook triggered on the solc compile of a compilation job, providing the
 * Solc input and output.
 *
 * @param context The hook context.
 * @param solcConfig The configuration used to setup solc e.g. version.
 * @param solcInput The solc input json passed to solc for this compilation
 * job.
 * @param solcOutput The solc output json received from solc for this
 * compilation job.
 * @param next A function to call the next handler for this hook, or the
 * default implementation if no more handlers exist.
 */
onSolcCompileComplete(
  context: HookContext,
  solcConfig: SolcConfig,
  solcInput: CompilerInput,
  solcOutput: CompilerOutput,
  next: (
    nextContext: HookContext,
    nextSolcConfig: SolcConfig,
    nextSolcInput: CompilerInput,
    nextSolcOutput: CompilerOutput,
  ) => Promise<void>,
): Promise<void>;

Resolve #7646

kanej avatar Dec 01 '25 14:12 kanej

🦋 Changeset detected

Latest commit: de9228df18a9c215c0300085b501fac22b84d202

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
hardhat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Dec 01 '25 14:12 changeset-bot[bot]

up

afa7789 avatar Dec 12 '25 12:12 afa7789

@fvictorio queried the hook, arguing it should be something more like:

solcCompile(
  context: HookContext,
  solcConfig: SolcConfig,
  solcInput: CompilerInput,
  next: (
    nextContext: HookContext,
    nextSolcConfig: SolcConfig,
    nextSolcInput: CompilerInput,
  ) => Promise<CompilerOutput>,
): Promise<CompilerOutput>;

So taking the input and giving the output. This would work if we could do this if we include the solcConfig settings that OpenZeppelin required as well.

When I looked to implement this though I ran into the question of how to deal with the compiler. Is it passed in also? It seems like the hook should encapsulate the selection and retrieval of the compiler. But then should the hook pass the compiler back as a result, to allow it to be propagated up the call chain as runCompilationJob requires?

kanej avatar Dec 18 '25 18:12 kanej