Skip to content

Commit 2e57541

Browse files
burgholzerwjakob
authored andcommitted
Preserve section GC in split mode
Linked targets inherit section compile and link flags from the static nanobind library. Split targets skip that library and lose the flags. Apply the same options directly to split targets. Assisted-by: Codex
1 parent 9632a38 commit 2e57541

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

cmake/nanobind-config.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,11 @@ function(nanobind_add_module name)
573573
${Python_INCLUDE_DIRS} ${NB_DIR}/include)
574574
target_compile_features(${name} PRIVATE cxx_std_17)
575575

576+
if (NOT WIN32 AND NOT APPLE AND NOT AIX)
577+
target_compile_options(${name} PRIVATE $<${NB_OPT_SIZE}:-ffunction-sections -fdata-sections>)
578+
target_link_options(${name} PRIVATE $<${NB_OPT_SIZE}:-Wl,--gc-sections>)
579+
endif()
580+
576581
if (WIN32)
577582
target_link_libraries(${name} PRIVATE Python::SABIModule)
578583
endif()

0 commit comments

Comments
 (0)