[Mlir-commits] [mlir] [mlir] Link libraries that aren't included in libMLIR to libMLIR (PR #123477)
Michał Górny
llvmlistbot at llvm.org
Sat Jan 18 12:33:40 PST 2025
https://github.com/mgorny created https://github.com/llvm/llvm-project/pull/123477
Use `mlir_target_link_libraries()` to link dependencies of libraries that are not included in libMLIR, to ensure that they link to the dylib when they are used in Flang. Otherwise, they implicitly pull in all their static dependencies, effectively causing Flang binaries to simultaneously link to the dylib and to static libraries, which is never a good idea.
I have only covered the libraries that are used by Flang. If you wish, I can extend this approach to all non-libMLIR libraries in MLIR, making MLIR itself also link to the dylib consistently.
>From bc0a0ef3e8a292dddc873fcf6fdfdaeb3a6e266f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny at gentoo.org>
Date: Sat, 18 Jan 2025 21:16:54 +0100
Subject: [PATCH] [mlir] Link libraries that aren't included in libMLIR to
libMLIR
Use `mlir_target_link_libraries()` to link dependencies of libraries
that are not included in libMLIR, to ensure that they link to the dylib
when they are used in Flang. Otherwise, they implicitly pull in all
their static dependencies, effectively causing Flang binaries to
simultaneously link to the dylib and to static libraries, which is never
a good idea.
I have only covered the libraries that are used by Flang. If you wish,
I can extend this approach to all non-libMLIR libraries in MLIR, making
MLIR itself also link to the dylib consistently.
---
mlir/test/lib/Analysis/CMakeLists.txt | 8 +++++++-
mlir/test/lib/Dialect/Test/CMakeLists.txt | 6 +++++-
mlir/test/lib/IR/CMakeLists.txt | 6 +++++-
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/mlir/test/lib/Analysis/CMakeLists.txt b/mlir/test/lib/Analysis/CMakeLists.txt
index 7c6b31ae8b73e5..8135d22d1f7baa 100644
--- a/mlir/test/lib/Analysis/CMakeLists.txt
+++ b/mlir/test/lib/Analysis/CMakeLists.txt
@@ -21,12 +21,18 @@ add_mlir_library(MLIRTestAnalysis
EXCLUDE_FROM_LIBMLIR
LINK_LIBS PUBLIC
+ MLIRTestDialect
+ )
+
+# Since this library is excluded from libMLIR, link it to the dylib
+# to ensure that it can be used in flang without implicitly pulling in
+# static libraries.
+mlir_target_link_libraries(MLIRTestAnalysis PUBLIC
MLIRAffineDialect
MLIRAnalysis
MLIRFunctionInterfaces
MLIRMemRefDialect
MLIRPass
- MLIRTestDialect
)
target_include_directories(MLIRTestAnalysis
diff --git a/mlir/test/lib/Dialect/Test/CMakeLists.txt b/mlir/test/lib/Dialect/Test/CMakeLists.txt
index 967101242e26b5..aebf4724be34e9 100644
--- a/mlir/test/lib/Dialect/Test/CMakeLists.txt
+++ b/mlir/test/lib/Dialect/Test/CMakeLists.txt
@@ -68,8 +68,12 @@ add_mlir_library(MLIRTestDialect
MLIRTestOpsIncGen
MLIRTestOpsSyntaxIncGen
MLIRTestOpsShardGen
+ )
- LINK_LIBS PUBLIC
+# Since this library is excluded from libMLIR, link it to the dylib
+# to ensure that it can be used in flang without implicitly pulling in
+# static libraries.
+mlir_target_link_libraries(MLIRTestDialect PUBLIC
MLIRControlFlowInterfaces
MLIRDataLayoutInterfaces
MLIRDerivedAttributeOpInterface
diff --git a/mlir/test/lib/IR/CMakeLists.txt b/mlir/test/lib/IR/CMakeLists.txt
index 01297ad0a11482..09e370007a424e 100644
--- a/mlir/test/lib/IR/CMakeLists.txt
+++ b/mlir/test/lib/IR/CMakeLists.txt
@@ -27,8 +27,12 @@ add_mlir_library(MLIRTestIR
TestVisitorsGeneric.cpp
EXCLUDE_FROM_LIBMLIR
+ )
- LINK_LIBS PUBLIC
+# Since this library is excluded from libMLIR, link it to the dylib
+# to ensure that it can be used in flang without implicitly pulling in
+# static libraries.
+mlir_target_link_libraries(MLIRTestIR PUBLIC
MLIRPass
MLIRBytecodeReader
MLIRBytecodeWriter
More information about the Mlir-commits
mailing list