diff --git a/bindings/python/nanobind.BUILD b/bindings/python/nanobind.BUILD index 2852019502..c7edfb2b93 100644 --- a/bindings/python/nanobind.BUILD +++ b/bindings/python/nanobind.BUILD @@ -2,18 +2,40 @@ licenses(["notice"]) package(default_visibility = ["//visibility:public"]) -filegroup( - name = "symboltable", - srcs = ["cmake/darwin-ld-cpython.sym"], +config_setting( + name = "msvc_compiler", + flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc-cl"}, ) cc_library( name = "nanobind", srcs = glob([ - "src/*.cpp" + "src/*.cpp", ]), - copts = ["-fexceptions"], - includes = ["include", "ext/robin_map/include"], + additional_linker_inputs = select({ + "@platforms//os:macos": [":cmake/darwin-ld-cpython.sym"], + "//conditions:default": [], + }), + copts = select({ + ":msvc_compiler": [ + "/EHsc", # exceptions + "/Os", # size optimizations + ], + # these should work on both clang and gcc. + "//conditions:default": [ + "-fexceptions", + "-flto", + "-Os", + ], + }), + includes = [ + "ext/robin_map/include", + "include", + ], + linkopts = select({ + "@platforms//os:macos": ["-Wl,@$(location :cmake/darwin-ld-cpython.sym)"], + "//conditions:default": [], + }), textual_hdrs = glob( [ "include/**/*.h", @@ -21,13 +43,5 @@ cc_library( "ext/robin_map/include/tsl/*.h", ], ), - linkopts = select({ - "@platforms//os:macos": ["-Wl,@$(location :cmake/darwin-ld-cpython.sym)"], - "//conditions:default": [], - }), - additional_linker_inputs = select({ - "@platforms//os:macos": [":cmake/darwin-ld-cpython.sym"], - "//conditions:default": [], - }), deps = ["@python_headers"], )