Skip to content

Commit 22ca12a

Browse files
committed
rustc_src is optional
This is a tar containing a huge number of files (hundreds of thousands) which can take double-digit seconds to extract. It's only used for rust analyzer support, so hide this behind a flag people can opt in to if they want.
1 parent 8d69e76 commit 22ca12a

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

rust/repositories.bzl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def rust_repositories(
3434
edition = None,
3535
dev_components = False,
3636
sha256s = None,
37+
include_rustc_src = False,
3738
urls = DEFAULT_STATIC_RUST_URL_TEMPLATES):
3839
"""Emits a default set of toolchains for Linux, MacOS, and Freebsd
3940
@@ -99,6 +100,7 @@ def rust_repositories(
99100
edition = edition,
100101
dev_components = dev_components,
101102
sha256s = sha256s,
103+
include_rustc_src = include_rustc_src,
102104
urls = urls,
103105
)
104106

@@ -285,7 +287,7 @@ rust_toolchain(
285287
cargo = "@{workspace_name}//:cargo",
286288
clippy_driver = "@{workspace_name}//:clippy_driver_bin",
287289
rustc_lib = "@{workspace_name}//:rustc_lib",
288-
rustc_src = "@{workspace_name}//:rustc_src",
290+
rustc_src = {rustc_src},
289291
binary_ext = "{binary_ext}",
290292
staticlib_ext = "{staticlib_ext}",
291293
dylib_ext = "{dylib_ext}",
@@ -303,6 +305,7 @@ def BUILD_for_rust_toolchain(
303305
name,
304306
exec_triple,
305307
target_triple,
308+
include_rustc_src,
306309
stdlib_linkflags = None,
307310
default_edition = "2015"):
308311
"""Emits a toolchain declaration to match an existing compiler and stdlib.
@@ -324,12 +327,17 @@ def BUILD_for_rust_toolchain(
324327
if stdlib_linkflags == None:
325328
stdlib_linkflags = ", ".join(['"%s"' % x for x in system_to_stdlib_linkflags(system)])
326329

330+
rustc_src = "None"
331+
if include_rustc_src:
332+
rustc_src = "\"@{workspace_name}//:rustc_src\"".format(workspace_name = workspace_name)
333+
327334
return _build_file_for_rust_toolchain_template.format(
328335
toolchain_name = name,
329336
workspace_name = workspace_name,
330337
binary_ext = system_to_binary_ext(system),
331338
staticlib_ext = system_to_staticlib_ext(system),
332339
dylib_ext = system_to_dylib_ext(system),
340+
rustc_src = rustc_src,
333341
stdlib_linkflags = stdlib_linkflags,
334342
system = system,
335343
default_edition = default_edition,
@@ -538,6 +546,7 @@ def _load_rust_stdlib(ctx, target_triple):
538546
target_triple = target_triple,
539547
),
540548
exec_triple = ctx.attr.exec_triple,
549+
include_rustc_src = ctx.attr.include_rustc_src,
541550
target_triple = target_triple,
542551
stdlib_linkflags = stdlib_linkflags,
543552
workspace_name = ctx.attr.name,
@@ -588,7 +597,10 @@ def _rust_toolchain_repository_impl(ctx):
588597

589598
_check_version_valid(ctx.attr.version, ctx.attr.iso_date)
590599

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))
592604

593605
if ctx.attr.rustfmt_version:
594606
build_components.append(_load_rustfmt(ctx))
@@ -645,6 +657,10 @@ rust_toolchain_repository = repository_rule(
645657
doc = "The Rust-style target that this compiler runs on",
646658
mandatory = True,
647659
),
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+
),
648664
"extra_target_triples": attr.string_list(
649665
doc = "Additional rust-style targets that this set of toolchains should support.",
650666
),
@@ -700,6 +716,7 @@ def rust_repository_set(
700716
name,
701717
version,
702718
exec_triple,
719+
include_rustc_src = False,
703720
extra_target_triples = [],
704721
iso_date = None,
705722
rustfmt_version = None,
@@ -733,6 +750,7 @@ def rust_repository_set(
733750
rust_toolchain_repository(
734751
name = name,
735752
exec_triple = exec_triple,
753+
include_rustc_src = include_rustc_src,
736754
extra_target_triples = extra_target_triples,
737755
iso_date = iso_date,
738756
toolchain_name_prefix = DEFAULT_TOOLCHAIN_NAME_PREFIX,

0 commit comments

Comments
 (0)