Update bazel_to_cmake to support testonly for iree_bytecode_module (#4337)
Also adds the testonly option to the iree_bytecode_modules that are only used for testing, and updates the iree_bytecode_module bazel rule to use kwargs for testonly and visibility
diff --git a/build_tools/bazel_to_cmake/bazel_to_cmake_converter.py b/build_tools/bazel_to_cmake/bazel_to_cmake_converter.py
index f6dca0b..c30c8c6 100644
--- a/build_tools/bazel_to_cmake/bazel_to_cmake_converter.py
+++ b/build_tools/bazel_to_cmake/bazel_to_cmake_converter.py
@@ -460,12 +460,14 @@
src,
flags=["-iree-mlir-to-vm-bytecode-module"],
translate_tool="//iree/tools:iree-translate",
- cc_namespace=None):
+ cc_namespace=None,
+ testonly=False):
name_block = self._convert_name_block(name)
src_block = self._convert_src_block(src)
namespace_block = self._convert_cc_namespace_block(cc_namespace)
translate_tool_block = self._convert_translate_tool_block(translate_tool)
flags_block = self._convert_string_list_block("FLAGS", flags)
+ testonly_block = self._convert_testonly_block(testonly)
self.converter.body += (f"iree_bytecode_module(\n"
f"{name_block}"
@@ -473,6 +475,7 @@
f"{namespace_block}"
f"{translate_tool_block}"
f"{flags_block}"
+ f"{testonly_block}"
f" PUBLIC\n)\n\n")
def iree_flatbuffer_c_library(self, name, srcs, flatcc_args=None):
diff --git a/iree/modules/strings/BUILD b/iree/modules/strings/BUILD
index da6012d..20b6a1f 100644
--- a/iree/modules/strings/BUILD
+++ b/iree/modules/strings/BUILD
@@ -34,7 +34,7 @@
iree_cmake_extra_content(
content = """
-if (NOT ${IREE_BUILD_COMPILER} OR NOT ${IREE_BUILD_TESTS})
+if (NOT ${IREE_BUILD_COMPILER})
return()
endif()
""",
@@ -65,6 +65,7 @@
iree_bytecode_module(
name = "strings_module_test_module",
+ testonly = True,
src = "strings_module_test.mlir",
cc_namespace = "iree::strings_module_test",
flags = ["-iree-mlir-to-vm-bytecode-module"],
diff --git a/iree/modules/strings/CMakeLists.txt b/iree/modules/strings/CMakeLists.txt
index 4dcbcf0..8347aee 100644
--- a/iree/modules/strings/CMakeLists.txt
+++ b/iree/modules/strings/CMakeLists.txt
@@ -38,7 +38,7 @@
PUBLIC
)
-if (NOT ${IREE_BUILD_COMPILER} OR NOT ${IREE_BUILD_TESTS})
+if (NOT ${IREE_BUILD_COMPILER})
return()
endif()
@@ -74,5 +74,6 @@
"iree::strings_module_test"
FLAGS
"-iree-mlir-to-vm-bytecode-module"
+ TESTONLY
PUBLIC
)
diff --git a/iree/modules/tensorlist/BUILD b/iree/modules/tensorlist/BUILD
index 86f1c2a..08ec5a7 100644
--- a/iree/modules/tensorlist/BUILD
+++ b/iree/modules/tensorlist/BUILD
@@ -40,7 +40,7 @@
iree_cmake_extra_content(
content = """
-if (NOT ${IREE_BUILD_COMPILER} OR NOT ${IREE_BUILD_TESTS})
+if (NOT ${IREE_BUILD_COMPILER})
return()
endif()
""",
@@ -49,6 +49,7 @@
iree_bytecode_module(
name = "tensorlist_test_module",
+ testonly = True,
src = "tensorlist_test.mlir",
cc_namespace = "iree::modules::tensorlist",
flags = ["-iree-mlir-to-vm-bytecode-module"],
diff --git a/iree/modules/tensorlist/CMakeLists.txt b/iree/modules/tensorlist/CMakeLists.txt
index a82e5f5..3e526b4 100644
--- a/iree/modules/tensorlist/CMakeLists.txt
+++ b/iree/modules/tensorlist/CMakeLists.txt
@@ -34,7 +34,7 @@
PUBLIC
)
-if (NOT ${IREE_BUILD_COMPILER} OR NOT ${IREE_BUILD_TESTS})
+if (NOT ${IREE_BUILD_COMPILER})
return()
endif()
@@ -47,6 +47,7 @@
"iree::modules::tensorlist"
FLAGS
"-iree-mlir-to-vm-bytecode-module"
+ TESTONLY
PUBLIC
)
diff --git a/iree/tools/compilation.bzl b/iree/tools/compilation.bzl
index 4d13c14..d5f7a14 100644
--- a/iree/tools/compilation.bzl
+++ b/iree/tools/compilation.bzl
@@ -23,7 +23,7 @@
flags = ["-iree-mlir-to-vm-bytecode-module"],
translate_tool = "//iree/tools:iree-translate",
cc_namespace = None,
- visibility = None):
+ **kwargs):
native.genrule(
name = name,
srcs = [src],
@@ -41,6 +41,7 @@
tools = [translate_tool],
message = "Compiling IREE module %s..." % (name),
output_to_bindir = 1,
+ **kwargs
)
# Embed the module for use in C++. This avoids the need for file IO in
@@ -53,6 +54,6 @@
cc_file_output = "%s.cc" % (name),
h_file_output = "%s.h" % (name),
cpp_namespace = cc_namespace,
- visibility = visibility,
flatten = True,
+ **kwargs
)
diff --git a/iree/vm/BUILD b/iree/vm/BUILD
index 17d82ab..4cc6d9f 100644
--- a/iree/vm/BUILD
+++ b/iree/vm/BUILD
@@ -215,7 +215,7 @@
iree_cmake_extra_content(
content = """
-if(${IREE_BUILD_COMPILER} AND ${IREE_BUILD_TESTS})
+if(${IREE_BUILD_COMPILER})
""",
inline = True,
)
@@ -256,6 +256,7 @@
iree_bytecode_module(
name = "bytecode_module_benchmark_module",
+ testonly = True,
src = "bytecode_module_benchmark.mlir",
cc_namespace = "iree::vm",
flags = ["-iree-vm-ir-to-bytecode-module"],
@@ -274,6 +275,7 @@
iree_bytecode_module(
name = "bytecode_module_size_benchmark_module",
+ testonly = True,
src = "bytecode_module_size_benchmark.mlir",
cc_namespace = "iree::vm",
flags = ["-iree-vm-ir-to-bytecode-module"],
diff --git a/iree/vm/CMakeLists.txt b/iree/vm/CMakeLists.txt
index 88c3fb7..71cd24d 100644
--- a/iree/vm/CMakeLists.txt
+++ b/iree/vm/CMakeLists.txt
@@ -177,7 +177,7 @@
PUBLIC
)
-if(${IREE_BUILD_COMPILER} AND ${IREE_BUILD_TESTS})
+if(${IREE_BUILD_COMPILER})
iree_cc_test(
NAME
@@ -222,6 +222,7 @@
"iree::vm"
FLAGS
"-iree-vm-ir-to-bytecode-module"
+ TESTONLY
PUBLIC
)
@@ -246,6 +247,7 @@
"iree::vm"
FLAGS
"-iree-vm-ir-to-bytecode-module"
+ TESTONLY
PUBLIC
)