Skip to content

Commit

Permalink
Construct domain define as a list to avoid frozen list error
Browse files Browse the repository at this point in the history
Apparently, input lists in rules are frozen, so calling append/+= is an
error.

This pattern is a little awkward, but accomplishes what we want.
  • Loading branch information
nicholasjng committed Mar 25, 2024
1 parent 5b868ce commit 3cc0f07
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def nanobind_extension(
A list of dependencies of this extension.
domain: str, default ''
The nanobind domain to set for this extension. A nanobind domain is
an optional attribute to set that scopes extension code to a named
an optional attribute that can be set to scope extension code to a named
domain, which avoids conflicts with other extensions.
local_defines: list
A list of preprocessor defines to set for this target.
Expand All @@ -72,15 +72,17 @@ def nanobind_extension(
directly to the resulting cc_binary target.
"""
if domain != "":
local_defines.append("NB_DOMAIN={}".format(domain))
ddomain = ["NB_DOMAIN={}".format(domain)]
else:
ddomain = []

native.cc_binary(
name = name + ".so",
srcs = srcs,
copts = copts + NANOBIND_COPTS,
features = features + NANOBIND_FEATURES,
deps = deps + NANOBIND_DEPS,
local_defines = local_defines,
local_defines = local_defines + ddomain,
linkshared = True, # Python extensions need to be shared libs.
**kwargs
)
Expand Down

0 comments on commit 3cc0f07

Please sign in to comment.