Skip to content

Commit

Permalink
Remove default LTO options, dead_strip in MacOS linker options (#16)
Browse files Browse the repository at this point in the history
* Remove default LTO options, dead_strip in MacOS linker options

Follows the official documentation's guidance that LTO is not strictly
necessary due to the library component. As an alternative, users can
give the `thin_lto` feature to a nanobind_extension instead.

The second dead_strip removal is due to it appearing twice in the
generated linker command. I also saw a missing symbol error during a
stubgen attempt earlier, which has since disappeared.
  • Loading branch information
nicholasjng authored Mar 24, 2024
1 parent 9a4e02b commit ed598ea
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions nanobind.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ package(default_visibility = ["//visibility:public"])
_NB_DEPS = [
"@robin_map",
"@rules_python//python/cc:current_py_cc_headers",
] + select({
# we need to link in the Python libs only on Windows to signal to the linker that it
# needs to go searching for these symbols at runtime.
# TODO: This seems Windows-specific, so change to `@platforms//os:windows`?
"@rules_cc//cc/compiler:msvc-cl": ["@rules_python//python/cc:current_py_cc_libs"],
"//conditions:default": [],
})
]

cc_library(
name = "nanobind",
Expand All @@ -31,13 +25,11 @@ cc_library(
}),
copts = select({
"@rules_cc//cc/compiler:msvc-cl": [
"/EHsc", # exceptions
"/GL", # LTO / whole program optimization
"/EHsc", # exceptions.
],
# clang and gcc, across all platforms.
"//conditions:default": [
"-fexceptions",
"-flto",
"-fno-strict-aliasing",
],
}) + sizeopts(),
Expand All @@ -49,9 +41,7 @@ cc_library(
],
"@platforms//os:macos": [
"-Wl,@$(location :cmake/darwin-ld-cpython.sym)", # Apple.
"-Wl,-dead_strip",
],
"@rules_cc//cc/compiler:msvc-cl": ["/LTCG"], # MSVC.
"//conditions:default": [],
}),
local_defines = sizedefs(), # sizeopts apply to nanobind only.
Expand Down

0 comments on commit ed598ea

Please sign in to comment.