diff --git a/BUILD b/BUILD index 92927b2..89c8f76 100644 --- a/BUILD +++ b/BUILD @@ -48,6 +48,26 @@ config_setting( flag_values = {":py-limited-api": "unset"}, ) +config_setting( + name = "MacReleaseBuild", + constraint_values = [ + "@platforms//os:macos", + ], + values = { + "compilation_mode": "opt", + }, +) + +config_setting( + name = "LinuxReleaseBuild", + constraint_values = [ + "@platforms//os:linux", + ], + values = { + "compilation_mode": "opt", + }, +) + selects.config_setting_group( name = "unix", match_any = [ diff --git a/helpers.bzl b/helpers.bzl index 9c5f963..c5905a8 100644 --- a/helpers.bzl +++ b/helpers.bzl @@ -7,6 +7,14 @@ def sizeopts(): "@nanobind_bazel//:without_sizeopts": [], }) +def stripopts(): + """Linker options to strip external and debug symbols from nanobind release builds.""" + return select({ + "@nanobind_bazel//:MacReleaseBuild": ["-Wl,-x", "-Wl,-S"], + "@nanobind_bazel//:LinuxReleaseBuild": ["-Wl,-s"], + "//conditions:default": [], + }) + def sizedefs(): return select({ "@nanobind_bazel//:with_sizeopts": ["NB_COMPACT_ASSERTIONS"], diff --git a/nanobind.BUILD b/nanobind.BUILD index fc96f3f..1e31011 100644 --- a/nanobind.BUILD +++ b/nanobind.BUILD @@ -5,7 +5,7 @@ Size optimizations used: -Os, LTO. Linker optimizations used: LTO (clang, gcc) / LTCG (MSVC), linker response file (macOS only). """ -load("@nanobind_bazel//:helpers.bzl", "py_limited_api", "sizedefs", "sizeopts") +load("@nanobind_bazel//:helpers.bzl", "py_limited_api", "sizedefs", "sizeopts", "stripopts") licenses(["notice"]) @@ -45,11 +45,9 @@ cc_library( # chained fixups on Apple platforms. "-Wl,@$(location :cmake/darwin-ld-cpython.sym)", "-Wl,-dead_strip", - "-Wl,-x", - "-Wl,-S", ], "//conditions:default": [], - }), + }) + stripopts(), local_defines = sizedefs(), # sizeopts apply to nanobind only. textual_hdrs = glob( [