|
| 1 | +name: 'Build wheel' |
| 2 | +description: 'Build the Python wheels for release on all platforms' |
| 3 | + |
| 4 | +inputs: |
| 5 | + cmake-args: |
| 6 | + description: 'The args for generating CMake project' |
| 7 | + required: true |
| 8 | + build-frontend: |
| 9 | + description: 'Build the frontend mlx package' |
| 10 | + required: false |
| 11 | + default: 'true' |
| 12 | + build-backend: |
| 13 | + description: 'Build the backend mlx-cpu/mlx-cuda/mlx-metal packages' |
| 14 | + required: false |
| 15 | + default: 'true' |
| 16 | + macos-target: |
| 17 | + description: 'The target macOS version to build for' |
| 18 | + required: false |
| 19 | + default: '26.2' |
| 20 | + arch-tag: |
| 21 | + description: 'Platform architecture tag' |
| 22 | + required: false |
| 23 | + default: |- |
| 24 | + ${{ case(runner.arch == 'x64', 'x86_64', |
| 25 | + runner.arch == 'x86', 'i686', |
| 26 | + runner.arch == 'arm', 'armv7l', |
| 27 | + runner.arch == 'arm64', 'aarch64', |
| 28 | + 'unknown') |
| 29 | + }} |
| 30 | +
|
| 31 | +runs: |
| 32 | + using: 'composite' |
| 33 | + steps: |
| 34 | + - name: Install dependencies |
| 35 | + shell: bash |
| 36 | + run: | |
| 37 | + echo "::group::Install dependencies" |
| 38 | + uv pip install 'build<=1.4.2' setuptools |
| 39 | + if ${{ runner.os == 'Linux' }} ; then |
| 40 | + uv pip install auditwheel patchelf |
| 41 | + fi |
| 42 | + mkdir -p wheelhouse |
| 43 | + echo "::endgroup::" |
| 44 | +
|
| 45 | + - name: Build frontend package |
| 46 | + if: inputs.build-frontend == 'true' |
| 47 | + shell: bash |
| 48 | + env: |
| 49 | + CMAKE_ARGS: ${{ inputs.cmake-args }} |
| 50 | + MACOSX_DEPLOYMENT_TARGET: ${{ inputs.macos-target }} |
| 51 | + run: | |
| 52 | + echo "::group::Build frontend package" |
| 53 | + python setup.py clean --all |
| 54 | + MLX_BUILD_STAGE=1 python -m build -w |
| 55 | + echo "::endgroup::" |
| 56 | +
|
| 57 | + - name: Post-process frontend package |
| 58 | + if: inputs.build-frontend == 'true' |
| 59 | + shell: bash |
| 60 | + run: | |
| 61 | + echo "::group::Post-process frontend package" |
| 62 | + if ${{ runner.os == 'Linux' }} ; then |
| 63 | + auditwheel repair dist/mlx-*.whl \ |
| 64 | + --plat manylinux_2_35_${{ inputs.arch-tag }} \ |
| 65 | + --exclude libmlx.so* \ |
| 66 | + --only-plat |
| 67 | + else |
| 68 | + mv dist/mlx-*.whl wheelhouse/ |
| 69 | + fi |
| 70 | + echo "::endgroup::" |
| 71 | +
|
| 72 | + - name: Build backend package |
| 73 | + if: inputs.build-backend == 'true' |
| 74 | + shell: bash |
| 75 | + env: |
| 76 | + CMAKE_ARGS: ${{ inputs.cmake-args }} |
| 77 | + MACOSX_DEPLOYMENT_TARGET: ${{ inputs.macos-target }} |
| 78 | + run: | |
| 79 | + echo "::group::Build backend package" |
| 80 | + python setup.py clean --all |
| 81 | + MLX_BUILD_STAGE=2 python -m build -w |
| 82 | + echo "::endgroup::" |
| 83 | +
|
| 84 | + - name: Post-process backend package |
| 85 | + if: inputs.build-backend == 'true' |
| 86 | + shell: bash |
| 87 | + run: | |
| 88 | + echo "::group::Post-process backend package" |
| 89 | + if ${{ runner.os == 'Linux' }} ; then |
| 90 | + if [ -f dist/mlx_cpu*.whl ]; then |
| 91 | + auditwheel repair dist/mlx_cpu*.whl \ |
| 92 | + --plat manylinux_2_35_${{ inputs.arch-tag }} |
| 93 | + fi |
| 94 | + if [ -f dist/mlx_cuda*.whl ]; then |
| 95 | + auditwheel repair dist/mlx_cuda*.whl \ |
| 96 | + --plat manylinux_2_35_${{ inputs.arch-tag }} \ |
| 97 | + --exclude libcublas* \ |
| 98 | + --exclude libcuda* \ |
| 99 | + --exclude libcudnn* \ |
| 100 | + --exclude libcufft* \ |
| 101 | + --exclude libnccl* \ |
| 102 | + --exclude libnvrtc* |
| 103 | + fi |
| 104 | + else |
| 105 | + if [ -f dist/mlx_cpu*.whl ]; then |
| 106 | + mv dist/mlx_cpu*.whl wheelhouse/ |
| 107 | + fi |
| 108 | + if [ -f dist/mlx_cuda*.whl ]; then |
| 109 | + mv dist/mlx_cuda*.whl wheelhouse/ |
| 110 | + fi |
| 111 | + if [ -f dist/mlx_metal*.whl ]; then |
| 112 | + mv dist/mlx_metal*.whl wheelhouse/ |
| 113 | + fi |
| 114 | + fi |
| 115 | + echo "::endgroup::" |
0 commit comments