@@ -31,6 +31,7 @@ _ATTRS = {
31
31
"node_urls" : attr .string_list (),
32
32
"node_version" : attr .string (),
33
33
"node_version_from_nvmrc" : attr .label (allow_single_file = True ),
34
+ "include_headers" : attr .bool (),
34
35
"platform" : attr .string (
35
36
doc = "Internal use only. Which platform to install as a toolchain. If unset, we assume the repository is named nodejs_[platform]" ,
36
37
values = BUILT_IN_NODE_PLATFORMS ,
@@ -241,6 +242,20 @@ filegroup(
241
242
name = "npm_files",
242
243
srcs = glob(["bin/nodejs/**"]) + [":node_files"],
243
244
)
245
+ """ .format (
246
+ node_bin_export = "\n \" %s\" ," % node_bin ,
247
+ npm_bin_export = "\n \" %s\" ," % npm_bin ,
248
+ npx_bin_export = "\n \" %s\" ," % npx_bin ,
249
+ node_bin_label = node_bin_label ,
250
+ npm_bin_label = npm_bin_label ,
251
+ npx_bin_label = npx_bin_label ,
252
+ node_entry = node_entry ,
253
+ npm_entry = npm_entry ,
254
+ npx_entry = npx_entry ,
255
+ )
256
+
257
+ if repository_ctx .attr .include_headers :
258
+ build_content += """
244
259
cc_library(
245
260
name = "headers",
246
261
hdrs = glob(
@@ -256,17 +271,7 @@ cc_library(
256
271
),
257
272
includes = ["bin/nodejs/include/node"],
258
273
)
259
- """ .format (
260
- node_bin_export = "\n \" %s\" ," % node_bin ,
261
- npm_bin_export = "\n \" %s\" ," % npm_bin ,
262
- npx_bin_export = "\n \" %s\" ," % npx_bin ,
263
- node_bin_label = node_bin_label ,
264
- npm_bin_label = npm_bin_label ,
265
- npx_bin_label = npx_bin_label ,
266
- node_entry = node_entry ,
267
- npm_entry = npm_entry ,
268
- npx_entry = npx_entry ,
269
- )
274
+ """
270
275
271
276
if repository_ctx .attr .platform :
272
277
build_content += """
@@ -276,14 +281,15 @@ nodejs_toolchain(
276
281
node = ":node_bin",
277
282
npm = ":npm",
278
283
npm_srcs = [":npm_files"],
279
- headers = ": headers" ,
284
+ headers = { headers} ,
280
285
)
281
286
# alias for backward compat
282
287
alias(
283
288
name = "node_toolchain",
284
289
actual = ":toolchain",
285
290
)
286
- """
291
+ """ .format (headers = "\" :headers\" " if repository_ctx .attr .include_headers else "None" )
292
+
287
293
repository_ctx .file ("BUILD.bazel" , content = build_content )
288
294
289
295
def _strip_bin (path ):
@@ -314,6 +320,7 @@ def nodejs_repositories(
314
320
node_urls = [DEFAULT_NODE_URL ],
315
321
node_version = DEFAULT_NODE_VERSION ,
316
322
node_version_from_nvmrc = None ,
323
+ include_headers = False ,
317
324
** kwargs ):
318
325
"""To be run in user's WORKSPACE to install rules_nodejs dependencies.
319
326
@@ -394,6 +401,10 @@ def nodejs_repositories(
394
401
395
402
If set then the version found in the .nvmrc file is used instead of the one specified by node_version.
396
403
404
+ include_headers: Set headers field in NodeInfo provided by this toolchain.
405
+
406
+ This setting creates a dependency on a c++ toolchain.
407
+
397
408
**kwargs: Additional parameters
398
409
"""
399
410
use_nvmrc = kwargs .pop ("use_nvmrc" , None )
@@ -411,6 +422,7 @@ WARNING: use_nvmrc attribute of node_repositories is deprecated; use node_versio
411
422
node_urls = node_urls ,
412
423
node_version = node_version ,
413
424
node_version_from_nvmrc = node_version_from_nvmrc ,
425
+ include_headers = include_headers ,
414
426
** kwargs
415
427
)
416
428
0 commit comments