diff --git a/WORKSPACE b/WORKSPACE index 34fa87395d..bf40fa27eb 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -506,3 +506,48 @@ http_archive( strip_prefix = "tinyusb-86c416d4c0fb38432460b3e11b08b9de76941bf5", url = "https://github.com/hathach/tinyusb/archive/86c416d4c0fb38432460b3e11b08b9de76941bf5.zip", ) + +# ---- probe-rs Paths ---- +# +# NOTE: These paths and sha-s have been manually copied from +# https://github.com/probe-rs/probe-rs/releases/tag/v0.24.0 + +http_archive( + name = "probe-rs-tools-x86_64-unknown-linux-gnu", + build_file = "@pigweed//third_party/probe-rs:probe-rs.BUILD.bazel", + sha256 = "21e8d7df39fa0cdc9a0421e0ac2ac5ba81ec295ea11306f26846089f6fe975c0", + strip_prefix = "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", +) + +http_archive( + name = "probe-rs-tools-aarch64-unknown-linux-gnu", + build_file = "@pigweed//third_party/probe-rs:probe-rs.BUILD.bazel", + sha256 = "95d91ebe08868d5119a698e3268ff60a4d71d72afa26ab207d43c807c729c90a", + strip_prefix = "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", +) + +http_archive( + name = "probe-rs-tools-x86_64-apple-darwin", + build_file = "@pigweed//third_party/probe-rs:probe-rs.BUILD.bazel", + sha256 = "0e35cc92ff34af1b1c72dd444e6ddd57c039ed31c2987e37578864211e843cf1", + strip_prefix = "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", +) + +http_archive( + name = "probe-rs-tools-aarch64-apple-darwin", + build_file = "@pigweed//third_party/probe-rs:probe-rs.BUILD.bazel", + sha256 = "7140d9c2c61f8712ba15887f74df0cb40a7b16728ec86d5f45cc93fe96a0a29a", + strip_prefix = "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", +) + +http_archive( + name = "probe-rs-tools-x86_64-pc-windows-msvc", + build_file = "@pigweed//third_party/probe-rs:probe-rs.BUILD.bazel", + sha256 = "d195dfa3466a87906251e27d6d70a0105274faa28ebf90ffadad0bdd89b1ec77", + strip_prefix = "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", +) diff --git a/third_party/probe-rs/BUILD.bazel b/third_party/probe-rs/BUILD.bazel new file mode 100644 index 0000000000..b4a07ea1ef --- /dev/null +++ b/third_party/probe-rs/BUILD.bazel @@ -0,0 +1,30 @@ +# Copyright 2024 The Pigweed Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +load("per_platform_alias.bzl", "per_platform_alias") + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +per_platform_alias( + name = "probe-rs", + platform_to_label = { + "aarch64-linux": "@probe-rs-tools-aarch64-unknown-linux-gnu//:probe-rs", + "aarch64-osx": "@probe-rs-tools-aarch64-apple-darwin//:probe-rs", + "x86_64-linux": "@probe-rs-tools-x86_64-unknown-linux-gnu//:probe-rs", + "x86_64-osx": "@probe-rs-tools-x86_64-apple-darwin//:probe-rs", + "x86_64-windows": "@probe-rs-tools-x86_64-pc-windows-msvc//:probe-rs", + }, +) diff --git a/third_party/probe-rs/per_platform_alias.bzl b/third_party/probe-rs/per_platform_alias.bzl new file mode 100644 index 0000000000..d3a5cc02a7 --- /dev/null +++ b/third_party/probe-rs/per_platform_alias.bzl @@ -0,0 +1,44 @@ +# Copyright 2024 The Pigweed Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +"""Defines the per_platform_alias rule.""" + +load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS") + +def _get_host_platform(): + """Return the - platform string (e.g. x86_64-linux).""" + + # HACK: HOST_CONSTRAINTS is a list containing the CPU constraint + # followed by the OS constraint. We use this to figure out the + # current CPU+OS pair. + if len(HOST_CONSTRAINTS) != 2: + fail("Unexpected HOST_CONSTRAINTS: " + HOST_CONSTRAINTS) + cpu_constraint, os_constraint = HOST_CONSTRAINTS + cpu = cpu_constraint.removeprefix("@platforms//cpu:") + os = os_constraint.removeprefix("@platforms//os:") + return cpu + "-" + os + +def per_platform_alias(name, platform_to_label): + """Aliases to a different target depending on platform. + + Args: + name: The name of the resulting target. + platform_to_label: A mapping from "-" platform string + (e.g. x86_64-linux") to label that you wish to alias. + """ + host_platform = _get_host_platform() + if not host_platform in platform_to_label: + fail("No alias provided for platform " + host_platform) + label = platform_to_label[host_platform] + native.alias(name = name, actual = label) diff --git a/third_party/probe-rs/probe-rs.BUILD.bazel b/third_party/probe-rs/probe-rs.BUILD.bazel new file mode 100644 index 0000000000..cc8ba386ef --- /dev/null +++ b/third_party/probe-rs/probe-rs.BUILD.bazel @@ -0,0 +1,23 @@ +# Copyright 2024 The Pigweed Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +""" +A build file for probe-rs releases which merely exports the probe-rs binary. +""" + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +exports_files(["probe-rs"])