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 3 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
8 changes: 8 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ project(
]
)

if meson.get_compiler('c').get_id() == 'gcc' or meson.get_compiler('c').get_id() == 'clang'
add_project_arguments(['-fvisibility=hidden'], language: 'c')
endif

if meson.get_compiler('cpp').get_id() == 'gcc' or meson.get_compiler('cpp').get_id() == 'clang'
add_project_arguments(['-fvisibility=hidden'], language: 'cpp')
endif

subdir('src/nanoarrow')

if get_option('benchmarks')
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
8 changes: 4 additions & 4 deletions src/nanoarrow/integration/c_data_integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,25 +209,25 @@ static const char* ConvertError(ArrowErrorCode errno_code) {

int64_t nanoarrow_BytesAllocated() { return kBytesAllocated; }

DLL_EXPORT const char* nanoarrow_CDataIntegration_ExportSchemaFromJson(
NANOARROW_DLL_EXPORT 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_EXPORT 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_EXPORT 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_EXPORT const char* nanoarrow_CDataIntegration_ImportBatchAndCompareToJson(
const char* json_path, int num_batch, ArrowArray* batch) {
ArrowErrorInit(&global_error);
return ConvertError(
Expand Down
17 changes: 6 additions & 11 deletions src/nanoarrow/integration/c_data_integration.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@
#ifndef NANOARROW_INTEGRATION_C_DATA_INTEGRATION_H_INCLUDED
#define NANOARROW_INTEGRATION_C_DATA_INTEGRATION_H_INCLUDED

#include <nanoarrow/nanoarrow_types.h>
#include <stdint.h>

#if defined(_MSC_VER)
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT
#endif

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

DLL_EXPORT const char* nanoarrow_CDataIntegration_ExportSchemaFromJson(
NANOARROW_DLL_EXPORT const char* nanoarrow_CDataIntegration_ExportSchemaFromJson(
Copy link
Member

@paleolimbot paleolimbot Jun 17, 2024

Choose a reason for hiding this comment

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

I believe that all of the functions in nanoarrow.h, nanoarrow_device.h, and nanoarrow_ipc.h will need NANOARROW_DLL_EXPORT as well.

Another way to think about it would be every symbol listed in the namespace defines (also the ones listed in nanoarrow_device_xxx.h and nanoarrow_ipc.h):

#define ArrowNanoarrowVersion NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowNanoarrowVersion)
#define ArrowNanoarrowVersionInt \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowNanoarrowVersionInt)
#define ArrowMalloc NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMalloc)
#define ArrowRealloc NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowRealloc)
#define ArrowFree NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowFree)
#define ArrowBufferAllocatorDefault \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowBufferAllocatorDefault)
#define ArrowBufferDeallocator \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowBufferDeallocator)
#define ArrowErrorSet NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowErrorSet)
#define ArrowLayoutInit NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowLayoutInit)
#define ArrowDecimalSetDigits NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowDecimalSetDigits)
#define ArrowDecimalAppendDigitsToBuffer \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowDecimalAppendDigitsToBuffer)
#define ArrowSchemaInit NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaInit)
#define ArrowSchemaInitFromType \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaInitFromType)
#define ArrowSchemaSetType NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetType)
#define ArrowSchemaSetTypeStruct \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeStruct)
#define ArrowSchemaSetTypeFixedSize \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeFixedSize)
#define ArrowSchemaSetTypeDecimal \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeDecimal)
#define ArrowSchemaSetTypeRunEndEncoded \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeRunEndEncoded)
#define ArrowSchemaSetTypeDateTime \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeDateTime)
#define ArrowSchemaSetTypeUnion \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeUnion)
#define ArrowSchemaDeepCopy NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaDeepCopy)
#define ArrowSchemaSetFormat NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetFormat)
#define ArrowSchemaSetName NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetName)
#define ArrowSchemaSetMetadata \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetMetadata)
#define ArrowSchemaAllocateChildren \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaAllocateChildren)
#define ArrowSchemaAllocateDictionary \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaAllocateDictionary)
#define ArrowMetadataReaderInit \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataReaderInit)
#define ArrowMetadataReaderRead \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataReaderRead)
#define ArrowMetadataSizeOf NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataSizeOf)
#define ArrowMetadataHasKey NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataHasKey)
#define ArrowMetadataGetValue NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataGetValue)
#define ArrowMetadataBuilderInit \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataBuilderInit)
#define ArrowMetadataBuilderAppend \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataBuilderAppend)
#define ArrowMetadataBuilderSet \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataBuilderSet)
#define ArrowMetadataBuilderRemove \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataBuilderRemove)
#define ArrowSchemaViewInit NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaViewInit)
#define ArrowSchemaToString NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaToString)
#define ArrowArrayInitFromType \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayInitFromType)
#define ArrowArrayInitFromSchema \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayInitFromSchema)
#define ArrowArrayInitFromArrayView \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayInitFromArrayView)
#define ArrowArrayInitFromArrayView \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayInitFromArrayView)
#define ArrowArrayAllocateChildren \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayAllocateChildren)
#define ArrowArrayAllocateDictionary \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayAllocateDictionary)
#define ArrowArraySetValidityBitmap \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArraySetValidityBitmap)
#define ArrowArraySetBuffer NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArraySetBuffer)
#define ArrowArrayReserve NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayReserve)
#define ArrowArrayFinishBuilding \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayFinishBuilding)
#define ArrowArrayFinishBuildingDefault \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayFinishBuildingDefault)
#define ArrowArrayViewInitFromType \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewInitFromType)
#define ArrowArrayViewInitFromSchema \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewInitFromSchema)
#define ArrowArrayViewAllocateChildren \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewAllocateChildren)
#define ArrowArrayViewAllocateDictionary \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewAllocateDictionary)
#define ArrowArrayViewSetLength \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewSetLength)
#define ArrowArrayViewSetArray \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewSetArray)
#define ArrowArrayViewSetArrayMinimal \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewSetArrayMinimal)
#define ArrowArrayViewValidate \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewValidate)
#define ArrowArrayViewReset NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewReset)
#define ArrowBasicArrayStreamInit \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowBasicArrayStreamInit)
#define ArrowBasicArrayStreamSetArray \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowBasicArrayStreamSetArray)
#define ArrowBasicArrayStreamValidate \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowBasicArrayStreamValidate)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good - went ahead and added the visibility to the C compiler and used the macro for any of the defines.

There might be a few defines missing? I noticed things like ArrowSchemaMove, ArrowArrayMove and ArrowArrayStreamMove, etc... were not part of the defines but the IPC/device move functions always were

Copy link
Member

Choose a reason for hiding this comment

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

To my understanding, any function that is static inline doesn't need to worry about this (i.e., those functions are header-only and are never public).

Copy link
Member

Choose a reason for hiding this comment

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

Correcting myself here...they're header-only but some of them are public. (None of them end up as exported symbols, though)

const char* json_path, struct ArrowSchema* out);

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

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

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

DLL_EXPORT int64_t nanoarrow_BytesAllocated(void);
NANOARROW_DLL_EXPORT int64_t nanoarrow_BytesAllocated(void);

#ifdef __cplusplus
}
Expand Down
18 changes: 3 additions & 15 deletions src/nanoarrow/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,13 @@ configure_file(input: 'nanoarrow_config.h.in',
output: 'nanoarrow_config.h',
configuration: conf_data)

# 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'
endif

nanoarrow_lib = build_target(
nanoarrow_lib = library(
'nanoarrow',
'array.c',
'schema.c',
'array_stream.c',
'utils.c',
install: true,
target_type: libtype,
)

curdir = include_directories('.') # only needed when used as subproject?
Expand All @@ -67,13 +57,12 @@ nanoarrow_dep = declare_dependency(include_directories: [curdir, incdir],
if get_option('ipc')
flatcc_dep = dependency('flatcc')

nanoarrow_ipc_lib = build_target(
nanoarrow_ipc_lib = library(
'nanoarrow_ipc',
'nanoarrow_ipc_decoder.c',
'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 @@ -99,12 +88,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
Loading
Loading