-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |