feat: Add musl support #2039
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Lint | |
| on: | |
| schedule: | |
| # runs every monday at midnight | |
| - cron: "0 0 * * 1" | |
| push: | |
| branches: | |
| - master | |
| pull_request: | |
| env: | |
| # increment this manually to force cache eviction | |
| RUST_CACHE_PREFIX: "v0-rust" | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} | |
| jobs: | |
| lint: | |
| name: Lint | |
| runs-on: ubuntu-latest | |
| env: | |
| clang: "17" | |
| php_version: "8.4" | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check typos | |
| uses: crate-ci/typos@master | |
| - name: Validate commit messages | |
| run: | | |
| git show-ref | |
| curl -sSfL https://github.com/convco/convco/releases/latest/download/convco-ubuntu.zip | zcat > convco | |
| chmod +x convco | |
| ./convco check refs/remotes/origin/master..HEAD | |
| rm convco | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ env.php_version }} | |
| env: | |
| debug: true | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@master | |
| with: | |
| components: rustfmt, clippy | |
| toolchain: stable | |
| - name: Cache cargo dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| prefix-key: ${{ env.RUST_CACHE_PREFIX }} | |
| - name: Cache LLVM and Clang | |
| id: cache-llvm | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ runner.temp }}/llvm-${{ env.clang }} | |
| key: ubuntu-latest-llvm-${{ env.clang }} | |
| - name: Setup LLVM & Clang | |
| id: clang | |
| uses: KyleMayes/install-llvm-action@v2 | |
| with: | |
| version: ${{ env.clang }} | |
| directory: ${{ runner.temp }}/llvm-${{ env.clang }} | |
| cached: ${{ steps.cache-llvm.outputs.cache-hit }} | |
| - name: Configure Clang | |
| run: | | |
| echo "LIBCLANG_PATH=${{ runner.temp }}/llvm-${{ env.clang }}/lib" >> $GITHUB_ENV | |
| echo "LLVM_VERSION=${{ steps.clang.outputs.version }}" >> $GITHUB_ENV | |
| echo "LLVM_CONFIG_PATH=${{ runner.temp }}/llvm-${{ env.clang }}/bin/llvm-config" >> $GITHUB_ENV | |
| - name: Run rustfmt | |
| run: cargo fmt --all -- --check | |
| - name: Run clippy | |
| run: cargo clippy --workspace --all-targets --features closure,embed,anyhow -- -W clippy::pedantic -D warnings | |
| # Docs | |
| - name: Run rustdoc | |
| run: cargo rustdoc -- -D warnings | |
| - name: Build with docs stub | |
| env: | |
| DOCS_RS: "" | |
| run: cargo clean && cargo build | |
| build: | |
| name: Build and Test | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| php: ["8.1", "8.2", "8.3", "8.4"] | |
| rust: [stable, nightly] | |
| clang: ["15", "17"] | |
| phpts: [ts, nts] | |
| target: [gnu, musl] | |
| exclude: | |
| # ext-php-rs requires nightly Rust when on Windows. | |
| - os: windows-latest | |
| rust: stable | |
| - os: macos-latest | |
| clang: "17" | |
| - os: ubuntu-latest | |
| clang: "15" | |
| - os: windows-latest | |
| clang: "15" | |
| # musl only supported on Linux with stable Rust | |
| - os: windows-latest | |
| target: musl | |
| - os: macos-latest | |
| target: musl | |
| - target: musl | |
| rust: nightly | |
| env: | |
| CARGO_TERM_COLOR: always | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Install musl toolchain | |
| if: matrix.target == 'musl' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y musl-tools musl-dev | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php }} | |
| env: | |
| phpts: ${{ matrix.phpts }} | |
| debug: true | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@master | |
| with: | |
| toolchain: ${{ matrix.rust }} | |
| components: rustfmt, clippy | |
| - name: Add musl target | |
| if: matrix.target == 'musl' | |
| run: rustup target add x86_64-unknown-linux-musl | |
| - run: rustup show | |
| - name: Cache cargo dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| # Uncomment the following if statement if caching nightly deps | |
| # ends up causing too much cache invalidation. | |
| # if: matrix.rust == 'stable' | |
| with: | |
| # increment this manually to force cache eviction | |
| prefix-key: ${{ env.RUST_CACHE_PREFIX }} | |
| - name: Install Cargo expand | |
| run: cargo install cargo-expand --locked | |
| if: "!contains(matrix.os, 'ubuntu')" | |
| - name: Install Cargo expand | |
| uses: dtolnay/install@cargo-expand | |
| if: "contains(matrix.os, 'ubuntu')" | |
| # LLVM & Clang | |
| - name: Cache LLVM and Clang | |
| id: cache-llvm | |
| uses: actions/cache@v4 | |
| # Macos build doesn't work with clang < 18. As a build for version 18 is not available, we skip the setup | |
| if: "!contains(matrix.os, 'windows') && !contains(matrix.os, 'macos')" | |
| with: | |
| path: ${{ runner.temp }}/llvm-${{ matrix.clang }} | |
| key: ${{ matrix.os }}-llvm-${{ matrix.clang }} | |
| - name: Setup LLVM & Clang | |
| id: clang | |
| uses: KyleMayes/install-llvm-action@v2 | |
| # Macos build doesn't work with clang < 18. As a build for version 18 is not available, we skip the setup | |
| if: "!contains(matrix.os, 'windows') && !contains(matrix.os, 'macos')" | |
| with: | |
| version: ${{ matrix.clang }} | |
| directory: ${{ runner.temp }}/llvm-${{ matrix.clang }} | |
| cached: ${{ steps.cache-llvm.outputs.cache-hit }} | |
| - name: Configure Clang | |
| # Macos build doesn't work with clang < 18. As a build for version 18 is not available, we skip the setup | |
| if: "!contains(matrix.os, 'windows') && !contains(matrix.os, 'macos')" | |
| run: | | |
| echo "LIBCLANG_PATH=${{ runner.temp }}/llvm-${{ matrix.clang }}/lib" >> $GITHUB_ENV | |
| echo "LLVM_VERSION=${{ steps.clang.outputs.version }}" >> $GITHUB_ENV | |
| echo "LLVM_CONFIG_PATH=${{ runner.temp }}/llvm-${{ matrix.clang }}/bin/llvm-config" >> $GITHUB_ENV | |
| # Build | |
| - name: Build | |
| env: | |
| EXT_PHP_RS_TEST: "" | |
| RUSTFLAGS: ${{ matrix.target == 'musl' && '-C target-feature=-crt-static' || '' }} | |
| run: cargo build --release --features closure,anyhow,runtime --workspace ${{ matrix.target == 'musl' && '--target x86_64-unknown-linux-musl' || '' }} | |
| # Test | |
| - name: Test inline examples | |
| # Macos fails on unstable rust. We skip the inline examples test for now. | |
| if: "!(contains(matrix.os, 'macos') && matrix.rust == 'nightly')" | |
| env: | |
| RUSTFLAGS: ${{ matrix.target == 'musl' && '-C target-feature=-crt-static' || '' }} | |
| run: cargo test --release --workspace --features closure,anyhow,runtime --no-fail-fast ${{ matrix.target == 'musl' && '--target x86_64-unknown-linux-musl' || '' }} | |
| test-embed: | |
| name: Test with embed | |
| runs-on: ubuntu-latest | |
| env: | |
| clang: "17" | |
| php_version: "8.4" | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ env.php_version }} | |
| env: | |
| debug: true | |
| - name: Install libphp-embed | |
| run: sudo apt update -y && sudo apt install -y libphp8.4-embed | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@master | |
| with: | |
| toolchain: stable | |
| components: rustfmt, clippy | |
| - name: Install cargo-expand | |
| uses: dtolnay/install@cargo-expand | |
| - name: Cache cargo dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| prefix-key: ${{ env.RUST_CACHE_PREFIX }} | |
| - name: Cache LLVM and Clang | |
| id: cache-llvm | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ runner.temp }}/llvm-${{ env.clang }} | |
| key: ubuntu-latest-llvm-${{ env.clang }} | |
| - name: Setup LLVM & Clang | |
| id: clang | |
| uses: KyleMayes/install-llvm-action@v2 | |
| with: | |
| version: ${{ env.clang }} | |
| directory: ${{ runner.temp }}/llvm-${{ env.clang }} | |
| cached: ${{ steps.cache-llvm.outputs.cache-hit }} | |
| - name: Configure Clang | |
| run: | | |
| echo "LIBCLANG_PATH=${{ runner.temp }}/llvm-${{ env.clang }}/lib" >> $GITHUB_ENV | |
| echo "LLVM_VERSION=${{ steps.clang.outputs.version }}" >> $GITHUB_ENV | |
| echo "LLVM_CONFIG_PATH=${{ runner.temp }}/llvm-${{ env.clang }}/bin/llvm-config" >> $GITHUB_ENV | |
| - name: Test with embed feature | |
| run: cargo test --workspace --release --features closure,embed,anyhow --no-fail-fast |