mimalloc-safe 0.1.57

Performance and security oriented drop-in allocator
Documentation
name: CI

on:
  push:
    branches:
      - main
  pull_request:
  # Run daily to catch when Rust updates cause problems to happen.
  schedule:
    - cron: '00 01 * * *'

jobs:
  rust:
    name: Rust

    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        toolchain: ["stable"]

    runs-on: ${{ matrix.os }}

    env:
      CARGO_INCREMENTAL: 0
      RUST_BACKTRACE: 1

    steps:
      - name: Checkout repository
        uses: actions/checkout@v6
        with:
          submodules: recursive

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.toolchain }}

      - name: Build (secure)
        run: cargo build --features secure

      - name: Test (secure)
        run: cargo test --features secure

      - name: Test libmimalloc-sys crate bindings (secure)
        run: cargo run --features secure -p libmimalloc-sys-test

      - name: Test libmimalloc-sys crate bindings (v3)
        run: cargo run --features v3 -p libmimalloc-sys-test

      - name: Build (no secure)
        run: cargo build

      - name: Test (no secure)
        run: cargo test

      - name: Test libmimalloc-sys crate bindings (no secure)
        run: cargo run -p libmimalloc-sys-test

      - name: Build (extended)
        run: cargo build --features extended

      - name: Test (extended)
        run: cargo test --features extended

      - name: Test (v3)
        run: cargo test --features v3

      - name: Test (extended, v3)
        run: cargo test --features extended,v3

      - name: Test libmimalloc-sys crate bindings (extended)
        run: cargo run --features extended -p libmimalloc-sys-test

  lint:
    name: Rustfmt / Clippy
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v6
        with:
          submodules: recursive

      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - name: Fmt
        run: cargo fmt --all -- --check

      - name: Clippy
        run: cargo clippy --workspace -- -D warnings

  # Detect cases where documentation links would be dead
  doc:
    name: Check documentation
    runs-on: ubuntu-latest
    steps:

      - uses: actions/checkout@v6
        with:
          submodules: recursive

      - uses: dtolnay/rust-toolchain@nightly

      # Note: We need to use nightly rust, and `cargo rustdoc` (yes, not `cargo
      # doc`) to actually get it to respect -D warnings... Using nightly also
      # gets us the nicer syntax for linking to functions, and is in-line with
      # what docs.rs uses.

      - name: 'Check documentation links in `mimalloc`'
        run: cargo rustdoc -- -D warnings

      - name: 'Check documentation links in `libmimalloc-sys`'
        run: cargo rustdoc -p libmimalloc-sys2 -- -D warnings

  build-example:
    name: Build example ${{ matrix.settings.target }}
    strategy:
      fail-fast: false
      matrix:
        settings:
          - host: macos-latest
            target: x86_64-apple-darwin
          - host: windows-latest
            target: x86_64-pc-windows-msvc
          - host: windows-latest
            target: i686-pc-windows-msvc
          - host: ubuntu-latest
            target: x86_64-unknown-linux-gnu
          - host: ubuntu-latest
            target: x86_64-unknown-linux-musl
          - host: macos-latest
            target: aarch64-apple-darwin
          - host: ubuntu-24.04-arm
            target: aarch64-unknown-linux-gnu
          - host: ubuntu-latest
            target: armv7-unknown-linux-gnueabihf
          - host: ubuntu-latest
            target: aarch64-linux-android
          - host: ubuntu-24.04-arm
            target: aarch64-unknown-linux-musl
          - host: windows-latest
            target: aarch64-pc-windows-msvc
          - host: ubuntu-latest
            target: powerpc64le-unknown-linux-gnu
          - host: ubuntu-latest
            target: s390x-unknown-linux-gnu
          - host: ubuntu-latest
            target: wasm32-wasip1-threads

    runs-on: ${{ matrix.settings.host }}

    steps:
      - uses: actions/checkout@v6
        with:
          submodules: recursive

      - name: Install
        run: rustup target add ${{ matrix.settings.target }}

      - uses: goto-bus-stop/setup-zig@v2
        if: ${{ contains(matrix.settings.target, 'musl') }}
        with:
          version: 0.15.2

      - name: Install cargo-zigbuild
        uses: taiki-e/install-action@v2
        if: ${{ contains(matrix.settings.target, 'musl') }}
        env:
          GITHUB_TOKEN: ${{ github.token }}
        with:
          tool: cargo-zigbuild

      - uses: actions/setup-node@v6
        with:
          node-version: 24

      - name: Install dependencies
        working-directory: example
        run: |
          corepack enable
          yarn install

      - name: Install wasi-sdk
        if: ${{ matrix.settings.target == 'wasm32-wasip1-threads' }}
        run: |
          mkdir -p $HOME/wasi-sdk
          curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-linux.tar.gz | tar -xzf - -C $HOME/wasi-sdk --strip-components=1
          echo "WASI_SDK_PATH=$HOME/wasi-sdk" >> $GITHUB_ENV

      - name: Build
        working-directory: example
        shell: bash
        run: |
          if [[ "${{ matrix.settings.target }}" == *"musl"* ]]; then
            yarn build --target ${{ matrix.settings.target }} -x
            yarn build --target ${{ matrix.settings.target }} -x --release
            yarn build --target ${{ matrix.settings.target }} -x --features v3
            yarn build --target ${{ matrix.settings.target }} -x --features v3 --release
          elif [[ "${{ matrix.settings.target }}" == *"gnu"* ]]; then
            export TARGET_CFLAGS="-fuse-ld=lld"
            export TARGET_CC=clang
            yarn build --target ${{ matrix.settings.target }} --use-napi-cross
            yarn build --target ${{ matrix.settings.target }} --use-napi-cross --release
            yarn build --target ${{ matrix.settings.target }} --use-napi-cross --features v3
            yarn build --target ${{ matrix.settings.target }} --use-napi-cross --features v3 --release
          elif [[ "${{ matrix.settings.target }}" == *"msvc"* ]]; then
            yarn build --target ${{ matrix.settings.target }}
            yarn build --target ${{ matrix.settings.target }} --release
            yarn build --target ${{ matrix.settings.target }} --features v3
            yarn build --target ${{ matrix.settings.target }} --features v3 --release
            mkdir -p .cargo
            echo "[target.${{ matrix.settings.target }}]" >> .cargo/config.toml
            echo "rustflags = [\"-C\", \"target-feature=+crt-static\"]" >> .cargo/config.toml
            yarn build --target ${{ matrix.settings.target }} --release
            yarn build --target ${{ matrix.settings.target }} --features v3 --release
          elif [[ "${{ matrix.settings.target }}" == *"wasm"* ]]; then
            yarn build --target ${{ matrix.settings.target }}
            yarn build --target ${{ matrix.settings.target }} --release
          else
            yarn build --target ${{ matrix.settings.target }}
            yarn build --target ${{ matrix.settings.target }} --release
            yarn build --target ${{ matrix.settings.target }} --features v3
            yarn build --target ${{ matrix.settings.target }} --features v3 --release
          fi