Skip to content

Commit 55c525a

Browse files
authored
Declare visibility without linking capi twice (#1314)
1 parent c93d807 commit 55c525a

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

src/enzyme_ad/jax/BUILD

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ cc_library(
2626
srcs = ["gpu.cc"],
2727
copts = ["-Wno-vla-cxx-extension"],
2828
deps = [
29-
"@llvm-project//mlir:CAPIIR",
3029
"@xla//xla/ffi:ffi_api",
3130
"@xla//xla/ffi/api:ffi",
3231
],
@@ -36,7 +35,6 @@ cc_library(
3635
name = "cpu",
3736
srcs = ["cpu.cc"],
3837
deps = [
39-
"@llvm-project//mlir:CAPIIR",
4038
"@xla//xla/service:custom_call_status",
4139
"@xla//xla/service:custom_call_target_registry",
4240
],
@@ -603,7 +601,6 @@ cc_library(
603601
"@llvm-project//mlir:VectorToLLVM",
604602
"@llvm-project//mlir:VectorToSCF",
605603
"@llvm-project//mlir:ViewLikeInterface",
606-
"@llvm-project//mlir:CAPIIR",
607604
"@shardy//shardy/dialect/sdy/ir:dialect",
608605
"@shardy//shardy/dialect/sdy/transforms/propagation:op_sharding_rule_builder",
609606
"@stablehlo//:base",

src/enzyme_ad/jax/Passes/LowerJIT.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,21 @@
8080

8181
#include "mlir/Target/LLVMIR/Export.h"
8282

83-
#include "mlir-c/Support.h"
83+
#if (defined(_WIN32) || defined(__CYGWIN__)) && \
84+
!defined(MLIR_CAPI_ENABLE_WINDOWS_DLL_DECLSPEC)
85+
// Visibility annotations disabled.
86+
#define MLIR_CAPI_EXPORTED
87+
#elif defined(_WIN32) || defined(__CYGWIN__)
88+
// Windows visibility declarations.
89+
#if MLIR_CAPI_BUILDING_LIBRARY
90+
#define MLIR_CAPI_EXPORTED __declspec(dllexport)
91+
#else
92+
#define MLIR_CAPI_EXPORTED __declspec(dllimport)
93+
#endif
94+
#else
95+
// Non-windows: use visibility attributes.
96+
#define MLIR_CAPI_EXPORTED __attribute__((visibility("default")))
97+
#endif
8498

8599
#define DEBUG_TYPE "lower-jit"
86100

src/enzyme_ad/jax/cpu.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,21 @@
22
#include "xla/service/custom_call_target_registry.h"
33
#include <cstring>
44

5-
#include "mlir-c/Support.h"
5+
#if (defined(_WIN32) || defined(__CYGWIN__)) && \
6+
!defined(MLIR_CAPI_ENABLE_WINDOWS_DLL_DECLSPEC)
7+
// Visibility annotations disabled.
8+
#define MLIR_CAPI_EXPORTED
9+
#elif defined(_WIN32) || defined(__CYGWIN__)
10+
// Windows visibility declarations.
11+
#if MLIR_CAPI_BUILDING_LIBRARY
12+
#define MLIR_CAPI_EXPORTED __declspec(dllexport)
13+
#else
14+
#define MLIR_CAPI_EXPORTED __declspec(dllimport)
15+
#endif
16+
#else
17+
// Non-windows: use visibility attributes.
18+
#define MLIR_CAPI_EXPORTED __attribute__((visibility("default")))
19+
#endif
620

721
template <bool withError> struct CallInfo;
822

src/enzyme_ad/jax/gpu.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
#include "xla/ffi/api/ffi.h"
22
#include "xla/ffi/ffi_api.h"
33

4-
#include "mlir-c/Support.h"
4+
#if (defined(_WIN32) || defined(__CYGWIN__)) && \
5+
!defined(MLIR_CAPI_ENABLE_WINDOWS_DLL_DECLSPEC)
6+
// Visibility annotations disabled.
7+
#define MLIR_CAPI_EXPORTED
8+
#elif defined(_WIN32) || defined(__CYGWIN__)
9+
// Windows visibility declarations.
10+
#if MLIR_CAPI_BUILDING_LIBRARY
11+
#define MLIR_CAPI_EXPORTED __declspec(dllexport)
12+
#else
13+
#define MLIR_CAPI_EXPORTED __declspec(dllimport)
14+
#endif
15+
#else
16+
// Non-windows: use visibility attributes.
17+
#define MLIR_CAPI_EXPORTED __attribute__((visibility("default")))
18+
#endif
519

620
template <bool withError> struct CallInfo;
721

0 commit comments

Comments
 (0)