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