@@ -34,6 +34,7 @@ def rust_repositories(
34
34
edition = None ,
35
35
dev_components = False ,
36
36
sha256s = None ,
37
+ include_rustc_src = False ,
37
38
urls = DEFAULT_STATIC_RUST_URL_TEMPLATES ):
38
39
"""Emits a default set of toolchains for Linux, MacOS, and Freebsd
39
40
@@ -99,6 +100,7 @@ def rust_repositories(
99
100
edition = edition ,
100
101
dev_components = dev_components ,
101
102
sha256s = sha256s ,
103
+ include_rustc_src = include_rustc_src ,
102
104
urls = urls ,
103
105
)
104
106
@@ -285,7 +287,7 @@ rust_toolchain(
285
287
cargo = "@{workspace_name}//:cargo",
286
288
clippy_driver = "@{workspace_name}//:clippy_driver_bin",
287
289
rustc_lib = "@{workspace_name}//:rustc_lib",
288
- rustc_src = "@{workspace_name}//: rustc_src" ,
290
+ rustc_src = { rustc_src} ,
289
291
binary_ext = "{binary_ext}",
290
292
staticlib_ext = "{staticlib_ext}",
291
293
dylib_ext = "{dylib_ext}",
@@ -303,6 +305,7 @@ def BUILD_for_rust_toolchain(
303
305
name ,
304
306
exec_triple ,
305
307
target_triple ,
308
+ include_rustc_src ,
306
309
stdlib_linkflags = None ,
307
310
default_edition = "2015" ):
308
311
"""Emits a toolchain declaration to match an existing compiler and stdlib.
@@ -324,12 +327,17 @@ def BUILD_for_rust_toolchain(
324
327
if stdlib_linkflags == None :
325
328
stdlib_linkflags = ", " .join (['"%s"' % x for x in system_to_stdlib_linkflags (system )])
326
329
330
+ rustc_src = "None"
331
+ if include_rustc_src :
332
+ rustc_src = "\" @{workspace_name}//:rustc_src\" " .format (workspace_name = workspace_name )
333
+
327
334
return _build_file_for_rust_toolchain_template .format (
328
335
toolchain_name = name ,
329
336
workspace_name = workspace_name ,
330
337
binary_ext = system_to_binary_ext (system ),
331
338
staticlib_ext = system_to_staticlib_ext (system ),
332
339
dylib_ext = system_to_dylib_ext (system ),
340
+ rustc_src = rustc_src ,
333
341
stdlib_linkflags = stdlib_linkflags ,
334
342
system = system ,
335
343
default_edition = default_edition ,
@@ -538,6 +546,7 @@ def _load_rust_stdlib(ctx, target_triple):
538
546
target_triple = target_triple ,
539
547
),
540
548
exec_triple = ctx .attr .exec_triple ,
549
+ include_rustc_src = ctx .attr .include_rustc_src ,
541
550
target_triple = target_triple ,
542
551
stdlib_linkflags = stdlib_linkflags ,
543
552
workspace_name = ctx .attr .name ,
@@ -588,7 +597,10 @@ def _rust_toolchain_repository_impl(ctx):
588
597
589
598
_check_version_valid (ctx .attr .version , ctx .attr .iso_date )
590
599
591
- build_components = [_load_rust_compiler (ctx ), _load_rust_src (ctx )]
600
+ build_components = [_load_rust_compiler (ctx )]
601
+
602
+ if ctx .attr .include_rustc_src :
603
+ build_components .append (_load_rust_src (ctx ))
592
604
593
605
if ctx .attr .rustfmt_version :
594
606
build_components .append (_load_rustfmt (ctx ))
@@ -645,6 +657,10 @@ rust_toolchain_repository = repository_rule(
645
657
doc = "The Rust-style target that this compiler runs on" ,
646
658
mandatory = True ,
647
659
),
660
+ "include_rustc_src" : attr .bool (
661
+ doc = "Whether to download and unpack the rustc source files. These are very large, and slow to unpack, but are required to support rust analyzer." ,
662
+ default = False ,
663
+ ),
648
664
"extra_target_triples" : attr .string_list (
649
665
doc = "Additional rust-style targets that this set of toolchains should support." ,
650
666
),
@@ -700,6 +716,7 @@ def rust_repository_set(
700
716
name ,
701
717
version ,
702
718
exec_triple ,
719
+ include_rustc_src = False ,
703
720
extra_target_triples = [],
704
721
iso_date = None ,
705
722
rustfmt_version = None ,
@@ -733,6 +750,7 @@ def rust_repository_set(
733
750
rust_toolchain_repository (
734
751
name = name ,
735
752
exec_triple = exec_triple ,
753
+ include_rustc_src = include_rustc_src ,
736
754
extra_target_triples = extra_target_triples ,
737
755
iso_date = iso_date ,
738
756
toolchain_name_prefix = DEFAULT_TOOLCHAIN_NAME_PREFIX ,
0 commit comments