Skip to content

Commit 430ccd8

Browse files
committed
build bindings using llvm distro wheel
1 parent 3004d9f commit 430ccd8

File tree

7 files changed

+120
-107
lines changed

7 files changed

+120
-107
lines changed

.github/workflows/build_llvm.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,7 @@ jobs:
321321

322322
- name: "Save cache"
323323
uses: actions/cache/save@v3
324-
if: (!cancelled())
325-
# if: (!cancelled() && github.event_name == 'push' && github.ref_name == 'main')
324+
if: (!cancelled() && github.event_name == 'push' && github.ref_name == 'main')
326325
with:
327326
path: ${{ steps.setup_base.outputs.cache-dir }}
328327
key: ${{ env.cache-key }}
@@ -356,7 +355,7 @@ jobs:
356355

357356
call-build-python-bindings:
358357

359-
needs: [build]
358+
needs: [build, build-wasm]
360359

361360
permissions:
362361
contents: write

.github/workflows/build_mlir_python_bindings_wheel.yml

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ jobs:
7575
runs-on: "macos-14"
7676
os: "macos"
7777
host-arch: "arm64"
78-
# - name: "macos_x86_64"
79-
# runs-on: "macos-13"
80-
# os: "macos"
81-
# host-arch: "x86_64"
8278

8379
runs-on: ${{ matrix.runs-on }}
8480

@@ -112,20 +108,15 @@ jobs:
112108

113109
- name: "Download MLIR from releases"
114110
if: ${{ !inputs.workflow_call }}
115-
env:
116-
GH_TOKEN: ${{ github.token }}
117111
run: |
118112
119-
if [[ "${{ matrix.os }}" == "almalinux" ]] || [[ "${{ matrix.os }}" == "ubuntu" ]]; then
120-
export RELEASE_PREFIX="mlir_manylinux_${{ matrix.host-arch }}"
121-
else
122-
export RELEASE_PREFIX="mlir_${{ matrix.name }}"
123-
fi
124-
RELEASE_URL=$(gh release view llvm --json assets -q '.assets |= sort_by(.createdAt) | .assets | map(select(.name | contains(env.RELEASE_PREFIX))) | .[-1] | .url')
125-
curl -sLO $RELEASE_URL
126-
RELEASE_NAME="$RELEASE_PREFIX*.tar.gz"
127-
tar xf $RELEASE_NAME
128-
echo WHEEL_VERSION="$(echo $RELEASE_NAME | sed "s/${RELEASE_PREFIX}_//g" | sed "s/.tar.gz//g" | sed "s/_/+/g" | sed "s/%2B/+/g" )" >> $GITHUB_ENV
113+
pip download mlir-wheel -f https://llvm.github.io/eudsl
114+
unzip mlir_wheel*.whl -d llvm-install
115+
116+
WHEEL_NAME=$(ls mlir_wheel*)
117+
pip install pkginfo
118+
WHEEL_VERSION=$($python3_command -c "from pkginfo import Wheel; print(Wheel('$WHEEL_NAME').version)")
119+
echo "WHEEL_VERSION=$WHEEL_VERSION" >> $GITHUB_ENV
129120
130121
- name: Download LLVM distro artifacts
131122
if: ${{ inputs.workflow_call }}
@@ -138,8 +129,7 @@ jobs:
138129
- name: "Set WHEEL_VERSION env var"
139130
if: ${{ inputs.workflow_call }}
140131
run: |
141-
WHEEL_VERSION="${{ inputs.wheel_version }}"
142-
echo "WHEEL_VERSION=${WHEEL_VERSION/_/+}" >> $GITHUB_ENV
132+
echo "WHEEL_VERSION=${{ inputs.wheel_version }}" >> $GITHUB_ENV
143133
144134
- name: "Configure build"
145135
run: |
@@ -166,10 +156,6 @@ jobs:
166156
if [[ "${{ matrix.os }}" == "macos" ]]; then
167157
brew install antlr boost libarchive
168158
fi
169-
if [[ "${{ matrix.runs-on }}" == "macos-13" ]]; then
170-
sudo xcode-select -s /Library/Developer/CommandLineTools
171-
echo "SDKROOT=$(xcrun --show-sdk-path)" >> $GITHUB_ENV
172-
fi
173159
174160
- name: "Build mlir-python-bindings"
175161
run: |
@@ -202,7 +188,6 @@ jobs:
202188
runs-on: [
203189
"ubuntu-22.04",
204190
"ubuntu-22.04-arm",
205-
# "macos-13",
206191
"macos-14",
207192
"windows-2022"
208193
]
@@ -215,7 +200,6 @@ jobs:
215200
{runs-on: "ubuntu-22.04-arm", name: "ubuntu_aarch64", os: "ubuntu"},
216201
{runs-on: "windows-2022", name: "windows_amd64", os: "windows"},
217202
{runs-on: "macos-14", name: "macos_arm64", os: "macos"},
218-
# {runs-on: "macos-13", name: "macos_x86_64", os: "macos"}
219203
]
220204
exclude:
221205
# <frozen importlib._bootstrap>:491: Warning: Numpy built with MINGW-W64 on Windows 64 bits is experimental, and only available for testing. You are advised not to use it for production.
@@ -225,12 +209,6 @@ jobs:
225209
- runs-on: windows-2022
226210
python-version: "3.14t"
227211

