blob: 8204e820e25163d2f81849fb7011203ddf54752e [file] [log] [blame]
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -07001# Copyright 2021 The IREE Authors
2#
3# Licensed under the Apache License v2.0 with LLVM Exceptions.
4# See https://llvm.org/LICENSE.txt for license information.
5# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
Scott Todd57b92392023-08-10 20:13:49 -07007# Build/install the iree-compiler python package.
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -07008# Note that this includes a relatively large build of LLVM (~2400 C++ files)
9# and can take a considerable amount of time, especially with defaults.
10# To install:
11# pip install .
12# To build a wheel:
13# pip wheel .
14#
15# It is recommended to build with Ninja and ccache. To do so, set environment
16# variables by prefixing to above invocations:
17# CMAKE_C_COMPILER_LAUNCHER=ccache CMAKE_CXX_COMPILER_LAUNCHER=ccache
18#
19# On CIs, it is often advantageous to re-use/control the CMake build directory.
20# This can be set with the IREE_COMPILER_API_CMAKE_BUILD_DIR env var.
21#
22# Select CMake options are available from environment variables:
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -070023# IREE_ENABLE_CPUINFO
24
25from gettext import install
26import json
27from multiprocessing.spawn import prepare
28import os
29import platform
30import re
31import shutil
32import subprocess
33import sys
34import sysconfig
35
36from distutils.command.build import build as _build
37from setuptools import find_namespace_packages, setup, Extension
38from setuptools.command.build_ext import build_ext as _build_ext
39from setuptools.command.build_py import build_py as _build_py
40
41
42def check_pip_version():
Jakub Kuderskibe24f022023-06-21 14:44:18 -040043 from packaging import version
44
45 # Pip versions < 22.0.3 default to out of tree builds, which is quite
46 # incompatible with what we do (and has other issues). Pip >= 22.0.4
47 # removed this option entirely and are only in-tree builds. Since the
48 # old behavior can silently produce unworking installations, we aggressively
49 # suppress it.
50 try:
51 import pip
52 except ModuleNotFoundError:
53 # If pip not installed, we are obviously not trying to package via pip.
54 pass
55 else:
56 if version.parse(pip.__version__) < version.parse("21.3"):
57 print("ERROR: pip version >= 21.3 required")
58 print("Upgrade: pip install pip --upgrade")
59 sys.exit(2)
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -070060
61
62check_pip_version()
63
64# This file can be run directly from the source tree or it can be CMake
65# configured so it can run from the build tree with an already existing
66# build tree. We detect the difference based on whether the following
67# are expanded by CMake.
68CONFIGURED_SOURCE_DIR = "@IREE_SOURCE_DIR@"
69CONFIGURED_BINARY_DIR = "@IREE_BINARY_DIR@"
70
71IREE_SOURCE_DIR = None
72IREE_BINARY_DIR = None
73
74# We must do the intermediate installation to a fixed location that agrees
75# between what we pass to setup() and cmake. So hard-code it here.
76# Note that setup() needs a relative path (to the setup.py file).
Scott Todd31738a82023-08-08 18:00:38 -070077# We keep the path short ('i' instead of 'install') for platforms like Windows
78# that have file length limits.
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -070079SETUPPY_DIR = os.path.realpath(os.path.dirname(__file__))
Scott Todd31738a82023-08-08 18:00:38 -070080CMAKE_INSTALL_DIR_REL = os.path.join("build", "i")
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -070081CMAKE_INSTALL_DIR_ABS = os.path.join(SETUPPY_DIR, CMAKE_INSTALL_DIR_REL)
82
83IS_CONFIGURED = CONFIGURED_SOURCE_DIR[0] != "@"
84if IS_CONFIGURED:
Jakub Kuderskibe24f022023-06-21 14:44:18 -040085 IREE_SOURCE_DIR = CONFIGURED_SOURCE_DIR
86 IREE_BINARY_DIR = CONFIGURED_BINARY_DIR
87 print(
88 f"Running setup.py from build tree: "
89 f"SOURCE_DIR = {IREE_SOURCE_DIR} "
90 f"BINARY_DIR = {IREE_BINARY_DIR}",
91 file=sys.stderr,
92 )
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -070093else:
Jakub Kuderskibe24f022023-06-21 14:44:18 -040094 IREE_SOURCE_DIR = os.path.join(SETUPPY_DIR, "..")
95 IREE_BINARY_DIR = os.getenv("IREE_COMPILER_API_CMAKE_BUILD_DIR")
96 if not IREE_BINARY_DIR:
97 # Note that setuptools always builds into a "build" directory that
98 # is a sibling of setup.py, so we just colonize a sub-directory of that
99 # by default.
Scott Todd31738a82023-08-08 18:00:38 -0700100 IREE_BINARY_DIR = os.path.join(SETUPPY_DIR, "build", "b")
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400101 print(
102 f"Running setup.py from source tree: "
103 f"SOURCE_DIR = {IREE_SOURCE_DIR} "
104 f"BINARY_DIR = {IREE_BINARY_DIR}",
105 file=sys.stderr,
106 )
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700107
108# Setup and get version information.
109VERSION_INFO_FILE = os.path.join(IREE_SOURCE_DIR, "version_info.json")
110
111
112def load_version_info():
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400113 with open(VERSION_INFO_FILE, "rt") as f:
114 return json.load(f)
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700115
116
117def find_git_versions():
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400118 revisions = {}
119 try:
120 revisions["IREE"] = (
121 subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=IREE_SOURCE_DIR)
122 .decode("utf-8")
123 .strip()
124 )
125 except subprocess.SubprocessError as e:
126 print(f"ERROR: Could not get IREE revision: {e}", file=sys.stderr)
127 return revisions
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700128
129
130def find_git_submodule_revision(submodule_path):
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400131 try:
132 data = (
133 subprocess.check_output(
134 ["git", "ls-tree", "HEAD", submodule_path], cwd=IREE_SOURCE_DIR
135 )
136 .decode("utf-8")
137 .strip()
138 )
139 columns = re.split("\\s+", data)
140 return columns[2]
141 except Exception as e:
142 print(
143 f"ERROR: Could not get submodule revision for {submodule_path}" f" ({e})",
144 file=sys.stderr,
145 )
146 return ""
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700147
148
149try:
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400150 version_info = load_version_info()
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700151except FileNotFoundError:
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400152 print("version_info.json not found. Using defaults", file=sys.stderr)
153 version_info = {}
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700154git_versions = find_git_versions()
155
156PACKAGE_SUFFIX = version_info.get("package-suffix") or ""
157PACKAGE_VERSION = version_info.get("package-version")
158if not PACKAGE_VERSION:
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400159 PACKAGE_VERSION = f"0.dev0+{git_versions.get('IREE') or '0'}"
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700160
161
Stella Laurenzo585d3872023-04-20 20:54:11 -0700162def get_cmake_version_info_args():
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400163 version_info_args = [
164 f"-DIREE_RELEASE_VERSION:STRING={PACKAGE_VERSION}",
165 f"-DIREE_RELEASE_REVISION:STRING={git_versions.get('IREE') or '0'}",
166 ]
167 if version_info:
168 version_info_args.append("-DIREE_EMBEDDED_RELEASE_INFO=ON")
169 return version_info_args
Stella Laurenzo585d3872023-04-20 20:54:11 -0700170
171
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700172def maybe_nuke_cmake_cache():
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400173 # From run to run under pip, we can end up with different paths to ninja,
174 # which isn't great and will confuse cmake. Detect if the location of
175 # ninja changes and force a cache flush.
176 ninja_path = ""
177 try:
178 import ninja
179 except ModuleNotFoundError:
180 pass
181 else:
182 ninja_path = ninja.__file__
183 expected_stamp_contents = f"{sys.executable}\n{ninja_path}"
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700184
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400185 # In order to speed things up on CI and not rebuild everything, we nuke
186 # the CMakeCache.txt file if the path to the Python interpreter changed.
187 # Ideally, CMake would let us reconfigure this dynamically... but it does
188 # not (and gets very confused).
189 # We only do this because the compiler is so expensive to build and very
190 # little of it depends on the Python version. This is a hack.
191 PYTHON_STAMP_FILE = os.path.join(IREE_BINARY_DIR, "python_stamp.txt")
192 if os.path.exists(PYTHON_STAMP_FILE):
193 with open(PYTHON_STAMP_FILE, "rt") as f:
194 actual_stamp_contents = f.read()
195 if actual_stamp_contents == expected_stamp_contents:
196 # All good.
197 return
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700198
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400199 # Mismatch or not found. Clean it.
200 cmake_cache_file = os.path.join(IREE_BINARY_DIR, "CMakeCache.txt")
201 if os.path.exists(cmake_cache_file):
202 print("Removing CMakeCache.txt because Python version changed", file=sys.stderr)
203 os.remove(cmake_cache_file)
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700204
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400205 # Also clean the install directory. This avoids version specific pileups
206 # of binaries that can occur with repeated builds against different
207 # Python versions.
208 if os.path.exists(CMAKE_INSTALL_DIR_ABS):
209 print(
210 f"Removing CMake install dir because Python version changed: "
211 f"{CMAKE_INSTALL_DIR_ABS}",
212 file=sys.stderr,
213 )
214 shutil.rmtree(CMAKE_INSTALL_DIR_ABS)
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700215
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400216 # And write.
217 with open(PYTHON_STAMP_FILE, "wt") as f:
218 f.write(expected_stamp_contents)
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700219
220
maxbartelc7351e12024-09-12 11:30:26 +0200221def get_env_cmake_option(name: str, default_value: str = "OFF") -> str:
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400222 svalue = os.getenv(name)
223 if not svalue:
maxbartelc7351e12024-09-12 11:30:26 +0200224 svalue = default_value
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400225 return f"-D{name}={svalue}"
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700226
227
228def add_env_cmake_setting(args, env_name: str, cmake_name=None) -> str:
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400229 svalue = os.getenv(env_name)
230 if svalue is not None:
231 if not cmake_name:
232 cmake_name = env_name
233 args.append(f"-D{cmake_name}={svalue}")
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700234
235
236def prepare_installation():
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400237 version_py_content = generate_version_py()
238 print(f"Generating version.py:\n{version_py_content}", file=sys.stderr)
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700239
Stella Laurenzoc003beb2023-07-19 13:19:14 -0700240 cfg = os.getenv("IREE_CMAKE_BUILD_TYPE", "Release")
241 strip_install = cfg == "Release"
242
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400243 if not IS_CONFIGURED:
244 # Build from source tree.
245 subprocess.check_call(["cmake", "--version"])
246 os.makedirs(IREE_BINARY_DIR, exist_ok=True)
247 maybe_nuke_cmake_cache()
248 print(f"CMake build dir: {IREE_BINARY_DIR}", file=sys.stderr)
249 print(f"CMake install dir: {CMAKE_INSTALL_DIR_ABS}", file=sys.stderr)
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400250 cmake_args = [
251 "-GNinja",
252 "--log-level=VERBOSE",
253 "-DIREE_BUILD_PYTHON_BINDINGS=ON",
Scott Todd57b92392023-08-10 20:13:49 -0700254 "-DIREE_BUILD_SAMPLES=OFF",
255 "-DIREE_BUILD_TESTS=OFF",
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400256 # Disable .so.0 style symlinking. Python wheels don't preserve links,
257 # so this ~doubles the binary size if not disabled (yikes!).
258 "-DCMAKE_PLATFORM_NO_VERSIONED_SONAME=ON",
259 "-DPython3_EXECUTABLE={}".format(sys.executable),
260 "-DCMAKE_BUILD_TYPE={}".format(cfg),
Ben Vanikeeda5ca2024-02-27 14:18:32 -0800261 # TODO(scotttodd): include IREE_TARGET_BACKEND_WEBGPU_SPIRV here (and in env)
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400262 get_env_cmake_option("IREE_ENABLE_CPUINFO", "ON"),
maxbartelf2bf6022024-09-04 17:53:38 +0200263 get_env_cmake_option("IREE_TARGET_BACKEND_ROCM", "OFF"),
264 get_env_cmake_option("IREE_TARGET_BACKEND_CUDA", "OFF"),
Stanley Winataebdb0982023-10-15 18:21:47 -0700265 get_env_cmake_option("IREE_ENABLE_LLD", "OFF"),
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400266 ]
267 cmake_args.extend(get_cmake_version_info_args())
268
269 # These usually flow through the environment, but we add them explicitly
270 # so that they show clearly in logs (getting them wrong can have bad
271 # outcomes).
272 add_env_cmake_setting(cmake_args, "CMAKE_OSX_ARCHITECTURES")
273 add_env_cmake_setting(
274 cmake_args, "MACOSX_DEPLOYMENT_TARGET", "CMAKE_OSX_DEPLOYMENT_TARGET"
275 )
276
277 # Only do a from-scratch configure if not already configured.
278 cmake_cache_file = os.path.join(IREE_BINARY_DIR, "CMakeCache.txt")
279 if not os.path.exists(cmake_cache_file):
280 print(f"Configuring with: {cmake_args}", file=sys.stderr)
281 subprocess.check_call(
282 ["cmake", IREE_SOURCE_DIR] + cmake_args, cwd=IREE_BINARY_DIR
283 )
284 else:
285 print(f"Not re-configuring (already configured)", file=sys.stderr)
286
287 # Build.
Stella Laurenzoc003beb2023-07-19 13:19:14 -0700288 subprocess.check_call(["cmake", "--build", "."], cwd=IREE_BINARY_DIR)
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400289 print("Build complete.", file=sys.stderr)
290
291 # Perform installation on the entire compiler/ tree as this is guaranteed
292 # to have all of our installation targets.
Stella Laurenzoc003beb2023-07-19 13:19:14 -0700293 install_subdirectory = os.path.join(IREE_BINARY_DIR)
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400294 install_args = [
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400295 f"-DCMAKE_INSTALL_PREFIX={CMAKE_INSTALL_DIR_ABS}",
296 "-P",
297 os.path.join(install_subdirectory, "cmake_install.cmake"),
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700298 ]
Stella Laurenzoc003beb2023-07-19 13:19:14 -0700299 if strip_install:
300 install_args.append("-DCMAKE_INSTALL_DO_STRIP=ON")
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400301 print(f"Installing with: {install_args}", file=sys.stderr)
302 subprocess.check_call(["cmake"] + install_args, cwd=install_subdirectory)
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700303
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400304 # Write version.py directly into install dir.
305 version_py_file = os.path.join(
306 CMAKE_INSTALL_DIR_ABS,
307 "python_packages",
308 "iree_compiler",
309 "iree",
310 "compiler",
311 "version.py",
312 )
313 os.makedirs(os.path.dirname(version_py_file), exist_ok=True)
314 with open(version_py_file, "wt") as f:
315 f.write(version_py_content)
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700316
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400317 print(f"Installation prepared: {CMAKE_INSTALL_DIR_ABS}", file=sys.stderr)
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700318
319
320class CMakeBuildPy(_build_py):
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400321 def run(self):
322 # It is critical that the target directory contain all built extensions,
323 # or else setuptools will helpfully compile an empty binary for us
324 # (this is the **worst** possible thing it could do). We just copy
325 # everything. What's another hundred megs between friends?
326 target_dir = os.path.abspath(self.build_lib)
327 print(f"Building in target dir: {target_dir}", file=sys.stderr)
328 os.makedirs(target_dir, exist_ok=True)
329 print("Copying install to target.", file=sys.stderr)
330 if os.path.exists(target_dir):
331 shutil.rmtree(target_dir)
332 shutil.copytree(
333 os.path.join(CMAKE_INSTALL_DIR_ABS, "python_packages", "iree_compiler"),
334 target_dir,
335 symlinks=False,
336 )
337 print("Target populated.", file=sys.stderr)
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700338
339
340class CustomBuild(_build):
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400341 def run(self):
342 self.run_command("build_py")
343 self.run_command("build_ext")
344 self.run_command("build_scripts")
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700345
346
347class CMakeExtension(Extension):
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400348 def __init__(self, name, sourcedir=""):
349 Extension.__init__(self, name, sources=[])
350 self.sourcedir = os.path.abspath(sourcedir)
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700351
352
353class NoopBuildExtension(_build_ext):
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400354 def __init__(self, *args, **kwargs):
355 assert False
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700356
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400357 def build_extension(self, ext):
358 pass
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700359
360
361def generate_version_py():
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400362 return f"""# Auto-generated version info.
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700363PACKAGE_SUFFIX = "{PACKAGE_SUFFIX}"
364VERSION = "{PACKAGE_VERSION}"
365REVISIONS = {json.dumps(git_versions)}
366"""
367
368
369def find_git_versions():
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400370 revisions = {}
371 try:
372 revisions["IREE"] = (
373 subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=IREE_SOURCE_DIR)
374 .decode("utf-8")
375 .strip()
376 )
377 except subprocess.SubprocessError as e:
378 print(f"ERROR: Could not get IREE revision: {e}", file=sys.stderr)
379 revisions["LLVM_PROJECT"] = find_git_submodule_revision("third_party/llvm-project")
380 revisions["STABLEHLO"] = find_git_submodule_revision("third_party/stablehlo")
381 return revisions
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700382
383
384def find_git_submodule_revision(submodule_path):
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400385 try:
386 data = (
387 subprocess.check_output(
388 ["git", "ls-tree", "HEAD", submodule_path], cwd=IREE_SOURCE_DIR
389 )
390 .decode("utf-8")
391 .strip()
392 )
393 columns = re.split("\\s+", data)
394 return columns[2]
395 except Exception as e:
396 print(
397 f"ERROR: Could not get submodule revision for {submodule_path}" f" ({e})",
398 file=sys.stderr,
399 )
400 return ""
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700401
402
403prepare_installation()
404
Jakub Kuderskibe24f022023-06-21 14:44:18 -0400405packages = find_namespace_packages(
406 where=os.path.join(CMAKE_INSTALL_DIR_ABS, "python_packages", "iree_compiler"),
407 include=[
408 "iree.compiler",
409 "iree.compiler.*",
410 ],
411)
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700412print(f"Found compiler packages: {packages}")
413
Stella Laurenzoc003beb2023-07-19 13:19:14 -0700414custom_package_suffix = os.getenv("IREE_COMPILER_CUSTOM_PACKAGE_SUFFIX", "")
415custom_package_prefix = os.getenv("IREE_COMPILER_CUSTOM_PACKAGE_PREFIX", "")
416
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700417setup(
Stella Laurenzoc003beb2023-07-19 13:19:14 -0700418 name=f"{custom_package_prefix}iree-compiler{custom_package_suffix}{PACKAGE_SUFFIX}",
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700419 version=f"{PACKAGE_VERSION}",
420 author="IREE Authors",
Marius Brehler45132f52024-09-05 00:21:41 +0200421 author_email="iree-technical-discussion@lists.lfaidata.foundation",
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700422 description="IREE Compiler API",
423 long_description="",
424 license="Apache-2.0",
425 classifiers=[
426 "Development Status :: 3 - Alpha",
427 "License :: OSI Approved :: Apache Software License",
Scott Toddfe9cb172022-12-08 09:17:52 -0800428 "Programming Language :: Python :: 3",
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700429 "Programming Language :: Python :: 3.9",
Scott Toddfe9cb172022-12-08 09:17:52 -0800430 "Programming Language :: Python :: 3.10",
powderluved105512023-02-11 23:01:43 -0800431 "Programming Language :: Python :: 3.11",
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700432 ],
433 ext_modules=[
434 CMakeExtension("iree.compiler._mlir_libs._mlir"),
435 CMakeExtension("iree.compiler._mlir_libs._ireeDialects"),
Stella Laurenzo7ed278e2022-11-25 10:36:57 -0800436 # TODO: MHLO has been broken for a while so disabling. If re-enabling,
437 # it also needs to be enabled on the build side.
438 # CMakeExtension("iree.compiler._mlir_libs._mlirHlo"),
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700439 CMakeExtension("iree.compiler._mlir_libs._mlirLinalgPasses"),
Dmitry Babokin360dc3e2024-05-01 11:42:25 -0700440 CMakeExtension("iree.compiler._mlir_libs._mlirGPUPasses"),
Stella Laurenzobf475bb2023-05-11 08:41:23 -0700441 CMakeExtension("iree.compiler._mlir_libs._site_initialize_0"),
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700442 ],
443 cmdclass={
444 "build": CustomBuild,
445 "built_ext": NoopBuildExtension,
446 "build_py": CMakeBuildPy,
447 },
448 zip_safe=False,
449 package_dir={
450 # Note: Must be relative path, so we line this up with the absolute
451 # path built above. Note that this must exist prior to the call.
452 "": f"{CMAKE_INSTALL_DIR_REL}/python_packages/iree_compiler",
453 },
454 packages=packages,
455 entry_points={
456 "console_scripts": [
Scott Todd84d07892024-09-06 08:55:14 -0700457 "iree-compile = iree.compiler.tools.scripts.iree_compile.__main__:main",
Stella Laurenzo7b7ffeb2023-12-20 19:03:59 -0800458 "iree-import-onnx = iree.compiler.tools.import_onnx.__main__:_cli_main",
Stella Laurenzoecc49f62023-08-10 23:37:22 -0700459 "iree-ir-tool = iree.compiler.tools.ir_tool.__main__:_cli_main",
Stella Laurenzo1b12b5e2024-08-26 16:49:48 -0700460 "iree-opt = iree.compiler.tools.scripts.iree_opt.__main__:main",
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700461 ],
462 },
463 install_requires=[
464 "numpy",
Lei Zhangac418d12024-06-20 19:24:08 -0700465 "sympy",
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700466 ],
Stella Laurenzo7b7ffeb2023-12-20 19:03:59 -0800467 extras_require={
468 "onnx": [
Scott Todd29e70ab2024-05-28 12:48:55 -0700469 "onnx>=1.16.0",
Stella Laurenzo7b7ffeb2023-12-20 19:03:59 -0800470 ],
471 },
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700472)