fork/rules_rust

git clone https://git.julia.blue/fork/rules_rust

UebelAndreBump various dependencies (#3002)43e5279e

cleanup
48.3 KiB1106 linesraw
1"""Repository rules for defining Rust dependencies and toolchains"""
2
3load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
5load("//rust/platform:triple.bzl", "get_host_triple", "triple")
6load("//rust/platform:triple_mappings.bzl", "triple_to_constraint_set")
7load("//rust/private:common.bzl", "rust_common")
8load(
9    "//rust/private:repository_utils.bzl",
10    "BUILD_for_rust_analyzer_proc_macro_srv",
11    "BUILD_for_rust_analyzer_toolchain",
12    "BUILD_for_rust_toolchain",
13    "BUILD_for_rustfmt_toolchain",
14    "BUILD_for_toolchain",
15    "DEFAULT_EXTRA_TARGET_TRIPLES",
16    "DEFAULT_NIGHTLY_VERSION",
17    "DEFAULT_STATIC_RUST_URL_TEMPLATES",
18    "TINYJSON_KWARGS",
19    "check_version_valid",
20    "includes_rust_analyzer_proc_macro_srv",
21    "load_cargo",
22    "load_clippy",
23    "load_llvm_tools",
24    "load_rust_compiler",
25    "load_rust_src",
26    "load_rust_stdlib",
27    "load_rustc_dev_nightly",
28    "load_rustfmt",
29    "select_rust_version",
30    "toolchain_repository_hub",
31    _load_arbitrary_tool = "load_arbitrary_tool",
32)
33
34# Re-export `load_arbitrary_tool` as it's historically been used in external repositories.
35load_arbitrary_tool = _load_arbitrary_tool
36
37# Note: Code in `.github/workflows/crate_universe.yaml` looks for this line, if you remove it or change its format, you will also need to update that code.
38DEFAULT_TOOLCHAIN_TRIPLES = {
39    "aarch64-apple-darwin": "rust_darwin_aarch64",
40    "aarch64-pc-windows-msvc": "rust_windows_aarch64",
41    "aarch64-unknown-linux-gnu": "rust_linux_aarch64",
42    "s390x-unknown-linux-gnu": "rust_linux_s390x",
43    "x86_64-apple-darwin": "rust_darwin_x86_64",
44    "x86_64-pc-windows-msvc": "rust_windows_x86_64",
45    "x86_64-unknown-freebsd": "rust_freebsd_x86_64",
46    "x86_64-unknown-linux-gnu": "rust_linux_x86_64",
47}
48
49def rules_rust_dependencies():
50    """Dependencies used in the implementation of `rules_rust`."""
51
52    maybe(
53        http_archive,
54        name = "platforms",
55        urls = [
56            "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz",
57            "https://github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz",
58        ],
59        sha256 = "218efe8ee736d26a3572663b374a253c012b716d8af0c07e842e82f238a0a7ee",
60    )
61
62    # Avoid the following issue https://github.com/bazelbuild/rules_cc/issues/274
63    rules_cc_kwargs = {}
64    if native.bazel_version.startswith(("6", "7")):
65        rules_cc_kwargs.update({
66            "patch_args": ["-p1"],
67            "patches": [Label("//rust/private/3rdparty:rules_cc.patch")],
68        })
69    maybe(
70        http_archive,
71        name = "rules_cc",
72        urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.17/rules_cc-0.0.17.tar.gz"],
73        sha256 = "abc605dd850f813bb37004b77db20106a19311a96b2da1c92b789da529d28fe1",
74        strip_prefix = "rules_cc-0.0.17",
75        **rules_cc_kwargs
76    )
77    maybe(
78        http_archive,
79        name = "rules_license",
80        urls = [
81            "https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/1.0.0/rules_license-1.0.0.tar.gz",
82            "https://github.com/bazelbuild/rules_license/releases/download/1.0.0/rules_license-1.0.0.tar.gz",
83        ],
84        sha256 = "26d4021f6898e23b82ef953078389dd49ac2b5618ac564ade4ef87cced147b38",
85    )
86    maybe(
87        http_archive,
88        name = "bazel_features",
89        sha256 = "af3d4fb1cf4f25942cb4a933b1ad93a0ea9fe9ee70c2af7f369fb72a67c266e5",
90        strip_prefix = "bazel_features-1.21.0",
91        url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.21.0/bazel_features-v1.21.0.tar.gz",
92    )
93
94    maybe(
95        http_archive,
96        name = "bazel_skylib",
97        sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f",
98        urls = [
99            "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
100            "https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
101        ],
102    )
103
104    # Make the iOS simulator constraint available, which is referenced in abi_to_constraints()
105    # rules_rust does not require this dependency; it is just imported as a convenience for users.
106    maybe(
107        http_archive,
108        name = "build_bazel_apple_support",
109        sha256 = "b53f6491e742549f13866628ddffcc75d1f3b2d6987dc4f14a16b242113c890b",
110        url = "https://github.com/bazelbuild/apple_support/releases/download/1.17.1/apple_support.1.17.1.tar.gz",
111    )
112
113    # process_wrapper needs a low-dependency way to process json.
114    maybe(
115        http_archive,
116        **TINYJSON_KWARGS
117    )
118
119_RUST_TOOLCHAIN_VERSIONS = [
120    rust_common.default_version,
121    DEFAULT_NIGHTLY_VERSION,
122]
123
124# buildifier: disable=unnamed-macro
125def rust_register_toolchains(
126        dev_components = False,
127        edition = None,
128        allocator_library = None,
129        global_allocator_library = None,
130        register_toolchains = True,
131        rustfmt_version = None,
132        rust_analyzer_version = None,
133        sha256s = None,
134        extra_target_triples = DEFAULT_EXTRA_TARGET_TRIPLES,
135        extra_rustc_flags = None,
136        extra_exec_rustc_flags = None,
137        urls = DEFAULT_STATIC_RUST_URL_TEMPLATES,
138        versions = _RUST_TOOLCHAIN_VERSIONS,
139        aliases = {}):
140    """Emits a default set of toolchains for Linux, MacOS, and Freebsd
141
142    Skip this macro and call the `rust_repository_set` macros directly if you need a compiler for \
143    other hosts or for additional target triples.
144
145    The `sha256s` attribute represents a dict associating tool subdirectories to sha256 hashes. As an example:
146    ```python
147    {
148        "rust-1.46.0-x86_64-unknown-linux-gnu": "e3b98bc3440fe92817881933f9564389eccb396f5f431f33d48b979fa2fbdcf5",
149        "rustfmt-1.4.12-x86_64-unknown-linux-gnu": "1894e76913303d66bf40885a601462844eec15fca9e76a6d13c390d7000d64b0",
150        "rust-std-1.46.0-x86_64-unknown-linux-gnu": "ac04aef80423f612c0079829b504902de27a6997214eb58ab0765d02f7ec1dbc",
151    }
152    ```
153    This would match for `exec_triple = "x86_64-unknown-linux-gnu"`.  If not specified, rules_rust pulls from a non-exhaustive \
154    list of known checksums..
155
156    See `load_arbitrary_tool` in `@rules_rust//rust:repositories.bzl` for more details.
157
158    Args:
159        dev_components (bool, optional): Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly".
160        edition (str, optional): The rust edition to be used by default (2015, 2018, or 2021). If absent, every target is required to specify its `edition` attribute.
161        allocator_library (str, optional): Target that provides allocator functions when rust_library targets are embedded in a cc_binary.
162        global_allocator_library (str, optional): Target that provides allocator functions when global allocator is used with cc_common.link.
163        register_toolchains (bool): If true, repositories will be generated to produce and register `rust_toolchain` targets.
164        rustfmt_version (str, optional): The version of rustfmt. If none is supplied and only a single version in `versions` is given, then this defaults to that version, otherwise will default to the default nightly version.
165        rust_analyzer_version (str, optional): The version of Rustc to pair with rust-analyzer.
166        sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes.
167        extra_target_triples (list, optional): Additional rust-style targets that rust toolchains should support.
168        extra_rustc_flags (dict, list, optional): Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration.
169        extra_exec_rustc_flags (list, optional): Extra flags to pass to rustc in exec configuration.
170        urls (list, optional): A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format).
171        versions (list, optional): A list of toolchain versions to download. This parameter only accepts one versions
172            per channel. E.g. `["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]`.
173        aliases (dict, optional): A mapping of "full" repository name to another name to use instead.
174    """
175    if not rustfmt_version:
176        if len(versions) == 1:
177            rustfmt_version = versions[0]
178        else:
179            rustfmt_version = DEFAULT_NIGHTLY_VERSION
180
181    if dev_components:
182        has_nightly = False
183        for ver in versions:
184            if ver.startswith("nightly"):
185                has_nightly = True
186                break
187        if not has_nightly:
188            fail("rustc-dev components were requested but no \"nightly\" is being registered. Please update `versions` to include a nightly version.")
189
190    if not rust_analyzer_version:
191        rust_analyzer_version = select_rust_version(versions)
192
193    # Convert to an unfrozen dict to remove mappings as they are used. This will allow us to determine if there
194    # are any unused aliases requested.
195    aliases = dict(aliases)
196
197    rust_analyzer_repo_name = "rust_analyzer_{}".format(rust_analyzer_version.replace("/", "-"))
198
199    toolchain_names = []
200    toolchain_labels = {}
201    toolchain_types = {}
202    exec_compatible_with_by_toolchain = {}
203    target_compatible_with_by_toolchain = {}
204
205    maybe(
206        rust_analyzer_toolchain_repository,
207        name = rust_analyzer_repo_name,
208        version = rust_analyzer_version,
209        urls = urls,
210        sha256s = sha256s,
211    )
212
213    toolchain_names.append(rust_analyzer_repo_name)
214    toolchain_labels[rust_analyzer_repo_name] = "@{}_tools//:rust_analyzer_toolchain".format(
215        rust_analyzer_repo_name,
216    )
217    exec_compatible_with_by_toolchain[rust_analyzer_repo_name] = []
218    target_compatible_with_by_toolchain[rust_analyzer_repo_name] = []
219    toolchain_types[rust_analyzer_repo_name] = "@rules_rust//rust/rust_analyzer:toolchain_type"
220
221    if register_toolchains:
222        native.register_toolchains("@{}//:toolchain".format(
223            rust_analyzer_repo_name,
224        ))
225
226    for exec_triple, name in DEFAULT_TOOLCHAIN_TRIPLES.items():
227        maybe(
228            rust_repository_set,
229            name = name,
230            dev_components = dev_components,
231            edition = edition,
232            exec_triple = exec_triple,
233            extra_target_triples = extra_target_triples,
234            allocator_library = allocator_library,
235            global_allocator_library = global_allocator_library,
236            register_toolchain = register_toolchains,
237            rustfmt_version = rustfmt_version,
238            extra_rustc_flags = extra_rustc_flags,
239            extra_exec_rustc_flags = extra_exec_rustc_flags,
240            sha256s = sha256s,
241            urls = urls,
242            versions = versions,
243            aliases = aliases,
244        )
245
246        rustfmt_repo_name = "rustfmt_{}__{}".format(rustfmt_version.replace("/", "-"), exec_triple)
247        if rustfmt_repo_name in aliases:
248            rustfmt_repo_name = aliases.pop(rustfmt_repo_name)
249
250        maybe(
251            rustfmt_toolchain_repository,
252            name = rustfmt_repo_name,
253            version = rustfmt_version,
254            urls = urls,
255            sha256s = sha256s,
256            exec_triple = exec_triple,
257        )
258
259        if register_toolchains:
260            native.register_toolchains("@{}//:toolchain".format(
261                rustfmt_repo_name,
262            ))
263
264        for toolchain in _get_toolchain_repositories(name, exec_triple, extra_target_triples, versions, fallback_target_compatible_with = None, aliases = aliases):
265            toolchain_names.append(toolchain.name)
266            toolchain_labels[toolchain.name] = "@{}//:{}".format(toolchain.name + "_tools", "rust_toolchain")
267            exec_compatible_with_by_toolchain[toolchain.name] = triple_to_constraint_set(exec_triple)
268            target_compatible_with_by_toolchain[toolchain.name] = toolchain.target_constraints
269            toolchain_types[toolchain.name] = "@rules_rust//rust:toolchain"
270
271        toolchain_names.append(rustfmt_repo_name)
272        toolchain_labels[rustfmt_repo_name] = "@{}_tools//:rustfmt_toolchain".format(rustfmt_repo_name)
273        exec_compatible_with_by_toolchain[rustfmt_repo_name] = triple_to_constraint_set(exec_triple)
274        target_compatible_with_by_toolchain[rustfmt_repo_name] = []
275        toolchain_types[rustfmt_repo_name] = "@rules_rust//rust/rustfmt:toolchain_type"
276
277    if aliases:
278        fail("No repositories were created matching the requested names to alias:\n{}".format("\n".join(sorted(aliases))))
279
280    toolchain_repository_hub(
281        name = "rust_toolchains",
282        toolchain_names = toolchain_names,
283        toolchain_labels = toolchain_labels,
284        toolchain_types = toolchain_types,
285        exec_compatible_with = exec_compatible_with_by_toolchain,
286        target_compatible_with = target_compatible_with_by_toolchain,
287    )
288
289# buildifier: disable=unnamed-macro
290def rust_repositories(**kwargs):
291    """**Deprecated**: Use [rules_rust_dependencies](#rules_rust_dependencies) \
292    and [rust_register_toolchains](#rust_register_toolchains) directly.
293
294    Args:
295        **kwargs (dict): Keyword arguments for the `rust_register_toolchains` macro.
296    """
297    rules_rust_dependencies()
298
299    rust_register_toolchains(**kwargs)
300
301_RUST_TOOLCHAIN_REPOSITORY_ATTRS = {
302    "allocator_library": attr.string(
303        doc = "Target that provides allocator functions when rust_library targets are embedded in a cc_binary.",
304        default = "@rules_rust//ffi/cc/allocator_library",
305    ),
306    "auth": attr.string_dict(
307        doc = (
308            "Auth object compatible with repository_ctx.download to use when downloading files. " +
309            "See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details."
310        ),
311    ),
312    "auth_patterns": attr.string_list(
313        doc = "A list of patterns to match against urls for which the auth object should be used.",
314    ),
315    "dev_components": attr.bool(
316        doc = "Whether to download the rustc-dev components (defaults to False). Requires version to be \"nightly\".",
317        default = False,
318    ),
319    "edition": attr.string(
320        doc = (
321            "The rust edition to be used by default (2015, 2018, or 2021). " +
322            "If absent, every rule is required to specify its `edition` attribute."
323        ),
324    ),
325    "exec_triple": attr.string(
326        doc = "The Rust-style target that this compiler runs on",
327        mandatory = True,
328    ),
329    "extra_exec_rustc_flags": attr.string_list(
330        doc = "Extra flags to pass to rustc in exec configuration",
331    ),
332    "extra_rustc_flags": attr.string_list(
333        doc = "Extra flags to pass to rustc in non-exec configuration",
334    ),
335    "global_allocator_library": attr.string(
336        doc = "Target that provides allocator functions when a global allocator is used with cc_common.link.",
337        default = "@rules_rust//ffi/cc/global_allocator_library",
338    ),
339    "netrc": attr.string(
340        doc = ".netrc file to use for authentication; mirrors the eponymous attribute from http_archive",
341    ),
342    "opt_level": attr.string_dict(
343        doc = "Rustc optimization levels. For more details see the documentation for `rust_toolchain.opt_level`.",
344    ),
345    "rustfmt_version": attr.string(
346        doc = "The version of the tool among \"nightly\", \"beta\", or an exact version.",
347    ),
348    "sha256s": attr.string_dict(
349        doc = "A dict associating tool subdirectories to sha256 hashes. See [rust_register_toolchains](#rust_register_toolchains) for more details.",
350    ),
351    "target_triple": attr.string(
352        doc = "The Rust-style target that this compiler builds for.",
353        mandatory = True,
354    ),
355    "urls": attr.string_list(
356        doc = "A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format).",
357        default = DEFAULT_STATIC_RUST_URL_TEMPLATES,
358    ),
359    "version": attr.string(
360        doc = "The version of the tool among \"nightly\", \"beta\", or an exact version.",
361        mandatory = True,
362    ),
363}
364
365def _rust_toolchain_tools_repository_impl(ctx):
366    """The implementation of the rust toolchain tools repository rule."""
367    sha256s = dict(ctx.attr.sha256s)
368    iso_date = None
369    version = ctx.attr.version
370    version_array = version.split("/")
371    if len(version_array) > 1:
372        version = version_array[0]
373        iso_date = version_array[1]
374
375    check_version_valid(ctx.attr.version, iso_date)
376
377    exec_triple = triple(ctx.attr.exec_triple)
378
379    rustc_content, rustc_sha256 = load_rust_compiler(
380        ctx = ctx,
381        iso_date = iso_date,
382        target_triple = exec_triple,
383        version = version,
384    )
385    clippy_content, clippy_sha256 = load_clippy(
386        ctx = ctx,
387        iso_date = iso_date,
388        target_triple = exec_triple,
389        version = version,
390    )
391    cargo_content, cargo_sha256 = load_cargo(
392        ctx = ctx,
393        iso_date = iso_date,
394        target_triple = exec_triple,
395        version = version,
396    )
397
398    build_components = [
399        rustc_content,
400        clippy_content,
401        cargo_content,
402    ]
403    sha256s.update(rustc_sha256 | clippy_sha256 | cargo_sha256)
404
405    if ctx.attr.rustfmt_version:
406        rustfmt_version = ctx.attr.rustfmt_version
407        rustfmt_iso_date = None
408        if rustfmt_version in ("nightly", "beta"):
409            if iso_date:
410                rustfmt_iso_date = iso_date
411            else:
412                fail("`rustfmt_version` does not include an iso_date. The following reposiotry should either set `iso_date` or update `rustfmt_version` to include an iso_date suffix: {}".format(
413                    ctx.name,
414                ))
415        elif rustfmt_version.startswith(("nightly", "beta")):
416            rustfmt_version, _, rustfmt_iso_date = rustfmt_version.partition("/")
417        rustfmt_content, rustfmt_sha256 = load_rustfmt(
418            ctx = ctx,
419            target_triple = triple(ctx.attr.exec_triple),
420            version = rustfmt_version,
421            iso_date = rustfmt_iso_date,
422        )
423        build_components.append(rustfmt_content)
424        sha256s.update(rustfmt_sha256)
425
426    # Rust 1.45.0 and nightly builds after 2020-05-22 need the llvm-tools gzip to get the libLLVM dylib
427    include_llvm_tools = version >= "1.45.0" or (version == "nightly" and iso_date > "2020-05-22")
428    if include_llvm_tools:
429        llvm_tools_content, llvm_tools_sha256 = load_llvm_tools(
430            ctx = ctx,
431            target_triple = exec_triple,
432            version = version,
433            iso_date = iso_date,
434        )
435        build_components.append(llvm_tools_content)
436        sha256s.update(llvm_tools_sha256)
437
438    target_triple = triple(ctx.attr.target_triple)
439    rust_stdlib_content, rust_stdlib_sha256 = load_rust_stdlib(
440        ctx = ctx,
441        target_triple = target_triple,
442        version = version,
443        iso_date = iso_date,
444    )
445    build_components.append(rust_stdlib_content)
446    sha256s.update(rust_stdlib_sha256)
447
448    stdlib_linkflags = None
449    if "BAZEL_RUST_STDLIB_LINKFLAGS" in ctx.os.environ:
450        stdlib_linkflags = ctx.os.environ["BAZEL_RUST_STDLIB_LINKFLAGS"].split(":")
451
452    build_components.append(BUILD_for_rust_toolchain(
453        name = "rust_toolchain",
454        exec_triple = exec_triple,
455        allocator_library = ctx.attr.allocator_library,
456        global_allocator_library = ctx.attr.global_allocator_library,
457        target_triple = target_triple,
458        stdlib_linkflags = stdlib_linkflags,
459        default_edition = ctx.attr.edition,
460        include_rustfmt = not (not ctx.attr.rustfmt_version),
461        include_llvm_tools = include_llvm_tools,
462        extra_rustc_flags = ctx.attr.extra_rustc_flags,
463        extra_exec_rustc_flags = ctx.attr.extra_exec_rustc_flags,
464        opt_level = ctx.attr.opt_level if ctx.attr.opt_level else None,
465    ))
466
467    # Not all target triples are expected to have dev components
468    if ctx.attr.dev_components:
469        rustc_dev_sha256 = load_rustc_dev_nightly(
470            ctx = ctx,
471            target_triple = target_triple,
472            version = version,
473            iso_date = iso_date,
474        )
475        sha256s.update(rustc_dev_sha256)
476
477    ctx.file("WORKSPACE.bazel", "")
478    ctx.file("BUILD.bazel", "\n".join(build_components))
479
480    repro = {"name": ctx.name}
481    for key in _RUST_TOOLCHAIN_REPOSITORY_ATTRS:
482        repro[key] = getattr(ctx.attr, key)
483    repro["sha256s"] = sha256s
484
485    return repro
486
487rust_toolchain_tools_repository = repository_rule(
488    doc = (
489        "Composes a single workspace containing the toolchain components for compiling on a given " +
490        "platform to a series of target platforms.\n" +
491        "\n" +
492        "A given instance of this rule should be accompanied by a toolchain_repository_proxy " +
493        "invocation to declare its toolchains to Bazel; the indirection allows separating toolchain " +
494        "selection from toolchain fetching."
495    ),
496    attrs = _RUST_TOOLCHAIN_REPOSITORY_ATTRS,
497    implementation = _rust_toolchain_tools_repository_impl,
498)
499
500def _toolchain_repository_proxy_impl(repository_ctx):
501    repository_ctx.file("WORKSPACE.bazel", """workspace(name = "{}")""".format(
502        repository_ctx.name,
503    ))
504
505    repository_ctx.file("BUILD.bazel", BUILD_for_toolchain(
506        name = "toolchain",
507        toolchain = repository_ctx.attr.toolchain,
508        target_settings = repository_ctx.attr.target_settings,
509        toolchain_type = repository_ctx.attr.toolchain_type,
510        target_compatible_with = repository_ctx.attr.target_compatible_with,
511        exec_compatible_with = repository_ctx.attr.exec_compatible_with,
512    ))
513
514toolchain_repository_proxy = repository_rule(
515    doc = (
516        "Generates a toolchain-bearing repository that declares the toolchains from some other " +
517        "rust_toolchain_repository."
518    ),
519    attrs = {
520        "exec_compatible_with": attr.string_list(
521            doc = "A list of constraints for the execution platform for this toolchain.",
522        ),
523        "target_compatible_with": attr.string_list(
524            doc = "A list of constraints for the target platform for this toolchain.",
525        ),
526        "target_settings": attr.string_list(
527            doc = "A list of config_settings that must be satisfied by the target configuration in order for this toolchain to be selected during toolchain resolution.",
528        ),
529        "toolchain": attr.string(
530            doc = "The name of the toolchain implementation target.",
531            mandatory = True,
532        ),
533        "toolchain_type": attr.string(
534            doc = "The toolchain type of the toolchain to declare",
535            mandatory = True,
536        ),
537    },
538    implementation = _toolchain_repository_proxy_impl,
539)
540
541# For legacy support
542rust_toolchain_repository_proxy = toolchain_repository_proxy
543
544# N.B. A "proxy repository" is needed to allow for registering the toolchain (with constraints)
545# without actually downloading the toolchain.
546def rust_toolchain_repository(
547        name,
548        version,
549        exec_triple,
550        target_triple,
551        exec_compatible_with = None,
552        target_compatible_with = None,
553        target_settings = [],
554        channel = None,
555        allocator_library = None,
556        global_allocator_library = None,
557        rustfmt_version = None,
558        edition = None,
559        dev_components = False,
560        extra_rustc_flags = None,
561        extra_exec_rustc_flags = None,
562        opt_level = None,
563        sha256s = None,
564        urls = DEFAULT_STATIC_RUST_URL_TEMPLATES,
565        auth = None,
566        netrc = None,
567        auth_patterns = None):
568    """Assembles a remote repository for the given toolchain params, produces a proxy repository \
569    to contain the toolchain declaration, and registers the toolchains.
570
571    Args:
572        name (str): The name of the generated repository
573        version (str): The version of the tool among "nightly", "beta", or an exact version.
574        exec_triple (str): The Rust-style target that this compiler runs on.
575        target_triple (str): The Rust-style target to build for.
576        channel (str, optional): The channel of the Rust toolchain.
577        exec_compatible_with (list, optional): A list of constraints for the execution platform for this toolchain.
578        target_compatible_with (list, optional): A list of constraints for the target platform for this toolchain.
579        target_settings (list, optional): A list of config_settings that must be satisfied by the target configuration in order for this toolchain to be selected during toolchain resolution.
580        allocator_library (str, optional): Target that provides allocator functions when rust_library targets are embedded in a cc_binary.
581        global_allocator_library (str, optional): Target that provides allocator functions when a global allocator is used with cc_common.link.
582        rustfmt_version (str, optional):  The version of rustfmt to be associated with the
583            toolchain.
584        edition (str, optional): The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its `edition` attribute.
585        dev_components (bool, optional): Whether to download the rustc-dev components.
586            Requires version to be "nightly". Defaults to False.
587        extra_rustc_flags (list, optional): Extra flags to pass to rustc in non-exec configuration.
588        extra_exec_rustc_flags (list, optional): Extra flags to pass to rustc in exec configuration.
589        opt_level (dict, optional): Optimization level config for this toolchain.
590        sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See
591            [rust_register_toolchains](#rust_register_toolchains) for more details.
592        urls (list, optional): A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.xz']
593        auth (dict): Auth object compatible with repository_ctx.download to use when downloading files.
594            See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details.
595        netrc (str, optional): .netrc file to use for authentication; mirrors the eponymous attribute from http_archive
596        auth_patterns (list, optional): A list of patterns to match against urls for which the auth object should be used.
597
598    Returns:
599        str: The name of the registerable toolchain created by this rule.
600    """
601    if exec_compatible_with == None:
602        exec_compatible_with = triple_to_constraint_set(exec_triple)
603
604    if target_compatible_with == None:
605        target_compatible_with = triple_to_constraint_set(target_triple)
606
607    tools_repo_name = "{}_tools".format(name)
608
609    rust_toolchain_tools_repository(
610        name = tools_repo_name,
611        exec_triple = exec_triple,
612        allocator_library = allocator_library,
613        global_allocator_library = global_allocator_library,
614        target_triple = target_triple,
615        version = version,
616        rustfmt_version = rustfmt_version,
617        edition = edition,
618        dev_components = dev_components,
619        extra_rustc_flags = extra_rustc_flags,
620        extra_exec_rustc_flags = extra_exec_rustc_flags,
621        opt_level = opt_level,
622        sha256s = sha256s,
623        urls = urls,
624        auth = auth,
625        netrc = netrc,
626        auth_patterns = auth_patterns,
627    )
628
629    channel_target_settings = ["@rules_rust//rust/toolchain/channel:{}".format(channel)] if channel else []
630
631    toolchain_repository_proxy(
632        name = name,
633        toolchain = "@{}//:rust_toolchain".format(tools_repo_name),
634        target_settings = channel_target_settings + target_settings,
635        toolchain_type = "@rules_rust//rust:toolchain",
636        exec_compatible_with = exec_compatible_with,
637        target_compatible_with = target_compatible_with,
638    )
639
640    return "@{name}//:toolchain".format(
641        name = name,
642    )
643
644_RUST_ANALYZER_TOOLCHAIN_TOOLS_REPOSITORY_ATTRS = {
645    "auth": attr.string_dict(
646        doc = (
647            "Auth object compatible with repository_ctx.download to use when downloading files. " +
648            "See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details."
649        ),
650    ),
651    "auth_patterns": attr.string_list(
652        doc = "A list of patterns to match against urls for which the auth object should be used.",
653    ),
654    "netrc": attr.string(
655        doc = ".netrc file to use for authentication; mirrors the eponymous attribute from http_archive",
656    ),
657    "sha256s": attr.string_dict(
658        doc = "A dict associating tool subdirectories to sha256 hashes. See [rust_register_toolchains](#rust_register_toolchains) for more details.",
659    ),
660    "urls": attr.string_list(
661        doc = "A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format).",
662        default = DEFAULT_STATIC_RUST_URL_TEMPLATES,
663    ),
664    "version": attr.string(
665        doc = "The version of the tool among \"nightly\", \"beta\" with an iso date, or an exact version.",
666        mandatory = True,
667    ),
668}
669
670def _rust_analyzer_toolchain_tools_repository_impl(repository_ctx):
671    sha256s = dict(repository_ctx.attr.sha256s)
672
673    iso_date = None
674    version = repository_ctx.attr.version
675    version_array = version.split("/")
676    if len(version_array) > 1:
677        version = version_array[0]
678        iso_date = version_array[1]
679
680    sha256s.update(load_rust_src(
681        ctx = repository_ctx,
682        iso_date = iso_date,
683        version = version,
684    ))
685
686    repository_ctx.file("WORKSPACE.bazel", """workspace(name = "{}")""".format(
687        repository_ctx.name,
688    ))
689
690    host_triple = get_host_triple(repository_ctx)
691    rustc_content, rustc_sha256 = load_rust_compiler(
692        ctx = repository_ctx,
693        iso_date = iso_date,
694        target_triple = host_triple,
695        version = version,
696    )
697    build_contents = [rustc_content]
698    sha256s.update(rustc_sha256)
699    rustc = "//:rustc"
700
701    proc_macro_srv = None
702    if includes_rust_analyzer_proc_macro_srv(version, iso_date):
703        build_contents.append(BUILD_for_rust_analyzer_proc_macro_srv(host_triple))
704        proc_macro_srv = "//:rust_analyzer_proc_macro_srv"
705
706    build_contents.append(BUILD_for_rust_analyzer_toolchain(
707        name = "rust_analyzer_toolchain",
708        rustc = rustc,
709        proc_macro_srv = proc_macro_srv,
710    ))
711
712    repository_ctx.file("BUILD.bazel", "\n".join(build_contents))
713    repository_ctx.file("WORKSPACE.bazel", """workspace(name = "{}")""".format(
714        repository_ctx.name,
715    ))
716
717    repro = {"name": repository_ctx.name}
718    for key in _RUST_ANALYZER_TOOLCHAIN_TOOLS_REPOSITORY_ATTRS:
719        repro[key] = getattr(repository_ctx.attr, key)
720    repro["sha256s"] = sha256s
721
722    return repro
723
724rust_analyzer_toolchain_tools_repository = repository_rule(
725    doc = "A repository rule for defining a rust_analyzer_toolchain with a `rust-src` artifact.",
726    implementation = _rust_analyzer_toolchain_tools_repository_impl,
727    attrs = _RUST_ANALYZER_TOOLCHAIN_TOOLS_REPOSITORY_ATTRS,
728)
729
730def rust_analyzer_toolchain_repository(
731        name,
732        version,
733        exec_compatible_with = [],
734        target_compatible_with = [],
735        sha256s = None,
736        urls = None,
737        auth = None,
738        netrc = None,
739        auth_patterns = None):
740    """Assemble a remote rust_analyzer_toolchain target based on the given params.
741
742    Args:
743        name (str): The name of the toolchain proxy repository contianing the registerable toolchain.
744        version (str): The version of the tool among "nightly", "beta', or an exact version.
745        exec_compatible_with (list, optional): A list of constraints for the execution platform for this toolchain.
746        target_compatible_with (list, optional): A list of constraints for the target platform for this toolchain.
747        sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See
748            [rust_register_toolchains](#rust_register_toolchains) for more details.
749        urls (list, optional): A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.xz']
750        auth (dict): Auth object compatible with repository_ctx.download to use when downloading files.
751            See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details.
752        netrc (str, optional): .netrc file to use for authentication; mirrors the eponymous attribute from http_archive
753        auth_patterns (dict, optional): Override mapping of hostnames to authorization patterns; mirrors the eponymous attribute from http_archive
754
755    Returns:
756        str: The name of a registerable rust_analyzer_toolchain.
757    """
758    rust_analyzer_toolchain_tools_repository(
759        name = name + "_tools",
760        version = version,
761        sha256s = sha256s,
762        urls = urls,
763        auth = auth,
764        netrc = netrc,
765        auth_patterns = auth_patterns,
766    )
767
768    toolchain_repository_proxy(
769        name = name,
770        toolchain = "@{}//:{}".format(name + "_tools", "rust_analyzer_toolchain"),
771        toolchain_type = "@rules_rust//rust/rust_analyzer:toolchain_type",
772        exec_compatible_with = exec_compatible_with,
773        target_compatible_with = target_compatible_with,
774    )
775
776    return "@{}//:toolchain".format(
777        name,
778    )
779
780_RUSTFMT_TOOLCHAIN_TOOLS_ATTRS = {
781    "auth": attr.string_dict(
782        doc = (
783            "Auth object compatible with repository_ctx.download to use when downloading files. " +
784            "See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details."
785        ),
786    ),
787    "auth_patterns": attr.string_dict(
788        doc = "Override mapping of hostnames to authorization patterns; mirrors the eponymous attribute from http_archive",
789    ),
790    "exec_triple": attr.string(
791        doc = "The Rust-style triple Rustfmt is expected to run on.",
792        mandatory = True,
793    ),
794    "netrc": attr.string(
795        doc = ".netrc file to use for authentication; mirrors the eponymous attribute from http_archive",
796    ),
797    "sha256s": attr.string_dict(
798        doc = "A dict associating tool subdirectories to sha256 hashes. See [rust_register_toolchains](#rust_register_toolchains) for more details.",
799    ),
800    "urls": attr.string_list(
801        doc = "A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format).",
802        default = DEFAULT_STATIC_RUST_URL_TEMPLATES,
803    ),
804    "version": attr.string(
805        doc = "The version of the tool among \"nightly\", \"beta\" with an iso date, or an exact version.",
806        mandatory = True,
807    ),
808}
809
810def _rustfmt_toolchain_tools_repository_impl(repository_ctx):
811    sha256s = dict(repository_ctx.attr.sha256s)
812    repository_ctx.file("WORKSPACE.bazel", """workspace(name = "{}")""".format(
813        repository_ctx.name,
814    ))
815
816    iso_date = None
817    version = repository_ctx.attr.version
818    version_array = version.split("/")
819    if len(version_array) > 1:
820        version = version_array[0]
821        iso_date = version_array[1]
822
823    rustfmt = "//:rustfmt_bin"
824    rustc = "//:rustc"
825    rustc_lib = "//:rustc_lib"
826
827    exec_triple = triple(repository_ctx.attr.exec_triple)
828
829    rustc_content, rustc_sha256 = load_rust_compiler(
830        ctx = repository_ctx,
831        iso_date = iso_date,
832        target_triple = exec_triple,
833        version = version,
834    )
835    rustfmt_content, rustfmt_sha256 = load_rustfmt(
836        ctx = repository_ctx,
837        iso_date = iso_date,
838        target_triple = exec_triple,
839        version = version,
840    )
841
842    build_contents = [
843        rustc_content,
844        rustfmt_content,
845        BUILD_for_rustfmt_toolchain(
846            name = "rustfmt_toolchain",
847            rustfmt = rustfmt,
848            rustc = rustc,
849            rustc_lib = rustc_lib,
850        ),
851    ]
852    sha256s.update(rustc_sha256 | rustfmt_sha256)
853
854    repository_ctx.file("BUILD.bazel", "\n".join(build_contents))
855    repository_ctx.file("WORKSPACE.bazel", """workspace(name = "{}")""".format(
856        repository_ctx.name,
857    ))
858
859    repro = {"name": repository_ctx.name}
860    for key in _RUSTFMT_TOOLCHAIN_TOOLS_ATTRS:
861        repro[key] = getattr(repository_ctx.attr, key)
862    repro["sha256s"] = sha256s
863
864    return repro
865
866rustfmt_toolchain_tools_repository = repository_rule(
867    doc = "A repository rule for defining a rustfmt_toolchain.",
868    attrs = _RUSTFMT_TOOLCHAIN_TOOLS_ATTRS,
869    implementation = _rustfmt_toolchain_tools_repository_impl,
870)
871
872def rustfmt_toolchain_repository(
873        name,
874        version,
875        exec_triple,
876        exec_compatible_with = None,
877        target_compatible_with = None,
878        channel = None,
879        sha256s = None,
880        urls = None,
881        auth = None,
882        netrc = None,
883        auth_patterns = None):
884    """Assemble a remote rustfmt_toolchain target based on the given params.
885
886    Args:
887        name (str): The name of the toolchain proxy repository contianing the registerable toolchain.
888        version (str): The version of the tool among "nightly", "beta', or an exact version.
889        exec_triple (str): The platform triple Rustfmt is expected to run on.
890        exec_compatible_with (list, optional): A list of constraints for the execution platform for this toolchain.
891        target_compatible_with (list, optional): A list of constraints for the target platform for this toolchain.
892        channel (str, optional): The channel value to with which to constrain the toolchain.
893        sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See
894            [rust_register_toolchains](#rust_register_toolchains) for more details.
895        urls (list, optional): A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.xz']
896        auth (dict): Auth object compatible with repository_ctx.download to use when downloading files.
897            See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details.
898        netrc (str, optional): .netrc file to use for authentication; mirrors the eponymous attribute from http_archive
899        auth_patterns (dict, optional): Override mapping of hostnames to authorization patterns; mirrors the eponymous attribute from http_archive
900
901    Returns:
902        str: The name of a registerable rustfmt_toolchain.
903    """
904    if exec_compatible_with == None:
905        exec_compatible_with = triple_to_constraint_set(exec_triple)
906
907    rustfmt_toolchain_tools_repository(
908        name = name + "_tools",
909        version = version,
910        sha256s = sha256s,
911        urls = urls,
912        auth = auth,
913        netrc = netrc,
914        auth_patterns = auth_patterns,
915        exec_triple = exec_triple,
916    )
917
918    toolchain_repository_proxy(
919        name = name,
920        toolchain = "@{}//:{}".format(name + "_tools", "rustfmt_toolchain"),
921        toolchain_type = "@rules_rust//rust/rustfmt:toolchain_type",
922        target_settings = ["@rules_rust//rust/toolchain/channel:{}".format(channel)] if channel else None,
923        exec_compatible_with = exec_compatible_with,
924        target_compatible_with = target_compatible_with,
925    )
926
927    return "@{}//:toolchain".format(
928        name,
929    )
930
931def _rust_toolchain_set_repository_impl(repository_ctx):
932    repository_ctx.file("WORKSPACE.bazel", """workspace(name = "{}")""".format(
933        repository_ctx.name,
934    ))
935
936    repository_ctx.file("BUILD.bazel", """exports_files(["defs.bzl"])""")
937    repository_ctx.file("defs.bzl", "ALL_TOOLCHAINS = {}\n".format(
938        json.encode_indent(repository_ctx.attr.toolchains, indent = " " * 4),
939    ))
940
941rust_toolchain_set_repository = repository_rule(
942    doc = (
943        "Generates a toolchain-bearing repository that declares the toolchains from some other " +
944        "rust_toolchain_repository."
945    ),
946    attrs = {
947        "toolchains": attr.string_list(
948            doc = "The list of all toolchains created by the current `rust_toolchain_set`",
949            mandatory = True,
950        ),
951    },
952    implementation = _rust_toolchain_set_repository_impl,
953)
954
955def _get_toolchain_repositories(name, exec_triple, extra_target_triples, versions, fallback_target_compatible_with, aliases = {}):
956    extra_target_triples_list = extra_target_triples.keys() if type(extra_target_triples) == "dict" else extra_target_triples
957
958    toolchain_repos = []
959
960    for target_triple in depset([exec_triple] + extra_target_triples_list).to_list():
961        # Parse all provided versions while checking for duplicates
962        channels = {}
963        for version in versions:
964            if version.startswith(("beta", "nightly")):
965                channel, _, _ = version.partition("/")
966            else:
967                channel = "stable"
968
969            if channel in channels:
970                fail("Duplicate {} channels provided for {}: {}".format(channel, name, versions))
971
972            channels.update({channel: struct(
973                name = channel,
974                version = version,
975            )})
976
977        if type(extra_target_triples) == "dict" and target_triple in extra_target_triples:
978            target_constraints = extra_target_triples[target_triple]
979        elif fallback_target_compatible_with != None:
980            target_constraints = fallback_target_compatible_with
981        else:
982            target_constraints = triple_to_constraint_set(target_triple)
983
984        # Define toolchains for each requested version
985        for channel in channels.values():
986            # Check if this toolchain is requested to be aliased.
987            full_name = "{}__{}__{}".format(name, target_triple, channel.name)
988            if full_name in aliases:
989                full_name = aliases.pop(full_name)
990            toolchain_repos.append(struct(
991                name = full_name,
992                target_triple = target_triple,
993                channel = channel,
994                target_constraints = target_constraints,
995            ))
996
997    return toolchain_repos
998
999def rust_repository_set(
1000        name,
1001        versions,
1002        exec_triple,
1003        target_settings = [],
1004        allocator_library = None,
1005        global_allocator_library = None,
1006        extra_target_triples = {},
1007        rustfmt_version = None,
1008        edition = None,
1009        dev_components = False,
1010        extra_rustc_flags = None,
1011        extra_exec_rustc_flags = None,
1012        opt_level = None,
1013        sha256s = None,
1014        urls = DEFAULT_STATIC_RUST_URL_TEMPLATES,
1015        auth = None,
1016        netrc = None,
1017        auth_patterns = None,
1018        register_toolchain = True,
1019        exec_compatible_with = None,
1020        default_target_compatible_with = None,
1021        aliases = {}):
1022    """Assembles a remote repository for the given toolchain params, produces a proxy repository \
1023    to contain the toolchain declaration, and registers the toolchains.
1024
1025    Args:
1026        name (str): The name of the generated repository
1027        versions (list, optional): A list of toolchain versions to download. This paramter only accepts one versions
1028            per channel. E.g. `["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]`.
1029        exec_triple (str): The Rust-style target that this compiler runs on
1030        target_settings (list, optional): A list of config_settings that must be satisfied by the target configuration in order for this set of toolchains to be selected during toolchain resolution.
1031        allocator_library (str, optional): Target that provides allocator functions when rust_library targets are
1032            embedded in a cc_binary.
1033        global_allocator_library (str, optional): Target that provides allocator functions a global allocator is used with cc_common.link.
1034        extra_target_triples (list or map, optional): Additional rust-style targets that this set of
1035            toolchains should support. If a map, values should be (optional) target_compatible_with lists for that particular target triple.
1036        rustfmt_version (str, optional):  The version of rustfmt to be associated with the
1037            toolchain.
1038        edition (str, optional): The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is
1039            required to specify its `edition` attribute.
1040        dev_components (bool, optional): Whether to download the rustc-dev components.
1041            Requires version to be "nightly".
1042        extra_rustc_flags (dict, list, optional): Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration.
1043        extra_exec_rustc_flags (list, optional): Extra flags to pass to rustc in exec configuration.
1044        opt_level (dict, dict, optional): Dictionary of target triples to optimiztion config.
1045        sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See
1046            [rust_register_toolchains](#rust_register_toolchains) for more details.
1047        urls (list, optional): A list of mirror urls containing the tools from the Rust-lang static file server. These
1048            must contain the '{}' used to substitute the tool being fetched (using .format).
1049        auth (dict): Auth object compatible with repository_ctx.download to use when downloading files.
1050            See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details.
1051        netrc (str, optional): .netrc file to use for authentication; mirrors the eponymous attribute from http_archive
1052        auth_patterns (dict, optional): Override mapping of hostnames to authorization patterns; mirrors the eponymous attribute from http_archive
1053
1054        register_toolchain (bool): If True, the generated `rust_toolchain` target will become a registered toolchain.
1055        exec_compatible_with (list, optional): A list of constraints for the execution platform for this toolchain.
1056        default_target_compatible_with (list, optional): A list of constraints for the target platform for this toolchain when the exec platform is the same as the target platform.
1057        aliases (dict): Replacement names to use for toolchains created by this macro.
1058    """
1059
1060    all_toolchain_names = []
1061    for toolchain in _get_toolchain_repositories(name, exec_triple, extra_target_triples, versions, default_target_compatible_with, aliases):
1062        # Infer toolchain-specific rustc flags depending on the type (list, dict, optional) of extra_rustc_flags
1063        if extra_rustc_flags == None:
1064            toolchain_extra_rustc_flags = []
1065        elif type(extra_rustc_flags) == "list":
1066            toolchain_extra_rustc_flags = extra_rustc_flags
1067        elif type(extra_rustc_flags) == "dict":
1068            toolchain_extra_rustc_flags = extra_rustc_flags.get(toolchain.target_triple)
1069        else:
1070            fail("extra_rustc_flags should be a list or a dict")
1071
1072        all_toolchain_names.append(rust_toolchain_repository(
1073            name = toolchain.name,
1074            allocator_library = allocator_library,
1075            global_allocator_library = global_allocator_library,
1076            auth = auth,
1077            netrc = netrc,
1078            auth_patterns = auth_patterns,
1079            channel = toolchain.channel.name,
1080            dev_components = dev_components,
1081            edition = edition,
1082            exec_triple = exec_triple,
1083            extra_exec_rustc_flags = extra_exec_rustc_flags,
1084            extra_rustc_flags = toolchain_extra_rustc_flags,
1085            opt_level = opt_level.get(toolchain.target_triple) if opt_level != None else None,
1086            target_settings = target_settings,
1087            rustfmt_version = rustfmt_version,
1088            sha256s = sha256s,
1089            target_triple = toolchain.target_triple,
1090            urls = urls,
1091            version = toolchain.channel.version,
1092            exec_compatible_with = exec_compatible_with,
1093            target_compatible_with = toolchain.target_constraints,
1094        ))
1095
1096    # This repository exists to allow `rust_repository_set` to work with the `maybe` wrapper.
1097    rust_toolchain_set_repository(
1098        name = name,
1099        toolchains = all_toolchain_names,
1100    )
1101
1102    # Register toolchains
1103    if register_toolchain:
1104        native.register_toolchains(*all_toolchain_names)
1105        native.register_toolchains(str(Label("//rust/private/dummy_cc_toolchain:dummy_cc_wasm32_toolchain")))
1106        native.register_toolchains(str(Label("//rust/private/dummy_cc_toolchain:dummy_cc_wasm64_toolchain")))