Skip to content

Commit

Permalink
Add teleprobe-meta
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Sep 2, 2023
1 parent 3d964b2 commit 4923183
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 0 deletions.
7 changes: 7 additions & 0 deletions teleprobe-meta/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions teleprobe-meta/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "teleprobe-meta"
version = "1.1.0"
edition = "2021"
description = "Embed teleprobe metadata into ELF binaries"
repository = "https://github.com/embassy-rs/teleprobe"
license = "MIT OR Apache-2.0"
categories = [
"embedded",
"no-std",
]

[dependencies]
42 changes: 42 additions & 0 deletions teleprobe-meta/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# teleprobe-meta

This crate allows embedding metadata into ELF binaries so that [teleprobe](https://github.com/embassy-rs/teleprobe)
can autodetect it. This way you can run the tests by simply doing `teleprobe client run <ELF>`, without
adding any extra flags.

## Usage

First, include the `teleprobe.x` linker script. Either via `build.rs` (recommended)

```rust
println!("cargo:rustc-link-arg-bins=-Tteleprobe.x");
```

or in `.cargo/config.toml` (older way, not recommended)

```toml
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
rustflags = [
"-C", "link-arg=-Tteleprobe.x",
]
```

Then, you can specify metadata, for example:

```rust
teleprobe_meta::target!(b"rpi-pico");
```

## Minimum supported Rust version (MSRV)

`teleprobe-meta` is guaranteed to compile on the latest stable Rust version at the time of release. It might compile with older versions but that may change in any new patch release.

## License

This work is licensed under either of

- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
<http://www.apache.org/licenses/LICENSE-2.0>)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)

at your option.
8 changes: 8 additions & 0 deletions teleprobe-meta/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::path::PathBuf;
use std::{env, fs};

fn main() {
let out = PathBuf::from(env::var("OUT_DIR").unwrap());
fs::write(out.join("teleprobe.x"), include_bytes!("teleprobe.x")).unwrap();
println!("cargo:rustc-link-search={}", out.display());
}
35 changes: 35 additions & 0 deletions teleprobe-meta/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#![no_std]
#![doc = include_str!("../README.md")]
#![warn(missing_docs)]

/// Set the teleprobe target.
///
/// ```rust
/// teleprobe_meta::target!(b"rpi-pico");
/// ```
///
/// Note that you MUST use binary strings `b""`. Regular strings `""` will not work.
#[macro_export]
macro_rules! target {
($val:literal) => {
#[link_section = ".teleprobe.target"]
#[used]
#[no_mangle] // prevent invoking the macro multiple times
static _TELEPROBE_TARGET: [u8; $val.len()] = *$val;
};
}

/// Set the teleprobe timeout, in seconds.
///
/// ```rust
/// teleprobe_meta::timeout!(60);
/// ```
#[macro_export]
macro_rules! timeout {
($val:literal) => {
#[link_section = ".teleprobe.timeout"]
#[used]
#[no_mangle] // prevent invoking the macro multiple times
static _TELEPROBE_TIMEOUT: u32 = $val;
};
}
11 changes: 11 additions & 0 deletions teleprobe-meta/teleprobe.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SECTIONS
{
.teleprobe.target (INFO) :
{
KEEP(*(.teleprobe.target));
}
.teleprobe.timeout (INFO) :
{
KEEP(*(.teleprobe.timeout));
}
}

0 comments on commit 4923183

Please sign in to comment.