|
| 1 | +load("@rules_rust//rust/platform:triple.bzl", _parse_triple = "triple") |
| 2 | +load("//rs/experimental/miri:defs.bzl", "miri_source_sysroot_from_deps", "miri_sysroot_from_files", "miri_sysroot_toolchain", "miri_toolchain") |
| 3 | +load("//rs/platforms:triples.bzl", "ALL_TARGET_TRIPLES", "SUPPORTED_EXEC_TRIPLES", "triple_to_constraint_set") |
| 4 | +load("//rs/toolchains:toolchain_utils.bzl", "sanitize_triple", "sanitize_version") |
| 5 | + |
| 6 | +def declare_miri_toolchains( |
| 7 | + *, |
| 8 | + version, |
| 9 | + execs = SUPPORTED_EXEC_TRIPLES, |
| 10 | + targets = ALL_TARGET_TRIPLES): |
| 11 | + version_key = sanitize_version(version) |
| 12 | + |
| 13 | + for triple in execs: |
| 14 | + exec_triple = _parse_triple(triple) |
| 15 | + triple_suffix = exec_triple.system + "_" + exec_triple.arch |
| 16 | + |
| 17 | + miri_repo_label = "@miri_{}_{}//:".format(triple_suffix, version_key) |
| 18 | + host_stdlib_label = "@rust_stdlib_{}_{}//:rust_std-{}".format(sanitize_triple(triple), version_key, triple) |
| 19 | + rust_src_repo_label = "@rustc_src_{}//src:rustc_srcs".format(version_key) |
| 20 | + generated_stdlib_root = "@rustc_src_{}//src:sysroot".format(version_key) |
| 21 | + |
| 22 | + generated_sysroot_name = "{}_{}_{}_miri_sysroot".format( |
| 23 | + exec_triple.system, |
| 24 | + exec_triple.arch, |
| 25 | + version_key, |
| 26 | + ) |
| 27 | + target_triple_select = {} |
| 28 | + |
| 29 | + for target_triple in targets: |
| 30 | + config_label = "@rules_rs//rs/platforms/config:{}".format(target_triple) |
| 31 | + target_triple_select[config_label] = target_triple |
| 32 | + |
| 33 | + sysroot_toolchain_name = "{}_{}_{}_miri_sysroot_toolchain".format( |
| 34 | + exec_triple.system, |
| 35 | + exec_triple.arch, |
| 36 | + version_key, |
| 37 | + ) |
| 38 | + miri_sysroot_toolchain( |
| 39 | + name = sysroot_toolchain_name, |
| 40 | + exec_triple = triple, |
| 41 | + miri = "{}miri".format(miri_repo_label), |
| 42 | + miri_lib = "{}miri_lib".format(miri_repo_label), |
| 43 | + rustc_lib = "{}rustc_lib".format(miri_repo_label), |
| 44 | + rustc_srcs = rust_src_repo_label, |
| 45 | + target_triple = select(target_triple_select), |
| 46 | + version = version, |
| 47 | + visibility = ["//visibility:public"], |
| 48 | + ) |
| 49 | + |
| 50 | + host_sysroot_name = "{}_{}_{}_miri_host_sysroot".format( |
| 51 | + exec_triple.system, |
| 52 | + exec_triple.arch, |
| 53 | + version_key, |
| 54 | + ) |
| 55 | + miri_sysroot_from_files( |
| 56 | + name = host_sysroot_name, |
| 57 | + srcs = [host_stdlib_label], |
| 58 | + target_triple = triple, |
| 59 | + visibility = ["//visibility:public"], |
| 60 | + ) |
| 61 | + |
| 62 | + miri_source_sysroot_from_deps( |
| 63 | + name = generated_sysroot_name, |
| 64 | + roots = [generated_stdlib_root], |
| 65 | + target_triple = select(target_triple_select), |
| 66 | + visibility = ["//visibility:public"], |
| 67 | + ) |
| 68 | + |
| 69 | + toolchain_name = "{}_{}_{}_miri_toolchain".format( |
| 70 | + exec_triple.system, |
| 71 | + exec_triple.arch, |
| 72 | + version_key, |
| 73 | + ) |
| 74 | + miri_toolchain( |
| 75 | + name = toolchain_name, |
| 76 | + exec_triple = triple, |
| 77 | + host_source_sysroot = ":" + host_sysroot_name, |
| 78 | + miri = "{}miri".format(miri_repo_label), |
| 79 | + miri_lib = "{}miri_lib".format(miri_repo_label), |
| 80 | + rustc_lib = "{}rustc_lib".format(miri_repo_label), |
| 81 | + source_sysroot = ":" + generated_sysroot_name, |
| 82 | + target_triple = select(target_triple_select), |
| 83 | + version = version, |
| 84 | + visibility = ["//visibility:public"], |
| 85 | + ) |
| 86 | + |
| 87 | + for target_triple in targets: |
| 88 | + target_key = sanitize_triple(target_triple) |
| 89 | + |
| 90 | + native.toolchain( |
| 91 | + name = "{}_{}_to_{}_{}_miri_sysroot".format(exec_triple.system, exec_triple.arch, target_key, version_key), |
| 92 | + exec_compatible_with = [ |
| 93 | + "@platforms//os:" + exec_triple.system, |
| 94 | + "@platforms//cpu:" + exec_triple.arch, |
| 95 | + ], |
| 96 | + target_compatible_with = triple_to_constraint_set(target_triple), |
| 97 | + toolchain = sysroot_toolchain_name, |
| 98 | + toolchain_type = "@rules_rs//rs/experimental/miri:sysroot_toolchain_type", |
| 99 | + visibility = ["//visibility:public"], |
| 100 | + ) |
| 101 | + |
| 102 | + native.toolchain( |
| 103 | + name = "{}_{}_to_{}_{}_miri".format(exec_triple.system, exec_triple.arch, target_key, version_key), |
| 104 | + exec_compatible_with = [ |
| 105 | + "@platforms//os:" + exec_triple.system, |
| 106 | + "@platforms//cpu:" + exec_triple.arch, |
| 107 | + ], |
| 108 | + target_compatible_with = triple_to_constraint_set(target_triple), |
| 109 | + toolchain = toolchain_name, |
| 110 | + toolchain_type = "@rules_rs//rs/experimental/miri:toolchain_type", |
| 111 | + visibility = ["//visibility:public"], |
| 112 | + ) |
0 commit comments