diff --git a/bindings/c/CMakeLists.txt b/bindings/c/CMakeLists.txt index b30a78bd84..75b0a4e323 100644 --- a/bindings/c/CMakeLists.txt +++ b/bindings/c/CMakeLists.txt @@ -38,6 +38,21 @@ else() endif() add_dependencies(fdb_c fdb_c_generated fdb_c_options) target_link_libraries(fdb_c PUBLIC $) +if(APPLE) + set(symbols ${CMAKE_CURRENT_BINARY_DIR}/fdb_c.symbols) + add_custom_command(OUTPUT ${symbols} + COMMAND $ ${CMAKE_CURRENT_SOURCE_DIR}/symbolify.py + ${CMAKE_CURRENT_SOURCE_DIR}/foundationdb/fdb_c.h + ${symbols} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/symbolify.py ${CMAKE_CURRENT_SOURCE_DIR}/foundationdb/fdb_c.h + COMMENT "Generate exported_symbols_list") + add_custom_target(exported_symbols_list DEPENDS ${symbols}) + add_dependencies(fdb_c exported_symbols_list) + target_link_options(fdb_c PRIVATE "LINKER:-no_weak_exports,-exported_symbols_list,${symbols}") +elseif(WIN32) +else() + target_link_options(fdb_c PRIVATE "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/fdb_c.map,-z,nodelete") +endif() target_include_directories(fdb_c PUBLIC $ $ diff --git a/bindings/c/symbolify.py b/bindings/c/symbolify.py new file mode 100644 index 0000000000..55d8dc81fd --- /dev/null +++ b/bindings/c/symbolify.py @@ -0,0 +1,10 @@ +if __name__ == '__main__': + import re + import sys + r = re.compile('DLLEXPORT[^(]*(fdb_[^(]*)[(]') + (fdb_c_h, symbols_file) = sys.argv[1:] + with open(fdb_c_h, 'r') as f: + symbols = sorted(set('_' + m.group(1) for m in r.finditer(f.read()))) + with open(symbols_file, 'w') as f: + f.write('\n'.join(symbols)) + f.write('\n')