From 68dbfd8a4ce412d89eb3def72765a4d97e54b213 Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Fri, 22 Mar 2024 13:25:06 +0100 Subject: [PATCH 1/2] 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. --- nanobind.BUILD | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/nanobind.BUILD b/nanobind.BUILD index 094a5a8..7f2aa79 100644 --- a/nanobind.BUILD +++ b/nanobind.BUILD @@ -31,13 +31,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(), @@ -49,9 +47,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. From 1b2e59648397e93719c3a795c6453e64fe403145 Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Fri, 22 Mar 2024 14:09:33 +0100 Subject: [PATCH 2/2] Try without linking any Windows libs this time --- nanobind.BUILD | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/nanobind.BUILD b/nanobind.BUILD index 7f2aa79..541bd19 100644 --- a/nanobind.BUILD +++ b/nanobind.BUILD @@ -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",