fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
352bfeb0
0.11.0
1# buildifier: disable=module-docstring 2load ( "@bazel_tools//tools/build_defs/repo:http.bzl" , "http_archive" ) 3load ( "@bazel_tools//tools/build_defs/repo:utils.bzl" , "maybe" ) 4load ( 5"//rust/platform:triple_mappings.bzl" , 6"triple_to_constraint_set" , 7) 8load ( "//rust/private:common.bzl" , "rust_common" ) 9load ( 10"//rust/private:repository_utils.bzl" , 11"BUILD_for_rust_analyzer_toolchain" , 12"BUILD_for_rust_toolchain" , 13"BUILD_for_toolchain" , 14"DEFAULT_STATIC_RUST_URL_TEMPLATES" , 15"check_version_valid" , 16"load_cargo" , 17"load_clippy" , 18"load_llvm_tools" , 19"load_rust_compiler" , 20"load_rust_src" , 21"load_rust_stdlib" , 22"load_rustc_dev_nightly" , 23"load_rustfmt" , 24"should_include_rustc_srcs" , 25_load_arbitrary_tool = "load_arbitrary_tool" , 26) 27 28# Reexport `load_arbitrary_tool` as it's currently in use in https://github.com/google/cargo-raze 29load_arbitrary_tool = _load_arbitrary_tool 30 31# 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. 32DEFAULT_TOOLCHAIN_TRIPLES = { 33"aarch64-apple-darwin" : "rust_darwin_aarch64" , 34"aarch64-unknown-linux-gnu" : "rust_linux_aarch64" , 35"x86_64-apple-darwin" : "rust_darwin_x86_64" , 36"x86_64-pc-windows-msvc" : "rust_windows_x86_64" , 37"x86_64-unknown-freebsd" : "rust_freebsd_x86_64" , 38"x86_64-unknown-linux-gnu" : "rust_linux_x86_64" , 39} 40 41def rules_rust_dependencies (): 42"""Dependencies used in the implementation of `rules_rust`.""" 43 44maybe ( 45http_archive , 46name = "platforms" , 47urls = [ 48"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz" , 49"https://github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz" , 50], 51sha256 = "379113459b0feaf6bfbb584a91874c065078aa673222846ac765f86661c27407" , 52) 53maybe ( 54http_archive , 55name = "rules_cc" , 56urls = [ "https://github.com/bazelbuild/rules_cc/releases/download/0.0.1/rules_cc-0.0.1.tar.gz" ], 57sha256 = "4dccbfd22c0def164c8f47458bd50e0c7148f3d92002cdb459c2a96a68498241" , 58) 59 60maybe ( 61http_archive , 62name = "bazel_skylib" , 63urls = [ 64"https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.0/bazel-skylib-1.2.0.tar.gz" , 65"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.2.0/bazel-skylib-1.2.0.tar.gz" , 66], 67sha256 = "af87959afe497dc8dfd4c6cb66e1279cb98ccc84284619ebfec27d9c09a903de" , 68) 69 70# Make the iOS simulator constraint available, which is referenced in abi_to_constraints() 71# rules_rust does not require this dependency; it is just imported as a convenience for users. 72maybe ( 73http_archive , 74name = "build_bazel_apple_support" , 75sha256 = "d94b7a0f49d735f196e1f36d2e6ef79c4e8e8b82132848dd8cd93cd82d9b12a8" , 76url = "https://github.com/bazelbuild/apple_support/releases/download/1.3.0/apple_support.1.3.0.tar.gz" , 77) 78 79# process_wrapper needs a low-dependency way to process json. 80maybe ( 81http_archive , 82name = "rules_rust_tinyjson" , 83sha256 = "1a8304da9f9370f6a6f9020b7903b044aa9ce3470f300a1fba5bc77c78145a16" , 84url = "https://crates.io/api/v1/crates/tinyjson/2.3.0/download" , 85strip_prefix = "tinyjson-2.3.0" , 86type = "tar.gz" , 87build_file = "@rules_rust//util/process_wrapper:BUILD.tinyjson.bazel" , 88) 89 90# buildifier: disable=unnamed-macro 91def rust_register_toolchains ( 92dev_components = False , 93edition = None , 94include_rustc_srcs = False , 95allocator_library = None , 96iso_date = None , 97register_toolchains = True , 98rustfmt_version = None , 99sha256s = None , 100extra_target_triples = [ "wasm32-unknown-unknown" , "wasm32-wasi" ], 101urls = DEFAULT_STATIC_RUST_URL_TEMPLATES , 102version = rust_common . default_version ): 103"""Emits a default set of toolchains for Linux, MacOS, and Freebsd 104 105Skip this macro and call the `rust_repository_set` macros directly if you need a compiler for \ 106other hosts or for additional target triples. 107 108The `sha256` attribute represents a dict associating tool subdirectories to sha256 hashes. As an example: 109```python 110{ 111"rust-1.46.0-x86_64-unknown-linux-gnu": "e3b98bc3440fe92817881933f9564389eccb396f5f431f33d48b979fa2fbdcf5", 112"rustfmt-1.4.12-x86_64-unknown-linux-gnu": "1894e76913303d66bf40885a601462844eec15fca9e76a6d13c390d7000d64b0", 113"rust-std-1.46.0-x86_64-unknown-linux-gnu": "ac04aef80423f612c0079829b504902de27a6997214eb58ab0765d02f7ec1dbc", 114} 115``` 116This would match for `exec_triple = "x86_64-unknown-linux-gnu"`. If not specified, rules_rust pulls from a non-exhaustive \ 117list of known checksums.. 118 119See `load_arbitrary_tool` in `@rules_rust//rust:repositories.bzl` for more details. 120 121Args: 122dev_components (bool, optional): Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly". 123edition (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. 124include_rustc_srcs (bool, optional): Whether to download rustc's src code. This is required in order to use rust-analyzer support. 125See [rust_toolchain_repository.include_rustc_srcs](#rust_toolchain_repository-include_rustc_srcs). for more details 126allocator_library (str, optional): Target that provides allocator functions when rust_library targets are embedded in a cc_binary. 127iso_date (str, optional): The date of the nightly or beta release (ignored if the version is a specific version). 128register_toolchains (bool): If true, repositories will be generated to produce and register `rust_toolchain` targets. 129rustfmt_version (str, optional): The version of rustfmt. Either "nightly", "beta", or an exact version. Defaults to `version` if not specified. 130sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. 131extra_target_triples (list, optional): Additional rust-style targets that rust toolchains should support. 132urls (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). 133version (str, optional): The version of Rust. Either "nightly", "beta", or an exact version. Defaults to a modern version. 134""" 135if dev_components and version != "nightly" : 136fail ( "Rust version must be set to \"nightly\" to enable rustc-dev components" ) 137 138if not rustfmt_version : 139rustfmt_version = version 140 141rust_analyzer_repo_name = "rust_analyzer_{}" . format ( version ) 142if iso_date : 143rust_analyzer_repo_name = "{}-{}" . format ( 144rust_analyzer_repo_name , 145iso_date , 146) 147 148maybe ( 149rust_analyzer_toolchain_repository , 150name = rust_analyzer_repo_name , 151version = version , 152urls = urls , 153sha256s = sha256s , 154iso_date = iso_date , 155) 156 157if register_toolchains : 158native . register_toolchains ( "@{}//:toolchain" . format ( 159rust_analyzer_repo_name , 160)) 161 162for exec_triple , name in DEFAULT_TOOLCHAIN_TRIPLES . items (): 163maybe ( 164rust_repository_set , 165name = name , 166dev_components = dev_components , 167edition = edition , 168exec_triple = exec_triple , 169extra_target_triples = extra_target_triples , 170include_rustc_srcs = include_rustc_srcs , 171allocator_library = allocator_library , 172iso_date = iso_date , 173register_toolchain = register_toolchains , 174rustfmt_version = rustfmt_version , 175sha256s = sha256s , 176urls = urls , 177version = version , 178) 179 180# buildifier: disable=unnamed-macro 181def rust_repositories ( ** kwargs ): 182"""**Deprecated**: Use [rules_rust_dependencies](#rules_rust_dependencies) \ 183and [rust_register_toolchains](#rust_register_toolchains) directly. 184 185Args: 186**kwargs (dict): Keyword arguments for the `rust_register_toolchains` macro. 187""" 188rules_rust_dependencies () 189 190rust_register_toolchains ( ** kwargs ) 191 192def _rust_toolchain_tools_repository_impl ( ctx ): 193"""The implementation of the rust toolchain tools repository rule.""" 194 195check_version_valid ( ctx . attr . version , ctx . attr . iso_date ) 196 197# Conditionally download rustc sources. Generally used for `rust-analyzer` 198if should_include_rustc_srcs ( ctx ): 199load_rust_src ( ctx ) 200 201build_components = [ 202load_rust_compiler ( ctx ), 203load_clippy ( ctx ), 204load_cargo ( ctx ), 205] 206 207if ctx . attr . rustfmt_version : 208build_components . append ( load_rustfmt ( ctx )) 209 210# Rust 1.45.0 and nightly builds after 2020-05-22 need the llvm-tools gzip to get the libLLVM dylib 211include_llvm_tools = ctx . attr . version >= "1.45.0" or ( ctx . attr . version == "nightly" and ctx . attr . iso_date > "2020-05-22" ) 212if include_llvm_tools : 213build_components . append ( load_llvm_tools ( ctx , ctx . attr . exec_triple )) 214 215build_components . append ( load_rust_stdlib ( ctx , ctx . attr . target_triple )) 216 217stdlib_linkflags = None 218if "BAZEL_RUST_STDLIB_LINKFLAGS" in ctx . os . environ : 219stdlib_linkflags = ctx . os . environ [ "BAZEL_RUST_STDLIB_LINKFLAGS" ]. split ( ":" ) 220 221build_components . append ( BUILD_for_rust_toolchain ( 222name = "rust_toolchain" , 223exec_triple = ctx . attr . exec_triple , 224include_rustc_srcs = should_include_rustc_srcs ( ctx ), 225allocator_library = ctx . attr . allocator_library , 226target_triple = ctx . attr . target_triple , 227stdlib_linkflags = stdlib_linkflags , 228workspace_name = ctx . attr . name , 229default_edition = ctx . attr . edition , 230include_rustfmt = not ( not ctx . attr . rustfmt_version ), 231include_llvm_tools = include_llvm_tools , 232)) 233 234# Not all target triples are expected to have dev components 235if ctx . attr . dev_components : 236load_rustc_dev_nightly ( ctx , ctx . attr . target_triple ) 237 238ctx . file ( "WORKSPACE.bazel" , "" ) 239ctx . file ( "BUILD.bazel" , "\n ". join ( build_components )) 240 241rust_toolchain_tools_repository = repository_rule ( 242doc = ( 243"Composes a single workspace containing the toolchain components for compiling on a given " + 244 "platform to a series of target platforms.\n "+ 245 "\n "+ 246"A given instance of this rule should be accompanied by a toolchain_repository_proxy " + 247"invocation to declare its toolchains to Bazel; the indirection allows separating toolchain " + 248"selection from toolchain fetching." 249), 250attrs = { 251"allocator_library" : attr . string ( 252doc = "Target that provides allocator functions when rust_library targets are embedded in a cc_binary." , 253), 254"auth" : attr . string_dict ( 255doc = ( 256"Auth object compatible with repository_ctx.download to use when downloading files. " + 257"See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details." 258), 259), 260"dev_components" : attr . bool ( 261doc = "Whether to download the rustc-dev components (defaults to False). Requires version to be \"nightly\"." , 262default = False , 263), 264"edition" : attr . string ( 265doc = ( 266"The rust edition to be used by default (2015, 2018, or 2021). " + 267"If absent, every rule is required to specify its `edition` attribute." 268), 269), 270"exec_triple" : attr . string ( 271doc = "The Rust-style target that this compiler runs on" , 272mandatory = True , 273), 274"include_rustc_srcs" : attr . bool ( 275doc = ( 276"Whether to download and unpack the rustc source files. These are very large, and " + 277"slow to unpack, but are required to support rust analyzer. An environment variable " + 278"`RULES_RUST_TOOLCHAIN_INCLUDE_RUSTC_SRCS` can also be used to control this attribute. " + 279"This variable will take precedence over the hard coded attribute. Setting it to `true` to " + 280"activates this attribute where all other values deactivate it." 281), 282default = False , 283), 284"iso_date" : attr . string ( 285doc = "The date of the tool (or None, if the version is a specific version)." , 286), 287"rustfmt_version" : attr . string ( 288doc = "The version of the tool among \"nightly\", \"beta\", or an exact version." , 289), 290"sha256s" : attr . string_dict ( 291doc = "A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details." , 292), 293"target_triple" : attr . string ( 294doc = "The Rust-style target that this compiler builds for" , 295mandatory = True , 296), 297"urls" : attr . string_list ( 298doc = "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)." , 299default = DEFAULT_STATIC_RUST_URL_TEMPLATES , 300), 301"version" : attr . string ( 302doc = "The version of the tool among \"nightly\", \"beta\", or an exact version." , 303mandatory = True , 304), 305}, 306implementation = _rust_toolchain_tools_repository_impl , 307environ = [ "RULES_RUST_TOOLCHAIN_INCLUDE_RUSTC_SRCS" ], 308) 309 310def _toolchain_repository_proxy_impl ( repository_ctx ): 311repository_ctx . file ( "WORKSPACE.bazel" , """workspace(name = "{}")""" . format ( 312repository_ctx . name , 313)) 314 315repository_ctx . file ( "BUILD.bazel" , BUILD_for_toolchain ( 316name = "toolchain" , 317toolchain = repository_ctx . attr . toolchain , 318toolchain_type = repository_ctx . attr . toolchain_type , 319target_compatible_with = json . encode ( repository_ctx . attr . target_compatible_with ), 320exec_compatible_with = json . encode ( repository_ctx . attr . exec_compatible_with ), 321)) 322 323toolchain_repository_proxy = repository_rule ( 324doc = ( 325"Generates a toolchain-bearing repository that declares the toolchains from some other " + 326"rust_toolchain_repository." 327), 328attrs = { 329"exec_compatible_with" : attr . string_list ( 330doc = "A list of constraints for the execution platform for this toolchain." , 331), 332"target_compatible_with" : attr . string_list ( 333doc = "A list of constraints for the target platform for this toolchain." , 334), 335"toolchain" : attr . string ( 336doc = "The name of the toolchain implementation target." , 337mandatory = True , 338), 339"toolchain_type" : attr . string ( 340doc = "The toolchain type of the toolchain to declare" , 341mandatory = True , 342), 343}, 344implementation = _toolchain_repository_proxy_impl , 345) 346 347# For legacy support 348rust_toolchain_repository_proxy = toolchain_repository_proxy 349 350def rust_toolchain_repository ( 351name , 352version , 353exec_triple , 354target_triple , 355exec_compatible_with = None , 356target_compatible_with = None , 357include_rustc_srcs = False , 358allocator_library = None , 359iso_date = None , 360rustfmt_version = None , 361edition = None , 362dev_components = False , 363sha256s = None , 364urls = DEFAULT_STATIC_RUST_URL_TEMPLATES , 365auth = None ): 366"""Assembles a remote repository for the given toolchain params, produces a proxy repository \ 367to contain the toolchain declaration, and registers the toolchains. 368 369N.B. A "proxy repository" is needed to allow for registering the toolchain (with constraints) \ 370without actually downloading the toolchain. 371 372Args: 373name (str): The name of the generated repository 374version (str): The version of the tool among "nightly", "beta', or an exact version. 375exec_triple (str): The Rust-style target that this compiler runs on. 376target_triple (str): The Rust-style target to build for. 377exec_compatible_with (list, optional): A list of constraints for the execution platform for this toolchain. 378target_compatible_with (list, optional): A list of constraints for the target platform for this toolchain. 379include_rustc_srcs (bool, optional): Whether to download rustc's src code. This is required in order to use rust-analyzer support. 380allocator_library (str, optional): Target that provides allocator functions when rust_library targets are embedded in a cc_binary. 381iso_date (str, optional): The date of the tool. 382rustfmt_version (str, optional): The version of rustfmt to be associated with the 383toolchain. 384edition (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. 385dev_components (bool, optional): Whether to download the rustc-dev components. 386Requires version to be "nightly". Defaults to False. 387sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See 388[rust_repositories](#rust_repositories) for more details. 389urls (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.gz'] 390auth (dict): Auth object compatible with repository_ctx.download to use when downloading files. 391See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. 392 393Returns: 394str: The name of the registerable toolchain created by this rule. 395""" 396 397if exec_compatible_with == None : 398exec_compatible_with = triple_to_constraint_set ( exec_triple ) 399 400if target_compatible_with == None : 401target_compatible_with = triple_to_constraint_set ( target_triple ) 402 403rust_toolchain_tools_repository ( 404name = name + "_tools" , 405exec_triple = exec_triple , 406include_rustc_srcs = include_rustc_srcs , 407allocator_library = allocator_library , 408target_triple = target_triple , 409iso_date = iso_date , 410version = version , 411rustfmt_version = rustfmt_version , 412edition = edition , 413dev_components = dev_components , 414sha256s = sha256s , 415urls = urls , 416auth = auth , 417) 418 419toolchain_repository_proxy ( 420name = name , 421toolchain = "@{}//:{}" . format ( name + "_tools" , "rust_toolchain" ), 422toolchain_type = "@rules_rust//rust:toolchain" , 423exec_compatible_with = exec_compatible_with , 424target_compatible_with = target_compatible_with , 425) 426 427return "@{name}//:toolchain" . format ( 428name = name , 429) 430 431def _rust_analyzer_toolchain_srcs_repository_impl ( repository_ctx ): 432load_rust_src ( repository_ctx ) 433 434repository_ctx . file ( "WORKSPACE.bazel" , """workspace(name = "{}")""" . format ( 435repository_ctx . name , 436)) 437 438repository_ctx . file ( "BUILD.bazel" , BUILD_for_rust_analyzer_toolchain ( 439name = "rust_analyzer_toolchain" , 440)) 441 442rust_analyzer_toolchain_srcs_repository = repository_rule ( 443doc = "A repository rule for defining a rust_analyzer_toolchain with a `rust-src` artifact." , 444attrs = { 445"auth" : attr . string_dict ( 446doc = ( 447"Auth object compatible with repository_ctx.download to use when downloading files. " + 448"See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details." 449), 450), 451"iso_date" : attr . string ( 452doc = "The date of the tool (or None, if the version is a specific version)." , 453), 454"sha256s" : attr . string_dict ( 455doc = "A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details." , 456), 457"urls" : attr . string_list ( 458doc = "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)." , 459default = DEFAULT_STATIC_RUST_URL_TEMPLATES , 460), 461"version" : attr . string ( 462doc = "The version of the tool among \"nightly\", \"beta\", or an exact version." , 463mandatory = True , 464), 465}, 466implementation = _rust_analyzer_toolchain_srcs_repository_impl , 467) 468 469def rust_analyzer_toolchain_repository ( 470name , 471version , 472exec_compatible_with = [], 473target_compatible_with = [], 474iso_date = None , 475sha256s = None , 476urls = None , 477auth = None ): 478"""Assemble a remote rust_analyzer_toolchain target based on the given params. 479 480Args: 481name (str): The name of the toolchain proxy repository contianing the registerable toolchain. 482version (str): The version of the tool among "nightly", "beta', or an exact version. 483exec_compatible_with (list, optional): A list of constraints for the execution platform for this toolchain. 484target_compatible_with (list, optional): A list of constraints for the target platform for this toolchain. 485iso_date (str, optional): The date of the tool. 486sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See 487[rust_repositories](#rust_repositories) for more details. 488urls (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.gz'] 489auth (dict): Auth object compatible with repository_ctx.download to use when downloading files. 490See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. 491 492Returns: 493str: The name of a registerable rust_analyzer_toolchain. 494""" 495rust_analyzer_toolchain_srcs_repository ( 496name = name + "_srcs" , 497version = version , 498iso_date = iso_date , 499sha256s = sha256s , 500urls = urls , 501auth = auth , 502) 503 504toolchain_repository_proxy ( 505name = name , 506toolchain = "@{}//:{}" . format ( name + "_srcs" , "rust_analyzer_toolchain" ), 507toolchain_type = "@rules_rust//rust/rust_analyzer:toolchain_type" , 508exec_compatible_with = exec_compatible_with , 509target_compatible_with = target_compatible_with , 510) 511 512return "@{}//:toolchain" . format ( 513name , 514) 515 516def _rust_toolchain_set_repository_impl ( repository_ctx ): 517repository_ctx . file ( "WORKSPACE.bazel" , """workspace(name = "{}")""" . format ( 518repository_ctx . name , 519)) 520 521repository_ctx . file ( "BUILD.bazel" , """exports_files(["defs.bzl"])""" ) 522repository_ctx . file ( "defs.bzl" , "ALL_TOOLCHAINS = {}\n ". format ( 523json . encode_indent ( repository_ctx . attr . toolchains , indent = " " * 4 ), 524)) 525 526rust_toolchain_set_repository = repository_rule ( 527doc = ( 528"Generates a toolchain-bearing repository that declares the toolchains from some other " + 529"rust_toolchain_repository." 530), 531attrs = { 532"toolchains" : attr . string_list ( 533doc = "The list of all toolchains created by the current `rust_toolchain_set`" , 534mandatory = True , 535), 536}, 537implementation = _rust_toolchain_set_repository_impl , 538) 539 540def rust_repository_set ( 541name , 542version , 543exec_triple , 544include_rustc_srcs = False , 545allocator_library = None , 546extra_target_triples = [], 547iso_date = None , 548rustfmt_version = None , 549edition = None , 550dev_components = False , 551sha256s = None , 552urls = DEFAULT_STATIC_RUST_URL_TEMPLATES , 553auth = None , 554register_toolchain = True ): 555"""Assembles a remote repository for the given toolchain params, produces a proxy repository \ 556to contain the toolchain declaration, and registers the toolchains. 557 558N.B. A "proxy repository" is needed to allow for registering the toolchain (with constraints) \ 559without actually downloading the toolchain. 560 561Args: 562name (str): The name of the generated repository 563version (str): The version of the tool among "nightly", "beta', or an exact version. 564exec_triple (str): The Rust-style target that this compiler runs on 565include_rustc_srcs (bool, optional): Whether to download rustc's src code. This is required in order to use rust-analyzer support. Defaults to False. 566allocator_library (str, optional): Target that provides allocator functions when rust_library targets are embedded in a cc_binary. 567extra_target_triples (list, optional): Additional rust-style targets that this set of 568toolchains should support. Defaults to []. 569iso_date (str, optional): The date of the tool. Defaults to None. 570rustfmt_version (str, optional): The version of rustfmt to be associated with the 571toolchain. Defaults to None. 572edition (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. 573dev_components (bool, optional): Whether to download the rustc-dev components. 574Requires version to be "nightly". Defaults to False. 575sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See 576[rust_repositories](#rust_repositories) for more details. 577urls (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.gz'] 578auth (dict): Auth object compatible with repository_ctx.download to use when downloading files. 579See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. 580register_toolchain (bool): If True, the generated `rust_toolchain` target will become a registered toolchain. 581""" 582 583all_toolchain_names = [] 584for target_triple in [ exec_triple ] + extra_target_triples : 585toolchain_name = "{}__{}" . format ( name , target_triple ) 586all_toolchain_names . append ( rust_toolchain_repository ( 587name = toolchain_name , 588exec_triple = exec_triple , 589include_rustc_srcs = include_rustc_srcs , 590allocator_library = allocator_library , 591target_triple = target_triple , 592iso_date = iso_date , 593version = version , 594rustfmt_version = rustfmt_version , 595edition = edition , 596dev_components = dev_components , 597sha256s = sha256s , 598urls = urls , 599auth = auth , 600)) 601 602# This repository exists to allow `rust_repository_set` to work with the `maybe` wrapper. 603rust_toolchain_set_repository ( 604name = name , 605toolchains = all_toolchain_names , 606) 607 608# Register toolchains 609if register_toolchain : 610native . register_toolchains ( * all_toolchain_names ) 611native . register_toolchains ( str ( Label ( "//rust/private/dummy_cc_toolchain:dummy_cc_wasm32_toolchain" )))