|
| 1 | +name: attach-static-libs |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + create_branch_name: |
| 7 | + description: "Name of the new branch to create and attach static libs" |
| 8 | + required: true |
| 9 | + push: |
| 10 | + tags: |
| 11 | + - "*" |
| 12 | + pull_request: |
| 13 | + |
| 14 | +env: |
| 15 | + CARGO_TERM_COLOR: always |
| 16 | + |
| 17 | +# Build, upload, and collect static libraries for each target architecture, |
| 18 | +# so that golang projects can import the FFI package without needing to |
| 19 | +# recompile Firewood locally. |
| 20 | +# Supported architectures are: |
| 21 | +# - x86_64-unknown-linux-gnu |
| 22 | +# - aarch64-unknown-linux-gnu |
| 23 | +# - x86_64-apple-darwin |
| 24 | +# - aarch64-apple-darwin |
| 25 | +jobs: |
| 26 | + # Build the static libraries for each target architecture and upload |
| 27 | + # them as artifacts to collect and attach in the next job. |
| 28 | + build-firewood-ffi-libs: |
| 29 | + runs-on: ${{ matrix.os }} |
| 30 | + strategy: |
| 31 | + matrix: |
| 32 | + include: |
| 33 | + - os: ubuntu-latest |
| 34 | + target: x86_64-unknown-linux-gnu |
| 35 | + - os: ubuntu-22.04-arm |
| 36 | + target: aarch64-unknown-linux-gnu |
| 37 | + - os: macos-latest |
| 38 | + target: aarch64-apple-darwin |
| 39 | + - os: macos-13 |
| 40 | + target: x86_64-apple-darwin |
| 41 | + steps: |
| 42 | + - uses: actions/checkout@v4 |
| 43 | + - uses: dtolnay/rust-toolchain@stable |
| 44 | + - uses: arduino/setup-protoc@v3 |
| 45 | + with: |
| 46 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + - uses: Swatinem/rust-cache@v2 |
| 48 | + |
| 49 | + - name: Build for ${{ matrix.target }} |
| 50 | + run: cargo build --profile maxperf --features ethhash,logger --target ${{ matrix.target }} -p firewood-ffi |
| 51 | + |
| 52 | + - name: Upload binary |
| 53 | + uses: actions/upload-artifact@v4 |
| 54 | + with: |
| 55 | + name: ${{ matrix.target }} |
| 56 | + path: target/${{ matrix.target }}/maxperf/libfirewood_ffi.a |
| 57 | + if-no-files-found: error |
| 58 | + |
| 59 | + # Collect all the static libraries built on the previous matrix of jobs |
| 60 | + # and add them into ffi/libs directory. |
| 61 | + # We commit and push this as a new branch with "--force" to overwrite |
| 62 | + # the previous static libs that will not be on our branch. |
| 63 | + push-firewood-ffi-libs: |
| 64 | + needs: build-firewood-ffi-libs |
| 65 | + runs-on: ubuntu-latest |
| 66 | + outputs: |
| 67 | + target_branch: ${{ steps.determine_branch.outputs.target_branch }} |
| 68 | + steps: |
| 69 | + - name: Determine branch name |
| 70 | + id: determine_branch |
| 71 | + run: | |
| 72 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.create_branch_name }}" ]]; then |
| 73 | + export target_branch="${{ github.event.inputs.create_branch_name }}" |
| 74 | + echo "Using workflow input as target branch: $target_branch" |
| 75 | + echo "target_branch=$target_branch" >> "$GITHUB_OUTPUT" |
| 76 | + elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref_type }}" == "tag" ]]; then |
| 77 | + export target_branch="${GITHUB_REF#refs/tags/}" |
| 78 | + echo "Using tag name as target_branch: $target_branch" |
| 79 | + echo "target_branch=$target_branch" >> "$GITHUB_OUTPUT" |
| 80 | + elif [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 81 | + export target_branch="${{ github.event.pull_request.head.ref }}" |
| 82 | + echo "Using PR head name as target branch: $target_branch" |
| 83 | + echo "target_branch=$target_branch" >> "$GITHUB_OUTPUT" |
| 84 | + else |
| 85 | + echo "No valid input or tag found." |
| 86 | + exit 1 |
| 87 | + fi |
| 88 | +
|
| 89 | + - uses: actions/checkout@v4 |
| 90 | + with: |
| 91 | + path: firewood |
| 92 | + |
| 93 | + - uses: actions/checkout@v4 |
| 94 | + with: |
| 95 | + repository: ava-labs/firewood-go |
| 96 | + token: ${{ secrets.FIREWOOD_GO_GITHUB_TOKEN }} |
| 97 | + path: firewood-go |
| 98 | + |
| 99 | + - name: Copy FFI Source Code |
| 100 | + run: cp -r firewood/ffi firewood-go |
| 101 | + |
| 102 | + - name: Download binaries into libs directory |
| 103 | + uses: actions/download-artifact@v4 |
| 104 | + with: |
| 105 | + path: firewood-go/ffi/libs |
| 106 | + |
| 107 | + - name: List downloaded target directory |
| 108 | + run: find firewood-go -type f | sort |
| 109 | + |
| 110 | + - name: Push static libs to branch |
| 111 | + working-directory: firewood-go |
| 112 | + # GITHUB_TOKEN is configured in the last actions/checkout step |
| 113 | + # to have read/write permissions to the firewood-go repo. |
| 114 | + run: | |
| 115 | + git config --global user.name "FirewoodCI" |
| 116 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 117 | + git checkout -b ${{ steps.determine_branch.outputs.target_branch }} |
| 118 | + git add . |
| 119 | + git commit -m "firewood ci ${{ github.sha }}: attach firewood static libs" |
| 120 | + |
| 121 | + if [[ "${{ github.ref_type }}" == "tag" ]]; then |
| 122 | + git tag -a "${GITHUB_REF#refs/tags/}" -m "firewood ci ${{ github.sha }}: attach firewood static libs" |
| 123 | + git push origin "refs/tags/${GITHUB_REF#refs/tags/}" |
| 124 | + else |
| 125 | + git push -u origin ${{ steps.determine_branch.outputs.target_branch }} --force |
| 126 | + fi |
| 127 | +
|
| 128 | + # Check out the branch created in the previous job on a matrix of |
| 129 | + # our target architectures and test the FFI package on a fresh |
| 130 | + # machine without re-compiling Firewood locally. |
| 131 | + # This tests that the Firewood FFI package passes tests on the target |
| 132 | + # architecture when it is forced to depend on the attached static libs. |
| 133 | + test-firewood-ffi-libs: |
| 134 | + runs-on: ${{ matrix.os }} |
| 135 | + strategy: |
| 136 | + matrix: |
| 137 | + os: [ubuntu-latest, ubuntu-22.04-arm, macos-latest, macos-13] |
| 138 | + needs: push-firewood-ffi-libs |
| 139 | + continue-on-error: true |
| 140 | + steps: |
| 141 | + - uses: actions/checkout@v4 |
| 142 | + with: |
| 143 | + repository: ava-labs/firewood-go |
| 144 | + token: ${{ secrets.FIREWOOD_GO_GITHUB_TOKEN }} |
| 145 | + ref: ${{ needs.push-firewood-ffi-libs.outputs.target_branch }} |
| 146 | + - name: Set up Go |
| 147 | + uses: actions/setup-go@v5 |
| 148 | + with: |
| 149 | + go-version-file: "ffi/go.mod" |
| 150 | + cache-dependency-path: "ffi/go.sum" |
| 151 | + - name: Test Go FFI bindings |
| 152 | + working-directory: ffi |
| 153 | + # cgocheck2 is expensive but provides complete pointer checks |
| 154 | + run: GOEXPERIMENT=cgocheck2 TEST_FIREWOOD_HASH_MODE=ethhash go test ./... |
| 155 | + |
| 156 | + remove-if-pr-only: |
| 157 | + runs-on: ubuntu-latest |
| 158 | + needs: [push-firewood-ffi-libs, test-firewood-ffi-libs] |
| 159 | + if: needs.push-firewood-ffi-libs.result == 'success' && github.event_name == 'pull_request' |
| 160 | + permissions: |
| 161 | + # Give the GITHUB_TOKEN write permission to delete the |
| 162 | + # branch created by the previous job if it is a pull request. |
| 163 | + contents: write |
| 164 | + steps: |
| 165 | + - uses: actions/checkout@v4 |
| 166 | + with: |
| 167 | + repository: ava-labs/firewood-go |
| 168 | + token: ${{ secrets.FIREWOOD_GO_GITHUB_TOKEN }} |
| 169 | + ref: ${{ needs.push-firewood-ffi-libs.outputs.target_branch }} |
| 170 | + - name: Delete branch |
| 171 | + run: | |
| 172 | + git push origin --delete ${{ needs.push-firewood-ffi-libs.outputs.target_branch }} |
0 commit comments