228-
- runs-on: macos-13
229-
python-version: "3.13"
230-
231-
- runs-on: macos-13
232-
python-version: "3.14t"
233-
234212
- runs-on: macos-14
235213
python-version: "3.10"
236214

@@ -366,6 +344,33 @@ jobs:
366344
host-arch: "x86_64"
367345
target-arch: "wasm32"
368346

347+
- name: "Pip download MLIR from releases"
348+
if: ${{ !inputs.workflow_call }}
349+
run: |
350+
351+
pip download mlir-wheel --plat pyodide_2024_0_wasm32 --no-deps --python-version 3.12 -f https://llvm.github.io/eudsl
352+
unzip mlir_wheel*.whl -d llvm-install
353+
echo "CMAKE_PREFIX_PATH=$PWD" >> $GITHUB_ENV
354+
355+
WHEEL_NAME=$(ls mlir_wheel*)
356+
pip install pkginfo
357+
WHEEL_VERSION=$($python3_command -c "from pkginfo import Wheel; print(Wheel('$WHEEL_NAME').version)")
358+
echo "WHEEL_VERSION=$WHEEL_VERSION" >> $GITHUB_ENV
359+
360+
- name: Download LLVM distro artifacts
361+
if: ${{ inputs.workflow_call }}
362+
uses: dawidd6/action-download-artifact@v11
363+
with:
364+
name: mlir_${{ matrix.os == 'ubuntu' && 'manylinux' || matrix.os }}_${{ matrix.host-arch }}_artifact
365+
path: "./"
366+
run_id: ${{ inputs.workflow_caller_run_id }}
367+
368+
- name: "Set WHEEL_VERSION env var"
369+
if: ${{ inputs.workflow_call }}
370+
run: |
371+
echo "WHEEL_VERSION=${{ inputs.wheel_version }}" >> $GITHUB_ENV
372+
373+
369374
- name: Download mlir-native-tools artifacts
370375
if: ${{ inputs.workflow_call }}
371376
uses: dawidd6/action-download-artifact@v11
@@ -380,28 +385,22 @@ jobs:
380385
381386
pip download mlir_native_tools -f https://llvm.github.io/eudsl
382387
383-
- name: Configure mlir-native-tools
388+
- name: "Configure build"
384389
run: |
385390
391+
echo "LLVM_DIR=$PWD/llvm-install/lib/cmake/llvm" >> $GITHUB_ENV
392+
echo "MLIR_DIR=$PWD/llvm-install/lib/cmake/mlir" >> $GITHUB_ENV
393+
echo "Clang_DIR=$PWD/llvm-install/lib/cmake/clang" >> $GITHUB_ENV
394+
echo "CMAKE_PREFIX_PATH=$PWD/llvm-install" >> $GITHUB_ENV
395+
386396
unzip -o -j mlir_native_tools-*whl -d mlir_native_tools
387397
rm -rf mlir_native_tools-*whl
388-
389398
export LLVM_NATIVE_TOOL_DIR="$PWD/mlir_native_tools"
390399
echo "LLVM_NATIVE_TOOL_DIR=$LLVM_NATIVE_TOOL_DIR" >> $GITHUB_ENV
391400
echo "LLVM_TABLEGEN=$LLVM_NATIVE_TOOL_DIR/llvm-tblgen" >> $GITHUB_ENV
392401
echo "MLIR_TABLEGEN=$LLVM_NATIVE_TOOL_DIR/mlir-tblgen" >> $GITHUB_ENV
393402
echo "MLIR_LINALG_ODS_YAML_GEN=$LLVM_NATIVE_TOOL_DIR/mlir-linalg-ods-yaml-gen" >> $GITHUB_ENV
394403
395-
- name: Wheel version
396-
run: |
397-
398-
pushd third_party/llvm-project
399-
LLVM_PROJECT_COMMIT=$(git rev-parse --short HEAD)
400-
popd
401-
402-
DATETIME=$(date +"%Y%m%d%H")
403-
echo "WHEEL_VERSION=${DATETIME}+${LLVM_PROJECT_COMMIT}" >> $GITHUB_ENV
404-
405404
- name: build wasm python wheel
406405
run: |
407406

