From 3cc0f075ffbbda1c9bf4c31037614c7b50326a2b Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Mon, 25 Mar 2024 17:08:39 +0100 Subject: [PATCH] Construct domain define as a list to avoid frozen list error Apparently, input lists in rules are frozen, so calling append/+= is an error. This pattern is a little awkward, but accomplishes what we want. --- build_defs.bzl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/build_defs.bzl b/build_defs.bzl index 2e88aa8..6750d75 100644 --- a/build_defs.bzl +++ b/build_defs.bzl @@ -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. @@ -72,7 +72,9 @@ 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", @@ -80,7 +82,7 @@ def nanobind_extension( 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 )