Skip to content

Commit 61636e2

Browse files
authored
fix: Fix symbol export visibility in c_data_integration_test (#531)
I believe this will fix the issues we found with the latest release when trying to distribute via Windows
1 parent c1f0f37 commit 61636e2

File tree

4 files changed

+39
-34
lines changed

4 files changed

+39
-34
lines changed

meson.build

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,42 +29,43 @@ project(
2929
]
3030
)
3131

32-
# Windows shared libraries are not exporting the right symbols
33-
# See https://github.com/mesonbuild/wrapdb/pull/1536#issuecomment-2136011408
34-
# and https://github.com/apache/arrow-nanoarrow/issues/495
35-
if host_machine.system() == 'windows'
36-
libtype = 'static_library'
37-
else
38-
libtype = 'library'
32+
if meson.get_compiler('cpp').get_id() == 'gcc' or meson.get_compiler('cpp').get_id() == 'clang'
33+
add_project_arguments(['-fvisibility=hidden'], language: 'cpp')
34+
endif
35+
36+
nanoarrow_dep_args = []
37+
if host_machine.system() == 'windows' and get_option('default_library') == 'shared'
38+
add_project_arguments(['-DNANOARROW_BUILD_DLL', '-DNANOARROW_EXPORT_DLL'], language: 'c')
39+
add_project_arguments(['-DNANOARROW_BUILD_DLL', '-DNANOARROW_EXPORT_DLL'], language: 'cpp')
40+
nanoarrow_dep_args += ['-DNANOARROW_BUILD_DLL']
3941
endif
4042

4143
subdir('src/nanoarrow')
4244
incdir = include_directories('src/')
4345

44-
nanoarrow_lib = build_target(
46+
nanoarrow_lib = library(
4547
'nanoarrow',
4648
'src/nanoarrow/array.c',
4749
'src/nanoarrow/schema.c',
4850
'src/nanoarrow/array_stream.c',
4951
'src/nanoarrow/utils.c',
5052
include_directories: [incdir],
5153
install: true,
52-
target_type: libtype,
5354
)
5455

5556
nanoarrow_dep = declare_dependency(include_directories: [incdir],
56-
link_with: nanoarrow_lib)
57+
link_with: nanoarrow_lib,
58+
compile_args: nanoarrow_dep_args)
5759

5860
if get_option('ipc')
5961
flatcc_dep = dependency('flatcc')
6062

61-
nanoarrow_ipc_lib = build_target(
63+
nanoarrow_ipc_lib = library(
6264
'nanoarrow_ipc',
6365
'src/nanoarrow/nanoarrow_ipc_decoder.c',
6466
'src/nanoarrow/nanoarrow_ipc_reader.c',
6567
dependencies: [nanoarrow_dep, flatcc_dep],
6668
install: true,
67-
target_type: libtype,
6869
)
6970
nanoarrow_ipc_dep = declare_dependency(include_directories: [incdir],
7071
link_with: nanoarrow_ipc_lib,
@@ -90,12 +91,11 @@ if needs_device
9091
error('CUDA support with the Meson build system is not implemented')
9192
endif
9293

93-
nanoarrow_device_lib = build_target(
94+
nanoarrow_device_lib = library(
9495
'nanoarrow_device',
9596
sources: device_srcs,
9697
dependencies: device_deps,
9798
install: true,
98-
target_type: libtype,
9999
cpp_args: device_defines,
100100
)
101101
endif
@@ -200,8 +200,7 @@ if get_option('tests')
200200
exc = executable(
201201
name + '-test',
202202
'src/nanoarrow/' + name.replace('-', '_') + '_test.cc',
203-
dependencies: config['deps']
204-
)
203+
dependencies: config['deps'])
205204
test(name, exc, timeout: config['timeout'])
206205
endforeach
207206
endif
@@ -213,8 +212,7 @@ if get_option('tests')
213212
device_test.replace('_', '-') + '-test',
214213
'src/nanoarrow/' + device_test + '_test.cc',
215214
link_with: nanoarrow_device_lib,
216-
dependencies: [nanoarrow_dep, gtest_dep],
217-
)
215+
dependencies: [nanoarrow_dep, gtest_dep])
218216
test(device_test.replace('_', '-'), exc)
219217
endforeach
220218

@@ -223,8 +221,7 @@ if get_option('tests')
223221
'nanoarrow-device-metal-test',
224222
'src/nanoarrow/nanoarrow_device_metal_test.cc',
225223
link_with: nanoarrow_device_lib,
226-
dependencies: [nanoarrow_dep, gtest_dep, metal_cpp_dep],
227-
)
224+
dependencies: [nanoarrow_dep, gtest_dep, metal_cpp_dep])
228225
test('nanoarrow-device-metal', exc)
229226
endif
230227
endif