.github/workflows/build_test_release_eudsl.yml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ jobs:
7676
runs-on: "macos-14"
7777
os: "macos"
7878
host-arch: "arm64"
79-
# - name: "macos_x86_64"
80-
# runs-on: "macos-13"
81-
# os: "macos"
82-
# host-arch: "x86_64"
8379

8480
runs-on: ${{ matrix.runs-on }}
8581

@@ -158,14 +154,6 @@ jobs:
158154
if [[ "${{ matrix.os }}" == "macos" ]]; then
159155
brew install antlr boost libarchive
160156
fi
161-
if [[ "${{ matrix.runs-on }}" == "macos-13" ]]; then
162-
sudo xcode-select -s /Library/Developer/CommandLineTools
163-
echo "SDKROOT=$(xcrun --show-sdk-path)" >> $GITHUB_ENV
164-
# https://github.com/pthom/srcml_caller/blob/a6431edf9ae4ab2aa19b78b5a4682ae3510b199c/setup.py#L38
165-
# very dumb
166-
cibw_dir="$(dirname $($python3_command -c "import cibuildwheel; import inspect; print(inspect.getfile(cibuildwheel))"))"
167-
sed -i.bak 's/CIBUILDWHEEL/__CIBUILDWHEEL__/g' "$cibw_dir/__main__.py"
168-
fi
169157
170158
$python3_command -m pip install -r requirements-dev.txt -v
171159
@@ -274,7 +262,6 @@ jobs:
274262
fail-fast: false
275263
matrix:
276264
runs-on: ["ubuntu-22.04", "ubuntu-22.04-arm",
277-
# "macos-13",
278265
"macos-14", "windows-2022"]
279266
python-version: [
280267
"3.10", "3.11", "3.12",
@@ -285,12 +272,8 @@ jobs:
285272
{runs-on: "ubuntu-22.04-arm", name: "ubuntu_aarch64", os: "ubuntu"},
286273
{runs-on: "windows-2022", name: "windows_amd64", os: "windows"},
287274
{runs-on: "macos-14", name: "macos_arm64", os: "macos"},
288-
# {runs-on: "macos-13", name: "macos_x86_64", os: "macos"}
289275
]
290276
exclude:
291-
- runs-on: macos-13
292-
python-version: "3.13"
293-
294277
- runs-on: macos-14
295278
python-version: "3.10"
296279

@@ -359,7 +342,6 @@ jobs:
359342
"ubuntu-22.04",
360343
"ubuntu-22.04-arm",
361344
"macos-14",
362-
# "macos-13",
363345
"windows-2022"
364346
]
365347
python-version: [
@@ -374,12 +356,8 @@ jobs:
374356
{runs-on: "ubuntu-22.04-arm", name: "ubuntu_aarch64", os: "ubuntu"},
375357
{runs-on: "windows-2022", name: "windows_amd64", os: "windows"},
376358
{runs-on: "macos-14", name: "macos_arm64", os: "macos"},
377-
# {runs-on: "macos-13", name: "macos_x86_64", os: "macos"}
378359
]
379360
exclude:
380-
- runs-on: macos-13
381-
python-version: "3.13"
382-
383361
- runs-on: macos-14
384362
python-version: "3.10"
385363

.github/workflows/build_test_release_eudsl_python_extras.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ jobs:
9191
runs-on: [
9292
"ubuntu-22.04",
9393
"ubuntu-22.04-arm",
94-
# "macos-13",
9594
"macos-14",
9695
"windows-2022"
9796
]
@@ -104,7 +103,6 @@ jobs:
104103
{runs-on: "ubuntu-22.04-arm", name: "ubuntu_aarch64", os: "ubuntu"},
105104
{runs-on: "windows-2022", name: "windows_amd64", os: "windows"},
106105
{runs-on: "macos-14", name: "macos_arm64", os: "macos"},
107-
# {runs-on: "macos-13", name: "macos_x86_64", os: "macos"}
108106
]
109107
exclude:
110108
# <frozen importlib._bootstrap>:491: Warning: Numpy built with MINGW-W64 on Windows 64 bits is experimental, and only available for testing. You are advised not to use it for production.
@@ -114,12 +112,6 @@ jobs:
114112
- runs-on: windows-2022
115113
python-version: "3.14t"
116114

