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 @@ -382,9 +382,11 @@ srcs = [ "lib/CAPI/Interfaces/Interfaces.cpp", ], + capi_deps = [ + ":CAPIIR", + ], includes = ["include"], deps = [ - ":CAPIIR", ":IR", ":InferTypeOpInterface", "//llvm:Support", @@ -398,15 +400,16 @@ "lib/CAPI/Dialect/AsyncPasses.cpp", ], hdrs = ["include/mlir-c/Dialect/Async.h"], + capi_deps = [ + ":CAPIIR", + ], header_deps = [ ":AsyncPassIncGen", - ":CAPIIRHeaders", ], includes = ["include"], deps = [ ":Async", ":AsyncTransforms", - ":CAPIIR", ":Pass", ], ) @@ -420,13 +423,14 @@ hdrs = [ "include/mlir-c/Dialect/Linalg.h", ], + capi_deps = [ + ":CAPIIR", + ], header_deps = [ - ":CAPIIRHeaders", ":LinalgPassIncGen", ], includes = ["include"], deps = [ - ":CAPIIR", ":LinalgOps", ":LinalgTransforms", ":Pass", @@ -441,12 +445,11 @@ hdrs = [ "include/mlir-c/Dialect/LLVM.h", ], - header_deps = [ - ":CAPIIRHeaders", + capi_deps = [ + ":CAPIIR", ], includes = ["include"], deps = [ - ":CAPIIR", ":LLVMDialect", ], ) @@ -460,13 +463,14 @@ hdrs = [ "include/mlir-c/Dialect/GPU.h", ], + capi_deps = [ + ":CAPIIR", + ], header_deps = [ - ":CAPIIRHeaders", ":GPUPassIncGen", ], includes = ["include"], deps = [ - ":CAPIIR", ":GPUDialect", ":GPUTransforms", ":Pass", @@ -482,13 +486,14 @@ hdrs = [ "include/mlir-c/Dialect/SparseTensor.h", ], + capi_deps = [ + ":CAPIIR", + ], header_deps = [ - ":CAPIIRHeaders", ":SparseTensorPassIncGen", ], includes = ["include"], deps = [ - ":CAPIIR", ":Pass", ":SparseTensor", ":SparseTensorTransforms", @@ -504,12 +509,11 @@ hdrs = [ "include/mlir-c/Dialect/Quant.h", ], - header_deps = [ - ":CAPIIRHeaders", + capi_deps = [ + ":CAPIIR", ], includes = ["include"], deps = [ - ":CAPIIR", ":QuantOps", ], ) @@ -518,13 +522,14 @@ name = "CAPIConversion", srcs = ["lib/CAPI/Conversion/Passes.cpp"], hdrs = ["include/mlir-c/Conversion.h"], + capi_deps = [ + ":CAPIIR", + ], header_deps = [ - ":CAPIIRHeaders", ":ConversionPassIncGen", ], includes = ["include"], deps = [ - ":CAPIIR", ":ConversionPasses", ":Pass", ], @@ -534,12 +539,11 @@ name = "CAPIDebug", srcs = ["lib/CAPI/Debug/Debug.cpp"], hdrs = ["include/mlir-c/Debug.h"], - header_deps = [ - ":CAPIIRHeaders", + capi_deps = [ + ":CAPIIR", ], includes = ["include"], deps = [ - ":CAPIIR", ":Support", "//llvm:Support", ], @@ -552,13 +556,14 @@ "include/mlir-c/ExecutionEngine.h", "include/mlir/CAPI/ExecutionEngine.h", ], + capi_deps = [ + ":CAPIIR", + ], header_deps = [ - ":CAPIIRHeaders", ":ExecutionEngine", ], includes = ["include"], deps = [ - ":CAPIIR", ":ExecutionEngineUtils", ":LLVMToLLVMIRTranslation", "//llvm:OrcJIT", @@ -570,13 +575,14 @@ name = "CAPITransforms", srcs = ["lib/CAPI/Transforms/Passes.cpp"], hdrs = ["include/mlir-c/Transforms.h"], + capi_deps = [ + ":CAPIIR", + ], header_deps = [ - ":CAPIIRHeaders", ":TransformsPassIncGen", ], includes = ["include"], deps = [ - ":CAPIIR", ":Pass", ":Transforms", ], @@ -586,13 +592,12 @@ name = "CAPIRegistration", srcs = ["lib/CAPI/Registration/Registration.cpp"], hdrs = ["include/mlir-c/Registration.h"], - header_deps = [ - ":CAPIIRHeaders", + capi_deps = [ + ":CAPIIR", ], includes = ["include"], deps = [ ":AllPassesAndDialects", - ":CAPIIR", ":LLVMToLLVMIRTranslation", ], ) 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 @@ -31,6 +31,7 @@ hdrs = [], deps = [], header_deps = [], + capi_deps = [], **kwargs): """Macro that generates three targets for MLIR C API libraries. @@ -38,26 +39,33 @@ * 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"). - """ + In order to avoid duplicate symbols, it is important that + mlir_c_api_cc_library targets only depend on other mlir_c_api_cc_library + targets via the "capi_deps" parameter. This makes it so that "FooObjects" + depend on "BarObjects" targets and "Foo" targets depend on "Bar" targets. + Don't cross the streams. + """ + capi_header_deps = ["%sHeaders" % d for d in capi_deps] + capi_object_deps = ["%sObjects" % d for d in capi_deps] native.cc_library( name = name, srcs = srcs, hdrs = hdrs, - deps = deps + header_deps, + deps = deps + capi_deps + header_deps, **kwargs ) native.cc_library( name = name + "Headers", hdrs = hdrs, - deps = header_deps, + deps = header_deps + capi_header_deps, **kwargs ) native.cc_library( name = name + "Objects", srcs = srcs, hdrs = hdrs, - deps = deps + header_deps, + deps = deps + capi_object_deps + capi_header_deps + header_deps, alwayslink = True, **kwargs )