|
1 | | -_DEFAULT_CRATE_ANNOTATION = struct( |
2 | | - additive_build_file = None, |
3 | | - additive_build_file_content = "", |
4 | | - gen_build_script = "auto", |
5 | | - build_script_data = [], |
6 | | - build_script_data_select = {}, |
7 | | - build_script_env = {}, |
8 | | - build_script_env_select = {}, |
9 | | - build_script_tools = [], |
10 | | - build_script_tools_select = {}, |
11 | | - build_script_toolchains = [], |
12 | | - build_script_tags = [], |
13 | | - data = [], |
14 | | - deps = [], |
15 | | - tags = [], |
16 | | - crate_features = [], |
17 | | - crate_features_select = {}, |
18 | | - gen_binaries = [], |
19 | | - rustc_flags = [], |
20 | | - rustc_flags_select = {}, |
21 | | - patch_args = [], |
22 | | - patch_tool = None, |
23 | | - patches = [], |
24 | | - strip_prefix = None, |
25 | | - workspace_cargo_toml = "Cargo.toml", |
| 1 | +def _crate_annotation( |
| 2 | + additive_build_file = None, |
| 3 | + additive_build_file_content = "", |
| 4 | + gen_build_script = "auto", |
| 5 | + build_script_data = [], |
| 6 | + build_script_data_select = {}, |
| 7 | + build_script_env = {}, |
| 8 | + build_script_env_select = {}, |
| 9 | + build_script_tools = [], |
| 10 | + build_script_tools_select = {}, |
| 11 | + build_script_toolchains = [], |
| 12 | + build_script_tags = [], |
| 13 | + data = [], |
| 14 | + deps = [], |
| 15 | + tags = [], |
| 16 | + crate_features = [], |
| 17 | + crate_features_select = {}, |
| 18 | + gen_binaries = [], |
| 19 | + rustc_flags = [], |
| 20 | + rustc_flags_select = {}, |
| 21 | + patch_args = [], |
| 22 | + patch_tool = None, |
| 23 | + patches = [], |
| 24 | + strip_prefix = None, |
| 25 | + workspace_cargo_toml = "Cargo.toml"): |
| 26 | + return struct( |
| 27 | + additive_build_file = additive_build_file, |
| 28 | + additive_build_file_content = additive_build_file_content, |
| 29 | + gen_build_script = gen_build_script, |
| 30 | + build_script_data = build_script_data, |
| 31 | + build_script_data_select = build_script_data_select, |
| 32 | + build_script_env = build_script_env, |
| 33 | + build_script_env_select = build_script_env_select, |
| 34 | + build_script_tools = build_script_tools, |
| 35 | + build_script_tools_select = build_script_tools_select, |
| 36 | + build_script_toolchains = build_script_toolchains, |
| 37 | + build_script_tags = build_script_tags, |
| 38 | + data = data, |
| 39 | + deps = deps, |
| 40 | + tags = tags, |
| 41 | + crate_features = crate_features, |
| 42 | + crate_features_select = crate_features_select, |
| 43 | + gen_binaries = gen_binaries, |
| 44 | + rustc_flags = rustc_flags, |
| 45 | + rustc_flags_select = rustc_flags_select, |
| 46 | + patch_args = patch_args, |
| 47 | + patch_tool = patch_tool, |
| 48 | + patches = patches, |
| 49 | + strip_prefix = strip_prefix, |
| 50 | + workspace_cargo_toml = workspace_cargo_toml, |
| 51 | + ) |
| 52 | + |
| 53 | +_DEFAULT_CRATE_ANNOTATION = _crate_annotation() |
| 54 | + |
| 55 | +_WINDOWS_GNULLVM_IMPLICIT_ANNOTATION = _crate_annotation( |
| 56 | + additive_build_file_content = """ |
| 57 | +load("@rules_cc//cc:defs.bzl", "cc_import") |
| 58 | +
|
| 59 | +cc_import( |
| 60 | + name = "windows_import_lib", |
| 61 | + static_library = glob(["lib/*.a"])[0], |
26 | 62 | ) |
| 63 | +""", |
| 64 | + gen_build_script = "off", |
| 65 | + deps = [":windows_import_lib"], |
| 66 | +) |
| 67 | + |
| 68 | +_IMPLICIT_ANNOTATIONS_BY_CRATE = { |
| 69 | + # These crates publish the needed import library in their package archive. |
| 70 | + # Treat the well-known snippet as a built-in default so users do not need |
| 71 | + # to include it manually. |
| 72 | + "windows_aarch64_gnullvm": _WINDOWS_GNULLVM_IMPLICIT_ANNOTATION, |
| 73 | + "windows_x86_64_gnullvm": _WINDOWS_GNULLVM_IMPLICIT_ANNOTATION, |
| 74 | +} |
27 | 75 |
|
28 | 76 | def annotation_for(annotations_by_crate, crate_name, version): |
29 | 77 | """Return the annotation matching crate/version, falling back to '*' or default.""" |
30 | 78 | version_map = annotations_by_crate.get(crate_name, {}) |
31 | | - return version_map.get(version) or version_map.get("*", _DEFAULT_CRATE_ANNOTATION) |
| 79 | + return ( |
| 80 | + version_map.get(version) or |
| 81 | + version_map.get("*") or |
| 82 | + _IMPLICIT_ANNOTATIONS_BY_CRATE.get(crate_name, _DEFAULT_CRATE_ANNOTATION) |
| 83 | + ) |
32 | 84 |
|
33 | 85 | def build_annotation_map(mod, cfg_name): |
34 | 86 | """Build mapping {crate: {version|\"*\": annotation}} for a cfg name.""" |
|
0 commit comments