Skip to content
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

fix: Fix symbol export visibility #531

Merged
merged 16 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,43 @@ project(
]
)

# Windows shared libraries are not exporting the right symbols
# See https://github.com/mesonbuild/wrapdb/pull/1536#issuecomment-2136011408
# and https://github.com/apache/arrow-nanoarrow/issues/495
if host_machine.system() == 'windows'
libtype = 'static_library'
else
libtype = 'library'
if meson.get_compiler('cpp').get_id() == 'gcc' or meson.get_compiler('cpp').get_id() == 'clang'
add_project_arguments(['-fvisibility=hidden'], language: 'cpp')
endif

nanoarrow_dep_args = []
if host_machine.system() == 'windows' and get_option('default_library') == 'shared'
add_project_arguments(['-DNANOARROW_BUILD_DLL', '-DNANOARROW_EXPORT_DLL'], language: 'c')
add_project_arguments(['-DNANOARROW_BUILD_DLL', '-DNANOARROW_EXPORT_DLL'], language: 'cpp')
nanoarrow_dep_args += ['-DNANOARROW_BUILD_DLL']
endif

subdir('src/nanoarrow')
incdir = include_directories('src/')

nanoarrow_lib = build_target(
nanoarrow_lib = library(
'nanoarrow',
'src/nanoarrow/array.c',
'src/nanoarrow/schema.c',
'src/nanoarrow/array_stream.c',
'src/nanoarrow/utils.c',
include_directories: [incdir],
install: true,
target_type: libtype,
)

nanoarrow_dep = declare_dependency(include_directories: [incdir],
link_with: nanoarrow_lib)
link_with: nanoarrow_lib,
compile_args: nanoarrow_dep_args)

if get_option('ipc')
flatcc_dep = dependency('flatcc')

nanoarrow_ipc_lib = build_target(
nanoarrow_ipc_lib = library(
'nanoarrow_ipc',
'src/nanoarrow/nanoarrow_ipc_decoder.c',
'src/nanoarrow/nanoarrow_ipc_reader.c',
dependencies: [nanoarrow_dep, flatcc_dep],
install: true,
target_type: libtype,
)
nanoarrow_ipc_dep = declare_dependency(include_directories: [incdir],
link_with: nanoarrow_ipc_lib,
Expand All @@ -90,12 +91,11 @@ if needs_device
error('CUDA support with the Meson build system is not implemented')
endif

nanoarrow_device_lib = build_target(
nanoarrow_device_lib = library(
'nanoarrow_device',
sources: device_srcs,
dependencies: device_deps,
install: true,
target_type: libtype,
cpp_args: device_defines,
)
endif
Expand Down Expand Up @@ -200,8 +200,7 @@ if get_option('tests')
exc = executable(
name + '-test',
'src/nanoarrow/' + name.replace('-', '_') + '_test.cc',
dependencies: config['deps']
)
dependencies: config['deps'])
test(name, exc, timeout: config['timeout'])
endforeach
endif
Expand All @@ -213,8 +212,7 @@ if get_option('tests')
device_test.replace('_', '-') + '-test',
'src/nanoarrow/' + device_test + '_test.cc',
link_with: nanoarrow_device_lib,
dependencies: [nanoarrow_dep, gtest_dep],
)
dependencies: [nanoarrow_dep, gtest_dep])
test(device_test.replace('_', '-'), exc)
endforeach

