|
| 1 | +# List available recipes |
| 2 | +default: |
| 3 | + ./scripts/run-just.sh --list |
| 4 | + |
| 5 | +# Build ffi with nix |
| 6 | +build-ffi-nix: check-nix |
| 7 | + cd ffi && nix build |
| 8 | + |
| 9 | +# Check if the git branch is clean |
| 10 | +check-clean-branch: |
| 11 | + #!/usr/bin/env bash |
| 12 | + set -euo pipefail |
| 13 | + |
| 14 | + git add --all |
| 15 | + git update-index --really-refresh >> /dev/null |
| 16 | + |
| 17 | + # Show the status of the working tree. |
| 18 | + git status --short |
| 19 | + |
| 20 | + # Exits if any uncommitted changes are found. |
| 21 | + git diff-index --quiet HEAD |
| 22 | + |
| 23 | +# Check if the FFI flake is up-to-date (requires clean git tree) |
| 24 | +check-ffi-flake: check-nix |
| 25 | + #!/usr/bin/env bash |
| 26 | + set -euo pipefail |
| 27 | + ./scripts/run-just.sh update-ffi-flake |
| 28 | + ./scripts/run-just.sh check-clean-branch |
| 29 | + |
| 30 | +# Check if the golang version is set consistently (requires clean git tree) |
| 31 | +check-golang-version: check-nix |
| 32 | + #!/usr/bin/env bash |
| 33 | + set -euo pipefail |
| 34 | + |
| 35 | + # Exit only at the end if any of the checks set FAILED=1 |
| 36 | + FAILED= |
| 37 | + |
| 38 | + cd ffi |
| 39 | + |
| 40 | + TOOLCHAIN_VERSION=$(nix develop --command bash -c "go mod edit -json | jq -r '.Toolchain'") |
| 41 | + echo "toolchain version in ffi/go.mod is ${TOOLCHAIN_VERSION}" |
| 42 | + |
| 43 | + ETH_TESTS_VERSION=$(nix develop --command bash -c "cd tests/eth && go mod edit -json | jq -r '.Toolchain'") |
| 44 | + echo "toolchain version in ffi/tests/eth/go.mod is ${ETH_TESTS_VERSION}" |
| 45 | + |
| 46 | + if [[ "${TOOLCHAIN_VERSION}" != "${ETH_TESTS_VERSION}" ]]; then |
| 47 | + echo "❌ toolchain version in ffi/tests/eth/go.mod should be ${TOOLCHAIN_VERSION}" |
| 48 | + FAILED=1 |
| 49 | + fi |
| 50 | + |
| 51 | + FIREWOOD_TESTS_VERSION=$(nix develop --command bash -c "cd tests/firewood && go mod edit -json | jq -r '.Toolchain'") |
| 52 | + echo "toolchain version in ffi/tests/firewood/go.mod is ${FIREWOOD_TESTS_VERSION}" |
| 53 | + |
| 54 | + if [[ "${TOOLCHAIN_VERSION}" != "${FIREWOOD_TESTS_VERSION}" ]]; then |
| 55 | + echo "❌ toolchain version in ffi/tests/firewood/go.mod should be ${TOOLCHAIN_VERSION}" |
| 56 | + FAILED=1 |
| 57 | + fi |
| 58 | + |
| 59 | + NIX_VERSION=$(nix run .#go -- version | awk '{print $3}') |
| 60 | + echo "golang provided by ffi/flake.nix is ${NIX_VERSION}" |
| 61 | + |
| 62 | + if [[ "${TOOLCHAIN_VERSION}" != "${NIX_VERSION}" ]]; then |
| 63 | + echo "❌ golang provided by ffi/flake/nix should be ${TOOLCHAIN_VERSION}" |
| 64 | + echo "It will be necessary to update the golang.url in ffi/flake.nix to point to a SHA of"\ |
| 65 | + "AvalancheGo whose nix/go/flake.nix provides ${TOOLCHAIN_VERSION}." |
| 66 | + fi |
| 67 | + |
| 68 | + if [[ -n "${FAILED}" ]]; then |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | + |
| 72 | +# Check if nix is installed |
| 73 | +check-nix: |
| 74 | + #!/usr/bin/env bash |
| 75 | + set -euo pipefail |
| 76 | + if ! command -v nix &> /dev/null; then |
| 77 | + echo "Error: 'nix' is not installed." >&2 |
| 78 | + echo "" >&2 |
| 79 | + echo "To install nix:" >&2 |
| 80 | + echo " - Visit: https://github.com/DeterminateSystems/nix-installer" >&2 |
| 81 | + echo " - Or run: curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install" >&2 |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | + |
| 85 | +# Run all checks of ffi built with nix |
| 86 | +test-ffi-nix: test-ffi-nix-build-equivalency test-ffi-nix-go-bindings |
| 87 | + |
| 88 | +# Test ffi build equivalency between nix and cargo |
| 89 | +test-ffi-nix-build-equivalency: check-nix |
| 90 | + #!/usr/bin/env bash |
| 91 | + set -euo pipefail |
| 92 | + |
| 93 | + echo "Testing ffi build equivalency between nix and cargo" |
| 94 | + |
| 95 | + bash -x ./ffi/test-build-equivalency.sh |
| 96 | + |
| 97 | +# Test golang ffi bindings using the nix-built artifacts |
| 98 | +test-ffi-nix-go-bindings: build-ffi-nix |
| 99 | + #!/usr/bin/env bash |
| 100 | + set -euo pipefail |
| 101 | + |
| 102 | + echo "running ffi tests against bindings built by nix..." |
| 103 | + |
| 104 | + cd ffi |
| 105 | + |
| 106 | + # Need to capture the flake path before changing directories to |
| 107 | + # result/ffi because `result` is a nix store symlink so ../../ |
| 108 | + # won't resolve to the ffi path containing the flake. |
| 109 | + FLAKE_PATH="$PWD" |
| 110 | + |
| 111 | + # This runs golang outside a nix shell to validate viability |
| 112 | + # without the env setup performed by a nix shell |
| 113 | + GO="nix run $FLAKE_PATH#go" |
| 114 | + |
| 115 | + cd result/ffi |
| 116 | + |
| 117 | + # - cgocheck2 is expensive but provides complete pointer checks |
| 118 | + # - use hash mode ethhash since the flake builds with `--features ethhash,logger` |
| 119 | + GOEXPERIMENT=cgocheck2 TEST_FIREWOOD_HASH_MODE=ethhash ${GO} test ./... |
| 120 | + |
| 121 | +# Ensure the FFI flake is up-to-date |
| 122 | +update-ffi-flake: check-nix |
| 123 | + #!/usr/bin/env bash |
| 124 | + set -euo pipefail |
| 125 | + cd ffi |
| 126 | + |
| 127 | + echo "ensuring flake lock file is current for golang" |
| 128 | + nix flake update golang |
| 129 | + |
| 130 | + echo "checking for a consistent golang verion" |
| 131 | + ../scripts/run-just.sh check-golang-version |
0 commit comments