Stella Laurenzo | 6f24a2f | 2023-03-27 17:08:20 -0700 | [diff] [blame] | 1 | # Copyright 2020 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 | |
| 7 | import bazel_to_cmake_converter |
| 8 | import bazel_to_cmake_targets |
| 9 | |
| 10 | DEFAULT_ROOT_DIRS = ["compiler", "runtime", "samples", "tests", "tools"] |
| 11 | |
| 12 | REPO_MAP = { |
| 13 | # Since this is the @iree_core repo, map to empty since all internal |
| 14 | # targets are of the form "//compiler", not "@iree_core//compiler". |
| 15 | "@iree_core": "", |
| 16 | } |
| 17 | |
| 18 | |
| 19 | class CustomBuildFileFunctions(bazel_to_cmake_converter.BuildFileFunctions): |
Scott Todd | 62efaee | 2024-05-31 13:33:55 -0700 | [diff] [blame] | 20 | def iree_compiler_cc_library(self, deps=[], **kwargs): |
| 21 | self.cc_library(deps=deps + ["//compiler/src:defs"], **kwargs) |
Stella Laurenzo | 6f24a2f | 2023-03-27 17:08:20 -0700 | [diff] [blame] | 22 | |
Scott Todd | 62efaee | 2024-05-31 13:33:55 -0700 | [diff] [blame] | 23 | def iree_runtime_cc_library(self, deps=[], **kwargs): |
| 24 | self.cc_library(deps=deps + ["//runtime/src:runtime_defines"], **kwargs) |
Stella Laurenzo | 6f24a2f | 2023-03-27 17:08:20 -0700 | [diff] [blame] | 25 | |
Scott Todd | 62efaee | 2024-05-31 13:33:55 -0700 | [diff] [blame] | 26 | def iree_runtime_cc_test(self, deps=[], **kwargs): |
| 27 | self.cc_test(deps=deps + ["//runtime/src:runtime_defines"], **kwargs) |
Stella Laurenzo | 6f24a2f | 2023-03-27 17:08:20 -0700 | [diff] [blame] | 28 | |
Scott Todd | 62efaee | 2024-05-31 13:33:55 -0700 | [diff] [blame] | 29 | def iree_compiler_cc_test(self, deps=[], **kwargs): |
| 30 | self.cc_test(deps=deps + ["//compiler/src:defs"], **kwargs) |
Stella Laurenzo | 6f24a2f | 2023-03-27 17:08:20 -0700 | [diff] [blame] | 31 | |
Scott Todd | 62efaee | 2024-05-31 13:33:55 -0700 | [diff] [blame] | 32 | def iree_runtime_cc_binary(self, deps=[], **kwargs): |
| 33 | self.cc_binary(deps=deps + ["//runtime/src:runtime_defines"], **kwargs) |
Stella Laurenzo | 6f24a2f | 2023-03-27 17:08:20 -0700 | [diff] [blame] | 34 | |
Scott Todd | 62efaee | 2024-05-31 13:33:55 -0700 | [diff] [blame] | 35 | def iree_compiler_cc_binary(self, deps=[], **kwargs): |
| 36 | self.cc_binary(deps=deps + ["//compiler/src:defs"], **kwargs) |
Stella Laurenzo | 6f24a2f | 2023-03-27 17:08:20 -0700 | [diff] [blame] | 37 | |
| 38 | |
| 39 | class CustomTargetConverter(bazel_to_cmake_targets.TargetConverter): |
Scott Todd | 62efaee | 2024-05-31 13:33:55 -0700 | [diff] [blame] | 40 | def _initialize(self): |
| 41 | self._update_target_mappings( |
| 42 | { |
| 43 | "//compiler/src:defs": [], |
| 44 | "//runtime/src:runtime_defines": [], |
| 45 | } |
| 46 | ) |
Stella Laurenzo | 6f24a2f | 2023-03-27 17:08:20 -0700 | [diff] [blame] | 47 | |
Scott Todd | 62efaee | 2024-05-31 13:33:55 -0700 | [diff] [blame] | 48 | def _convert_unmatched_target(self, target: str) -> str: |
| 49 | """Converts unmatched targets in a repo specific way.""" |
| 50 | # Default rewrite: prefix with "iree::", without pruning the path. |
| 51 | return ["iree::" + self._convert_to_cmake_path(target)] |