diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel @@ -7,7 +7,12 @@ load(":tblgen.bzl", "gentbl_cc_library", "td_library") load(":linalggen.bzl", "genlinalg") -load(":build_defs.bzl", "cc_headers_only", "if_cuda_available") +load( + ":build_defs.bzl", + "cc_headers_only", + "if_cuda_available", + "mlir_c_api_cc_library", +) package( default_visibility = ["//visibility:public"], @@ -308,7 +313,7 @@ ], ) -cc_library( +mlir_c_api_cc_library( name = "CAPIIR", srcs = [ "lib/CAPI/Dialect/Standard.cpp", @@ -348,20 +353,22 @@ "include/mlir/CAPI/Utils.h", "include/mlir/CAPI/Wrap.h", ], + header_deps = [ + ":IR", + ":Pass", + ":Support", + "//llvm:Support", + ], includes = ["include"], deps = [ ":ConversionPassIncGen", - ":IR", ":InferTypeOpInterface", ":Parser", - ":Pass", ":StandardOps", - ":Support", - "//llvm:Support", ], ) -cc_library( +mlir_c_api_cc_library( name = "CAPIInterfaces", srcs = [ "lib/CAPI/Interfaces/Interfaces.cpp", @@ -375,26 +382,27 @@ ], ) -cc_library( +mlir_c_api_cc_library( name = "CAPIAsync", srcs = [ "lib/CAPI/Dialect/Async.cpp", "lib/CAPI/Dialect/AsyncPasses.cpp", ], - hdrs = [ - "include/mlir-c/Dialect/Async.h", + hdrs = ["include/mlir-c/Dialect/Async.h"], + header_deps = [ + ":AsyncPassIncGen", + ":CAPIIRHeaders", ], includes = ["include"], deps = [ ":Async", - ":AsyncPassIncGen", ":AsyncTransforms", ":CAPIIR", ":Pass", ], ) -cc_library( +mlir_c_api_cc_library( name = "CAPILinalg", srcs = [ "lib/CAPI/Dialect/Linalg.cpp", @@ -403,17 +411,20 @@ hdrs = [ "include/mlir-c/Dialect/Linalg.h", ], + header_deps = [ + ":CAPIIRHeaders", + ":LinalgPassIncGen", + ], includes = ["include"], deps = [ ":CAPIIR", ":LinalgOps", - ":LinalgPassIncGen", ":LinalgTransforms", ":Pass", ], ) -cc_library( +mlir_c_api_cc_library( name = "CAPILLVM", srcs = [ "lib/CAPI/Dialect/LLVM.cpp", @@ -421,6 +432,9 @@ hdrs = [ "include/mlir-c/Dialect/LLVM.h", ], + header_deps = [ + ":CAPIIRHeaders", + ], includes = ["include"], deps = [ ":CAPIIR", @@ -428,7 +442,7 @@ ], ) -cc_library( +mlir_c_api_cc_library( name = "CAPIGPU", srcs = [ "lib/CAPI/Dialect/GPU.cpp", @@ -437,17 +451,20 @@ hdrs = [ "include/mlir-c/Dialect/GPU.h", ], + header_deps = [ + ":CAPIIRHeaders", + ":GPUPassIncGen", + ], includes = ["include"], deps = [ ":CAPIIR", ":GPUDialect", - ":GPUPassIncGen", ":GPUTransforms", ":Pass", ], ) -cc_library( +mlir_c_api_cc_library( name = "CAPISparseTensor", srcs = [ "lib/CAPI/Dialect/SparseTensor.cpp", @@ -456,34 +473,43 @@ hdrs = [ "include/mlir-c/Dialect/SparseTensor.h", ], + header_deps = [ + ":CAPIIRHeaders", + ":SparseTensorPassIncGen", + ], includes = ["include"], deps = [ ":CAPIIR", ":Pass", ":SparseTensor", - ":SparseTensorPassIncGen", ":SparseTensorTransforms", ":Support", ], ) -cc_library( +mlir_c_api_cc_library( name = "CAPIConversion", srcs = ["lib/CAPI/Conversion/Passes.cpp"], hdrs = ["include/mlir-c/Conversion.h"], + header_deps = [ + ":CAPIIRHeaders", + ":ConversionPassIncGen", + ], includes = ["include"], deps = [ ":CAPIIR", - ":ConversionPassIncGen", ":ConversionPasses", ":Pass", ], ) -cc_library( +mlir_c_api_cc_library( name = "CAPIDebug", srcs = ["lib/CAPI/Debug/Debug.cpp"], hdrs = ["include/mlir-c/Debug.h"], + header_deps = [ + ":CAPIIRHeaders", + ], includes = ["include"], deps = [ ":CAPIIR", @@ -492,17 +518,20 @@ ], ) -cc_library( +mlir_c_api_cc_library( name = "CAPIExecutionEngine", srcs = ["lib/CAPI/ExecutionEngine/ExecutionEngine.cpp"], hdrs = [ "include/mlir-c/ExecutionEngine.h", "include/mlir/CAPI/ExecutionEngine.h", ], + header_deps = [ + ":CAPIIRHeaders", + ":ExecutionEngine", + ], includes = ["include"], deps = [ ":CAPIIR", - ":ExecutionEngine", ":ExecutionEngineUtils", ":LLVMToLLVMIRTranslation", "//llvm:OrcJIT", @@ -510,23 +539,29 @@ ], ) -cc_library( +mlir_c_api_cc_library( name = "CAPITransforms", srcs = ["lib/CAPI/Transforms/Passes.cpp"], hdrs = ["include/mlir-c/Transforms.h"], + header_deps = [ + ":CAPIIRHeaders", + ":TransformsPassIncGen", + ], includes = ["include"], deps = [ ":CAPIIR", ":Pass", ":Transforms", - ":TransformsPassIncGen", ], ) -cc_library( +mlir_c_api_cc_library( name = "CAPIRegistration", srcs = ["lib/CAPI/Registration/Registration.cpp"], hdrs = ["include/mlir-c/Registration.h"], + header_deps = [ + ":CAPIIRHeaders", + ], includes = ["include"], deps = [ ":AllPassesAndDialects", @@ -543,6 +578,30 @@ glob(["lib/Bindings/Python/**/*.cpp"]), ) +MLIR_BINDINGS_PYTHON_HEADERS = [ + "lib/Bindings/Python/*.h", + "include/mlir-c/Bindings/Python/*.h", + "include/mlir/Bindings/Python/*.h", +] + +cc_library( + name = "MLIRBindingsPythonHeaders", + includes = [ + "include", + "lib/Bindings/Python", + ], + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + textual_hdrs = glob(MLIR_BINDINGS_PYTHON_HEADERS), + deps = [ + ":CAPIIRHeaders", + "@pybind11", + "@python_runtime//:headers", + ], +) + cc_library( name = "MLIRBindingsPythonHeadersAndDeps", includes = [ @@ -553,11 +612,7 @@ "manual", # External dependency "nobuildkite", # TODO(gcmn): Add support for this target ], - textual_hdrs = glob([ - "lib/Bindings/Python/*.h", - "include/mlir-c/Bindings/Python/*.h", - "include/mlir/Bindings/Python/*.h", - ]), + textual_hdrs = glob(MLIR_BINDINGS_PYTHON_HEADERS), deps = [ ":CAPIIR", "@pybind11", @@ -566,7 +621,7 @@ ) cc_library( - name = "MLIRBindingsPythonCore", + name = "MLIRBindingsPythonCoreNoCAPI", srcs = [ "lib/Bindings/Python/DialectLinalg.cpp", "lib/Bindings/Python/DialectSparseTensor.cpp", @@ -592,6 +647,27 @@ "manual", # External dependency "nobuildkite", # TODO(gcmn): Add support for this target ], + deps = [ + ":CAPIAsyncHeaders", + ":CAPIDebugHeaders", + ":CAPIGPUHeaders", + ":CAPIIRHeaders", + ":CAPILinalgHeaders", + ":CAPIRegistrationHeaders", + ":CAPISparseTensorHeaders", + ":MLIRBindingsPythonHeaders", + "//llvm:Support", + "@pybind11", + "@python_runtime//:headers", + ], +) + +cc_library( + name = "MLIRBindingsPythonCAPIDeps", + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], deps = [ ":CAPIAsync", ":CAPIDebug", @@ -601,10 +677,36 @@ ":CAPILinalg", ":CAPIRegistration", ":CAPISparseTensor", - ":MLIRBindingsPythonHeadersAndDeps", - "//llvm:Support", - "@pybind11", - "@python_runtime//:headers", + ], +) + +cc_library( + name = "MLIRBindingsPythonCAPIObjects", + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":CAPIAsyncObjects", + ":CAPIDebugObjects", + ":CAPIGPUObjects", + ":CAPIIRObjects", + ":CAPIInterfacesObjects", + ":CAPILinalgObjects", + ":CAPIRegistrationObjects", + ":CAPISparseTensorObjects", + ], +) + +cc_library( + name = "MLIRBindingsPythonCore", + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":MLIRBindingsPythonCAPIDeps", + ":MLIRBindingsPythonCoreNoCAPI", ], ) diff --git a/utils/bazel/llvm-project-overlay/mlir/build_defs.bzl b/utils/bazel/llvm-project-overlay/mlir/build_defs.bzl --- a/utils/bazel/llvm-project-overlay/mlir/build_defs.bzl +++ b/utils/bazel/llvm-project-overlay/mlir/build_defs.bzl @@ -24,3 +24,40 @@ doc = "Provides the headers from 'src' without linking anything.", provides = [CcInfo], ) + +def mlir_c_api_cc_library( + name, + srcs = [], + hdrs = [], + deps = [], + header_deps = [], + **kwargs): + """Macro that generates three targets for MLIR C API libraries. + + * A standard cc_library target ("Name"), + * A header-only cc_library target ("NameHeaders") + * An implementation cc_library target tagged `alwayslink` suitable for + inclusion in a shared library built with cc_binary() ("NameObjects"). + """ + + native.cc_library( + name = name, + srcs = srcs, + hdrs = hdrs, + deps = deps + header_deps, + **kwargs + ) + native.cc_library( + name = name + "Headers", + hdrs = hdrs, + deps = header_deps, + **kwargs + ) + native.cc_library( + name = name + "Objects", + srcs = srcs, + hdrs = hdrs, + deps = deps + header_deps, + alwayslink = True, + **kwargs + )