src/apps/dump_stream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ int main(int argc, char* argv[]) {
122122

123123
end = clock();
124124
elapsed = (end - begin) / ((double)CLOCKS_PER_SEC);
125-
fprintf(stdout, "Read %l" PRId64 " rows in %" PRId64 " batch(es) <%.06f seconds>\n",
125+
fprintf(stdout, "Read %" PRId64 " rows in %" PRId64 " batch(es) <%.06f seconds>\n",
126126
row_count, batch_count, elapsed);
127127

128128
ArrowArrayStreamRelease(&stream);

src/nanoarrow/integration/c_data_integration.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,27 +207,27 @@ static const char* ConvertError(ArrowErrorCode errno_code) {
207207
}
208208
}
209209

210-
int64_t nanoarrow_BytesAllocated() { return kBytesAllocated; }
210+
NANOARROW_DLL int64_t nanoarrow_BytesAllocated() { return kBytesAllocated; }
211211

212-
DLL_EXPORT const char* nanoarrow_CDataIntegration_ExportSchemaFromJson(
212+
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ExportSchemaFromJson(
213213
const char* json_path, ArrowSchema* out) {
214214
ArrowErrorInit(&global_error);
215215
return ConvertError(ExportSchemaFromJson(json_path, out, &global_error));
216216
}
217217

218-
DLL_EXPORT const char* nanoarrow_CDataIntegration_ImportSchemaAndCompareToJson(
218+
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ImportSchemaAndCompareToJson(
219219
const char* json_path, ArrowSchema* schema) {
220220
ArrowErrorInit(&global_error);
221221
return ConvertError(ImportSchemaAndCompareToJson(json_path, schema, &global_error));
222222
}
223223

224-
DLL_EXPORT const char* nanoarrow_CDataIntegration_ExportBatchFromJson(
224+
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ExportBatchFromJson(
225225
const char* json_path, int num_batch, ArrowArray* out) {
226226
ArrowErrorInit(&global_error);
227227
return ConvertError(ExportBatchFromJson(json_path, num_batch, out, &global_error));
228228
}
229229

230-
DLL_EXPORT const char* nanoarrow_CDataIntegration_ImportBatchAndCompareToJson(
230+
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ImportBatchAndCompareToJson(
231231
const char* json_path, int num_batch, ArrowArray* batch) {
232232
ArrowErrorInit(&global_error);
233233
return ConvertError(

src/nanoarrow/integration/c_data_integration.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@
2020

2121
#include <stdint.h>
2222

23-
#if defined(_MSC_VER)
24-
#define DLL_EXPORT __declspec(dllexport)
23+
#if (defined _WIN32 || defined __CYGWIN__) && defined(NANOARROW_BUILD_DLL)
24+
#if defined(NANOARROW_EXPORT_DLL)
25+
#define NANOARROW_DLL __declspec(dllexport)
2526
#else
26-
#define DLL_EXPORT
27+
#define NANOARROW_DLL __declspec(dllimport)
28+
#endif // defined(NANOARROW_EXPORT_DLL)
29+
#elif !defined(NANOARROW_DLL)
30+
#if __GNUC__ >= 4
31+
#define NANOARROW_DLL __attribute__((visibility("default")))
32+
#else
33+
#define NANOARROW_DLL
34+
#endif // __GNUC__ >= 4
2735
#endif
2836

2937
#ifdef __cplusplus
@@ -76,19 +84,19 @@ struct ArrowArray {
7684
#endif // ARROW_C_DATA_INTERFACE
7785
#endif // ARROW_FLAG_DICTIONARY_ORDERED
7886

79-
DLL_EXPORT const char* nanoarrow_CDataIntegration_ExportSchemaFromJson(
87+
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ExportSchemaFromJson(
8088
const char* json_path, struct ArrowSchema* out);
8189

82-
DLL_EXPORT const char* nanoarrow_CDataIntegration_ImportSchemaAndCompareToJson(
90+
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ImportSchemaAndCompareToJson(
8391
const char* json_path, struct ArrowSchema* schema);
8492

85-
DLL_EXPORT const char* nanoarrow_CDataIntegration_ExportBatchFromJson(
93+
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ExportBatchFromJson(
8694
const char* json_path, int num_batch, struct ArrowArray* out);
8795

88-
DLL_EXPORT const char* nanoarrow_CDataIntegration_ImportBatchAndCompareToJson(
96+
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ImportBatchAndCompareToJson(
8997
const char* json_path, int num_batch, struct ArrowArray* batch);
9098

91-
DLL_EXPORT int64_t nanoarrow_BytesAllocated(void);
99+
NANOARROW_DLL int64_t nanoarrow_BytesAllocated(void);
92100

93101
#ifdef __cplusplus
94102
}

0 commit comments

Comments
 (0)