-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[Clang][Cygwin] attempt to fix building shared libclang. #138351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Clang][Cygwin] attempt to fix building shared libclang. #138351
Conversation
@llvm/pr-subscribers-clang Author: None (jeremyd2019) Changes@mstorsjo I don't understand why this isn't working. We know it works for MinGW right? Full diff: https://github.com/llvm/llvm-project/pull/138351.diff 2 Files Affected:
diff --git a/clang/include/clang-c/Platform.h b/clang/include/clang-c/Platform.h
index 67c1fff8ff783..8d341ddd6f8eb 100644
--- a/clang/include/clang-c/Platform.h
+++ b/clang/include/clang-c/Platform.h
@@ -22,7 +22,7 @@ LLVM_CLANG_C_EXTERN_C_BEGIN
#ifndef CINDEX_NO_EXPORTS
#define CINDEX_EXPORTS
#endif
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
#ifdef CINDEX_EXPORTS
#ifdef _CINDEX_LIB_
#define CINDEX_LINKAGE __declspec(dllexport)
diff --git a/clang/tools/libclang/CMakeLists.txt b/clang/tools/libclang/CMakeLists.txt
index 37a939ffcada7..454dfead0bcf5 100644
--- a/clang/tools/libclang/CMakeLists.txt
+++ b/clang/tools/libclang/CMakeLists.txt
@@ -158,7 +158,7 @@ if(ENABLE_STATIC)
endif()
if(ENABLE_SHARED)
- if(WIN32)
+ if(WIN32 OR CYGWIN)
set_target_properties(libclang
PROPERTIES
VERSION ${LIBCLANG_LIBRARY_VERSION}
|
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions h -- clang/include/clang-c/Platform.h View the diff from clang-format here.diff --git a/clang/include/clang-c/Platform.h b/clang/include/clang-c/Platform.h
index 8d341ddd6..1c28ccf81 100644
--- a/clang/include/clang-c/Platform.h
+++ b/clang/include/clang-c/Platform.h
@@ -23,13 +23,13 @@ LLVM_CLANG_C_EXTERN_C_BEGIN
#define CINDEX_EXPORTS
#endif
#if defined(_WIN32) || defined(__CYGWIN__)
- #ifdef CINDEX_EXPORTS
- #ifdef _CINDEX_LIB_
- #define CINDEX_LINKAGE __declspec(dllexport)
- #else
- #define CINDEX_LINKAGE __declspec(dllimport)
- #endif
- #endif
+#ifdef CINDEX_EXPORTS
+#ifdef _CINDEX_LIB_
+#define CINDEX_LINKAGE __declspec(dllexport)
+#else
+#define CINDEX_LINKAGE __declspec(dllimport)
+#endif
+#endif
#elif defined(CINDEX_EXPORTS) && defined(__GNUC__)
#define CINDEX_LINKAGE __attribute__((visibility("default")))
#endif
|
I think it works when you build with Clang rather than GCC. Clang will not export symbols with hidden visibility. |
But people build mingw clang with gcc, right? They presumably don't set |
Dunno.
Yes, linker exports all the symbols by default, but explicit export disable that. |
Offhand, I don't quite know here. Which configurations is this about? For mingw, the only cases I'm familiar with is building with Building that kind of dylib used to work with GCC, but these days it probably hits the limit on the number of exported symbols (initially in libLLVM-*.dll), unless you reduce the number of enabled targets a lot. |
Now we know that adding |
Surprisingly, it looks like Cygwin (@tyan0) is working around the export limit on gcc by setting |
This was my misunderstanding. Building successfully was due to I wonder why your msys2 build scripts does not fail to build even with |
Thanks for clarifying this! Indeed, |
@mstorsjo I don't understand why this isn't working. We know it works for MinGW right?