Closed nicholasjng closed 3 months ago
Link to a failed CI job, e.g. for Python 3.8 -> https://github.com/nicholasjng/nanobind-bazel/actions/runs/8216397874/job/22470929403.
On that note, I am suspicious of the large amount of duplication that I'm currently doing for options of libnanobind-static
, where the only variety is really the different Linux linker options.
Maybe it's possible by giving specific args to the nanobind_extension
to force static linking (e.g. features = ["fully_static_link"]
by the looks of it from the docs) and build a libnanobind.a
only if that feature (or linkstatic = True
) is given.
Closed by #7, the @nanobind//:nanobind
target now becomes a shared or static library depending on what the user requests.
In #7, converting the
@nanobind//:nanobind
target into a sharedlibnanobind[.so]
by using theNB_SHARED
macro didn't work, causing inconsistent DLL linkage warnings (MSVC C4273) and subsequent build errors.My understanding is that this happens because the addition of the
libnanobind-static
target results in both@nanobind//:nanobind
and@nanobind//:libnanobind
making it into the build deps, and then MSVC's linker cannot decide between the symbols from either one or the other.It would be best to dynamically select between either of these two deps depending on what is needed, on all platforms. The decision could possibly be made as easily as by the
linkstatic
attribute of thenanobind_library
or thefully_static_link
feature of thecc_binary
features.