From 0dd805b2b5ffca22dfd90eee316c33bdb33111c1 Mon Sep 17 00:00:00 2001 From: 52 69 63 68 61 72 64 Date: Sun, 29 Dec 2024 04:30:35 +0100 Subject: [PATCH] feat: generate vendored bindings from CI Co-authored-by: Irate-Walrus <71628949+Irate-Walrus@users.noreply.github.com> --- .github/workflows/rust.yml | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6dfafec..80b23e7 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -26,5 +26,59 @@ jobs: components: rustfmt - name: Build run: cargo build -v -F regenerate --target ${{ matrix.target }} + - name: Extract architecture from target triple and move bindings + shell: bash + run: | + # Extract architecture (i686, x86_64 or aarch64) from target triple + ARCH=$(echo "${{ matrix.target }}" | cut -d'-' -f1) + echo "Extracted architecture: $ARCH" + + # Set the architecture as an environment variable + echo "ARCH=$ARCH" >> $GITHUB_ENV + + # Path to the generated binding + GENERATED_BINDING=$(find target/${{ matrix.target }}/debug/build -type f -name "${ARCH}_bindgen.rs") + + if [ -z "$GENERATED_BINDING" ]; then + echo "Error: Generated binding file not found for $ARCH." + exit 1 + fi + + # Move the generated file to the repository directory + cp "$GENERATED_BINDING" "src/ffi/${ARCH}_bindgen.rs" + echo "Moved $GENERATED_BINDING to src/ffi/${ARCH}_bindgen.rs" - name: Run tests run: cargo test --verbose + commit-and-push: + runs-on: ubuntu-latest + needs: build + if: success() # Run only if the generate-bindgen job succeeds + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Download generated files + uses: actions/download-artifact@v4 + with: + pattern: "*bindgen.rs" + path: src/ffi + merge-multiple: true + + - name: Configure Git + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + + - name: Commit and push changes + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git add src/ffi + + # Check if there are any changes to commit + if git diff --exit-code --cached; then + echo "No changes to commit." + else + git commit -m "Update bindgen files" + git push + fi