nicholasjng / nanobind-bazel

Bazel defs and rules for building Python projects with nanobind extensions.
Apache License 2.0
6 stars 0 forks source link

Add strip optimizations to linker flags #22

Closed nicholasjng closed 6 months ago

nicholasjng commented 6 months ago

Previously, mangled symbols would show up in the exports list on MacOS (as seen in nm -U commands on the Python bindings shared objects).

The fix here is to supply -Wl,-x and -Wl,-S to the macOS linker, which ends up producing the same output as CMake does (verified on my machine).

Similarly, after checking the Linux ninja build manifest, Linux needs a -Wl,-s.

wjakob commented 6 months ago

A quick comment: these flags impede debugging. Is there a way to apply them conditionally in release builds? This is what the nanobind cmake build system does.

nicholasjng commented 6 months ago

Thanks for the clarification. Perhaps this will work?

config_setting(
    name = "release_build",
    flag_values = {"compilation_mode": "opt"},
)
nicholasjng commented 6 months ago

@wjakob looks like this works, are there any more release-mode-only optimizations you can think of?

(I will redesign the skylib setting groups in a subsequent PR.)

wjakob commented 6 months ago

Nanobind tweaks the following depending on whether or not the user performs a release or a debug build.

It's probably a good idea for you to replicate these two behaviors as well.

The following are more opinionated and with opt-outs:

nicholasjng commented 6 months ago

Thanks, then I'm all set. I'm currently not supporting the PROTECT_STACK flag, but I'll note it down for the future.

Actually, the debug stripping had the neat side effect of the abi3audit passing again (though perhaps for the wrong reasons).