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 @@ -308,6 +308,36 @@ ], ) +# CAPI targets have both implementation targets and header-only targets. +# This allows clients of the C API to build against the interface without +# including the implementation. + +CAPI_IR_HEADERS = [ + "include/mlir-c/AffineExpr.h", + "include/mlir-c/AffineMap.h", + "include/mlir-c/BuiltinAttributes.h", + "include/mlir-c/BuiltinTypes.h", + "include/mlir-c/Diagnostics.h", + "include/mlir-c/Dialect/Standard.h", + "include/mlir-c/ExecutionEngine.h", + "include/mlir-c/IR.h", + "include/mlir-c/IntegerSet.h", + "include/mlir-c/Interfaces.h", + "include/mlir-c/Pass.h", + "include/mlir-c/Registration.h", + "include/mlir-c/Support.h", + "include/mlir/CAPI/AffineExpr.h", + "include/mlir/CAPI/AffineMap.h", + "include/mlir/CAPI/Diagnostics.h", + "include/mlir/CAPI/IR.h", + "include/mlir/CAPI/IntegerSet.h", + "include/mlir/CAPI/Pass.h", + "include/mlir/CAPI/Registration.h", + "include/mlir/CAPI/Support.h", + "include/mlir/CAPI/Utils.h", + "include/mlir/CAPI/Wrap.h", +] + cc_library( name = "CAPIIR", srcs = [ @@ -323,31 +353,7 @@ "lib/CAPI/IR/Pass.cpp", "lib/CAPI/IR/Support.cpp", ], - hdrs = [ - "include/mlir-c/AffineExpr.h", - "include/mlir-c/AffineMap.h", - "include/mlir-c/BuiltinAttributes.h", - "include/mlir-c/BuiltinTypes.h", - "include/mlir-c/Diagnostics.h", - "include/mlir-c/Dialect/Standard.h", - "include/mlir-c/ExecutionEngine.h", - "include/mlir-c/IR.h", - "include/mlir-c/IntegerSet.h", - "include/mlir-c/Interfaces.h", - "include/mlir-c/Pass.h", - "include/mlir-c/Registration.h", - "include/mlir-c/Support.h", - "include/mlir/CAPI/AffineExpr.h", - "include/mlir/CAPI/AffineMap.h", - "include/mlir/CAPI/Diagnostics.h", - "include/mlir/CAPI/IR.h", - "include/mlir/CAPI/IntegerSet.h", - "include/mlir/CAPI/Pass.h", - "include/mlir/CAPI/Registration.h", - "include/mlir/CAPI/Support.h", - "include/mlir/CAPI/Utils.h", - "include/mlir/CAPI/Wrap.h", - ], + hdrs = CAPI_IR_HEADERS, includes = ["include"], deps = [ ":ConversionPassIncGen", @@ -359,6 +365,19 @@ ":Support", "//llvm:Support", ], + alwayslink = True, +) + +cc_library( + name = "CAPIIRHeaders", + hdrs = CAPI_IR_HEADERS, + includes = ["include"], + deps = [ + ":IR", + ":Pass", + ":Support", + "//llvm:Support", + ], ) cc_library( @@ -373,17 +392,20 @@ ":InferTypeOpInterface", "//llvm:Support", ], + alwayslink = True, ) +CAPI_ASYNC_HEADERS = [ + "include/mlir-c/Dialect/Async.h", +] + cc_library( name = "CAPIAsync", srcs = [ "lib/CAPI/Dialect/Async.cpp", "lib/CAPI/Dialect/AsyncPasses.cpp", ], - hdrs = [ - "include/mlir-c/Dialect/Async.h", - ], + hdrs = CAPI_ASYNC_HEADERS, includes = ["include"], deps = [ ":Async", @@ -392,17 +414,30 @@ ":CAPIIR", ":Pass", ], + alwayslink = True, +) + +cc_library( + name = "CAPIAsyncHeaders", + hdrs = CAPI_ASYNC_HEADERS, + includes = ["include"], + deps = [ + ":AsyncPassIncGen", + ":CAPIIRHeaders", + ], ) +CAPI_LINALG_HEADERS = [ + "include/mlir-c/Dialect/Linalg.h", +] + cc_library( name = "CAPILinalg", srcs = [ "lib/CAPI/Dialect/Linalg.cpp", "lib/CAPI/Dialect/LinalgPasses.cpp", ], - hdrs = [ - "include/mlir-c/Dialect/Linalg.h", - ], + hdrs = CAPI_LINALG_HEADERS, includes = ["include"], deps = [ ":CAPIIR", @@ -411,32 +446,57 @@ ":LinalgTransforms", ":Pass", ], + alwayslink = True, ) +cc_library( + name = "CAPILinalgHeaders", + hdrs = CAPI_LINALG_HEADERS, + includes = ["include"], + deps = [ + ":CAPIIRHeaders", + ":LinalgPassIncGen", + ], +) + +CAPI_LLVM_HEADERS = [ + "include/mlir-c/Dialect/LLVM.h", +] + cc_library( name = "CAPILLVM", srcs = [ "lib/CAPI/Dialect/LLVM.cpp", ], - hdrs = [ - "include/mlir-c/Dialect/LLVM.h", - ], + hdrs = CAPI_LLVM_HEADERS, includes = ["include"], deps = [ ":CAPIIR", ":LLVMDialect", ], + alwayslink = True, ) +cc_library( + name = "CAPILLVMHeaders", + hdrs = CAPI_LLVM_HEADERS, + includes = ["include"], + deps = [ + ":CAPIIRHeaders", + ], +) + +CAPI_GPU_HEADERS = [ + "include/mlir-c/Dialect/GPU.h", +] + cc_library( name = "CAPIGPU", srcs = [ "lib/CAPI/Dialect/GPU.cpp", "lib/CAPI/Dialect/GPUPasses.cpp", ], - hdrs = [ - "include/mlir-c/Dialect/GPU.h", - ], + hdrs = CAPI_GPU_HEADERS, includes = ["include"], deps = [ ":CAPIIR", @@ -445,17 +505,30 @@ ":GPUTransforms", ":Pass", ], + alwayslink = True, +) + +cc_library( + name = "CAPIGPUHeaders", + hdrs = CAPI_GPU_HEADERS, + includes = ["include"], + deps = [ + ":CAPIIRHeaders", + ":GPUPassIncGen", + ], ) +CAPI_SPARSE_TENSOR_HEADERS = [ + "include/mlir-c/Dialect/SparseTensor.h", +] + cc_library( name = "CAPISparseTensor", srcs = [ "lib/CAPI/Dialect/SparseTensor.cpp", "lib/CAPI/Dialect/SparseTensorPasses.cpp", ], - hdrs = [ - "include/mlir-c/Dialect/SparseTensor.h", - ], + hdrs = CAPI_SPARSE_TENSOR_HEADERS, includes = ["include"], deps = [ ":CAPIIR", @@ -465,12 +538,25 @@ ":SparseTensorTransforms", ":Support", ], + alwayslink = True, +) + +cc_library( + name = "CAPISparseTensorHeaders", + hdrs = CAPI_SPARSE_TENSOR_HEADERS, + includes = ["include"], + deps = [ + ":CAPIIRHeaders", + ":SparseTensorPassIncGen", + ], ) +CAPI_CONVERSION_HEADERS = ["include/mlir-c/Conversion.h"] + cc_library( name = "CAPIConversion", srcs = ["lib/CAPI/Conversion/Passes.cpp"], - hdrs = ["include/mlir-c/Conversion.h"], + hdrs = CAPI_CONVERSION_HEADERS, includes = ["include"], deps = [ ":CAPIIR", @@ -478,18 +564,41 @@ ":ConversionPasses", ":Pass", ], + alwayslink = True, ) +cc_library( + name = "CAPIConversionHeaders", + hdrs = CAPI_CONVERSION_HEADERS, + includes = ["include"], + deps = [ + ":CAPIIRHeaders", + ":ConversionPassIncGen", + ], +) + +CAPI_DEBUG_HEADERS = ["include/mlir-c/Debug.h"] + cc_library( name = "CAPIDebug", srcs = ["lib/CAPI/Debug/Debug.cpp"], - hdrs = ["include/mlir-c/Debug.h"], + hdrs = CAPI_DEBUG_HEADERS, includes = ["include"], deps = [ ":CAPIIR", ":Support", "//llvm:Support", ], + alwayslink = True, +) + +cc_library( + name = "CAPIDebugHeaders", + hdrs = CAPI_DEBUG_HEADERS, + includes = ["include"], + deps = [ + ":CAPIIRHeaders", + ], ) cc_library( @@ -523,16 +632,28 @@ ], ) +CAPI_REGISTRATION_HEADERS = ["include/mlir-c/Registration.h"] + cc_library( name = "CAPIRegistration", srcs = ["lib/CAPI/Registration/Registration.cpp"], - hdrs = ["include/mlir-c/Registration.h"], + hdrs = CAPI_REGISTRATION_HEADERS, includes = ["include"], deps = [ ":AllPassesAndDialects", ":CAPIIR", ":LLVMToLLVMIRTranslation", ], + alwayslink = True, +) + +cc_library( + name = "CAPIRegistrationHeaders", + hdrs = CAPI_REGISTRATION_HEADERS, + includes = ["include"], + deps = [ + ":CAPIIRHeaders", + ], ) ##---------------------------------------------------------------------------## @@ -543,6 +664,28 @@ glob(["lib/Bindings/Python/**/*.cpp"]), ) +cc_library( + name = "MLIRBindingsPythonHeaders", + includes = [ + "include", + "lib/Bindings/Python", + ], + tags = [ + "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", + ]), + deps = [ + ":CAPIIRHeaders", + "@pybind11", + "@python_runtime//:headers", + ], +) + cc_library( name = "MLIRBindingsPythonHeadersAndDeps", includes = [ @@ -566,7 +709,7 @@ ) cc_library( - name = "MLIRBindingsPythonCore", + name = "MLIRBindingsPythonCoreNoCAPI", srcs = [ "lib/Bindings/Python/DialectLinalg.cpp", "lib/Bindings/Python/DialectSparseTensor.cpp", @@ -592,6 +735,23 @@ "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", deps = [ ":CAPIAsync", ":CAPIDebug", @@ -601,11 +761,17 @@ ":CAPILinalg", ":CAPIRegistration", ":CAPISparseTensor", - ":MLIRBindingsPythonHeadersAndDeps", - "//llvm:Support", - "@pybind11", - "@python_runtime//:headers", ], + alwayslink = True, +) + +cc_library( + name = "MLIRBindingsPythonCore", + deps = [ + ":MLIRBindingsPythonCAPIDeps", + ":MLIRBindingsPythonCoreNoCAPI", + ], + alwayslink = True, ) PYBIND11_COPTS = [