Improve building python bindings with CMake
Depends on #702.
Closes https://github.com/google/iree/pull/703
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/iree/pull/703 from iml130:cmake-python-bindings 28c96ea7d7784c09a3234a009d3221514f955407
PiperOrigin-RevId: 294261982
diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt
index 2048418..3febc3b 100644
--- a/bindings/python/CMakeLists.txt
+++ b/bindings/python/CMakeLists.txt
@@ -14,8 +14,6 @@
set(NUMPY_DEPS "")
-# TODO(marbre): Set PYTHON_HEADERS_DEPS to something useful
-set(PYTHON_HEADERS_DEPS "")
set(PYBIND_COPTS "-fexceptions")
set(PYBIND_EXTENSION_COPTS "-fvisibility=hidden")
diff --git a/bindings/python/pyiree/CMakeLists.txt b/bindings/python/pyiree/CMakeLists.txt
index 2e8d6a9..55ac43d 100644
--- a/bindings/python/pyiree/CMakeLists.txt
+++ b/bindings/python/pyiree/CMakeLists.txt
@@ -15,9 +15,6 @@
add_subdirectory(common)
add_subdirectory(rt)
-# TODO(marbre): The base pyiree-compiler supporting build-in dialects should be
-# buildable with CMake after TensorFlow components are moved to
-# pyiree-tf-compiler
-#if(${IREE_BUILD_COMPILER})
-# add_subdirectory(compiler)
-#endif()
+if(${IREE_BUILD_COMPILER})
+ add_subdirectory(compiler)
+endif()
diff --git a/bindings/python/pyiree/compiler/CMakeLists.txt b/bindings/python/pyiree/compiler/CMakeLists.txt
new file mode 100644
index 0000000..2f62aa0
--- /dev/null
+++ b/bindings/python/pyiree/compiler/CMakeLists.txt
@@ -0,0 +1,55 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+iree_py_extension(
+ NAME
+ binding
+ SRCS
+ "initialize_module.cc"
+ DEPS
+ ::compiler_library
+ bindings::python::pyiree::common
+ COPTS
+ ${PYBIND_COPTS}
+ ${PYBIND_EXTENSION_COPTS}
+ TYPE
+ SHARED
+)
+
+iree_pybind_cc_library(
+ NAME
+ compiler_library
+ HDRS
+ "compiler.h"
+ SRCS
+ "compiler.cc"
+ DEPS
+ # Transforms. Adopted from the Bazel variable COMPILER_DEPS.
+ iree::compiler::Dialect::Flow::Transforms
+ iree::compiler::Dialect::HAL::Transforms
+ iree::compiler::Dialect::HAL::Target::ExecutableTarget
+ iree::compiler::Dialect::VM::Transforms
+ # Targets. Adopted from the Bazel variable COMPILER_DEPS.
+ iree::compiler::Dialect::HAL::Target::LegacyInterpreter
+ iree::compiler::Dialect::HAL::Target::VMLA
+ iree::compiler::Dialect::HAL::Target::VulkanSPIRV
+ iree::compiler::Dialect::VM::Target::Bytecode
+ bindings::python::pyiree::common
+ LLVMSupport
+ MLIRIR
+ MLIRParser
+ MLIRPass
+ TYPE
+ SHARED
+)
diff --git a/bindings/python/pyiree/rt/CMakeLists.txt b/bindings/python/pyiree/rt/CMakeLists.txt
index 02d701f..7f9aacb 100644
--- a/bindings/python/pyiree/rt/CMakeLists.txt
+++ b/bindings/python/pyiree/rt/CMakeLists.txt
@@ -26,6 +26,9 @@
iree::base::tracing
# TODO(marbre): Add dependency
# "@com_google_tracing_framework_cpp//:tracing_framework_bindings_cpp",
+ COPTS
+ ${PYBIND_COPTS}
+ ${PYBIND_EXTENSION_COPTS}
TYPE
SHARED
)