|  | 
|  | 1 | +name: Precompile NIFs | 
|  | 2 | + | 
|  | 3 | +on: | 
|  | 4 | +  push: | 
|  | 5 | +    branches: | 
|  | 6 | +      - main | 
|  | 7 | +    paths: | 
|  | 8 | +      - "native/**" | 
|  | 9 | +      - ".github/workflows/release.yml" | 
|  | 10 | +    tags: | 
|  | 11 | +      - "*" | 
|  | 12 | +  pull_request: | 
|  | 13 | +    paths: | 
|  | 14 | +      - ".github/workflows/release.yml" | 
|  | 15 | +  workflow_dispatch: | 
|  | 16 | +     | 
|  | 17 | +jobs: | 
|  | 18 | +  build_release: | 
|  | 19 | +    name: NIF ${{ matrix.nif }} - ${{ matrix.job.target }} (${{ matrix.job.os }} | ${{ matrix.job.variant || 'default' }}) | 
|  | 20 | +    runs-on: ${{ matrix.job.os }} | 
|  | 21 | + | 
|  | 22 | +    permissions: | 
|  | 23 | +      contents: write | 
|  | 24 | +      id-token: write | 
|  | 25 | +      attestations: write | 
|  | 26 | + | 
|  | 27 | +    strategy: | 
|  | 28 | +      fail-fast: false | 
|  | 29 | +      matrix: | 
|  | 30 | +        nif: ["2.15"] | 
|  | 31 | +        job: | 
|  | 32 | +          - { target: aarch64-apple-darwin, os: macos-12 } | 
|  | 33 | +          - { target: aarch64-unknown-linux-gnu, os: ubuntu-20.04, use-cross: true } | 
|  | 34 | +          - { target: aarch64-unknown-linux-musl, os: ubuntu-20.04, use-cross: true } | 
|  | 35 | +          - { target: x86_64-apple-darwin, os: macos-12 } | 
|  | 36 | +          - { target: x86_64-pc-windows-gnu, os: windows-2022 } | 
|  | 37 | +          - { target: x86_64-pc-windows-msvc, os: windows-2019 } | 
|  | 38 | +          - { target: x86_64-unknown-freebsd, os: ubuntu-22.04, use-cross: true } | 
|  | 39 | +          - { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04 } | 
|  | 40 | +          - { target: x86_64-unknown-linux-musl, os: ubuntu-20.04, use-cross: true } | 
|  | 41 | + | 
|  | 42 | +    steps: | 
|  | 43 | +      - name: Checkout source code | 
|  | 44 | +        uses: actions/checkout@v4 | 
|  | 45 | + | 
|  | 46 | +      - name: Extract crate information | 
|  | 47 | +        shell: bash | 
|  | 48 | +        run: | | 
|  | 49 | +          # Get the project version from mix.exs | 
|  | 50 | +          echo "PROJECT_VERSION=$(sed -n 's/^  @version "\(.*\)"/\1/p' mix.exs | head -n1)" >> $GITHUB_ENV | 
|  | 51 | +
 | 
|  | 52 | +      - name: Maybe add Rust flags for compilation | 
|  | 53 | +        shell: bash | 
|  | 54 | +        run: | | 
|  | 55 | +          echo "RUSTFLAGS=${{ matrix.job.rustflags }}" >> $GITHUB_ENV | 
|  | 56 | +        if: ${{ matrix.job.rustflags }} | 
|  | 57 | + | 
|  | 58 | +      - name: Add target | 
|  | 59 | +        shell: bash | 
|  | 60 | +        run: | | 
|  | 61 | +          rustup target add ${{ matrix.job.target }} | 
|  | 62 | +
 | 
|  | 63 | +      - uses: Swatinem/rust-cache@v2 | 
|  | 64 | +        with: | 
|  | 65 | +          prefix-key: v0-precomp | 
|  | 66 | +          shared-key: ${{ matrix.job.target }}-${{ matrix.nif }} | 
|  | 67 | +          workspaces: | | 
|  | 68 | +            native/typst_nif | 
|  | 69 | +
 | 
|  | 70 | +      - name: Build the project | 
|  | 71 | +        id: build-crate | 
|  | 72 | + | 
|  | 73 | +        with: | 
|  | 74 | +          project-name: explorer | 
|  | 75 | +          project-version: ${{ env.PROJECT_VERSION }} | 
|  | 76 | +          target: ${{ matrix.job.target }} | 
|  | 77 | +          nif-version: ${{ matrix.nif }} | 
|  | 78 | +          use-cross: ${{ matrix.job.use-cross }} | 
|  | 79 | +          cross-version: ${{ matrix.job.cross-version || 'from-source' }} | 
|  | 80 | +          project-dir: "native/explorer" | 
|  | 81 | +          cargo-args: ${{ matrix.job.cargo-args }} | 
|  | 82 | +          variant: ${{ matrix.job.variant }} | 
|  | 83 | + | 
|  | 84 | +      - name: Artifact attestation | 
|  | 85 | +        uses: actions/attest-build-provenance@v1 | 
|  | 86 | +        with: | 
|  | 87 | +          subject-path: ${{ steps.build-crate.outputs.file-path }} | 
|  | 88 | + | 
|  | 89 | +      - name: Artifact upload | 
|  | 90 | +        uses: actions/upload-artifact@v4 | 
|  | 91 | +        with: | 
|  | 92 | +          name: ${{ steps.build-crate.outputs.file-name }} | 
|  | 93 | +          path: ${{ steps.build-crate.outputs.file-path }} | 
|  | 94 | + | 
|  | 95 | +      - name: Publish archives and packages | 
|  | 96 | +        uses: softprops/action-gh-release@v2 | 
|  | 97 | +        with: | 
|  | 98 | +          files: | | 
|  | 99 | +            ${{ steps.build-crate.outputs.file-path }} | 
|  | 100 | +        if: startsWith(github.ref, 'refs/tags/') | 
|  | 101 | + | 
|  | 102 | + | 
|  | 103 | + | 
0 commit comments