Expand All @@ -223,8 +221,7 @@ if get_option('tests')
'nanoarrow-device-metal-test',
'src/nanoarrow/nanoarrow_device_metal_test.cc',
link_with: nanoarrow_device_lib,
dependencies: [nanoarrow_dep, gtest_dep, metal_cpp_dep],
)
dependencies: [nanoarrow_dep, gtest_dep, metal_cpp_dep])
test('nanoarrow-device-metal', exc)
endif
endif
Expand Down
2 changes: 1 addition & 1 deletion src/apps/dump_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ int main(int argc, char* argv[]) {

end = clock();
elapsed = (end - begin) / ((double)CLOCKS_PER_SEC);
fprintf(stdout, "Read %l" PRId64 " rows in %" PRId64 " batch(es) <%.06f seconds>\n",
fprintf(stdout, "Read %" PRId64 " rows in %" PRId64 " batch(es) <%.06f seconds>\n",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated but figure minor enough to toss in

row_count, batch_count, elapsed);

ArrowArrayStreamRelease(&stream);
Expand Down
10 changes: 5 additions & 5 deletions src/nanoarrow/integration/c_data_integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,27 +207,27 @@ static const char* ConvertError(ArrowErrorCode errno_code) {
}
}

int64_t nanoarrow_BytesAllocated() { return kBytesAllocated; }
NANOARROW_DLL int64_t nanoarrow_BytesAllocated() { return kBytesAllocated; }

DLL_EXPORT const char* nanoarrow_CDataIntegration_ExportSchemaFromJson(
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ExportSchemaFromJson(
const char* json_path, ArrowSchema* out) {
ArrowErrorInit(&global_error);
return ConvertError(ExportSchemaFromJson(json_path, out, &global_error));
}

DLL_EXPORT const char* nanoarrow_CDataIntegration_ImportSchemaAndCompareToJson(
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ImportSchemaAndCompareToJson(
const char* json_path, ArrowSchema* schema) {
ArrowErrorInit(&global_error);
return ConvertError(ImportSchemaAndCompareToJson(json_path, schema, &global_error));
}

DLL_EXPORT const char* nanoarrow_CDataIntegration_ExportBatchFromJson(
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ExportBatchFromJson(
const char* json_path, int num_batch, ArrowArray* out) {
ArrowErrorInit(&global_error);
return ConvertError(ExportBatchFromJson(json_path, num_batch, out, &global_error));
}

DLL_EXPORT const char* nanoarrow_CDataIntegration_ImportBatchAndCompareToJson(
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ImportBatchAndCompareToJson(
const char* json_path, int num_batch, ArrowArray* batch) {
ArrowErrorInit(&global_error);
return ConvertError(
Expand Down
26 changes: 17 additions & 9 deletions src/nanoarrow/integration/c_data_integration.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@

#include <stdint.h>

#if defined(_MSC_VER)
#define DLL_EXPORT __declspec(dllexport)
#if (defined _WIN32 || defined __CYGWIN__) && defined(NANOARROW_BUILD_DLL)
#if defined(NANOARROW_EXPORT_DLL)
#define NANOARROW_DLL __declspec(dllexport)
#else
#define DLL_EXPORT
#endif
#define NANOARROW_DLL __declspec(dllimport)
#endif // (defined _WIN32 || defined __CYGWIN__) && defined(NANOARROW_BUILD_DLL)
#else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe here: #elif !defined(NANOARROW_DLL) (i.e., let the user override this logic if they need to do something else)

#if __GNUC__ >= 4
#define NANOARROW_DLL __attribute__((visibility("default")))
#else
#define NANOARROW_DLL
#endif // __GNUC__ >= 4
#endif // defined _WIN32 || defined __CYGWIN__

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -76,19 +84,19 @@ struct ArrowArray {
#endif // ARROW_C_DATA_INTERFACE
#endif // ARROW_FLAG_DICTIONARY_ORDERED

DLL_EXPORT const char* nanoarrow_CDataIntegration_ExportSchemaFromJson(
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ExportSchemaFromJson(
const char* json_path, struct ArrowSchema* out);

DLL_EXPORT const char* nanoarrow_CDataIntegration_ImportSchemaAndCompareToJson(
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ImportSchemaAndCompareToJson(
const char* json_path, struct ArrowSchema* schema);

DLL_EXPORT const char* nanoarrow_CDataIntegration_ExportBatchFromJson(
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ExportBatchFromJson(
const char* json_path, int num_batch, struct ArrowArray* out);

DLL_EXPORT const char* nanoarrow_CDataIntegration_ImportBatchAndCompareToJson(
NANOARROW_DLL const char* nanoarrow_CDataIntegration_ImportBatchAndCompareToJson(
const char* json_path, int num_batch, struct ArrowArray* batch);

DLL_EXPORT int64_t nanoarrow_BytesAllocated(void);
NANOARROW_DLL int64_t nanoarrow_BytesAllocated(void);

#ifdef __cplusplus
}
Expand Down
Loading