Skip to content

Commit

Permalink
third_party: Add probe-rs
Browse files Browse the repository at this point in the history
This change adds a platform-independent //third-party:probe-rs
executable target in order to allow flashing utilities to make
use of prebuilt probe-rs binaries.

Change-Id: Ia23a59610b99dc33abb7722c0eae80c1d1f86c63
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/213693
Lint: Lint 🤖 <[email protected]>
Commit-Queue: Taylor Cramer <[email protected]>
Reviewed-by: Ted Pudlik <[email protected]>
  • Loading branch information
cramertj authored and CQ Bot Account committed Jun 4, 2024
1 parent ad07970 commit 0f2537e
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
45 changes: 45 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
30 changes: 30 additions & 0 deletions third_party/probe-rs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
},
)
44 changes: 44 additions & 0 deletions third_party/probe-rs/per_platform_alias.bzl
Original file line number Diff line number Diff line change
@@ -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 <cpu>-<os> 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 "<cpu>-<os>" 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)
23 changes: 23 additions & 0 deletions third_party/probe-rs/probe-rs.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"])

0 comments on commit 0f2537e

Please sign in to comment.