[TOOLS] add alias repo
diff --git a/e2e/smoke/MODULE.bazel b/e2e/smoke/MODULE.bazel index 45b6fb0..d6c7568 100644 --- a/e2e/smoke/MODULE.bazel +++ b/e2e/smoke/MODULE.bazel
@@ -5,3 +5,10 @@ module_name = "probe_rs_tools", path = "../..", ) + +probe_rs = use_extension("@probe_rs_tools//probe_rs_tools:extensions.bzl", "probe_rs") +probe_rs.tools( + name = "probe_rs", + version = "0.24.0", +) +use_repo(probe_rs, "probe_rs")
diff --git a/e2e/smoke/MODULE.bazel.lock b/e2e/smoke/MODULE.bazel.lock new file mode 100644 index 0000000..8d3c884 --- /dev/null +++ b/e2e/smoke/MODULE.bazel.lock
@@ -0,0 +1,213 @@ +{ + "lockFileVersion": 11, + "registryFileHashes": { + "https://bcr.bazel.build/bazel_registry.json": "8a28e4aff06ee60aed2a8c281907fb8bcbf3b753c91fb5a5c57da3215d5b3497", + "https://bcr.bazel.build/modules/abseil-cpp/20210324.2/MODULE.bazel": "7cd0312e064fde87c8d1cd79ba06c876bd23630c83466e9500321be55c96ace2", + "https://bcr.bazel.build/modules/abseil-cpp/20211102.0/MODULE.bazel": "70390338f7a5106231d20620712f7cccb659cd0e9d073d1991c038eb9fc57589", + "https://bcr.bazel.build/modules/abseil-cpp/20211102.0/source.json": "7e3a9adf473e9af076ae485ed649d5641ad50ec5c11718103f34de03170d94ad", + "https://bcr.bazel.build/modules/apple_support/1.5.0/MODULE.bazel": "50341a62efbc483e8a2a6aec30994a58749bd7b885e18dd96aa8c33031e558ef", + "https://bcr.bazel.build/modules/apple_support/1.5.0/source.json": "eb98a7627c0bc486b57f598ad8da50f6625d974c8f723e9ea71bd39f709c9862", + "https://bcr.bazel.build/modules/bazel_features/1.11.0/MODULE.bazel": "f9382337dd5a474c3b7d334c2f83e50b6eaedc284253334cf823044a26de03e8", + "https://bcr.bazel.build/modules/bazel_features/1.11.0/source.json": "c9320aa53cd1c441d24bd6b716da087ad7e4ff0d9742a9884587596edfe53015", + "https://bcr.bazel.build/modules/bazel_skylib/1.0.3/MODULE.bazel": "bcb0fd896384802d1ad283b4e4eb4d718eebd8cb820b0a2c3a347fb971afd9d8", + "https://bcr.bazel.build/modules/bazel_skylib/1.2.1/MODULE.bazel": "f35baf9da0efe45fa3da1696ae906eea3d615ad41e2e3def4aeb4e8bc0ef9a7a", + "https://bcr.bazel.build/modules/bazel_skylib/1.3.0/MODULE.bazel": "20228b92868bf5cfc41bda7afc8a8ba2a543201851de39d990ec957b513579c5", + "https://bcr.bazel.build/modules/bazel_skylib/1.4.1/MODULE.bazel": "a0dcb779424be33100dcae821e9e27e4f2901d9dfd5333efe5ac6a8d7ab75e1d", + "https://bcr.bazel.build/modules/bazel_skylib/1.6.1/MODULE.bazel": "8fdee2dbaace6c252131c00e1de4b165dc65af02ea278476187765e1a617b917", + "https://bcr.bazel.build/modules/bazel_skylib/1.7.1/MODULE.bazel": "3120d80c5861aa616222ec015332e5f8d3171e062e3e804a2a0253e1be26e59b", + "https://bcr.bazel.build/modules/bazel_skylib/1.7.1/source.json": "f121b43eeefc7c29efbd51b83d08631e2347297c95aac9764a701f2a6a2bb953", + "https://bcr.bazel.build/modules/buildozer/7.1.2/MODULE.bazel": "2e8dd40ede9c454042645fd8d8d0cd1527966aa5c919de86661e62953cd73d84", + "https://bcr.bazel.build/modules/buildozer/7.1.2/source.json": "c9028a501d2db85793a6996205c8de120944f50a0d570438fcae0457a5f9d1f8", + "https://bcr.bazel.build/modules/googletest/1.11.0/MODULE.bazel": "3a83f095183f66345ca86aa13c58b59f9f94a2f81999c093d4eeaa2d262d12f4", + "https://bcr.bazel.build/modules/googletest/1.11.0/source.json": "c73d9ef4268c91bd0c1cd88f1f9dfa08e814b1dbe89b5f594a9f08ba0244d206", + "https://bcr.bazel.build/modules/platforms/0.0.4/MODULE.bazel": "9b328e31ee156f53f3c416a64f8491f7eb731742655a47c9eec4703a71644aee", + "https://bcr.bazel.build/modules/platforms/0.0.5/MODULE.bazel": "5733b54ea419d5eaf7997054bb55f6a1d0b5ff8aedf0176fef9eea44f3acda37", + "https://bcr.bazel.build/modules/platforms/0.0.6/MODULE.bazel": "ad6eeef431dc52aefd2d77ed20a4b353f8ebf0f4ecdd26a807d2da5aa8cd0615", + "https://bcr.bazel.build/modules/platforms/0.0.7/MODULE.bazel": "72fd4a0ede9ee5c021f6a8dd92b503e089f46c227ba2813ff183b71616034814", + "https://bcr.bazel.build/modules/platforms/0.0.9/MODULE.bazel": "4a87a60c927b56ddd67db50c89acaa62f4ce2a1d2149ccb63ffd871d5ce29ebc", + "https://bcr.bazel.build/modules/platforms/0.0.9/source.json": "cd74d854bf16a9e002fb2ca7b1a421f4403cda29f824a765acd3a8c56f8d43e6", + "https://bcr.bazel.build/modules/protobuf/21.7/MODULE.bazel": "a5a29bb89544f9b97edce05642fac225a808b5b7be74038ea3640fae2f8e66a7", + "https://bcr.bazel.build/modules/protobuf/21.7/source.json": "bbe500720421e582ff2d18b0802464205138c06056f443184de39fbb8187b09b", + "https://bcr.bazel.build/modules/protobuf/3.19.0/MODULE.bazel": "6b5fbb433f760a99a22b18b6850ed5784ef0e9928a72668b66e4d7ccd47db9b0", + "https://bcr.bazel.build/modules/protobuf/3.19.6/MODULE.bazel": "9233edc5e1f2ee276a60de3eaa47ac4132302ef9643238f23128fea53ea12858", + "https://bcr.bazel.build/modules/rules_cc/0.0.1/MODULE.bazel": "cb2aa0747f84c6c3a78dad4e2049c154f08ab9d166b1273835a8174940365647", + "https://bcr.bazel.build/modules/rules_cc/0.0.2/MODULE.bazel": "6915987c90970493ab97393024c156ea8fb9f3bea953b2f3ec05c34f19b5695c", + "https://bcr.bazel.build/modules/rules_cc/0.0.8/MODULE.bazel": "964c85c82cfeb6f3855e6a07054fdb159aced38e99a5eecf7bce9d53990afa3e", + "https://bcr.bazel.build/modules/rules_cc/0.0.9/MODULE.bazel": "836e76439f354b89afe6a911a7adf59a6b2518fafb174483ad78a2a2fde7b1c5", + "https://bcr.bazel.build/modules/rules_cc/0.0.9/source.json": "1f1ba6fea244b616de4a554a0f4983c91a9301640c8fe0dd1d410254115c8430", + "https://bcr.bazel.build/modules/rules_java/4.0.0/MODULE.bazel": "5a78a7ae82cd1a33cef56dc578c7d2a46ed0dca12643ee45edbb8417899e6f74", + "https://bcr.bazel.build/modules/rules_java/7.6.5/MODULE.bazel": "481164be5e02e4cab6e77a36927683263be56b7e36fef918b458d7a8a1ebadb1", + "https://bcr.bazel.build/modules/rules_java/7.6.5/source.json": "a805b889531d1690e3c72a7a7e47a870d00323186a9904b36af83aa3d053ee8d", + "https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7", + "https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/source.json": "a075731e1b46bc8425098512d038d416e966ab19684a10a34f4741295642fc35", + "https://bcr.bazel.build/modules/rules_license/0.0.3/MODULE.bazel": "627e9ab0247f7d1e05736b59dbb1b6871373de5ad31c3011880b4133cafd4bd0", + "https://bcr.bazel.build/modules/rules_license/0.0.7/MODULE.bazel": "088fbeb0b6a419005b89cf93fe62d9517c0a2b8bb56af3244af65ecfe37e7d5d", + "https://bcr.bazel.build/modules/rules_license/0.0.7/source.json": "355cc5737a0f294e560d52b1b7a6492d4fff2caf0bef1a315df5a298fca2d34a", + "https://bcr.bazel.build/modules/rules_pkg/0.7.0/MODULE.bazel": "df99f03fc7934a4737122518bb87e667e62d780b610910f0447665a7e2be62dc", + "https://bcr.bazel.build/modules/rules_pkg/0.7.0/source.json": "c2557066e0c0342223ba592510ad3d812d4963b9024831f7f66fd0584dd8c66c", + "https://bcr.bazel.build/modules/rules_proto/4.0.0/MODULE.bazel": "a7a7b6ce9bee418c1a760b3d84f83a299ad6952f9903c67f19e4edd964894e06", + "https://bcr.bazel.build/modules/rules_proto/5.3.0-21.7/MODULE.bazel": "e8dff86b0971688790ae75528fe1813f71809b5afd57facb44dad9e8eca631b7", + "https://bcr.bazel.build/modules/rules_proto/5.3.0-21.7/source.json": "d57902c052424dfda0e71646cb12668d39c4620ee0544294d9d941e7d12bc3a9", + "https://bcr.bazel.build/modules/rules_python/0.10.2/MODULE.bazel": "cc82bc96f2997baa545ab3ce73f196d040ffb8756fd2d66125a530031cd90e5f", + "https://bcr.bazel.build/modules/rules_python/0.22.1/MODULE.bazel": "26114f0c0b5e93018c0c066d6673f1a2c3737c7e90af95eff30cfee38d0bbac7", + "https://bcr.bazel.build/modules/rules_python/0.22.1/source.json": "57226905e783bae7c37c2dd662be078728e48fa28ee4324a7eabcafb5a43d014", + "https://bcr.bazel.build/modules/rules_python/0.4.0/MODULE.bazel": "9208ee05fd48bf09ac60ed269791cf17fb343db56c8226a720fbb1cdf467166c", + "https://bcr.bazel.build/modules/stardoc/0.5.1/MODULE.bazel": "1a05d92974d0c122f5ccf09291442580317cdd859f07a8655f1db9a60374f9f8", + "https://bcr.bazel.build/modules/stardoc/0.5.1/source.json": "a96f95e02123320aa015b956f29c00cb818fa891ef823d55148e1a362caacf29", + "https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/MODULE.bazel": "7298990c00040a0e2f121f6c32544bab27d4452f80d9ce51349b1a28f3005c43", + "https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/source.json": "f1ef7d3f9e0e26d4b23d1c39b5f5de71f584dd7d1b4ef83d9bbba6ec7a6a6459", + "https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0", + "https://bcr.bazel.build/modules/zlib/1.2.12/MODULE.bazel": "3b1a8834ada2a883674be8cbd36ede1b6ec481477ada359cd2d3ddc562340b27", + "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/MODULE.bazel": "af322bc08976524477c79d1e45e241b6efbeb918c497e8840b8ab116802dda79", + "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/source.json": "2be409ac3c7601245958cd4fcdff4288be79ed23bd690b4b951f500d54ee6e7d" + }, + "selectedYankedVersions": {}, + "moduleExtensions": { + "@@platforms//host:extension.bzl%host_platform": { + "general": { + "bzlTransitiveDigest": "xelQcPZH8+tmuOHVjL9vDxMnnQNMlwj0SlvgoqBkm4U=", + "usagesDigest": "meSzxn3DUCcYEhq4HQwExWkWtU4EjriRBQLsZN+Q0SU=", + "recordedFileInputs": {}, + "recordedDirentsInputs": {}, + "envVariables": {}, + "generatedRepoSpecs": { + "host_platform": { + "bzlFile": "@@platforms//host:extension.bzl", + "ruleClassName": "host_platform_repo", + "attributes": {} + } + }, + "recordedRepoMappingEntries": [] + } + }, + "@@probe_rs_tools~//probe_rs_tools:extensions.bzl%probe_rs": { + "general": { + "bzlTransitiveDigest": "MqAqMuOUqn/Cy2uSYsNr7tS60ziRLjkLIigTlb/f4IU=", + "usagesDigest": "mCq3temXDGlkB9H7JdtvLCgwJmJWaaGuw/R68kQnK6o=", + "recordedFileInputs": {}, + "recordedDirentsInputs": {}, + "envVariables": {}, + "generatedRepoSpecs": { + "probe_rs_tools_aarch64_unknown_linux_gnu": { + "bzlFile": "@@probe_rs_tools~//probe_rs_tools/private:repositories.bzl", + "ruleClassName": "probe_rs_tools_archive_repo", + "attributes": { + "tools": [ + "probe-rs" + ], + "url": "https://github.com/probe-rs/probe-rs/releases/download/v0.24.0/probe-rs-tools-aarch64-unknown-linux-gnu.tar.xz", + "sha256": "95d91ebe08868d5119a698e3268ff60a4d71d72afa26ab207d43c807c729c90a", + "strip_prefix": "probe-rs-tools-aarch64-unknown-linux-gnu", + "exec_compatible_with": [ + "@platforms//os:linux", + "@platforms//cpu:arm64" + ] + } + }, + "probe_rs_tools_x86_64_apple_darwin": { + "bzlFile": "@@probe_rs_tools~//probe_rs_tools/private:repositories.bzl", + "ruleClassName": "probe_rs_tools_archive_repo", + "attributes": { + "tools": [ + "probe-rs" + ], + "url": "https://github.com/probe-rs/probe-rs/releases/download/v0.24.0/probe-rs-tools-x86_64-apple-darwin.tar.xz", + "sha256": "0e35cc92ff34af1b1c72dd444e6ddd57c039ed31c2987e37578864211e843cf1", + "strip_prefix": "probe-rs-tools-x86_64-apple-darwin", + "exec_compatible_with": [ + "@platforms//os:macos", + "@platforms//cpu:x86_64" + ] + } + }, + "probe_rs": { + "bzlFile": "@@probe_rs_tools~//probe_rs_tools/private:repositories.bzl", + "ruleClassName": "probe_rs_repo", + "attributes": { + "tools": [ + "probe-rs" + ], + "platforms": { + "probe_rs_tools_x86_64_unknown_linux_gnu": [ + "@platforms//os:linux", + "@platforms//cpu:x86_64" + ], + "probe_rs_tools_aarch64_unknown_linux_gnu": [ + "@platforms//os:linux", + "@platforms//cpu:arm64" + ], + "probe_rs_tools_x86_64_apple_darwin": [ + "@platforms//os:macos", + "@platforms//cpu:x86_64" + ], + "probe_rs_tools_aarch64_apple_darwin": [ + "@platforms//os:macos", + "@platforms//cpu:arm64" + ], + "probe_rs_tools_x86_64_pc_windows_msvc": [ + "@platforms//os:windows", + "@platforms//cpu:x86_64" + ] + } + } + }, + "probe_rs_tools_x86_64_unknown_linux_gnu": { + "bzlFile": "@@probe_rs_tools~//probe_rs_tools/private:repositories.bzl", + "ruleClassName": "probe_rs_tools_archive_repo", + "attributes": { + "tools": [ + "probe-rs" + ], + "url": "https://github.com/probe-rs/probe-rs/releases/download/v0.24.0/probe-rs-tools-x86_64-unknown-linux-gnu.tar.xz", + "sha256": "21e8d7df39fa0cdc9a0421e0ac2ac5ba81ec295ea11306f26846089f6fe975c0", + "strip_prefix": "probe-rs-tools-x86_64-unknown-linux-gnu", + "exec_compatible_with": [ + "@platforms//os:linux", + "@platforms//cpu:x86_64" + ] + } + }, + "probe_rs_tools_x86_64_pc_windows_msvc": { + "bzlFile": "@@probe_rs_tools~//probe_rs_tools/private:repositories.bzl", + "ruleClassName": "probe_rs_tools_archive_repo", + "attributes": { + "tools": [ + "probe-rs" + ], + "url": "https://github.com/probe-rs/probe-rs/releases/download/v0.24.0/probe-rs-tools-x86_64-pc-windows-msvc.zip", + "sha256": "d195dfa3466a87906251e27d6d70a0105274faa28ebf90ffadad0bdd89b1ec77", + "strip_prefix": "probe-rs-tools-x86_64-pc-windows-msvc", + "exec_compatible_with": [ + "@platforms//os:windows", + "@platforms//cpu:x86_64" + ] + } + }, + "probe_rs_tools_aarch64_apple_darwin": { + "bzlFile": "@@probe_rs_tools~//probe_rs_tools/private:repositories.bzl", + "ruleClassName": "probe_rs_tools_archive_repo", + "attributes": { + "tools": [ + "probe-rs" + ], + "url": "https://github.com/probe-rs/probe-rs/releases/download/v0.24.0/probe-rs-tools-aarch64-apple-darwin.tar.xz", + "sha256": "7140d9c2c61f8712ba15887f74df0cb40a7b16728ec86d5f45cc93fe96a0a29a", + "strip_prefix": "probe-rs-tools-aarch64-apple-darwin", + "exec_compatible_with": [ + "@platforms//os:macos", + "@platforms//cpu:arm64" + ] + } + } + }, + "recordedRepoMappingEntries": [ + [ + "probe_rs_tools~", + "probe_rs_tools", + "probe_rs_tools~" + ] + ] + } + } + } +}
diff --git a/probe_rs_tools/BUILD.bazel b/probe_rs_tools/BUILD.bazel index 32c26aa..d9dbac1 100644 --- a/probe_rs_tools/BUILD.bazel +++ b/probe_rs_tools/BUILD.bazel
@@ -1,24 +1,4 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -load("//probe_rs_tools/private:resolved_toolchain.bzl", "resolved_toolchain") - -# For stardoc to reference the files -exports_files(["defs.bzl"]) - -# This is the target rule authors should put in their "toolchains" -# attribute in order to get a runtime for the correct platform. -# See https://docs.bazel.build/versions/main/toolchains.html#writing-rules-that-use-toolchains -toolchain_type( - name = "toolchain_type", - visibility = ["//visibility:public"], -) - -resolved_toolchain( - name = "resolved_toolchain", - # Marked manual so that `bazel test //...` passes - # even if no toolchain is registered. - tags = ["manual"], - visibility = ["//visibility:public"], -) bzl_library( name = "repositories",
diff --git a/probe_rs_tools/extensions.bzl b/probe_rs_tools/extensions.bzl index 8817edf..516176c 100644 --- a/probe_rs_tools/extensions.bzl +++ b/probe_rs_tools/extensions.bzl
@@ -10,22 +10,21 @@ effectively overriding the default named toolchain due to toolchain resolution precedence. """ -load(":repositories.bzl", "probe_rs_tools_register_toolchains") +load("@probe_rs_tools//probe_rs_tools/private:repositories.bzl", "probe_rs_tools_repositories") -_DEFAULT_NAME = "probe_rs_tools" +_DEFAULT_NAME = "probe_rs" -probe_rs_tools_toolchain = tag_class(attrs = { - "name": attr.string(doc = """\ -Base name for generated repositories, allowing more than one probe_rs_tools toolchain to be registered. -Overriding the default is only permitted in the root module. -""", default = _DEFAULT_NAME), - "probe_rs_tools_version": attr.string(doc = "Explicit version of probe_rs_tools.", mandatory = True), +probe_rs_tools = tag_class(attrs = { + "name": attr.string(doc = "Base name for generated repositories", default = _DEFAULT_NAME), + "version": attr.string(doc = "Explicit version of probe_rs_tools.", mandatory = True), }) -def _toolchain_extension(module_ctx): +def _probe_rs_extension(module_ctx): registrations = {} + + # Module resolution for mod in module_ctx.modules: - for toolchain in mod.tags.toolchain: + for toolchain in mod.tags.tools: if toolchain.name != _DEFAULT_NAME and not mod.is_root: fail("""\ Only the root module may override the default name for the probe_rs_tools toolchain. @@ -33,7 +32,9 @@ """) if toolchain.name not in registrations.keys(): registrations[toolchain.name] = [] - registrations[toolchain.name].append(toolchain.probe_rs_tools_version) + registrations[toolchain.name].append(toolchain.version) + + # Version resolution for name, versions in registrations.items(): if len(versions) > 1: # TODO: should be semver-aware, using MVS @@ -44,13 +45,12 @@ else: selected = versions[0] - probe_rs_tools_register_toolchains( + probe_rs_tools_repositories( name = name, - probe_rs_tools_version = selected, - register = False, + version = selected, ) -probe_rs_tools = module_extension( - implementation = _toolchain_extension, - tag_classes = {"toolchain": probe_rs_tools_toolchain}, +probe_rs = module_extension( + implementation = _probe_rs_extension, + tag_classes = {"tools": probe_rs_tools}, )
diff --git a/probe_rs_tools/private/archives.bzl b/probe_rs_tools/private/archives.bzl new file mode 100644 index 0000000..a5ae7e1 --- /dev/null +++ b/probe_rs_tools/private/archives.bzl
@@ -0,0 +1,56 @@ +"""aarch64_none_elf toolchiain archives""" + +PROBE_RS_TOOLS = { + "0.24.0": [ + { + "name": "probe_rs_tools_x86_64_unknown_linux_gnu", + "url": "https://github.com/probe-rs/probe-rs/releases/download/v0.24.0/probe-rs-tools-x86_64-unknown-linux-gnu.tar.xz", + "sha256": "21e8d7df39fa0cdc9a0421e0ac2ac5ba81ec295ea11306f26846089f6fe975c0", + "strip_prefix": "probe-rs-tools-x86_64-unknown-linux-gnu", + "exec_compatible_with": [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], + }, + { + "name": "probe_rs_tools_aarch64_unknown_linux_gnu", + "url": "https://github.com/probe-rs/probe-rs/releases/download/v0.24.0/probe-rs-tools-aarch64-unknown-linux-gnu.tar.xz", + "sha256": "95d91ebe08868d5119a698e3268ff60a4d71d72afa26ab207d43c807c729c90a", + "strip_prefix": "probe-rs-tools-aarch64-unknown-linux-gnu", + "exec_compatible_with": [ + "@platforms//os:linux", + "@platforms//cpu:arm64", + ], + }, + { + "name": "probe_rs_tools_x86_64_apple_darwin", + "url": "https://github.com/probe-rs/probe-rs/releases/download/v0.24.0/probe-rs-tools-x86_64-apple-darwin.tar.xz", + "sha256": "0e35cc92ff34af1b1c72dd444e6ddd57c039ed31c2987e37578864211e843cf1", + "strip_prefix": "probe-rs-tools-x86_64-apple-darwin", + "exec_compatible_with": [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], + }, + { + "name": "probe_rs_tools_aarch64_apple_darwin", + "url": "https://github.com/probe-rs/probe-rs/releases/download/v0.24.0/probe-rs-tools-aarch64-apple-darwin.tar.xz", + "sha256": "7140d9c2c61f8712ba15887f74df0cb40a7b16728ec86d5f45cc93fe96a0a29a", + "strip_prefix": "probe-rs-tools-aarch64-apple-darwin", + "exec_compatible_with": [ + "@platforms//os:macos", + "@platforms//cpu:arm64", + ], + }, + { + "name": "probe_rs_tools_x86_64_pc_windows_msvc", + "url": "https://github.com/probe-rs/probe-rs/releases/download/v0.24.0/probe-rs-tools-x86_64-pc-windows-msvc.zip", + "sha256": "d195dfa3466a87906251e27d6d70a0105274faa28ebf90ffadad0bdd89b1ec77", + "strip_prefix": "probe-rs-tools-x86_64-pc-windows-msvc", + "exec_compatible_with": [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], + }, + ], +}
diff --git a/probe_rs_tools/private/repositories.bzl b/probe_rs_tools/private/repositories.bzl new file mode 100644 index 0000000..e37b4b3 --- /dev/null +++ b/probe_rs_tools/private/repositories.bzl
@@ -0,0 +1,85 @@ +"""deps.bzl""" + +load(":archives.bzl", "PROBE_RS_TOOLS") + +def _probe_rs_tools_archive_repo_impl(repository_ctx): + """Defines a host-specific repository for the probe-rs tool.""" + bin_extension = ".exe" if "windows" in repository_ctx.name else "" + tools = [tool + bin_extension for tool in repository_ctx.attr.tools] + + repository_ctx.download_and_extract( + sha256 = repository_ctx.attr.sha256, + url = repository_ctx.attr.url, + stripPrefix = repository_ctx.attr.strip_prefix, + ) + + repository_ctx.template( + "BUILD.bazel", + Label(":templates/probe_rs_archive.BUILD.tpl"), + substitutions = { + "%tools%": "{}".format(tools), + }, + ) + + for patch in repository_ctx.attr.patches: + repository_ctx.patch(patch, strip = 1) + +probe_rs_tools_archive_repo = repository_rule( + implementation = _probe_rs_tools_archive_repo_impl, + attrs = { + "tools": attr.string_list(mandatory = True), + "sha256": attr.string(mandatory = True), + "url": attr.string(mandatory = True), + "strip_prefix": attr.string(), + "patches": attr.label_list(), + "exec_compatible_with": attr.string_list(), + }, +) + +def _probe_rs_impl(repository_ctx): + """Defines the probe-rs alias repository.""" + repository_ctx.template( + "BUILD", + Label(":templates/probe_rs.BUILD.tpl"), + substitutions = { + "%platforms%": "{}".format(repository_ctx.attr.platforms), + "%tools%": "{}".format(repository_ctx.attr.tools), + }, + ) + +probe_rs_repo = repository_rule( + implementation = _probe_rs_impl, + attrs = { + "platforms": attr.string_list_dict(mandatory = True), + "tools": attr.string_list(mandatory = True), + }, +) + +def probe_rs_tools_repositories(name, version, tools = ["probe-rs"], archives = PROBE_RS_TOOLS): + """Generate probe-rs repositories for the given version and tools. + + Args: + name: The name of the repository. + version: The version of the probe-rs tool to use. + tools: A list of tools to include in the repository. + archives: A dictionary of version to archive attributes. + """ + archive = archives.get(version) + + if not archive: + fail("Version {} not available in {}".format(version, archives.keys())) + + probe_rs_repo( + name = name, + tools = tools, + platforms = { + repo["name"]: repo["exec_compatible_with"] + for repo in archive + }, + ) + + for attrs in archive: + probe_rs_tools_archive_repo( + tools = tools, + **attrs + )
diff --git a/probe_rs_tools/private/resolved_toolchain.bzl b/probe_rs_tools/private/resolved_toolchain.bzl deleted file mode 100644 index 0613e32..0000000 --- a/probe_rs_tools/private/resolved_toolchain.bzl +++ /dev/null
@@ -1,26 +0,0 @@ -"""This module implements an alias rule to the resolved toolchain. -""" - -DOC = """\ -Exposes a concrete toolchain which is the result of Bazel resolving the -toolchain for the execution or target platform. -Workaround for https://github.com/bazelbuild/bazel/issues/14009 -""" - -# Forward all the providers -def _resolved_toolchain_impl(ctx): - toolchain_info = ctx.toolchains["//probe_rs_tools:toolchain_type"] - return [ - toolchain_info, - toolchain_info.default, - toolchain_info.probe_rs_toolsinfo, - toolchain_info.template_variables, - ] - -# Copied from java_toolchain_alias -# https://cs.opensource.google/bazel/bazel/+/master:tools/jdk/java_toolchain_alias.bzl -resolved_toolchain = rule( - implementation = _resolved_toolchain_impl, - toolchains = ["//probe_rs_tools:toolchain_type"], - doc = DOC, -)
diff --git a/probe_rs_tools/private/templates/probe_rs.BUILD.tpl b/probe_rs_tools/private/templates/probe_rs.BUILD.tpl new file mode 100644 index 0000000..fa17356 --- /dev/null +++ b/probe_rs_tools/private/templates/probe_rs.BUILD.tpl
@@ -0,0 +1,31 @@ +load("@bazel_skylib//rules:native_binary.bzl", "native_binary") + +package(default_visibility = ["//visibility:public"]) + +PLATFORMS = %platforms% +[ + config_setting( + name = platform, + constraint_values = constraint_values, + ) + for platform, constraint_values in PLATFORMS.items() +] + +TOOLS = %tools% +[ + native_binary( + name = tool, + src = select({ + platform: "@{}//:{}".format(platform, tool) + for platform in PLATFORMS.keys() + }), + out = tool, + target_compatible_with = select({ + platform: constraint_values + for platform, constraint_values in PLATFORMS.items() + } | { + "//conditions:default": ["@platforms//:incompatible"], + }), + ) + for tool in TOOLS +] \ No newline at end of file
diff --git a/probe_rs_tools/private/templates/probe_rs_archive.BUILD.tpl b/probe_rs_tools/private/templates/probe_rs_archive.BUILD.tpl new file mode 100644 index 0000000..974c1aa --- /dev/null +++ b/probe_rs_tools/private/templates/probe_rs_archive.BUILD.tpl
@@ -0,0 +1,5 @@ +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +exports_files(%tools%) \ No newline at end of file
diff --git a/probe_rs_tools/private/toolchains_repo.bzl b/probe_rs_tools/private/toolchains_repo.bzl deleted file mode 100644 index 04de4f7..0000000 --- a/probe_rs_tools/private/toolchains_repo.bzl +++ /dev/null
@@ -1,84 +0,0 @@ -"""Create a repository to hold the toolchains - -This follows guidance here: -https://docs.bazel.build/versions/main/skylark/deploying.html#registering-toolchains -" -Note that in order to resolve toolchains in the analysis phase -Bazel needs to analyze all toolchain targets that are registered. -Bazel will not need to analyze all targets referenced by toolchain.toolchain attribute. -If in order to register toolchains you need to perform complex computation in the repository, -consider splitting the repository with toolchain targets -from the repository with <LANG>_toolchain targets. -Former will be always fetched, -and the latter will only be fetched when user actually needs to build <LANG> code. -" -The "complex computation" in our case is simply downloading large artifacts. -This guidance tells us how to avoid that: we put the toolchain targets in the alias repository -with only the toolchain attribute pointing into the platform-specific repositories. -""" - -# Add more platforms as needed to mirror all the binaries -# published by the upstream project. -PLATFORMS = { - "x86_64-apple-darwin": struct( - compatible_with = [ - "@platforms//os:macos", - "@platforms//cpu:x86_64", - ], - ), - "aarch64-apple-darwin": struct( - compatible_with = [ - "@platforms//os:macos", - "@platforms//cpu:aarch64", - ], - ), - "x86_64-unknown-linux-gnu": struct( - compatible_with = [ - "@platforms//os:linux", - "@platforms//cpu:x86_64", - ], - ), - "x86_64-pc-windows-msvc": struct( - compatible_with = [ - "@platforms//os:windows", - "@platforms//cpu:x86_64", - ], - ), -} - -def _toolchains_repo_impl(repository_ctx): - build_content = """# Generated by toolchains_repo.bzl -# -# These can be registered in the workspace file or passed to --extra_toolchains flag. -# By default all these toolchains are registered by the probe_rs_tools_register_toolchains macro -# so you don't normally need to interact with these targets. - -""" - - for [platform, meta] in PLATFORMS.items(): - build_content += """ -# Declare a toolchain Bazel will select for running the tool in an action -# on the execution platform. -toolchain( - name = "{platform}_toolchain", - exec_compatible_with = {compatible_with}, - toolchain = "@{user_repository_name}_{platform}//:probe_rs_tools_toolchain", - toolchain_type = "@probe_rs_tools//probe_rs_tools:toolchain_type", -) -""".format( - platform = platform, - user_repository_name = repository_ctx.attr.user_repository_name, - compatible_with = meta.compatible_with, - ) - - # Base BUILD file for this repository - repository_ctx.file("BUILD.bazel", build_content) - -toolchains_repo = repository_rule( - _toolchains_repo_impl, - doc = """Creates a repository with toolchain definitions for all known platforms - which can be registered or selected.""", - attrs = { - "user_repository_name": attr.string(doc = "what the user chose for the base name"), - }, -)
diff --git a/probe_rs_tools/repositories.bzl b/probe_rs_tools/repositories.bzl deleted file mode 100644 index 7d28812..0000000 --- a/probe_rs_tools/repositories.bzl +++ /dev/null
@@ -1,99 +0,0 @@ -"""Declare runtime dependencies - -These are needed for local dev, and users must install them as well. -See https://docs.bazel.build/versions/main/skylark/deploying.html#dependencies -""" - -load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive") -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load("//probe_rs_tools/private:toolchains_repo.bzl", "PLATFORMS", "toolchains_repo") -load("//probe_rs_tools/private:versions.bzl", "TOOL_VERSIONS") - -def http_archive(name, **kwargs): - maybe(_http_archive, name = name, **kwargs) - -# WARNING: any changes in this function may be BREAKING CHANGES for users -# because we'll fetch a dependency which may be different from one that -# they were previously fetching later in their WORKSPACE setup, and now -# ours took precedence. Such breakages are challenging for users, so any -# changes in this function should be marked as BREAKING in the commit message -# and released only in semver majors. -# This is all fixed by bzlmod, so we just tolerate it for now. -def probe_rs_tools_dependencies(): - # The minimal version of bazel_skylib we require - http_archive( - name = "bazel_skylib", - sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f", - urls = [ - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", - ], - ) - -######## -# Remaining content of the file is only used to support toolchains. -######## -_DOC = "Fetch external tools needed for probe_rs_tools toolchain" -_ATTRS = { - "probe_rs_tools_version": attr.string(mandatory = True, values = TOOL_VERSIONS.keys()), - "platform": attr.string(mandatory = True, values = PLATFORMS.keys()), -} - -def _probe_rs_tools_repo_impl(repository_ctx): - url = "https://github.com/someorg/someproject/releases/download/v{0}/probe_rs_tools-{1}.zip".format( - repository_ctx.attr.probe_rs_tools_version, - repository_ctx.attr.platform, - ) - repository_ctx.download_and_extract( - url = url, - integrity = TOOL_VERSIONS[repository_ctx.attr.probe_rs_tools_version][repository_ctx.attr.platform], - ) - build_content = """# Generated by probe_rs_tools/repositories.bzl -load("@probe_rs_tools//probe_rs_tools:toolchain.bzl", "probe_rs_tools_toolchain") - -probe_rs_tools_toolchain( - name = "probe_rs_tools_toolchain", - target_tool = select({ - "@bazel_tools//src/conditions:host_windows": "probe_rs_tools_tool.exe", - "//conditions:default": "probe_rs_tools_tool", - }), -) -""" - - # Base BUILD file for this repository - repository_ctx.file("BUILD.bazel", build_content) - -probe_rs_tools_repositories = repository_rule( - _probe_rs_tools_repo_impl, - doc = _DOC, - attrs = _ATTRS, -) - -# Wrapper macro around everything above, this is the primary API -def probe_rs_tools_register_toolchains(name, register = True, **kwargs): - """Convenience macro for users which does typical setup. - - - create a repository for each built-in platform like "probe_rs_tools_linux_amd64" - - TODO: create a convenience repository for the host platform like "probe_rs_tools_host" - - create a repository exposing toolchains for each platform like "probe_rs_tools_platforms" - - register a toolchain pointing at each platform - Users can avoid this macro and do these steps themselves, if they want more control. - Args: - name: base name for all created repos, like "probe_rs_tools1_14" - register: whether to call through to native.register_toolchains. - Should be True for WORKSPACE users, but false when used under bzlmod extension - **kwargs: passed to each probe_rs_tools_repositories call - """ - for platform in PLATFORMS.keys(): - probe_rs_tools_repositories( - name = name + "_" + platform, - platform = platform, - **kwargs - ) - if register: - native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform)) - - toolchains_repo( - name = name + "_toolchains", - user_repository_name = name, - )
diff --git a/probe_rs_tools/toolchain.bzl b/probe_rs_tools/toolchain.bzl deleted file mode 100644 index 12e69c3..0000000 --- a/probe_rs_tools/toolchain.bzl +++ /dev/null
@@ -1,78 +0,0 @@ -"""This module implements the language-specific toolchain rule. -""" - -ProbeRsToolsInfo = provider( - doc = "Information about how to invoke the tool executable.", - fields = { - "target_tool_path": "Path to the tool executable for the target platform.", - "tool_files": """Files required in runfiles to make the tool executable available. - -May be empty if the target_tool_path points to a locally installed tool binary.""", - }, -) - -# Avoid using non-normalized paths (workspace/../other_workspace/path) -def _to_manifest_path(ctx, file): - if file.short_path.startswith("../"): - return "external/" + file.short_path[3:] - else: - return ctx.workspace_name + "/" + file.short_path - -def _probe_rs_tools_toolchain_impl(ctx): - if ctx.attr.target_tool and ctx.attr.target_tool_path: - fail("Can only set one of target_tool or target_tool_path but both were set.") - if not ctx.attr.target_tool and not ctx.attr.target_tool_path: - fail("Must set one of target_tool or target_tool_path.") - - tool_files = [] - target_tool_path = ctx.attr.target_tool_path - - if ctx.attr.target_tool: - tool_files = ctx.attr.target_tool.files.to_list() - target_tool_path = _to_manifest_path(ctx, tool_files[0]) - - # Make the $(tool_BIN) variable available in places like genrules. - # See https://docs.bazel.build/versions/main/be/make-variables.html#custom_variables - template_variables = platform_common.TemplateVariableInfo({ - "PROBE_RS_TOOLS_BIN": target_tool_path, - }) - default = DefaultInfo( - files = depset(tool_files), - runfiles = ctx.runfiles(files = tool_files), - ) - probe_rs_toolsinfo = ProbeRsToolsInfo( - target_tool_path = target_tool_path, - tool_files = tool_files, - ) - - # Export all the providers inside our ToolchainInfo - # so the resolved_toolchain rule can grab and re-export them. - toolchain_info = platform_common.ToolchainInfo( - probe_rs_toolsinfo = probe_rs_toolsinfo, - template_variables = template_variables, - default = default, - ) - return [ - default, - toolchain_info, - template_variables, - ] - -probe_rs_tools_toolchain = rule( - implementation = _probe_rs_tools_toolchain_impl, - attrs = { - "target_tool": attr.label( - doc = "A hermetically downloaded executable target for the target platform.", - mandatory = False, - allow_single_file = True, - ), - "target_tool_path": attr.string( - doc = "Path to an existing executable for the target platform.", - mandatory = False, - ), - }, - doc = """Defines a probe_rs_tools compiler/runtime toolchain. - -For usage see https://docs.bazel.build/versions/main/toolchains.html#defining-toolchains. -""", -)