name: Build Native Dependencies description: Build zlib as needed inputs: deps: description: Space-separated list of deps to build (zlib) required: true prefix: description: Install prefix required: true cc: description: C compiler required: true cxx: description: C++ compiler required: false default: '' ar: description: AR tool required: false default: ar ranlib: description: RANLIB tool required: false default: ranlib cmake_generator: description: CMake generator (Ninja, MinGW Makefiles, etc) required: false default: '' zlib_version: required: true runs: using: composite steps: - name: Compute deps hash id: deps-hash shell: bash run: echo "hash=$(echo '${{ inputs.deps }}' | tr ' ' '-')" >> $GITHUB_OUTPUT - name: Cache native deps id: cache uses: actions/cache@v5 with: path: ${{ inputs.prefix }} key: deps-${{ runner.os }}-${{ runner.arch }}-${{ steps.deps-hash.outputs.hash }}-${{ hashFiles('.github/versions.json') }}-v1 - name: Prepare build environment id: prep if: steps.cache.outputs.cache-hit != 'true' shell: bash run: | if [[ "$RUNNER_OS" == "Windows" ]]; then PREFIX=$(cygpath -m "${{ inputs.prefix }}") else PREFIX="${{ inputs.prefix }}" fi echo "prefix=$PREFIX" >> $GITHUB_OUTPUT mkdir -p "$PREFIX" - name: Build zlib if: steps.cache.outputs.cache-hit != 'true' && contains(inputs.deps, 'zlib') shell: bash run: | if [[ "$RUNNER_OS" == "Windows" ]]; then export PATH="$(cygpath "$RUNNER_TEMP/msys64/clang64/bin"):$PATH" fi git clone --depth 1 --branch v${{ inputs.zlib_version }} https://github.com/madler/zlib.git /tmp/zlib cd /tmp/zlib CMAKE_GENERATOR="${{ inputs.cmake_generator }}" if [[ "$RUNNER_OS" != "macOS" ]]; then export AR="${{ inputs.ar }}" export RANLIB="${{ inputs.ranlib }}" fi CMAKE_ARGS="-DCMAKE_C_COMPILER=${{ inputs.cc }}" if [[ "$RUNNER_OS" == "Windows" ]]; then AR_PATH="$(which ${{ inputs.ar }})" RANLIB_PATH="$(which ${{ inputs.ranlib }})" CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_AR=$AR_PATH -DCMAKE_RANLIB=$RANLIB_PATH" fi if [[ -n "${{ inputs.cxx }}" ]]; then CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CXX_COMPILER=${{ inputs.cxx }}" fi cmake -B build \ ${CMAKE_GENERATOR:+-G "$CMAKE_GENERATOR"} \ $CMAKE_ARGS \ -DCMAKE_INSTALL_PREFIX=${{ steps.prep.outputs.prefix }} \ -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_BUILD_TYPE=MinSizeRel cmake --build build cmake --install build rm -f ${{ steps.prep.outputs.prefix }}/lib/libz.so* 2>/dev/null || true