-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add @nomicfoundation/hardhat-solx plugin #8034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
612175b
Add @nomicfoundation/hardhat-solx extension plugin
marianfe b8f827e
Add validation, default settings, error codes, and plugin conventions
marianfe df4184b
Align hardhat-solx plugin with revised design doc
marianfe a92b222
Use solx binary version in SolxCompiler for display output
marianfe 15c03dd
Skip download message when solx binary is already cached
marianfe b3355e1
Code review fixes: README, overrides validation, parallel downloads, …
marianfe ded472b
Address PR review comments
marianfe 25abf44
Address new PR comments — config validation and resolution
marianfe 1dba2c0
Address new PR comments — test improvements
marianfe 12e7a3e
Replace auto test profile with manual solx build profile
marianfe d939394
Merge main into feat/solx-step3-hardhat-solx-plugin
marianfe aa73e6b
Merge main into feat/solx-step3-hardhat-solx-plugin
marianfe c8d7705
Move hardhat-solx from v-next/ to packages/
marianfe 1f1a0ab
Address remaining review comments, rebase on latest main packages/, a…
marianfe eaef43d
chore: exclude package from publishing
kanej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@nomicfoundation/hardhat-solx": major | ||
| "@nomicfoundation/hardhat-errors": patch | ||
| --- | ||
|
|
||
| Add `@nomicfoundation/hardhat-solx` plugin for solx compiler support in test builds ([#8034](https://github.com/NomicFoundation/hardhat/pull/8034)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Node modules | ||
| /node_modules | ||
|
|
||
| # Compilation output | ||
| /dist | ||
|
|
||
| # pnpm deploy output | ||
| /bundle | ||
|
|
||
| # test coverage output | ||
| coverage | ||
|
|
||
| # all the tmp folders in the fixture projects | ||
| /test/fixture-projects/tmp/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /node_modules | ||
| /dist | ||
| /coverage | ||
| CHANGELOG.md | ||
| /test/fixture-projects/**/artifacts | ||
| /test/fixture-projects/**/cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2026 Nomic Foundation | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # Hardhat Solx plugin | ||
|
|
||
| This plugin enables the [solx](https://github.com/NomicFoundation/solx) Solidity compiler in Hardhat 3. | ||
|
|
||
| The `solx` compiler is currently experimental and is not ready for production use-cases. We recommend using the compiler for test builds and test execution locally, and continuing to use `solc` for production use-cases (including during deployment for example with `hardhat-ignition` and in your CI). Care should be taken before enabling compilation with `solx` in other build profiles, see configuration flags further below. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| npm install --save-dev @nomicfoundation/hardhat-solx | ||
| ``` | ||
|
|
||
| Then add the plugin to your `hardhat.config.ts` and create a `solx` build profile. You must use the build profiles config format, which requires both a `default` and a `solx` profile: | ||
|
|
||
| ```typescript | ||
| import { defineConfig } from "hardhat/config"; | ||
| import hardhatSolx from "@nomicfoundation/hardhat-solx"; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [hardhatSolx], | ||
| solidity: { | ||
| profiles: { | ||
| default: { | ||
| version: "0.8.29", | ||
| }, | ||
| solx: { | ||
| type: "solx", | ||
| version: "0.8.33", | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| The `default` profile uses solc as usual. The `solx` profile uses the solx compiler — identified by `type: "solx"`. Your `.sol` files should have compatible pragmas, for example `pragma solidity ^0.8.29;`. Strict pragmas for unsupported Solidity versions, for example `pragma solidity 0.8.28;`, will currently not compile with this hardhat-solx plugin. See more details below for the currently supported Solidity versions and EVM versions. | ||
|
|
||
| ## Usage | ||
|
|
||
| Run tests or compile using the solx-powered build profile: | ||
|
|
||
| ```bash | ||
| hardhat test --build-profile solx | ||
| hardhat build --build-profile solx | ||
| ``` | ||
|
|
||
| The default profile continues to use solc as usual: | ||
|
|
||
| ```bash | ||
| hardhat build # uses solc (default profile) | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### Multi-version example | ||
|
|
||
| You can configure the `solx` profile with multiple compilers. Compilers without `type: "solx"` will use solc: | ||
|
|
||
| ```typescript | ||
| export default defineConfig({ | ||
| plugins: [hardhatSolx], | ||
| solidity: { | ||
| profiles: { | ||
| default: { | ||
| compilers: [{ version: "0.8.33" }, { version: "0.8.20" }], | ||
| }, | ||
| solx: { | ||
| compilers: [ | ||
| { type: "solx", version: "0.8.33" }, | ||
| { version: "0.8.20" }, // uses solc — solx doesn't support this version | ||
| ], | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| - `dangerouslyAllowSolxInProduction` (`boolean`, default: `false`) — Allow compiler type `"solx"` in build profiles other than `solx`. By default, using `type: "solx"` in any other profile (e.g. `default`, `production`) will produce a validation error. | ||
|
|
||
| ```typescript | ||
| export default defineConfig({ | ||
| plugins: [hardhatSolx], | ||
| solidity: { | ||
| profiles: { | ||
| default: { | ||
| type: "solx", // returns a validation error. | ||
| version: "0.8.33", | ||
| }, | ||
| }, | ||
| }, | ||
| solx: { | ||
| dangerouslyAllowSolxInProduction: false, // default false, switching this to true will allow `type: "solx"` on the default profile. | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| ### Supported Solidity versions | ||
|
|
||
| solx maps each Solidity version to a specific solx binary version internally. Currently supported: `0.8.33` (solx 0.1.3). | ||
|
|
||
| ### EVM version support | ||
|
|
||
| solx supports EVM versions `cancun`, `prague`, and `osaka`. Using an older EVM target (e.g., `paris`, `shanghai`) with compiler type `"solx"` will result in a validation error. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { createConfig } from "../config/eslint.config.js"; | ||
|
|
||
| export default createConfig(import.meta.filename); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| { | ||
| "name": "@nomicfoundation/hardhat-solx", | ||
| "version": "2.0.0", | ||
| "description": "Hardhat plugin for using solx compiler in test builds", | ||
| "homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/hardhat-solx", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/NomicFoundation/hardhat", | ||
| "directory": "v-next/hardhat-solx" | ||
| }, | ||
| "author": "Nomic Foundation", | ||
| "license": "MIT", | ||
| "type": "module", | ||
| "types": "dist/src/index.d.ts", | ||
| "exports": { | ||
| ".": "./dist/src/index.js" | ||
| }, | ||
| "keywords": [ | ||
| "ethereum", | ||
| "smart-contracts", | ||
| "hardhat", | ||
| "solx", | ||
| "compiler" | ||
| ], | ||
| "scripts": { | ||
| "lint": "pnpm prettier --check && pnpm eslint", | ||
| "lint:fix": "pnpm prettier --write && pnpm eslint --fix", | ||
| "eslint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"", | ||
| "prettier": "prettier \"**/*.{ts,js,md,json}\"", | ||
| "test": "node --import tsx/esm --test --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"", | ||
| "test:only": "node --import tsx/esm --test --test-only --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"", | ||
| "test:coverage": "c8 --reporter html --reporter text --all --exclude test --exclude \"src/**/{types,type-extensions}.ts\" --src src node --import tsx/esm --test --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"", | ||
| "pretest": "pnpm build", | ||
| "pretest:only": "pnpm build", | ||
| "build": "tsc --build .", | ||
| "prepublishOnly": "pnpm build", | ||
| "clean": "rimraf dist" | ||
| }, | ||
| "files": [ | ||
| "dist/src/", | ||
| "src/", | ||
| "CHANGELOG.md", | ||
| "LICENSE", | ||
| "README.md" | ||
| ], | ||
| "devDependencies": { | ||
| "@nomicfoundation/hardhat-node-test-reporter": "workspace:^3.0.0", | ||
| "@nomicfoundation/hardhat-test-utils": "workspace:^", | ||
| "@types/debug": "^4.1.7", | ||
| "@types/node": "^22.0.0", | ||
| "c8": "^9.1.0", | ||
| "eslint": "9.25.1", | ||
| "prettier": "3.2.5", | ||
| "rimraf": "^5.0.5", | ||
| "tsx": "^4.19.3", | ||
| "typescript": "~5.8.0", | ||
| "hardhat": "workspace:^3.1.6" | ||
| }, | ||
| "dependencies": { | ||
| "@nomicfoundation/hardhat-errors": "workspace:^3.0.3", | ||
| "@nomicfoundation/hardhat-utils": "workspace:^3.0.5", | ||
| "@nomicfoundation/hardhat-zod-utils": "workspace:^3.0.0", | ||
| "debug": "^4.3.2", | ||
| "zod": "^3.23.8" | ||
| }, | ||
| "peerDependencies": { | ||
| "hardhat": "workspace:^3.1.6" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import type { HardhatPlugin } from "hardhat/types/plugins"; | ||
|
|
||
| import "./type-extensions.js"; | ||
|
|
||
| const hardhatSolxPlugin: HardhatPlugin = { | ||
| id: "hardhat-solx", | ||
| npmPackage: "@nomicfoundation/hardhat-solx", | ||
| hookHandlers: { | ||
| config: () => import("./internal/hook-handlers/config.js"), | ||
| solidity: () => import("./internal/hook-handlers/solidity.js"), | ||
| }, | ||
| }; | ||
|
|
||
| export default hardhatSolxPlugin; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import type { SolidityCompilerType } from "hardhat/types/config"; | ||
|
|
||
| /** | ||
| * The compiler type identifier registered by this plugin. | ||
| * Typed as SolidityCompilerType for type-safe comparisons. | ||
| */ | ||
| export const SOLX_COMPILER_TYPE: SolidityCompilerType = "solx"; | ||
|
|
||
| export const SOLX_RELEASES_BASE_URL = | ||
| "https://solx-releases-mirror.hardhat.org"; | ||
|
|
||
| export const SUPPORTED_SOLX_EVM_VERSIONS: readonly string[] = [ | ||
| "cancun", | ||
| "prague", | ||
| "osaka", | ||
| ] as const; | ||
|
|
||
| export const DEFAULT_SOLX_SETTINGS: Record<string, unknown> = { | ||
| viaIR: false, | ||
| LLVMOptimization: "1", | ||
| }; | ||
|
|
||
| /** | ||
| * Maps Solidity compiler versions to the solx version that embeds them. | ||
| * Only stable solx releases are included. | ||
| */ | ||
| export const SOLIDITY_TO_SOLX_VERSION_MAP: Record<string, string> = { | ||
| "0.8.33": "0.1.3", | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The HARDHAT_SOLX.GENERAL.DOWNLOAD_FAILED website description says the binary couldn’t be downloaded from GitHub releases, but the implementation downloads from
https://solx-releases-mirror.hardhat.org. Updating this text would avoid sending users to the wrong place when troubleshooting download failures.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed