diff --git a/.github/scripts/create-tag.js b/.github/scripts/create-tag.js index ac7dcc0..d16b4f2 100644 --- a/.github/scripts/create-tag.js +++ b/.github/scripts/create-tag.js @@ -1,14 +1,15 @@ -module.exports = async ({github, context}, tagName) => { - try { - await github.rest.git.createRef({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: `refs/tags/${tagName}`, - sha: context.sha, - force: true - }) - } catch (err) { - console.error(`Failed to create tag: ${tagName}`) - console.error(err) - } -} \ No newline at end of file +// From https://github.com/foundry-rs/foundry/ +module.exports = async ({ github, context }, tagName) => { + try { + await github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `refs/tags/${tagName}`, + sha: context.sha, + force: true, + }); + } catch (err) { + console.error(`Failed to create tag: ${tagName}`); + console.error(err); + } +}; diff --git a/.github/scripts/move-tag.js b/.github/scripts/move-tag.js index 7a01da7..5b91f1a 100644 --- a/.github/scripts/move-tag.js +++ b/.github/scripts/move-tag.js @@ -1,15 +1,16 @@ -module.exports = async ({github, context}, tagName) => { - try { - await github.rest.git.updateRef({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: `tags/${tagName}`, - sha: context.sha, - force: true - }) - } catch (err) { - console.error(`Failed to move nightly tag.`) - console.error(`This should only happen the first time.`) - console.error(err) - } -} \ No newline at end of file +// From https://github.com/foundry-rs +module.exports = async ({ github, context }, tagName) => { + try { + await github.rest.git.updateRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `tags/${tagName}`, + sha: context.sha, + force: true, + }); + } catch (err) { + console.error(`Failed to move nightly tag.`); + console.error(`This should only happen the first time.`); + console.error(err); + } +}; diff --git a/.github/scripts/prune-prereleases.js b/.github/scripts/prune-prereleases.js index 9e16e48..e9dbef8 100644 --- a/.github/scripts/prune-prereleases.js +++ b/.github/scripts/prune-prereleases.js @@ -1,33 +1,69 @@ -module.exports = async ({github, context}) => { - console.log('Pruning old prereleases') - - const { data: releases } = await github.rest.repos.listReleases({ - owner: context.repo.owner, - repo: context.repo.repo - }) - - // Only consider releases tagged `nightly-${SHA}` for deletion - let nightlies = releases.filter( - (release) => release.tag_name.includes('nightly') && release.tag_name !== 'nightly' - ) - - // Keep newest 3 nightlies - nightlies = nightlies.slice(3) - - for (const nightly of nightlies) { - console.log(`Deleting nightly: ${nightly.tag_name}`) - await github.rest.repos.deleteRelease({ - owner: context.repo.owner, - repo: context.repo.repo, - release_id: nightly.id - }) - console.log(`Deleting nightly tag: ${nightly.tag_name}`) - await github.rest.git.deleteRef({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: `tags/${nightly.tag_name}` - }) - } - - console.log('Done.') -} \ No newline at end of file +// From https://github.com/foundry-rs +// In case node 21 is not used. +function groupBy(array, keyOrIterator) { + var iterator; + + // use the function passed in, or create one + if(typeof keyOrIterator !== 'function') { + const key = String(keyOrIterator); + iterator = function (item) { return item[key]; }; + } else { + iterator = keyOrIterator; + } + + return array.reduce(function (memo, item) { + const key = iterator(item); + memo[key] = memo[key] || []; + memo[key].push(item); + return memo; + }, {}); +} + +module.exports = async ({ github, context }) => { + console.log("Pruning old prereleases"); + + // doc: https://docs.github.com/en/rest/releases/releases + const { data: releases } = await github.rest.repos.listReleases({ + owner: context.repo.owner, + repo: context.repo.repo, + }); + + let nightlies = releases.filter( + release => + // Only consider releases tagged `nightly-${SHA}` for deletion + release.tag_name.includes("nightly") && + release.tag_name !== "nightly" + ); + + // Pruning rules: + // 1. only keep the earliest (by created_at) release of the month + // 2. to keep the newest 30 nightlies (to make sure nightlies are kept until the next monthly release) + // Notes: + // - This addresses https://github.com/foundry-rs/foundry/issues/6732 + // - Name of the release may deviate from created_at due to the usage of different timezones. + + // Group releases by months. + // Per doc: + // > The latest release is the most recent non-prerelease, non-draft release, sorted by the created_at attribute. + const groups = groupBy(nightlies, i => i.created_at.slice(0, 7)); + const nightliesToPrune = Object.values(groups) + .reduce((acc, cur) => acc.concat(cur.slice(0, -1)), []) // rule 1 + .slice(30); // rule 2 + + for (const nightly of nightliesToPrune) { + console.log(`Deleting nightly: ${nightly.tag_name}`); + await github.rest.repos.deleteRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: nightly.id, + }); + console.log(`Deleting nightly tag: ${nightly.tag_name}`); + await github.rest.git.deleteRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `tags/${nightly.tag_name}`, + }); + } + + console.log("Done."); +}; diff --git a/.github/workflows/docker-publish.yaml b/.github/workflows/docker-publish.yaml deleted file mode 100644 index de4ecdc..0000000 --- a/.github/workflows/docker-publish.yaml +++ /dev/null @@ -1,76 +0,0 @@ -name: Build and Publish Docker - -on: - workflow_dispatch: - workflow_call: - -env: - REGISTRY: ghcr.io - # Will resolve to huff-language/huff-neo-rs - IMAGE_NAME: ${{ github.repository }} - IS_NIGHTLY: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} - - -jobs: - build: - - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Checkout sources - uses: actions/checkout@v2 - with: - ref: 'main' - - # Login against a Docker registry except on PR - # https://github.com/docker/login-action - - name: Log into registry ${{ env.REGISTRY }} - uses: docker/login-action@v1.14.1 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - # Extract metadata (tags, labels) for Docker - # https://github.com/docker/metadata-action - - name: Extract Docker metadata - id: meta - uses: docker/metadata-action@v3.6.2 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - # Creates an additional 'latest' or 'nightly' tag - # If the job is triggered via cron schedule, tag nightly and nightly-{SHA} - # If the job is triggered via workflow dispatch and on a master branch, tag branch and latest - # Otherwise, just tag as the branch name - - name: Finalize Docker Metadata - id: docker_tagging - run: | - if [[ "${{ github.event_name }}" == 'schedule' ]]; then - echo "cron trigger, assigning nightly tag" - echo "::set-output name=docker_tags::${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly-${GITHUB_SHA}" - elif [[ "${GITHUB_REF##*/}" == "main" ]] || [[ ${GITHUB_REF##*/} == "master" ]]; then - echo "manual trigger from master/main branch, assigning latest tag" - echo "::set-output name=docker_tags::${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" - else - echo "Neither scheduled nor manual release from main branch. Just tagging as branch name" - echo "::set-output name=docker_tags::${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/}" - fi - # Log docker metadata to explicitly know what is being pushed - - name: Inspect Docker Metadata - run: | - echo "TAGS -> ${{ steps.docker_tagging.outputs.docker_tags }}" - echo "LABELS -> ${{ steps.meta.outputs.labels }}" - # Build and push Docker image - # https://github.com/docker/build-push-action - - name: Build and push Docker image - id: build-and-push - uses: docker/build-push-action@v2.10.0 - with: - context: . - push: true - tags: ${{ steps.docker_tagging.outputs.docker_tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 1bf11cb..744264c 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,5 +1,5 @@ -name: Release version - +name: release +# Modified from: https://github.com/foundry-rs/foundry/blob/master/.github/workflows/release.yml on: push: tags: @@ -9,193 +9,221 @@ on: workflow_dispatch: env: + CARGO_TERM_COLOR: always IS_NIGHTLY: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} + PROFILE: maxperf jobs: prepare: name: Prepare release runs-on: ubuntu-latest - + timeout-minutes: 30 outputs: tag_name: ${{ steps.release_info.outputs.tag_name }} release_name: ${{ steps.release_info.outputs.release_name }} changelog: ${{ steps.build_changelog.outputs.changelog }} - steps: - - name: Checkout sources - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: - ref: 'main' fetch-depth: 0 - name: Compute release name and tag id: release_info run: | - if [[ $IS_NIGHTLY ]]; then - echo "::set-output name=tag_name::nightly-${GITHUB_SHA}" - echo "::set-output name=release_name::Nightly ($(date '+%Y-%m-%d'))" + if [[ ${IS_NIGHTLY} == 'true' ]]; then + echo "tag_name=nightly-${GITHUB_SHA}" >> $GITHUB_OUTPUT + echo "release_name=Nightly ($(date '+%Y-%m-%d'))" >> $GITHUB_OUTPUT else - echo "::set-output name=tag_name::${GITHUB_REF_NAME}" - echo "::set-output name=release_name::${GITHUB_REF_NAME}" + echo "tag_name=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT + echo "release_name=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT fi + # Creates a `nightly-SHA` tag for this specific nightly # This tag is used for this specific nightly version's release # which allows users to roll back. It is also used to build # the changelog. - name: Create build-specific nightly tag - if: ${{ env.IS_NIGHTLY }} - uses: actions/github-script@v5 + if: ${{ env.IS_NIGHTLY == 'true' }} + uses: actions/github-script@v7 env: TAG_NAME: ${{ steps.release_info.outputs.tag_name }} with: script: | const createTag = require('./.github/scripts/create-tag.js') await createTag({ github, context }, process.env.TAG_NAME) + - name: Build changelog id: build_changelog - uses: mikepenz/release-changelog-builder-action@v2 + uses: mikepenz/release-changelog-builder-action@v4 with: configuration: "./.github/changelog.json" - fromTag: ${{ env.IS_NIGHTLY && 'nightly' || '' }} + fromTag: ${{ env.IS_NIGHTLY == 'true' && 'nightly' || '' }} toTag: ${{ steps.release_info.outputs.tag_name }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} #release-docker: # name: Release Docker - # uses: ./.github/workflows/docker-publish.yaml + # uses: ./.github/workflows/docker-publish.yml release: - name: ${{ matrix.job.target }} (${{ matrix.job.os }}) - runs-on: ${{ matrix.job.os }} + permissions: + id-token: write + contents: write + attestations: write + name: ${{ matrix.target }} (${{ matrix.runner }}) + runs-on: ${{ matrix.runner }} + timeout-minutes: 240 needs: prepare strategy: + fail-fast: false matrix: - job: - # The OS is used for the runner - # The platform is a generic platform name - # The target is used by Cargo - # The arch is either 386, arm64 or amd64 - # The svm target platform to use for the binary https://github.com/roynalnaruto/svm-rs/blob/84cbe0ac705becabdc13168bae28a45ad2299749/svm-builds/build.rs#L4-L24 - - os: ubuntu-20.04 - platform: linux + include: + # `runner`: GHA runner label + # `target`: Rust build target triple + # `platform` and `arch`: Used in tarball names + # `svm`: target platform to use for the Solc binary: https://github.com/roynalnaruto/svm-rs/blob/84cbe0ac705becabdc13168bae28a45ad2299749/svm-builds/build.rs#L4-L24 + - runner: Linux-20.04 target: x86_64-unknown-linux-gnu - arch: amd64 svm_target_platform: linux-amd64 - - os: ubuntu-20.04 platform: linux + arch: amd64 + - runner: Linux-20.04 target: aarch64-unknown-linux-gnu - arch: arm64 svm_target_platform: linux-aarch64 - - os: macos-latest - platform: darwin + platform: linux + arch: arm64 + - runner: macos-12-large target: x86_64-apple-darwin - arch: amd64 svm_target_platform: macosx-amd64 - - os: macos-latest platform: darwin + arch: amd64 + - runner: macos-latest-large target: aarch64-apple-darwin - arch: arm64 svm_target_platform: macosx-aarch64 - #- os: windows-latest - # platform: win32 + platform: darwin + arch: arm64 + #- runner: Windows # target: x86_64-pc-windows-msvc + # svm_target_platform: windows-amd64 + # platform: win32 # arch: amd64 - # svm_target_platform: macosx-amd64 - steps: - - name: Checkout sources - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable with: - ref: 'main' - - - name: Install toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - target: ${{ matrix.job.target }} - override: true - + targets: ${{ matrix.target }} - uses: Swatinem/rust-cache@v2 with: + key: ${{ matrix.target }} cache-on-failure: true - name: Apple M1 setup - if: ${{ matrix.job.target == 'aarch64-apple-darwin' }} + if: matrix.target == 'aarch64-apple-darwin' run: | echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV + - name: Linux ARM setup - if: ${{ matrix.job.target == 'aarch64-unknown-linux-gnu' }} + if: matrix.target == 'aarch64-unknown-linux-gnu' run: | sudo apt-get update -y sudo apt-get install -y gcc-aarch64-linux-gnu echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV + - name: Build binaries - uses: actions-rs/cargo@v1 env: - SVM_TARGET_PLATFORM: ${{ matrix.job.svm_target_platform }} - with: - command: build - args: --release --bins --target ${{ matrix.job.target }} + SVM_TARGET_PLATFORM: ${{ matrix.svm_target_platform }} + PLATFORM_NAME: ${{ matrix.platform }} + TARGET: ${{ matrix.target }} + OUT_DIR: target/${{ matrix.target }}/${{ env.PROFILE }} + shell: bash + run: | + set -eo pipefail + flags=(--target $TARGET --profile $PROFILE --bins + --no-default-features --features rustls,aws-kms,cli,asm-keccak) + + # `jemalloc` is not fully supported on MSVC or aarch64 Linux. + if [[ "$TARGET" != *msvc* && "$TARGET" != "aarch64-unknown-linux-gnu" ]]; then + flags+=(--features jemalloc) + fi + + [[ "$TARGET" == *windows* ]] && ext=".exe" + + cargo build "${flags[@]}" + + bins=(hnc) + for name in "${bins[@]}"; do + bin=$OUT_DIR/$name$ext + echo "" + file "$bin" || true + du -h "$bin" || true + ldd "$bin" || true + $bin --version || true + echo "${name}_bin_path=${bin}" >> $GITHUB_ENV + done - name: Archive binaries id: artifacts env: - PLATFORM_NAME: ${{ matrix.job.platform }} - TARGET: ${{ matrix.job.target }} - ARCH: ${{ matrix.job.arch }} - VERSION_NAME: ${{ (env.IS_NIGHTLY && 'nightly') || needs.prepare.outputs.tag_name }} + PLATFORM_NAME: ${{ matrix.platform }} + OUT_DIR: target/${{ matrix.target }}/${{ env.PROFILE }} + VERSION_NAME: ${{ (env.IS_NIGHTLY == 'true' && 'nightly') || needs.prepare.outputs.tag_name }} + ARCH: ${{ matrix.arch }} + shell: bash run: | if [ "$PLATFORM_NAME" == "linux" ]; then - tar -czvf "huff_neo_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz" -C ./target/${TARGET}/release huff-neo - echo "::set-output name=file_name::huff_neo_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz" + tar -czvf "huff_neo_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz" -C $OUT_DIR hnc + echo "file_name=huff_neo_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz" >> $GITHUB_OUTPUT elif [ "$PLATFORM_NAME" == "darwin" ]; then # We need to use gtar here otherwise the archive is corrupt. # See: https://github.com/actions/virtual-environments/issues/2619 - gtar -czvf "huff_neo_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz" -C ./target/${TARGET}/release huff-neo - echo "::set-output name=file_name::huff_neo_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz" + gtar -czvf "huff_neo_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz" -C $OUT_DIR hnc + echo "file_name=huff_neo_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz" >> $GITHUB_OUTPUT else - cd ./target/${TARGET}/release - 7z a -tzip "huff_neo_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.zip" huff.exe + cd $OUT_DIR + 7z a -tzip "huff_neo_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.zip" hnc.exe mv "huff_neo_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.zip" ../../../ - echo "::set-output name=file_name::huff_neo_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.zip" + echo "file_name=huff_neo_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.zip" >> $GITHUB_OUTPUT fi - shell: bash - name: Build man page id: man - if: ${{ matrix.job.target == 'x86_64-unknown-linux-gnu' }} + if: matrix.target == 'x86_64-unknown-linux-gnu' env: - PLATFORM_NAME: ${{ matrix.job.platform }} - TARGET: ${{ matrix.job.target }} - VERSION_NAME: ${{ (env.IS_NIGHTLY && 'nightly') || needs.prepare.outputs.tag_name }} + OUT_DIR: target/${{ matrix.target }}/${{ env.PROFILE }} + VERSION_NAME: ${{ (env.IS_NIGHTLY == 'true' && 'nightly') || needs.prepare.outputs.tag_name }} + shell: bash run: | sudo apt-get -y install help2man - help2man -N ./target/${TARGET}/release/huff-neo > huff-neo.1 - gzip huff-neo.1 - tar -czvf "huff_neo_man_${VERSION_NAME}.tar.gz" huff-neo.1.gz - echo "::set-output name=huff_neo_man::huff_neo_man_${VERSION_NAME}.tar.gz" - shell: bash + help2man -N $OUT_DIR/hnc > hnc.1 + gzip hnc.1 + tar -czvf "hnc_man_${VERSION_NAME}.tar.gz" hnc.1.gz + echo "hnc_man=hnc_man_${VERSION_NAME}.tar.gz" >> $GITHUB_OUTPUT # Creates the release for this specific version - name: Create release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: name: ${{ needs.prepare.outputs.release_name }} tag_name: ${{ needs.prepare.outputs.tag_name }} - prerelease: ${{ env.IS_NIGHTLY }} + prerelease: ${{ env.IS_NIGHTLY == 'true' }} body: ${{ needs.prepare.outputs.changelog }} files: | ${{ steps.artifacts.outputs.file_name }} - ${{ steps.man.outputs.huff_neo_man }} + ${{ steps.man.outputs.hnc_man }} + + - name: Binaries attestation + uses: actions/attest-build-provenance@v2 + with: + subject-path: | + ${{ env.hnc_bin_path }} # If this is a nightly release, it also updates the release - # tagged `nightly` for compatability with `huff-neo-up` + # tagged `nightly` for compatibility with `hnc-up` - name: Update nightly release - if: ${{ env.IS_NIGHTLY }} - uses: softprops/action-gh-release@v1 + if: ${{ env.IS_NIGHTLY == 'true' }} + uses: softprops/action-gh-release@v2 with: name: "Nightly" tag_name: "nightly" @@ -203,30 +231,28 @@ jobs: body: ${{ needs.prepare.outputs.changelog }} files: | ${{ steps.artifacts.outputs.file_name }} - ${{ steps.man.outputs.huff_neo_man }} + ${{ steps.man.outputs.hnc_man }} cleanup: name: Release cleanup runs-on: ubuntu-latest + timeout-minutes: 30 needs: release - + if: always() steps: - - name: Checkout sources - uses: actions/checkout@v2 - with: - ref: 'main' + - uses: actions/checkout@v4 # Moves the `nightly` tag to `HEAD` - name: Move nightly tag - if: ${{ env.IS_NIGHTLY }} - uses: actions/github-script@v5 + if: ${{ env.IS_NIGHTLY == 'true' }} + uses: actions/github-script@v7 with: script: | const moveTag = require('./.github/scripts/move-tag.js') await moveTag({ github, context }, 'nightly') - name: Delete old nightlies - uses: actions/github-script@v5 + uses: actions/github-script@v7 with: script: | const prunePrereleases = require('./.github/scripts/prune-prereleases.js') diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f1684a1 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ + + +# Node cache changelog + +## [Unreleased] + +## [0.0.3] - 2025-01-09 +- Initial release of `huff-neo` \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 7ff5ac4..43ce945 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,6 +183,15 @@ dependencies = [ "serde", ] +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anes" version = "0.1.6" @@ -515,6 +524,8 @@ version = "1.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a012a0df96dd6d06ba9a1b29d6402d1a5d77c6befd2566afdc26e10603dc93d7" dependencies = [ + "jobserver", + "libc", "shlex", ] @@ -628,6 +639,38 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "const_fn" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f8a2ca5ac02d09563609681103aada9e1777d54fc57a5acd7a41404f9c93b6e" + +[[package]] +name = "const_format" +version = "0.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126f97965c8ad46d6d9163268ff28432e8f6a1196a55578867832e3049df63dd" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d57c2eccfb16dbac1f4e61e206105db5820c9d26c3c472bc17c774259ef7744" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "cpufeatures" version = "0.2.16" @@ -758,6 +801,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + [[package]] name = "derivative" version = "2.2.0" @@ -811,6 +863,17 @@ dependencies = [ "subtle", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.95", +] + [[package]] name = "dunce" version = "1.0.5" @@ -951,6 +1014,15 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f" +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + [[package]] name = "funty" version = "2.0.0" @@ -981,6 +1053,19 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "git2" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b903b73e45dc0c6c596f2d37eccece7c1c8bb6e4407b001096387c63d0d93724" +dependencies = [ + "bitflags", + "libc", + "libgit2-sys", + "log", + "url", +] + [[package]] name = "glob" version = "0.3.2" @@ -1055,8 +1140,8 @@ dependencies = [ ] [[package]] -name = "huff-neo-cli" -version = "0.0.2" +name = "hnc" +version = "0.0.3" dependencies = [ "alloy-primitives", "clap", @@ -1065,6 +1150,7 @@ dependencies = [ "huff-neo-core", "huff-neo-tests", "huff-neo-utils", + "shadow-rs", "tracing", "uuid", "yansi", @@ -1072,11 +1158,10 @@ dependencies = [ [[package]] name = "huff-neo-codegen" -version = "0.0.2" +version = "0.0.3" dependencies = [ "alloy-dyn-abi", "alloy-primitives", - "hex", "huff-neo-utils", "regex", "serde_json", @@ -1086,7 +1171,7 @@ dependencies = [ [[package]] name = "huff-neo-core" -version = "0.0.2" +version = "0.0.3" dependencies = [ "alloy-dyn-abi", "alloy-primitives", @@ -1107,19 +1192,18 @@ dependencies = [ [[package]] name = "huff-neo-js" -version = "0.0.2" +version = "0.0.3" dependencies = [ "huff-neo-core", "huff-neo-utils", "serde", "serde-wasm-bindgen", - "serde_json", "wasm-bindgen", ] [[package]] name = "huff-neo-lexer" -version = "0.0.2" +version = "0.0.3" dependencies = [ "huff-neo-utils", "lazy_static", @@ -1129,8 +1213,9 @@ dependencies = [ [[package]] name = "huff-neo-parser" -version = "0.0.2" +version = "0.0.3" dependencies = [ + "alloy-primitives", "hex", "huff-neo-lexer", "huff-neo-utils", @@ -1140,7 +1225,7 @@ dependencies = [ [[package]] name = "huff-neo-tests" -version = "0.0.2" +version = "0.0.3" dependencies = [ "alloy-primitives", "comfy-table", @@ -1158,7 +1243,7 @@ dependencies = [ [[package]] name = "huff-neo-utils" -version = "0.0.2" +version = "0.0.3" dependencies = [ "alloy-dyn-abi", "alloy-primitives", @@ -1172,13 +1257,174 @@ dependencies = [ "serde_json", "strum", "strum_macros", - "tiny-keccak", "toml", "tracing", "tracing-subscriber", "uuid", ] +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.95", +] + +[[package]] +name = "idna" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + [[package]] name = "impl-codec" version = "0.6.0" @@ -1221,6 +1467,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "is_debug" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8ea828c9d6638a5bd3d8b14e37502b4d56cae910ccf8a5b7f51c7a0eb1d0508" + [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -1251,6 +1503,15 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.76" @@ -1308,18 +1569,48 @@ version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" +[[package]] +name = "libgit2-sys" +version = "0.17.0+1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10472326a8a6477c3c20a64547b0059e4b0d086869eee31e6d7da728a8eb7224" +dependencies = [ + "cc", + "libc", + "libz-sys", + "pkg-config", +] + [[package]] name = "libm" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" +[[package]] +name = "libz-sys" +version = "1.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9b68e50e6e0b26f672573834882eb57759f6db9b3be2ea3c35c91188bb4eaa" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linux-raw-sys" version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" +[[package]] +name = "litemap" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" + [[package]] name = "lock_api" version = "0.4.12" @@ -1384,6 +1675,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.46" @@ -1435,6 +1732,15 @@ dependencies = [ "libc", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "once_cell" version = "1.20.2" @@ -1502,6 +1808,12 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + [[package]] name = "pest" version = "2.7.15" @@ -1571,6 +1883,12 @@ dependencies = [ "spki", ] +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + [[package]] name = "plotters" version = "0.3.7" @@ -1599,6 +1917,12 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.20" @@ -2161,6 +2485,19 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "shadow-rs" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "974eb8222c62a8588bc0f02794dd1ba5b60b3ec88b58e050729d0907ed6af610" +dependencies = [ + "const_format", + "git2", + "is_debug", + "time", + "tzdb", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -2214,6 +2551,12 @@ dependencies = [ "der", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions" version = "1.1.0" @@ -2298,6 +2641,17 @@ dependencies = [ "syn 2.0.95", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.95", +] + [[package]] name = "tap" version = "1.0.1" @@ -2357,6 +2711,39 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "time" +version = "0.3.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" +dependencies = [ + "deranged", + "itoa", + "libc", + "num-conv", + "num_threads", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -2366,6 +2753,16 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinytemplate" version = "1.2.1" @@ -2462,6 +2859,35 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "tz-rs" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33851b15c848fad2cf4b105c6bb66eb9512b6f6c44a4b13f57c53c73c707e2b4" +dependencies = [ + "const_fn", +] + +[[package]] +name = "tzdb" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b580f6b365fa89f5767cdb619a55d534d04a4e14c2d7e5b9a31e94598687fb1" +dependencies = [ + "iana-time-zone", + "tz-rs", + "tzdb_data", +] + +[[package]] +name = "tzdb_data" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "654c1ec546942ce0594e8d220e6b8e3899e0a0a8fe70ddd54d32a376dfefe3f8" +dependencies = [ + "tz-rs", +] + [[package]] name = "ucd-trie" version = "0.1.7" @@ -2504,6 +2930,29 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" +[[package]] +name = "url" +version = "2.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "utf8parse" version = "0.2.2" @@ -2525,6 +2974,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.5" @@ -2651,6 +3106,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.52.0" @@ -2742,6 +3206,18 @@ dependencies = [ "memchr", ] +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + [[package]] name = "wyz" version = "0.5.1" @@ -2757,6 +3233,30 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.95", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.7.35" @@ -2778,6 +3278,27 @@ dependencies = [ "syn 2.0.95", ] +[[package]] +name = "zerofrom" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.95", + "synstructure", +] + [[package]] name = "zeroize" version = "1.8.1" @@ -2797,3 +3318,25 @@ dependencies = [ "quote", "syn 2.0.95", ] + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.95", +] diff --git a/Cargo.toml b/Cargo.toml index 35e549c..3a4f5a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,73 +1,65 @@ [workspace] -members = [ - "crates/core", - "crates/codegen", - "crates/lexer", - "crates/utils", - "bin/huff-neo", - "crates/parser", - "crates/js", - "crates/tests" -] -exclude = [ "assets", "huff-neo-up", "huff-examples" ] -default-members = ["bin/huff-neo"] +default-members = ["bin/hnc"] +exclude = ["assets", "hnc-up", "huff-examples"] +members = ["bin/hnc", "crates/codegen", "crates/core", "crates/js", "crates/lexer", "crates/parser", "crates/tests", "crates/utils"] resolver = "2" [workspace.package] -version = "0.0.2" edition = "2021" +license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/cakevm/huff-neo" -license = "MIT OR Apache-2.0" +version = "0.0.3" [workspace.dependencies] -huff-neo-core = { path = "crates/core" } huff-neo-codegen = { path = "crates/codegen" } +huff-neo-core = { path = "crates/core" } huff-neo-lexer = { path = "crates/lexer" } huff-neo-parser = { path = "crates/parser" } -huff-neo-utils = { path = "crates/utils" } huff-neo-tests = { path = "crates/tests" } -huff-neo-js = { path = "crates/js" } - +huff-neo-utils = { path = "crates/utils" } +alloy-dyn-abi = "0.8.18" +alloy-primitives = "0.8.18" +cfg-if = "1.0.0" clap = { version = "4.5.23", features = ["derive"] } -comfy-table = "7.1" -tracing = "0.1.34" -yansi = "1.0.1" -uuid = { version = "1.1.1", features = ["v4"] } -serde_json = "1.0.81" +comfy-table = "7.1.3" hex = "0.4.3" -regex = "1.6.0" -tracing-subscriber = { version = "0.3", default-features = false, features = ["env-filter", "fmt"] } -walkdir = "2" -cfg-if = "1" +itertools = "0.14.0" +js-sys = { version = "0.3.76" } +lazy_static = "1.5.0" +phf = { version = "0.11.1", features = ["macros"] } +rand = "0.8.5" +regex = "1.11.1" +revm = "19.1.0" +shadow-rs = "0.37.0" +tracing = "0.1.41" +tracing-subscriber = { version = "0.3.19", default-features = false, features = ["env-filter", "fmt"] } +uuid = { version = "1.11.0", features = ["v4"] } +walkdir = "2.5.0" +wasm-bindgen = "0.2" +yansi = "1.0.1" + +# serde serde = { version = "1.0", features = ["derive", "rc"] } serde-wasm-bindgen = "0.6.5" -wasm-bindgen = "0.2" -revm = "19.1.0" -phf = { version = "0.11.1", features = ["macros"] } +serde_json = "1.0.131" strum = "0.26.3" strum_macros = "0.26.4" -lazy_static = "1" -itertools = "0.14.0" -tiny-keccak = { version = "2.0.2", features = ["keccak"] } toml = "0.8.19" -js-sys = { version = "0.3" } -alloy-primitives = "0.8" -alloy-dyn-abi = "0.8" -rand = "0.8.5" -#dev -rayon = "1.5.3" +# dev criterion = "0.5.1" +getrandom = { version = "0.2.15", features = ["js"] } +rayon = "1.10.0" [profile.test] debug = 1 incremental = true [profile.release] -debug = "line-tables-only" codegen-units = 32 +debug = "line-tables-only" lto = "thin" opt-level = 3 panic = "unwind" diff --git a/README.md b/README.md index 440401a..f0903dd 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ -# huff-neo +# Huff Neo Compiler -`huff-neo` marks a new dawn for the once-abandoned [huff-rs](https://github.com/huff-language/huff-rs), breathing fresh life into its legacy. This is a hard-fork with update dependencies and brings the project up-to-date with the latest Rust version and dependencies. +The Huff Neo Compiler (`hnc`) marks a new dawn for the once-abandoned [huff-rs](https://github.com/huff-language/huff-rs), breathing fresh life into its legacy. This is a hard-fork with update dependencies and brings the project up-to-date with the latest Rust version and dependencies. ## What is a Huff? @@ -24,33 +24,33 @@ We are very happy that someone picked up the work. In the meantime we still need ## Installation -Choose one of the following methods to install `huff-neo`: +Choose one of the following methods to install the Huff Neo Compiler: -**Option 1:** Install the latest version with cargo: +**Option 1:** You can use the installer `hnc-up` to install the latest version of `hnc` from a release or nightly build: ```bash -cargo install --git https://github.com/cakevm/huff-neo +curl -L https://raw.githubusercontent.com/cakevm/huff-neo/refs/heads/main/hnc-up/install | bash ``` -**Option 2:** You can use the installer `huff-neo-up` to install the latest version of `huff-neo` from a release or nightly build: +**Option 2:** Build it by cloning the repository and running the following command: ```bash -curl -L https://raw.githubusercontent.com/cakevm/huff-neo/refs/heads/main/huff-neo-up/install | bash +make release ``` -**Option 3:** Build it by cloning the repository and running the following command: +**Option 3:** Install the latest version with cargo: ```bash -make release +cargo install --git https://github.com/cakevm/huff-neo --locked ``` ## Modules - [core](crates/core): The core module to huff-neo-rs. Resolves source file paths, executes compilation, and exports artifacts. -- [cli](bin/huff-neo): The command line interface for the Huff compiler. +- [cli](bin/hnc): The command line interface for the Huff compiler. - [js](crates/js): A wasm compatible interface to the Huff compiler for JavaScript bindings. - [lexer](crates/lexer): Takes in the source of a `.huff` file and generates a vector of `Token`s. - [parser](crates/parser): Crafts a `Contract` AST from the vector of `Token`s generated by [huff-lexer](crates/lexer). - [codegen](crates/codegen): EVM Bytecode generation module that accepts an AST generated by [huff-parser](crates/parser). - [utils](crates/utils): Various utilities and types used by all modules. -- [huff-neo-up](./huff-neo-up): Update or revert to a specific huff-neo-rs branch with ease. (Forked from [foundry](https://github.com/foundry-rs/foundry)) +- [hnc-up](./hnc-up): Update or revert to a specific huff-neo-rs branch with ease. (Forked from [foundry](https://github.com/foundry-rs/foundry)) ## Contributing diff --git a/bin/huff-neo/Cargo.toml b/bin/hnc/Cargo.toml similarity index 83% rename from bin/huff-neo/Cargo.toml rename to bin/hnc/Cargo.toml index 4575a87..aeedafb 100644 --- a/bin/huff-neo/Cargo.toml +++ b/bin/hnc/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "huff-neo-cli" +name = "hnc" version.workspace = true edition.workspace = true readme.workspace = true @@ -9,6 +9,7 @@ description = """ Huff Language Compiler built in Pure Rust. """ keywords = ["bytecode", "compiler", "evm", "huff", "rust"] +build = "build.rs" [dependencies] huff-neo-codegen.workspace = true @@ -19,11 +20,15 @@ huff-neo-utils.workspace = true alloy-primitives.workspace = true clap.workspace = true comfy-table.workspace = true +shadow-rs.workspace = true tracing.workspace = true uuid.workspace = true yansi.workspace = true +[build-dependencies] +shadow-rs.workspace = true + [[bin]] doc = false -name = "huff-neo" +name = "hnc" path = "src/main.rs" diff --git a/bin/hnc/README.md b/bin/hnc/README.md new file mode 100644 index 0000000..587327d --- /dev/null +++ b/bin/hnc/README.md @@ -0,0 +1,124 @@ +# Huff Neo Compiler + +The `hnc` CLI (short for Huff Neo Compiler) allows for compiling Huff contracts to EVM bytecode. + +## Usage + +To run `hnc` from the command line, you can simply run: + +```bash +hnc --help +``` + +By default, hnc will attempt to compile all contracts in the `contracts` directory. If there is no `contracts` directory present, the following will spit out an error like so: + +```bash,color=red +~ hnc + +Error: Invalid File Directory ./contracts + +``` + +#### Examples using [`huff-examples`](https://github.com/huff-language/huff-examples) + +The [huff-examples](https://github.com/huff-language/huff-examples) github repository is added as a submodule to this repo for testing. + +To run `hnc` against one of the examples, the path may simply be passed to `hnc`. + +For example, to compile huff-example's [ERC20.huff](../../huff-examples/erc20/contracts/ERC20.huff) contract, run: + +```bash +hnc --bytecode ./huff-examples/erc20/contracts/ERC20.huff +``` + +_NOTE: The `--bytecode` flag will output the full deploy bytecode._ + +`hnc` also supports tracing using the [`tracing`](https://docs.rs/tracing/0.1.29/tracing/) crate. To produce a verbose output using tracing, append the `--verbose` or `-v` flag like so: + +```bash +hnc --verbose --bytecode ./huff-examples/erc20/contracts/ERC20.huff +``` + +#### Specifying Artifact Outputs + +**By default**, `hnc` will export json build artifacts to a `./artifacts` directory. This can be overidden using the `--output-directory` flag or shorthand `-d` flag and specifying a string following. For example: + +```bash +hnc -d ./output ./huff-examples/erc20/contracts/ERC20.huff +``` + +_NOTE: The huff cli will gracefully remove double and single quotes, so the following will also compile:_ + +```bash +hnc -d "./output" './huff-examples/erc20/contracts/ERC20.huff' +``` + +If a specific contract is specified for compiling (ie not a directory), a single `json` file may be specified as an output location for the contract artifact like so: + +```bash +hnc -o ./artifact.json ./huff-examples/erc20/contracts/ERC20.huff +``` + +**NOTE**: The following will _not_ compile since multiple artifacts cannot be output to the same artifact json file. + +```bash +hnc -o ./artifact.json ./contracts/ +``` + +#### Entering Constructor Arguments + +`hnc` supports passing in constructor arguments to the contract. This is done by passing in the `--interactive` (shorthand: `-n`) flag or passing the `--inputs` (shorthand: `-i`) flag. + +and passing in the arguments as a comma separated list. + +For example, to compile a contract (let's call it `example.huff`) with the following constructor definition: + +```huff +#define macro CONSTRUCTOR(uint256, address) = takes(0) returns (0) { + 0x04 calldataload + 0x00 sstore + 0x24 calldataload + 0x01 sstore +} +``` + +You can enter the arguments `(100, 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef)` interactively by passing in the `-n` or `--interactive` flag like so: + +```bash +$ hnc -b -n ./contracts/example.huff +[INTERACTIVE] Constructor Arguments for Contract: "./contracts/example.huff" +[INTERACTIVE] Enter a uint256 for constructor param: 100 +[INTERACTIVE] Enter a address for constructor param: 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef + +335f.....f30000000000000000000000000000000000000000000000000000000000000064000000000000000000000000deadbeefdeadbeefdeadbeefdeadbeefdeadbeef +``` + +Alternatively, you can enter the arguments as a comma separated list by using the `-i` or `--inputs` flag like so: + +```bash +$ hnc -b -i 100, 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef ./contracts/example.huff +335f0.....f30000000000000000000000000000000000000000000000000000000000000064000000000000000000000000deadbeefdeadbeefdeadbeefdeadbeefdeadbeef +``` + +#### Other Options + +- `-v` or `--verbose`: Outputs detailed logs to the terminal using the [tracing](https://crates.io/crates/tracing) crate. +- `-V` or `--version`: Prints the version of `hnc`. +- `-z` or `--optimize`: Optimizes the contract compilation - a work in progress. +- `-g` or `--interface`: Generates a solidity interface for the contract. + +## Building hnc from source + +To run `hnc` from the command line, you can use the following command: + +```bash +cargo run --bin hnc +``` + +To pass arguments into the `hnc` binary, simply pass them in after a `--` flag. For example, to get the `hnc` version (a `-V` flag), you can run: + +```bash +cargo run --bin hnc -- -V +``` + +All commands specified in [Usage](#usage) are also available from source by passing them in after the `--` flag. diff --git a/bin/hnc/build.rs b/bin/hnc/build.rs new file mode 100644 index 0000000..44fad00 --- /dev/null +++ b/bin/hnc/build.rs @@ -0,0 +1,5 @@ +use shadow_rs::ShadowBuilder; + +fn main() { + ShadowBuilder::builder().build().unwrap(); +} diff --git a/bin/huff-neo/src/arguments.rs b/bin/hnc/src/arguments.rs similarity index 97% rename from bin/huff-neo/src/arguments.rs rename to bin/hnc/src/arguments.rs index 3f30480..a35cce9 100644 --- a/bin/huff-neo/src/arguments.rs +++ b/bin/hnc/src/arguments.rs @@ -7,7 +7,7 @@ use yansi::Paint; /// The Huff CLI Args #[derive(Parser, Debug, Clone)] -#[clap(name = "huff-neo", version, about, long_about = None)] +#[clap(name = "hnc", version, about, long_about = None)] pub struct HuffArgs { /// The contract(s) to compile. pub path: Option, @@ -83,6 +83,10 @@ pub struct HuffArgs { /// Test subcommand #[clap(subcommand)] pub test: Option, + + /// Print version + #[arg(long)] + pub version_long: bool, } #[derive(Subcommand, Clone, Debug)] diff --git a/bin/huff-neo/src/main.rs b/bin/hnc/src/main.rs similarity index 97% rename from bin/huff-neo/src/main.rs rename to bin/hnc/src/main.rs index 0d9c593..9b43ae9 100644 --- a/bin/huff-neo/src/main.rs +++ b/bin/hnc/src/main.rs @@ -25,16 +25,25 @@ use huff_neo_utils::prelude::{ export_interfaces, gen_sol_interfaces, str_to_bytes32, AstSpan, BytecodeRes, CodegenError, CodegenErrorKind, CompilerError, EVMVersion, Literal, Span, }; +use shadow_rs::shadow; use std::process::exit; use std::{collections::BTreeMap, rc::Rc, sync::Arc, time::Instant}; use yansi::Paint; +shadow!(build); + fn main() { let mut command = HuffArgs::command(); // Parse the command line arguments let mut cli = HuffArgs::parse(); + if cli.version_long { + let git_clean = if build::GIT_CLEAN { "" } else { "-dirty" }; + println!("hnc {} ({}{})", build::PKG_VERSION, build::SHORT_COMMIT, git_clean); + return; + } + // Initiate Tracing if Verbose if cli.verbose { Compiler::init_tracing_subscriber(Some(vec![tracing::Level::DEBUG.into()])); @@ -42,6 +51,7 @@ fn main() { // Check if no argument is provided if cli.path.is_none() { + println!("{}", Paint::red("No input file provided")); // Print help and exit command.print_help().unwrap(); return; diff --git a/bin/huff-neo/README.md b/bin/huff-neo/README.md deleted file mode 100644 index 4ef1849..0000000 --- a/bin/huff-neo/README.md +++ /dev/null @@ -1,198 +0,0 @@ -# Huff CLI - -The `huff-neo` CLI is written using [clap's](https://docs.rs/clap) [derive feature](https://docs.rs/clap/latest/clap/_derive/index.html). - -## huff-neo - -``` -huff-neo 0.0.1 -Huff Language Compiler built in Pure Rust. - -USAGE: - huff-nei [OPTIONS] [PATH] [SUBCOMMAND] - -ARGS: - The contract(s) to compile - -OPTIONS: - -a, --artifacts - Whether to generate artifacts or not - - -b, --bytecode - Generate and log bytecode - - -c, --constants ... - Override / set constants for the compilation environment - - -d, --output-directory - The output directory [default: ./artifacts] - - -e, --evm-version - Set the EVM version - - -g, --interface [...] - Generate solidity interface for a Huff artifact - - -h, --help - Print help information - - -i, --inputs ... - The input constructor arguments - - -l, --label-indices - Prints out the jump label PC indices for the specified contract - - -m, --alt-main - Compile a specific macro - - -n, --interactive - Interactively input the constructor args - - -o, --output - The output file path - - -p, --print - Prints out to the terminal - - -r, --bin-runtime - Generate and log runtime bytecode - - -s, --source-path - The contracts source path [default: ./contracts] - - -t, --alt-constructor - Compile a specific constructor macro - - -v, --verbose - Verbose output - - -V, --version - Print version information - - -z, --optimize - Optimize compilation [WIP] - -``` - -_NOTE: To generate the above output, run: `huff-neo --help`_ - -## Usage - -To run `huff-neo` from the command line, you can simply run: - -```bash -huff-neo --help -``` - -By default, huff-neo will attempt to compile all contracts in the `contracts` directory. If there is no `contracts` directory present, the following will spit out an error like so: - -```bash,color=red -~ huff-neo - -Error: Invalid File Directory ./contracts - -``` - -#### Examples using [`huff-examples`](https://github.com/huff-language/huff-examples) - -The [huff-examples](https://github.com/huff-language/huff-examples) github repository is added as a submodule to this repo for testing. - -To run `huff-neo` against one of the examples, the path may simply be passed to `huff-neo`. - -For example, to compile huff-example's [ERC20.huff](../../huff-examples/erc20/contracts/ERC20.huff) contract, run: - -```bash -huff-neo --bytecode ./huff-examples/erc20/contracts/ERC20.huff -``` - -_NOTE: The `--bytecode` flag will output the full deploy bytecode._ - -`huff-neo` also supports tracing using the [`tracing`](https://docs.rs/tracing/0.1.29/tracing/) crate. To produce a verbose output using tracing, append the `--verbose` or `-v` flag like so: - -```bash -huff-neo --verbose --bytecode ./huff-examples/erc20/contracts/ERC20.huff -``` - -#### Specifying Artifact Outputs - -**By default**, `huff-neo` will export json build artifacts to a `./artifacts` directory. This can be overidden using the `--output-directory` flag or shorthand `-d` flag and specifying a string following. For example: - -```bash -huff-neo -d ./output ./huff-examples/erc20/contracts/ERC20.huff -``` - -_NOTE: The huff cli will gracefully remove double and single quotes, so the following will also compile:_ - -```bash -huff-neo -d "./output" './huff-examples/erc20/contracts/ERC20.huff' -``` - -If a specific contract is specified for compiling (ie not a directory), a single `json` file may be specified as an output location for the contract artifact like so: - -```bash -huff-neo -o ./artifact.json ./huff-examples/erc20/contracts/ERC20.huff -``` - -**NOTE**: The following will _not_ compile since multiple artifacts cannot be output to the same artifact json file. - -```bash -huff-neo -o ./artifact.json ./contracts/ -``` - -#### Entering Constructor Arguments - -`huff-neo` supports passing in constructor arguments to the contract. This is done by passing in the `--interactive` (shorthand: `-n`) flag or passing the `--inputs` (shorthand: `-i`) flag. - -and passing in the arguments as a comma separated list. - -For example, to compile a contract (let's call it `example.huff`) with the following constructor definition: - -```huff -#define macro CONSTRUCTOR(uint256, address) = takes(0) returns (0) { - 0x04 calldataload - 0x00 sstore - 0x24 calldataload - 0x01 sstore -} -``` - -You can enter the arguments `(100, 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef)` interactively by passing in the `-n` or `--interactive` flag like so: - -```bash -$ huff-neo -b -n ./contracts/example.huff -[INTERACTIVE] Constructor Arguments for Contract: "./contracts/example.huff" -[INTERACTIVE] Enter a uint256 for constructor param: 100 -[INTERACTIVE] Enter a address for constructor param: 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef - -335f.....f30000000000000000000000000000000000000000000000000000000000000064000000000000000000000000deadbeefdeadbeefdeadbeefdeadbeefdeadbeef -``` - -Alternatively, you can enter the arguments as a comma separated list by using the `-i` or `--inputs` flag like so: - -```bash -$ huff-neo -b -i 100, 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef ./contracts/example.huff -335f0.....f30000000000000000000000000000000000000000000000000000000000000064000000000000000000000000deadbeefdeadbeefdeadbeefdeadbeefdeadbeef -``` - -#### Other Options - -- `-v` or `--verbose`: Outputs detailed logs to the terminal using the [tracing](https://crates.io/crates/tracing) crate. -- `-V` or `--version`: Prints the version of `huff-neo`. -- `-z` or `--optimize`: Optimizes the contract compilation - a work in progress. -- `-g` or `--interface`: Generates a solidity interface for the contract. - -## Building huff-neo from source - -To run `huff-neo` from the command line, you can use the following command: - -```bash -cargo run --bin huff-neo -``` - -To pass arguments into the `huff-neo` binary, simply pass them in after a `--` flag. For example, to get the `huff-neo` version (a `-V` flag), you can run: - -```bash -cargo run --bin huff-neo -- -V -``` - -All commands specified in [Usage](#usage) are also available from source by passing them in after the `--` flag. diff --git a/crates/codegen/Cargo.toml b/crates/codegen/Cargo.toml index c82d6a3..7c42d25 100644 --- a/crates/codegen/Cargo.toml +++ b/crates/codegen/Cargo.toml @@ -15,7 +15,6 @@ huff-neo-utils.workspace = true alloy-dyn-abi.workspace = true alloy-primitives.workspace = true -hex.workspace = true regex.workspace = true serde_json.workspace = true tracing.workspace = true diff --git a/crates/codegen/src/irgen/statements.rs b/crates/codegen/src/irgen/statements.rs index 365858b..ff71451 100644 --- a/crates/codegen/src/irgen/statements.rs +++ b/crates/codegen/src/irgen/statements.rs @@ -1,3 +1,4 @@ +use alloy_primitives::{hex, keccak256}; use huff_neo_utils::prelude::*; use crate::Codegen; @@ -287,10 +288,9 @@ pub fn statement_gen<'a>( *offset += push_bytes.len() / 2; bytes.push((starting_offset, Bytes(push_bytes))); } else if let Some(s) = &bf.args[0].name { - let mut signature = [0u8; 4]; // Only keep first 4 bytes - hash_bytes(&mut signature, s); + let function_selector: [u8; 4] = keccak256(s)[..4].try_into().unwrap(); - let push_bytes = format!("{}{}", Opcode::Push4, hex::encode(signature)); + let push_bytes = format!("{}{}", Opcode::Push4, hex::encode(function_selector)); *offset += push_bytes.len() / 2; bytes.push((starting_offset, Bytes(push_bytes))); } else { @@ -329,10 +329,9 @@ pub fn statement_gen<'a>( *offset += push_bytes.len() / 2; bytes.push((starting_offset, Bytes(push_bytes))); } else if let Some(s) = &bf.args[0].name { - let mut hash = [0u8; 32]; - hash_bytes(&mut hash, s); + let event_selector = keccak256(s).0; - let push_bytes = format!("{}{}", Opcode::Push32, hex::encode(hash)); + let push_bytes = format!("{}{}", Opcode::Push32, hex::encode(event_selector)); *offset += push_bytes.len() / 2; bytes.push((starting_offset, Bytes(push_bytes))); } else { @@ -372,10 +371,9 @@ pub fn statement_gen<'a>( *offset += push_bytes.len() / 2; bytes.push((starting_offset, Bytes(push_bytes))); } else if let Some(s) = &bf.args[0].name { - let mut signature = [0u8; 4]; // Only keep first 4 bytes - hash_bytes(&mut signature, s); + let function_selector: [u8; 4] = keccak256(s)[..4].try_into().unwrap(); - let push_bytes = format!("{}{}", Opcode::Push4, hex::encode(signature)); + let push_bytes = format!("{}{}", Opcode::Push4, hex::encode(function_selector)); *offset += push_bytes.len() / 2; bytes.push((starting_offset, Bytes(push_bytes))); } else { diff --git a/crates/codegen/src/lib.rs b/crates/codegen/src/lib.rs index 2589ebd..d46bd6e 100644 --- a/crates/codegen/src/lib.rs +++ b/crates/codegen/src/lib.rs @@ -3,6 +3,7 @@ #![warn(unused_extern_crates)] #![forbid(unsafe_code)] +use alloy_primitives::hex; use huff_neo_utils::file::file_source::FileSource; use huff_neo_utils::{ abi::*, diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index f68c897..1f770eb 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -32,7 +32,7 @@ rand.workspace = true rayon.workspace = true [target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] -getrandom = { version = "0.2", features = ["js"] } +getrandom.workspace = true [[bench]] harness = false diff --git a/crates/js/Cargo.toml b/crates/js/Cargo.toml index 0d304f8..8b3c515 100644 --- a/crates/js/Cargo.toml +++ b/crates/js/Cargo.toml @@ -19,5 +19,4 @@ huff-neo-utils.workspace = true serde.workspace = true serde-wasm-bindgen.workspace = true -serde_json.workspace = true wasm-bindgen.workspace = true diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index f7a87fe..0fcd18c 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -14,6 +14,7 @@ keywords = ["bytecode", "compiler", "evm", "huff", "rust"] huff-neo-lexer.workspace = true huff-neo-utils.workspace = true +alloy-primitives.workspace = true hex.workspace = true regex.workspace = true tracing.workspace = true diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index 05a1ef8..76bbe51 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -3,11 +3,12 @@ #![warn(unused_extern_crates)] #![forbid(unsafe_code)] +use alloy_primitives::keccak256; use huff_neo_utils::file::remapper; use huff_neo_utils::{ ast::*, error::*, - prelude::{bytes32_to_string, hash_bytes, str_to_bytes32, Span}, + prelude::{bytes32_to_string, str_to_bytes32, Span}, token::{Token, TokenKind}, types::*, }; @@ -303,11 +304,11 @@ impl Parser { // function outputs should be next let outputs = self.parse_args(true, true, false, false)?; - let mut signature = [0u8; 4]; // Only keep first 4 bytes let input_types = inputs.iter().map(|i| i.arg_type.as_ref().unwrap().clone()).collect::>(); - hash_bytes(&mut signature, &format!("{name}({})", input_types.join(","))); + let method_signature = format!("{name}({})", input_types.join(",")); + let selector = keccak256(method_signature)[..4].try_into().unwrap(); - Ok(FunctionDefinition { name, signature, inputs, fn_type, outputs, span: AstSpan(self.spans.clone()) }) + Ok(FunctionDefinition { name, signature: selector, inputs, fn_type, outputs, span: AstSpan(self.spans.clone()) }) } /// Parse an event. @@ -335,11 +336,11 @@ impl Parser { // Parse the event's parameters let parameters = self.parse_args(true, true, true, false)?; - let mut hash = [0u8; 32]; let input_types = parameters.iter().map(|i| i.arg_type.as_ref().unwrap().clone()).collect::>(); - hash_bytes(&mut hash, &format!("{name}({})", input_types.join(","))); + let event_signature = format!("{name}({})", input_types.join(",")); + let event_selector = keccak256(event_signature).0; - Ok(EventDefinition { name, parameters, span: AstSpan(self.spans.clone()), hash }) + Ok(EventDefinition { name, parameters, span: AstSpan(self.spans.clone()), hash: event_selector }) } /// Parse a constant. @@ -418,9 +419,9 @@ impl Parser { // Get arguments for signature let parameters = self.parse_args(true, true, false, false)?; - let mut selector = [0u8; 4]; // Only keep first 4 bytes let input_types = parameters.iter().map(|i| i.arg_type.as_ref().unwrap().clone()).collect::>(); - hash_bytes(&mut selector, &format!("{name}({})", input_types.join(","))); + let method_signature = format!("{name}({})", input_types.join(",")); + let selector = keccak256(method_signature)[..4].try_into().unwrap(); // Clone spans and set to nothing let new_spans = self.spans.clone(); diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index 685ab3c..5441fb5 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -22,7 +22,6 @@ serde.workspace = true serde_json.workspace = true strum.workspace = true strum_macros.workspace = true -tiny-keccak.workspace = true toml.workspace = true tracing.workspace = true tracing-subscriber.workspace = true diff --git a/crates/utils/src/bytes_util.rs b/crates/utils/src/bytes_util.rs index af04e2d..1e91105 100644 --- a/crates/utils/src/bytes_util.rs +++ b/crates/utils/src/bytes_util.rs @@ -1,6 +1,5 @@ use crate::{evm_version::EVMVersion, opcodes::Opcode}; use std::num::ParseIntError; -use tiny_keccak::{Hasher, Keccak}; /// Convert a string slice to a `[u8; 32]` /// Pads zeros to the left of significant bytes in the `[u8; 32]` slice. @@ -60,13 +59,6 @@ pub fn str_to_vec(s: &str) -> Result, std::num::ParseIntError> { bytes } -/// Hash a string with Keccak256 -pub fn hash_bytes(dest: &mut [u8], to_hash: &String) { - let mut hasher = Keccak::v256(); - hasher.update(to_hash.as_bytes()); - hasher.finalize(dest); -} - /// Converts a value literal to its smallest equivalent `PUSHX` bytecode pub fn literal_gen(evm_version: &EVMVersion, l: &[u8; 32]) -> String { let hex_literal: String = bytes32_to_string(l, false); diff --git a/deny.toml b/deny.toml index 129d532..5f998cd 100644 --- a/deny.toml +++ b/deny.toml @@ -5,6 +5,7 @@ allow = [ "BSD-3-Clause", "BSL-1.0", "MIT", + "MIT-0", "Unicode-3.0", "Unlicense", "Zlib", diff --git a/huff-neo-up/README.md b/hnc-up/README.md similarity index 73% rename from huff-neo-up/README.md rename to hnc-up/README.md index b42798a..60ded18 100644 --- a/huff-neo-up/README.md +++ b/hnc-up/README.md @@ -1,4 +1,4 @@ -# `huff-neo-up` +# `hnc-up` Update or revert to a specific Huff branch with ease. @@ -7,9 +7,9 @@ _Forked from [foundry](https://github.com/foundry-rs/foundry/tree/master/foundry ## Installing -`curl -L get.huff.sh | bash` (installs the `huff-neo-up` installer) +`curl -L get.huff.sh | bash` (installs the `hnc-up` installer) -Run `huff-neo-up` to install the latest version of `huff-neo`. +Run `hnc-up` to install the latest version of `huff-neo`. ## Usage @@ -17,49 +17,49 @@ Run `huff-neo-up` to install the latest version of `huff-neo`. To install the **nightly** version: ```sh -huff-neo-up +hnc-up ``` To install a specific **version** (in this case the `nightly` version): ```sh -huff-neo-up --version nightly +hnc-up --version nightly ``` To install a specific **branch** (in this case the `release/0.3.1` branch's latest commit): ```sh -huff-neo-up --branch release/0.3.1 +hnc-up --branch release/0.3.1 ``` To install a **fork's main branch** (in this case `abigger87/huff-neo`'s main branch): ```sh -huff-neo-up --repo abigger87/huff-neo +hnc-up --repo abigger87/huff-neo ``` To install a **specific branch in a fork** (in this case the `patch-10` branch's latest commit in `abigger87/huff-neo`): ```sh -huff-neo-up --repo abigger87/huff-neo --branch patch-10 +hnc-up --repo abigger87/huff-neo --branch patch-10 ``` To install from a **specific Pull Request**: ```sh -huff-neo-up --pr 1071 +hnc-up --pr 1071 ``` To install from a **specific commit**: ```sh -huff-neo-up -C 94bfdb2 +hnc-up -C 94bfdb2 ``` To install a local directory or repository (e.g. one located at `~/git/huff`, assuming you're in the home directory) ##### Note: --branch, --repo, and --version flags are ignored during local installations. ```sh -huff-neo-up --path ./git/huff +hnc-up --path ./git/huff ``` --- diff --git a/huff-neo-up/huff-neo-up b/hnc-up/hnc-up similarity index 91% rename from huff-neo-up/huff-neo-up rename to hnc-up/hnc-up index a1037f4..b246066 100755 --- a/huff-neo-up/huff-neo-up +++ b/hnc-up/hnc-up @@ -14,7 +14,7 @@ main() { need_cmd git need_cmd curl - # Otherwise, continue with huff-neo-up script + # Otherwise, continue with hnc-up script while [[ $1 ]]; do case $1 in --) shift; break;; @@ -61,7 +61,7 @@ main() { rm -f "$HUFF_BIN_DIR/huff-neo" # Symlink from local repo binaries to bin dir - ensure ln -s "$PWD/target/release/huff-neo" "$HUFF_BIN_DIR/huff-neo" + ensure ln -s "$PWD/target/release/hnc" "$HUFF_BIN_DIR/hnc" say "done" exit 0 @@ -90,7 +90,7 @@ main() { HUFF_NEO_UP_TAG="${HUFF_NEO_UP_VERSION}" fi - say "installing huff-neo (version ${HUFF_NEO_UP_VERSION}, tag ${HUFF_NEO_UP_TAG})" + say "installing hnc (version ${HUFF_NEO_UP_VERSION}, tag ${HUFF_NEO_UP_TAG})" PLATFORM="$(uname -s)" case $PLATFORM in @@ -125,16 +125,16 @@ main() { MAN_TARBALL_URL="${RELEASE_URL}huff_neo_man_${HUFF_NEO_UP_VERSION}.tar.gz" # Download the binaries tarball and unpack it into the .huff bin directory. - say "downloading latest huff-neo" + say "downloading latest hnc" ensure curl -# -L $BIN_TARBALL_URL | tar -xzC $HUFF_BIN_DIR # Download the man tarball and unpack it into the .huff man directory. say "downloading manpages" ensure curl -# -L $MAN_TARBALL_URL | tar -xzC $HUFF_MAN_DIR - say "installed - $($HUFF_BIN_DIR/huff-neo --version)" + say "installed - $($HUFF_BIN_DIR/hnc --version)" say "done" - if [[ $(which huff-neo) =~ "cargo" ]]; then - warn "it appears your system already has huff-neo installed via cargo. you may need to run 'rm $(which huff-neo)' to allow huff-neo-up to take precedence!" + if [[ $(which hnc) =~ "cargo" ]]; then + warn "it appears your system already has hnc installed via cargo. you may need to run 'rm $(which hnc)' to allow hnc-up to take precedence!" fi else need_cmd cargo @@ -163,7 +163,7 @@ main() { # If help2man is installed, use it to add Huff man pages. if command -v help2man &> /dev/null ; then - help2man -N $HUFF_BIN_DIR/huff-neo > $HUFF_MAN_DIR/huff.1 + help2man -N $HUFF_BIN_DIR/hnc > $HUFF_MAN_DIR/huff.1 fi say "done" fi @@ -174,7 +174,7 @@ usage() { The installer for Huff Neo compiler. Update or revert to a specific Huff version with ease. USAGE: - huff-neo-up + hnc-up OPTIONS: -h, --help Print help information -v, --version Install a specific version @@ -187,7 +187,7 @@ EOF } say() { - printf 'huff-neo-up: %s\n' "$1" + printf 'hnc-up: %s\n' "$1" } warn() { diff --git a/huff-neo-up/install b/hnc-up/install similarity index 70% rename from huff-neo-up/install rename to hnc-up/install index 3e5ec5d..a53eaad 100755 --- a/huff-neo-up/install +++ b/hnc-up/install @@ -6,17 +6,17 @@ set -e # https://github.com/foundry-rs/foundry/tree/master/foundryup # ----------------------------------------------------------- -echo "Installing huff-neo-up..." +echo "Installing hnc-up..." HUFF_DIR=${HUFF_DIR-"$HOME/.huff-neo"} HUFF_BIN_DIR="$HUFF_DIR/bin" HUFF_MAN_DIR="$HUFF_DIR/share/man/man1" -BIN_URL="https://raw.githubusercontent.com/cakevm/huff-neo/main/huff-neo-up/huff-neo-up" -BIN_PATH="$HUFF_BIN_DIR/huff-neo-up" +BIN_URL="https://raw.githubusercontent.com/cakevm/huff-neo/main/hnc-up/hnc-up" +BIN_PATH="$HUFF_BIN_DIR/hnc-up" -# Create the .huff bin directory and huff-neo-up binary if it doesn't exist. +# Create the .huff bin directory and hnc-up binary if it doesn't exist. mkdir -p $HUFF_BIN_DIR curl -# -L $BIN_URL -o $BIN_PATH chmod +x $BIN_PATH @@ -39,13 +39,13 @@ case $SHELL in PREF_SHELL=fish ;; *) - echo "huff-neo-up: could not detect shell, manually add ${HUFF_BIN_DIR} to your PATH." + echo "hnc-up: could not detect shell, manually add ${HUFF_BIN_DIR} to your PATH." exit 1 esac -# Only add huff-neo-up if it isn't already in PATH. +# Only add hnc-up if it isn't already in PATH. if [[ ":$PATH:" != *":${HUFF_BIN_DIR}:"* ]]; then - # Add the huff-neo-up directory to the path and ensure the old PATH variables remain. + # Add the hnc-up directory to the path and ensure the old PATH variables remain. echo >> $PROFILE && echo "export PATH=\"\$PATH:$HUFF_BIN_DIR\"" >> $PROFILE fi @@ -54,5 +54,5 @@ if [[ "$OSTYPE" =~ ^darwin && ! -f /usr/local/opt/libusb/lib/libusb-1.0.0.dylib echo && echo "warning: libusb not found. You may need to install it manually on MacOS via Homebrew (brew install libusb)." fi -echo && echo "Detected your preferred shell is ${PREF_SHELL} and added huff-neo-up to PATH. Run 'source ${PROFILE}' or start a new terminal session to use huff-neo-up." -echo "Then, simply run 'huff-neo-up' to install the Huff compiler." \ No newline at end of file +echo && echo "Detected your preferred shell is ${PREF_SHELL} and added hnc-up to PATH. Run 'source ${PROFILE}' or start a new terminal session to use hnc-up." +echo "Then, simply run 'hnc-up' to install the Huff compiler." \ No newline at end of file diff --git a/taplo.toml b/taplo.toml index 4ebbf24..61e262e 100644 --- a/taplo.toml +++ b/taplo.toml @@ -1,4 +1,4 @@ -include = ["crates/**/Cargo.toml", "bin/**/Cargo.toml", "deny.toml", "rust-toolchain.toml", "rustfmt.toml"] +include = ["crates/**/Cargo.toml", "bin/**/Cargo.toml", "deny.toml", "rust-toolchain.toml", "rustfmt.toml", "Cargo.toml"] [formatting]