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