fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
223d1e79
cleanup
1"""Module extension for generating third-party crates for use in bazel.""" 2 3load ( "@bazel_features//:features.bzl" , "bazel_features" ) 4load ( "@bazel_skylib//lib:structs.bzl" , "structs" ) 5load ( "@bazel_tools//tools/build_defs/repo:git.bzl" , "new_git_repository" ) 6load ( "@bazel_tools//tools/build_defs/repo:http.bzl" , "http_archive" ) 7load ( "//crate_universe:defs.bzl" , _crate_universe_crate = "crate" ) 8load ( "//crate_universe/private:crates_vendor.bzl" , "CRATES_VENDOR_ATTRS" , "generate_config_file" , "generate_splicing_manifest" ) 9load ( "//crate_universe/private:generate_utils.bzl" , "CARGO_BAZEL_GENERATOR_SHA256" , "CARGO_BAZEL_GENERATOR_URL" , "GENERATOR_ENV_VARS" , "render_config" ) 10load ( "//crate_universe/private:urls.bzl" , "CARGO_BAZEL_SHA256S" , "CARGO_BAZEL_URLS" ) 11load ( "//crate_universe/private/module_extensions:cargo_bazel_bootstrap.bzl" , "get_cargo_bazel_runner" , "get_host_cargo_rustc" ) 12load ( "//rust/platform:triple.bzl" , "get_host_triple" ) 13 14# A list of labels which may be relative (and if so, is within the repo the rule is generated in). 15# 16# If I were to write ":foo", with attr.label_list, it would evaluate to 17# "@@//:foo". However, for a tag such as deps, ":foo" should refer to 18# "@@rules_rust~crates~<crate>//:foo". 19_relative_label_list = attr . string_list 20 21_OPT_BOOL_VALUES = { 22"auto" : None , 23"off" : False , 24"on" : True , 25} 26 27def optional_bool ( doc ): 28return attr . string ( 29doc = doc , 30values = _OPT_BOOL_VALUES . keys (), 31default = "auto" , 32) 33 34def _get_or_insert ( d , key , value ): 35if key not in d : 36d [ key ] = value 37return d [ key ] 38 39def _generate_repo_impl ( repo_ctx ): 40for path , contents in repo_ctx . attr . contents . items (): 41repo_ctx . file ( path , contents ) 42 43_generate_repo = repository_rule ( 44implementation = _generate_repo_impl , 45attrs = dict ( 46contents = attr . string_dict ( mandatory = True ), 47), 48) 49 50def _annotations_for_repo ( module_annotations , repo_specific_annotations ): 51"""Merges the set of global annotations with the repo-specific ones 52 53Args: 54module_annotations (dict): The annotation tags that apply to all repos, keyed by crate. 55repo_specific_annotations (dict): The annotation tags that apply to only this repo, keyed by crate. 56""" 57 58if not repo_specific_annotations : 59return module_annotations 60 61annotations = dict ( module_annotations ) 62for crate , values in repo_specific_annotations . items (): 63_get_or_insert ( annotations , crate , []). extend ( values ) 64return annotations 65 66def _generate_hub_and_spokes ( module_ctx , cargo_bazel , cfg , annotations , cargo_lockfile = None , manifests = {}, packages = {}): 67"""Generates repositories for the transitive closure of crates defined by manifests and packages. 68 69Args: 70module_ctx (module_ctx): The module context object. 71cargo_bazel (function): A function that can be called to execute cargo_bazel. 72cfg (object): The module tag from `from_cargo` or `from_specs` 73annotations (dict): The set of annotation tag classes that apply to this closure, keyed by crate name. 74cargo_lockfile (path): Path to Cargo.lock, if we have one. This is optional for `from_specs` closures. 75manifests (dict): The set of Cargo.toml manifests that apply to this closure, if any, keyed by path. 76packages (dict): The set of extra cargo crate tags that apply to this closure, if any, keyed by package name. 77""" 78 79tag_path = module_ctx . path ( cfg . name ) 80 81rendering_config = json . decode ( render_config ( 82regen_command = "Run 'cargo update [--workspace]'" , 83)) 84config_file = tag_path . get_child ( "config.json" ) 85module_ctx . file ( 86config_file , 87executable = False , 88content = generate_config_file ( 89module_ctx , 90mode = "remote" , 91annotations = annotations , 92generate_build_scripts = cfg . generate_build_scripts , 93supported_platform_triples = cfg . supported_platform_triples , 94generate_target_compatible_with = True , 95repository_name = cfg . name , 96output_pkg = cfg . name , 97workspace_name = cfg . name , 98generate_binaries = cfg . generate_binaries , 99render_config = rendering_config , 100repository_ctx = module_ctx , 101), 102) 103 104splicing_manifest = tag_path . get_child ( "splicing_manifest.json" ) 105module_ctx . file ( 106splicing_manifest , 107executable = False , 108content = generate_splicing_manifest ( 109packages = packages , 110splicing_config = cfg . splicing_config , 111cargo_config = cfg . cargo_config , 112manifests = manifests , 113manifest_to_path = module_ctx . path , 114), 115) 116 117splicing_output_dir = tag_path . get_child ( "splicing-output" ) 118splice_args = [ 119"splice" , 120"--output-dir" , 121splicing_output_dir , 122"--config" , 123config_file , 124"--splicing-manifest" , 125splicing_manifest , 126] 127if cargo_lockfile : 128splice_args . extend ([ 129"--cargo-lockfile" , 130cargo_lockfile , 131]) 132cargo_bazel ( splice_args ) 133 134# Create a lockfile, since we need to parse it to generate spoke 135# repos. 136lockfile_path = tag_path . get_child ( "lockfile.json" ) 137module_ctx . file ( lockfile_path , "" ) 138 139cargo_bazel ([ 140"generate" , 141"--cargo-lockfile" , 142cargo_lockfile or splicing_output_dir . get_child ( "Cargo.lock" ), 143"--config" , 144config_file , 145"--splicing-manifest" , 146splicing_manifest , 147"--repository-dir" , 148tag_path , 149"--metadata" , 150splicing_output_dir . get_child ( "metadata.json" ), 151"--repin" , 152"--lockfile" , 153lockfile_path , 154]) 155 156crates_dir = tag_path . get_child ( cfg . name ) 157_generate_repo ( 158name = cfg . name , 159contents = { 160"BUILD.bazel" : module_ctx . read ( crates_dir . get_child ( "BUILD.bazel" )), 161"defs.bzl" : module_ctx . read ( crates_dir . get_child ( "defs.bzl" )), 162}, 163) 164 165contents = json . decode ( module_ctx . read ( lockfile_path )) 166 167for crate in contents [ "crates" ]. values (): 168repo = crate [ "repository" ] 169if repo == None : 170 continue 171name = crate [ "name" ] 172version = crate [ "version" ] 173 174# "+" isn't valid in a repo name. 175crate_repo_name = "{repo_name}__{name}-{version}" . format ( 176repo_name = cfg . name , 177name = name , 178version = version . replace ( "+" , "-" ), 179) 180 181build_file_content = module_ctx . read ( crates_dir . get_child ( "BUILD.%s-%s.bazel" % ( name , version ))) 182if "Http" in repo : 183# Replicates functionality in repo_http.j2. 184repo = repo [ "Http" ] 185http_archive ( 186name = crate_repo_name , 187patch_args = repo . get ( "patch_args" , None ), 188patch_tool = repo . get ( "patch_tool" , None ), 189patches = repo . get ( "patches" , None ), 190remote_patch_strip = 1 , 191sha256 = repo . get ( "sha256" , None ), 192type = "tar.gz" , 193urls = [ repo [ "url" ]], 194strip_prefix = "%s-%s" % ( crate [ "name" ], crate [ "version" ]), 195build_file_content = build_file_content , 196) 197elif "Git" in repo : 198# Replicates functionality in repo_git.j2 199repo = repo [ "Git" ] 200kwargs = {} 201for k , v in repo [ "commitish" ]. items (): 202if k == "Rev" : 203kwargs [ "commit" ] = v 204else : 205kwargs [ k . lower ()] = v 206new_git_repository ( 207name = crate_repo_name , 208init_submodules = True , 209patch_args = repo . get ( "patch_args" , None ), 210patch_tool = repo . get ( "patch_tool" , None ), 211patches = repo . get ( "patches" , None ), 212shallow_since = repo . get ( "shallow_since" , None ), 213remote = repo [ "remote" ], 214build_file_content = build_file_content , 215strip_prefix = repo . get ( "strip_prefix" , None ), 216** kwargs 217) 218else : 219fail ( "Invalid repo: expected Http or Git to exist for crate %s-%s, got %s" % ( name , version , repo )) 220 221def _package_to_json ( p ): 222# Avoid adding unspecified properties. 223# If we add them as empty strings, cargo-bazel will be unhappy. 224return json . encode ({ 225k : v 226for k , v in structs . to_dict ( p ). items () 227if v or k == "default_features" 228}) 229 230def _get_generator ( module_ctx ): 231"""Query Network Resources to local a `cargo-bazel` binary. 232 233Based off get_generator in crates_universe/private/generate_utils.bzl 234 235Args: 236module_ctx (module_ctx): The rules context object 237 238Returns: 239tuple(path, dict) The path to a 'cargo-bazel' binary. The pairing (dict) 240may be `None` if there is not need to update the attribute 241""" 242host_triple = get_host_triple ( module_ctx ) 243use_environ = False 244for var in GENERATOR_ENV_VARS : 245if var in module_ctx . os . environ : 246use_environ = True 247 248if use_environ : 249generator_sha256 = module_ctx . os . environ . get ( CARGO_BAZEL_GENERATOR_SHA256 ) 250generator_url = module_ctx . os . environ . get ( CARGO_BAZEL_GENERATOR_URL ) 251elif len ( CARGO_BAZEL_URLS ) == 0 : 252return module_ctx . path ( Label ( "@cargo_bazel_bootstrap//:cargo-bazel" )) 253else : 254generator_sha256 = CARGO_BAZEL_SHA256S . get ( host_triple . str ) 255generator_url = CARGO_BAZEL_URLS . get ( host_triple . str ) 256 257if not generator_url : 258fail (( 259"No generator URL was found either in the `CARGO_BAZEL_GENERATOR_URL` " + 260"environment variable or for the `{}` triple in the `generator_urls` attribute" 261). format ( host_triple . str )) 262 263output = module_ctx . path ( "cargo-bazel.exe" if "win" in module_ctx . os . name else "cargo-bazel" ) 264 265# Download the file into place 266download_kwargs = { 267"executable" : True , 268"output" : output , 269"url" : generator_url , 270} 271 272if generator_sha256 : 273download_kwargs . update ({ "sha256" : generator_sha256 }) 274 275module_ctx . download ( ** download_kwargs ) 276return output 277 278def _crate_impl ( module_ctx ): 279# Preload all external repositories. Calling `module_ctx.path` will cause restarts of the implementation 280# function of the module extension, so we want to trigger all restarts before we start the actual work. 281# Once https://github.com/bazelbuild/bazel/issues/22729 has been fixed, this code can be removed. 282get_host_cargo_rustc ( module_ctx ) 283for mod in module_ctx . modules : 284for cfg in mod . tags . from_cargo : 285module_ctx . path ( cfg . cargo_lockfile ) 286for m in cfg . manifests : 287module_ctx . path ( m ) 288 289cargo_bazel_output = _get_generator ( module_ctx ) 290cargo_bazel = get_cargo_bazel_runner ( module_ctx , cargo_bazel_output ) 291 292all_repos = [] 293reproducible = True 294 295for mod in module_ctx . modules : 296module_annotations = {} 297repo_specific_annotations = {} 298for annotation_tag in mod . tags . annotation : 299annotation_dict = structs . to_dict ( annotation_tag ) 300repositories = annotation_dict . pop ( "repositories" ) 301crate = annotation_dict . pop ( "crate" ) 302 303# The crate.annotation function can take in either a list or a bool. 304# For the tag-based method, because it has type safety, we have to 305# split it into two parameters. 306if annotation_dict . pop ( "gen_all_binaries" ): 307annotation_dict [ "gen_binaries" ] = True 308annotation_dict [ "gen_build_script" ] = _OPT_BOOL_VALUES [ annotation_dict [ "gen_build_script" ]] 309 310# Process the override targets for the annotation. 311# In the non-bzlmod approach, this is given as a dict 312# with the possible keys "`proc_macro`, `build_script`, `lib`, `bin`". 313# With the tag-based approach used in Bzlmod, we run into an issue 314# where there is no dict type that takes a string as a key and a Label as the value. 315# To work around this, we split the override option into four, and reconstruct the 316# dictionary here during processing 317annotation_dict [ "override_targets" ] = dict () 318replacement = annotation_dict . pop ( "override_target_lib" ) 319if replacement : 320annotation_dict [ "override_targets" ][ "lib" ] = str ( replacement ) 321 322replacement = annotation_dict . pop ( "override_target_proc_macro" ) 323if replacement : 324annotation_dict [ "override_targets" ][ "proc_macro" ] = str ( replacement ) 325 326replacement = annotation_dict . pop ( "override_target_build_script" ) 327if replacement : 328annotation_dict [ "override_targets" ][ "build_script" ] = str ( replacement ) 329 330replacement = annotation_dict . pop ( "override_target_bin" ) 331if replacement : 332annotation_dict [ "override_targets" ][ "bin" ] = str ( replacement ) 333 334annotation = _crate_universe_crate . annotation ( ** { 335k : v 336for k , v in annotation_dict . items () 337# Tag classes can't take in None, but the function requires None 338# instead of the empty values in many cases. 339# https://github.com/bazelbuild/bazel/issues/20744 340if v != "" and v != [] and v != {} 341}) 342if not repositories : 343_get_or_insert ( module_annotations , crate , []). append ( annotation ) 344for repo in repositories : 345_get_or_insert ( 346_get_or_insert ( repo_specific_annotations , repo , {}), 347crate , 348[], 349). append ( annotation ) 350 351local_repos = [] 352 353for cfg in mod . tags . from_cargo + mod . tags . from_specs : 354if cfg . name in local_repos : 355fail ( "Defined two crate universes with the same name in the same MODULE.bazel file. Use the name tag to give them different names." ) 356elif cfg . name in all_repos : 357fail ( "Defined two crate universes with the same name in different MODULE.bazel files. Either give one a different name, or use use_extension(isolate=True)" ) 358all_repos . append ( cfg . name ) 359local_repos . append ( cfg . name ) 360 361for cfg in mod . tags . from_cargo : 362annotations = _annotations_for_repo ( 363module_annotations , 364repo_specific_annotations . get ( cfg . name ), 365) 366 367cargo_lockfile = module_ctx . path ( cfg . cargo_lockfile ) 368manifests = { str ( module_ctx . path ( m )): str ( m ) for m in cfg . manifests } 369_generate_hub_and_spokes ( module_ctx , cargo_bazel , cfg , annotations , cargo_lockfile = cargo_lockfile , manifests = manifests ) 370 371for cfg in mod . tags . from_specs : 372# We don't have a Cargo.lock so the resolution can change. 373# We could maybe make this reproducible by using `-minimal-version` during resolution. 374# See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#minimal-versions 375reproducible = False 376 377annotations = _annotations_for_repo ( 378module_annotations , 379repo_specific_annotations . get ( cfg . name ), 380) 381 382packages = { p . package : _package_to_json ( p ) for p in mod . tags . spec } 383_generate_hub_and_spokes ( module_ctx , cargo_bazel , cfg , annotations , packages = packages ) 384 385for repo in repo_specific_annotations : 386if repo not in local_repos : 387fail ( "Annotation specified for repo %s, but the module defined repositories %s" % ( repo , local_repos )) 388 389metadata_kwargs = {} 390if bazel_features . external_deps . extension_metadata_has_reproducible : 391metadata_kwargs [ "reproducible" ] = reproducible 392 393return module_ctx . extension_metadata ( ** metadata_kwargs ) 394 395_from_cargo = tag_class ( 396doc = "Generates a repo @crates from a Cargo.toml / Cargo.lock pair" , 397attrs = dict ( 398name = attr . string ( 399doc = "The name of the repo to generate" , 400default = "crates" , 401), 402cargo_lockfile = CRATES_VENDOR_ATTRS [ "cargo_lockfile" ], 403manifests = CRATES_VENDOR_ATTRS [ "manifests" ], 404cargo_config = CRATES_VENDOR_ATTRS [ "cargo_config" ], 405generate_binaries = CRATES_VENDOR_ATTRS [ "generate_binaries" ], 406generate_build_scripts = CRATES_VENDOR_ATTRS [ "generate_build_scripts" ], 407splicing_config = CRATES_VENDOR_ATTRS [ "splicing_config" ], 408supported_platform_triples = CRATES_VENDOR_ATTRS [ "supported_platform_triples" ], 409), 410) 411 412# This should be kept in sync with crate_universe/private/crate.bzl. 413_annotation = tag_class ( 414attrs = dict ( 415repositories = attr . string_list ( 416doc = "A list of repository names specified from `crate.from_cargo(name=...)` that this annotation is applied to. Defaults to all repositories." , 417default = [], 418), 419crate = attr . string ( 420doc = "The name of the crate the annotation is applied to" , 421mandatory = True , 422), 423version = attr . string ( 424doc = "The versions of the crate the annotation is applied to. Defaults to all versions." , 425default = "*" , 426), 427additive_build_file_content = attr . string ( 428doc = "Extra contents to write to the bottom of generated BUILD files." , 429), 430additive_build_file = attr . label ( 431doc = "A file containing extra contents to write to the bottom of generated BUILD files." , 432), 433alias_rule = attr . string ( 434doc = "Alias rule to use instead of `native.alias()`. Overrides [render_config](#render_config)'s 'default_alias_rule'." , 435), 436build_script_data = _relative_label_list ( 437doc = "A list of labels to add to a crate's `cargo_build_script::data` attribute." , 438), 439build_script_tools = _relative_label_list ( 440doc = "A list of labels to add to a crate's `cargo_build_script::tools` attribute." , 441), 442build_script_data_glob = attr . string_list ( 443doc = "A list of glob patterns to add to a crate's `cargo_build_script::data` attribute" , 444), 445build_script_deps = _relative_label_list ( 446doc = "A list of labels to add to a crate's `cargo_build_script::deps` attribute." , 447), 448build_script_env = attr . string_dict ( 449doc = "Additional environment variables to set on a crate's `cargo_build_script::env` attribute." , 450), 451build_script_proc_macro_deps = _relative_label_list ( 452doc = "A list of labels to add to a crate's `cargo_build_script::proc_macro_deps` attribute." , 453), 454build_script_rundir = attr . string ( 455doc = "An override for the build script's rundir attribute." , 456), 457build_script_rustc_env = attr . string_dict ( 458doc = "Additional environment variables to set on a crate's `cargo_build_script::env` attribute." , 459), 460build_script_toolchains = attr . label_list ( 461doc = "A list of labels to set on a crates's `cargo_build_script::toolchains` attribute." , 462), 463compile_data = _relative_label_list ( 464doc = "A list of labels to add to a crate's `rust_library::compile_data` attribute." , 465), 466compile_data_glob = attr . string_list ( 467doc = "A list of glob patterns to add to a crate's `rust_library::compile_data` attribute." , 468), 469crate_features = attr . string_list ( 470doc = "A list of strings to add to a crate's `rust_library::crate_features` attribute." , 471), 472data = _relative_label_list ( 473doc = "A list of labels to add to a crate's `rust_library::data` attribute." , 474), 475data_glob = attr . string_list ( 476doc = "A list of glob patterns to add to a crate's `rust_library::data` attribute." , 477), 478deps = _relative_label_list ( 479doc = "A list of labels to add to a crate's `rust_library::deps` attribute." , 480), 481extra_aliased_targets = attr . string_dict ( 482doc = "A list of targets to add to the generated aliases in the root crate_universe repository." , 483), 484gen_binaries = attr . string_list ( 485doc = "As a list, the subset of the crate's bins that should get `rust_binary` targets produced." , 486), 487gen_all_binaries = attr . bool ( 488doc = "If true, generates `rust_binary` targets for all of the crates bins" , 489), 490disable_pipelining = attr . bool ( 491doc = "If True, disables pipelining for library targets for this crate." , 492), 493gen_build_script = attr . string ( 494doc = "An authorative flag to determine whether or not to produce `cargo_build_script` targets for the current crate. Supported values are 'on', 'off', and 'auto'." , 495values = _OPT_BOOL_VALUES . keys (), 496default = "auto" , 497), 498patch_args = attr . string_list ( 499doc = "The `patch_args` attribute of a Bazel repository rule. See [http_archive.patch_args](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_args)" , 500), 501patch_tool = attr . string ( 502doc = "The `patch_tool` attribute of a Bazel repository rule. See [http_archive.patch_tool](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_tool)" , 503), 504patches = attr . label_list ( 505doc = "The `patches` attribute of a Bazel repository rule. See [http_archive.patches](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patches)" , 506), 507proc_macro_deps = _relative_label_list ( 508doc = "A list of labels to add to a crate's `rust_library::proc_macro_deps` attribute." , 509), 510rustc_env = attr . string_dict ( 511doc = "Additional variables to set on a crate's `rust_library::rustc_env` attribute." , 512), 513rustc_env_files = _relative_label_list ( 514doc = "A list of labels to set on a crate's `rust_library::rustc_env_files` attribute." , 515), 516rustc_flags = attr . string_list ( 517doc = "A list of strings to set on a crate's `rust_library::rustc_flags` attribute." , 518), 519shallow_since = attr . string ( 520doc = "An optional timestamp used for crates originating from a git repository instead of a crate registry. This flag optimizes fetching the source code." , 521), 522override_target_lib = attr . label ( 523doc = "An optional alternate taget to use when something depends on this crate to allow the parent repo to provide its own version of this dependency." , 524), 525override_target_proc_macro = attr . label ( 526doc = "An optional alternate taget to use when something depends on this crate to allow the parent repo to provide its own version of this dependency." , 527), 528override_target_build_script = attr . label ( 529doc = "An optional alternate taget to use when something depends on this crate to allow the parent repo to provide its own version of this dependency." , 530), 531override_target_bin = attr . label ( 532doc = "An optional alternate taget to use when something depends on this crate to allow the parent repo to provide its own version of this dependency." , 533), 534), 535) 536 537_from_specs = tag_class ( 538doc = "Generates a repo @crates from the defined `spec` tags" , 539attrs = dict ( 540name = attr . string ( doc = "The name of the repo to generate" , default = "crates" ), 541cargo_config = CRATES_VENDOR_ATTRS [ "cargo_config" ], 542generate_binaries = CRATES_VENDOR_ATTRS [ "generate_binaries" ], 543generate_build_scripts = CRATES_VENDOR_ATTRS [ "generate_build_scripts" ], 544splicing_config = CRATES_VENDOR_ATTRS [ "splicing_config" ], 545supported_platform_triples = CRATES_VENDOR_ATTRS [ "supported_platform_triples" ], 546), 547) 548 549# This should be kept in sync with crate_universe/private/crate.bzl. 550_spec = tag_class ( 551attrs = dict ( 552package = attr . string ( 553doc = "The explicit name of the package." , 554mandatory = True , 555), 556version = attr . string ( 557doc = "The exact version of the crate. Cannot be used with `git`." , 558), 559artifact = attr . string ( 560doc = "Set to 'bin' to pull in a binary crate as an artifact dependency. Requires a nightly Cargo." , 561), 562lib = attr . bool ( 563doc = "If using `artifact = 'bin'`, additionally setting `lib = True` declares a dependency on both the package's library and binary, as opposed to just the binary." , 564), 565default_features = attr . bool ( 566doc = "Maps to the `default-features` flag." , 567default = True , 568), 569features = attr . string_list ( 570doc = "A list of features to use for the crate." , 571), 572git = attr . string ( 573doc = "The Git url to use for the crate. Cannot be used with `version`." , 574), 575branch = attr . string ( 576doc = "The git branch of the remote crate. Tied with the `git` param. Only one of branch, tag or rev may be specified. Specifying `rev` is recommended for fully-reproducible builds." , 577), 578tag = attr . string ( 579doc = "The git tag of the remote crate. Tied with the `git` param. Only one of branch, tag or rev may be specified. Specifying `rev` is recommended for fully-reproducible builds." , 580), 581rev = attr . string ( 582doc = "The git revision of the remote crate. Tied with the `git` param. Only one of branch, tag or rev may be specified." , 583), 584), 585) 586 587_conditional_crate_args = { 588"arch_dependent" : True , 589"os_dependent" : True , 590} if bazel_features . external_deps . module_extension_has_os_arch_dependent else {} 591 592crate = module_extension ( 593implementation = _crate_impl , 594tag_classes = dict ( 595from_cargo = _from_cargo , 596annotation = _annotation , 597from_specs = _from_specs , 598spec = _spec , 599), 600** _conditional_crate_args 601)