Skip to content

Commit e165efd

Browse files
authored
[MLIR] add mlir-native-tools wheel (#196)
1 parent 16b8eb8 commit e165efd

3 files changed

Lines changed: 79 additions & 4 deletions

File tree

.github/workflows/build_llvm.yml

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,16 @@ jobs:
136136
export LLVM_BUILD_DIR="$PWD/llvm-build"
137137
# double nested so that upload artifacts uploads a folder
138138
export LLVM_INSTALL_DIR="$PWD/llvm-install/llvm-install"
139+
pushd $LLVM_SOURCE_DIR && LLVM_SHA_SHORT="$(git rev-parse --short HEAD)" && popd
140+
export WHEEL_VERSION="$(date +'%Y%m%d')_$LLVM_SHA_SHORT"
139141
140142
ccache -z
141143
$python3_command -m pip install -r third_party/llvm-project/mlir/python/requirements.txt
144+
$python3_command -m pip install setuptools wheel
142145
146+
###############################
147+
# Build MLIR/LLVM distro
148+
###############################
143149
if [[ "${{ matrix.arch }}" == "wasm32-wasi" ]]; then
144150
scripts/build_llvm_wasi.sh
145151
else
@@ -150,17 +156,49 @@ jobs:
150156
fi
151157
ccache -s
152158
153-
pushd $LLVM_SOURCE_DIR && LLVM_SHA_SHORT=$(git rev-parse --short HEAD) && popd
154-
tar -czf mlir_${{ matrix.name }}_$(date +'%Y%m%d')_$LLVM_SHA_SHORT.tar.gz -C "$LLVM_INSTALL_DIR/.." llvm-install
159+
###############################
160+
# Build mlir-native-tools wheel
161+
###############################
162+
for TOOL in "llvm-tblgen" "mlir-tblgen" "mlir-linalg-ods-yaml-gen" "mlir-pdll" "llvm-config" "FileCheck"; do
163+
if [ x"${{ matrix.os }}" == x"windows" ]; then
164+
TOOL="$TOOL.exe"
165+
fi
166+
cp "$LLVM_INSTALL_DIR/bin/$TOOL" projects/mlir-native-tools
167+
done
168+
169+
if [ x"${{ matrix.os }}" == x"almalinux" ] || [ x"${{ matrix.os }}" == x"ubuntu" ]; then
170+
PLAT="linux"
171+
elif [ x"${{ matrix.os }}" == x"macos" ]; then
172+
PLAT="macosx_12_0"
173+
elif [ x"${{ matrix.os }}" == x"windows" ]; then
174+
PLAT="win"
175+
fi
176+
PLAT="${PLAT}_$(echo ${{ matrix.arch }} | tr '[:upper:]' '[:lower:]')"
177+
178+
pushd projects/mlir-native-tools
179+
$python3_command setup.py bdist_wheel --dist-dir ../../wheelhouse --plat $PLAT
180+
popd
181+
182+
###############################
183+
# Tar up MLIR/LLVM distro
184+
###############################
185+
tar -czf "mlir_${{ matrix.name }}_$WHEEL_VERSION.tar.gz" -C "$LLVM_INSTALL_DIR/.." llvm-install
155186
rm -rf "$LLVM_BUILD_DIR" "$LLVM_SOURCE_DIR"
156187
157-
- name: Upload artifacts
188+
- name: Upload LLVM distro artifacts
158189
uses: actions/upload-artifact@v4
159190
with:
160191
name: mlir_${{ matrix.name }}_artifact
161192
path: llvm-install
162193
if-no-files-found: warn
163194

195+
- name: Upload mlir-native-tools artifact
196+
uses: actions/upload-artifact@v4
197+
with:
198+
name: mlir_native_tools_${{ matrix.name }}_artifact
199+
path: wheelhouse
200+
if-no-files-found: warn
201+
164202
- name: Upload ccache log
165203
uses: actions/upload-artifact@v4
166204
with:
@@ -171,7 +209,7 @@ jobs:
171209
if: (!cancelled() && ((github.event_name == 'push' && github.ref_name == 'main') || github.event_name == 'workflow_dispatch'))
172210
uses: ncipollo/[email protected]
173211
with:
174-
artifacts: "*.tar.gz"
212+
artifacts: "*.tar.gz,wheelhouse/*.whl"
175213
token: "${{ secrets.GITHUB_TOKEN }}"
176214
tag: "llvm"
177215
name: "llvm"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
import os
5+
import platform
6+
7+
from setuptools import setup
8+
9+
10+
def get_exe_suffix():
11+
if platform.system() == "Windows":
12+
suffix = ".exe"
13+
else:
14+
suffix = ""
15+
return suffix
16+
17+
18+
version = os.environ.get("WHEEL_VERSION", "0.0.0+DEADBEEF").replace("_", "+")
19+
20+
data_files = []
21+
for bin in [
22+
"FileCheck",
23+
"llvm-config",
24+
"llvm-tblgen",
25+
"mlir-linalg-ods-yaml-gen",
26+
"mlir-pdll",
27+
"mlir-tblgen",
28+
]:
29+
data_files.append(bin + get_exe_suffix())
30+
31+
setup(
32+
version=version,
33+
name="mlir-native-tools",
34+
include_package_data=True,
35+
data_files=[("bin", data_files)],
36+
)

scripts/cmake/llvm_cache.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ set(LLVM_MlirDevelopment_DISTRIBUTION_COMPONENTS
108108
mlir-libraries
109109
mlir-linalg-ods-yaml-gen
110110
mlir-opt
111+
mlir-pdll
111112
mlir-python-sources
112113
mlir-reduce
113114
mlir-tblgen

0 commit comments

Comments
 (0)