117-
- runs-on: macos-13
118-
python-version: "3.14"
119-
120-
- runs-on: macos-13
121-
python-version: "3.14t"
122-
123115
- runs-on: macos-14
124116
python-version: "3.10"
125117

projects/mlir-python-bindings-wasm/CMakeLists.txt

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,70 @@
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
# Copyright (c) 2025.
55

6-
include_directories(${LLVM_SOURCE_DIR}/include)
7-
include_directories(${LLVM_EXTERNAL_MLIR_SOURCE_DIR}/include)
8-
include_directories(${LLVM_BINARY_DIR}/include)
9-
include_directories(${LLVM_BINARY_DIR}/tools/mlir/include)
6+
cmake_minimum_required(VERSION 3.29)
7+
project(mlir-python-bindings-wasm LANGUAGES CXX C)
108

11-
add_mlir_upstream_c_api_library(WasmCompilerLinkerLoaderCAPI
9+
set(CMAKE_CXX_STANDARD 17)
10+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
11+
set(CMAKE_CXX_EXTENSIONS OFF)
12+
13+
if(POLICY CMP0068)
14+
cmake_policy(SET CMP0068 NEW)
15+
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
16+
endif()
17+
18+
if(POLICY CMP0075)
19+
cmake_policy(SET CMP0075 NEW)
20+
endif()
21+
22+
if(POLICY CMP0077)
23+
cmake_policy(SET CMP0077 NEW)
24+
endif()
25+
26+
if(POLICY CMP0091)
27+
cmake_policy(SET CMP0091 NEW)
28+
endif()
29+
30+
if(POLICY CMP0116)
31+
cmake_policy(SET CMP0116 NEW)
32+
endif()
33+
34+
if(POLICY CMP0135)
35+
cmake_policy(SET CMP0116 OLD)
36+
endif()
37+
38+
find_package(MLIR REQUIRED CONFIG)
39+
find_package(LLD REQUIRED CONFIG)
40+
41+
message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
42+
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
43+
message(STATUS "Using LLDConfig.cmake in: ${LLD_DIR}")
44+
45+
set(MLIR_BINDINGS_PYTHON_NB_DOMAIN "mlir" CACHE STRING "")
46+
set(MLIR_PYTHON_PACKAGE_PREFIX "mlir" CACHE STRING "")
47+
48+
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/bin)
49+
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/lib)
50+
51+
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
52+
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
53+
include(TableGen)
54+
include(AddLLVM)
55+
include(AddMLIR)
56+
include(AddMLIRPython)
57+
include(MLIRDetectPythonEnv)
58+
include(HandleLLVMOptions)
59+
60+
include_directories(${LLVM_INCLUDE_DIRS})
61+
include_directories(${MLIR_INCLUDE_DIRS})
62+
link_directories(${LLVM_BUILD_LIBRARY_DIR})
63+
add_definitions(${LLVM_DEFINITIONS})
64+
65+
add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=${MLIR_PYTHON_PACKAGE_PREFIX}.")
66+
67+
mlir_configure_python_dev_packages()
68+
69+
add_mlir_public_c_api_library(WasmCompilerLinkerLoaderCAPI
1270
WasmCompilerLinkerLoaderCAPI.cpp
1371

1472
PARTIAL_SOURCES_INTENDED
@@ -61,16 +119,12 @@ add_mlir_python_common_capi_library(MLIRPythonWasmCAPI
61119
# The fully assembled package of modules. This must come last.
62120
# ##############################################################################
63121

64-
set(_declared_sources MLIRPythonSources MLIRPythonExtension.RegisterEverything)
65-
if(NOT CMAKE_CROSSCOMPILING)
66-
list(APPEND _declared_sources MLIRPythonExtension.Core.type_stub_gen)
67-
endif()
68-
69122
add_mlir_python_modules(MLIRPythonWasmModules
70123
ROOT_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/mlir"
71124
INSTALL_PREFIX "mlir"
72125
DECLARED_SOURCES
73-
${_declared_sources}
126+
MLIRPythonSources
127+
MLIRPythonExtension.RegisterEverything
74128
COMMON_CAPI_LINK_LIBS
75129
MLIRPythonWasmCAPI
76130
)
@@ -100,3 +154,5 @@ install(
100154
LIBRARY DESTINATION "mlir/_mlir_libs"
101155
COMPONENT MLIRPythonWasmModules
102156
)
157+
158+
message(STATUS "CMAKE_GENERATOR=${CMAKE_GENERATOR}")

0 commit comments

Comments
 (0)