Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to probe-rs now that probe-run is deprecated #246

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ jobs:
~/.cargo/git/db/
.root/
target/
key: ${{ hashFiles('rust-toolchain.toml') }}-${{ hashFiles('**/Cargo.lock') }}
key: >-
${{ hashFiles('rust-toolchain.toml') }}-${{ hashFiles(
'**/Cargo.lock', 'scripts/wrapper.sh'
) }}
restore-keys: ${{ hashFiles('rust-toolchain.toml') }}
- run: ./scripts/setup.sh
- run: ./scripts/ci.sh
20 changes: 7 additions & 13 deletions book/src/applet/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,15 @@ runner with the following command:
cargo xtask applet rust tutorial runner nordic
```

You might need additional tooling to run (like `probe-rs`). Please open an
[issue](https://github.com/google/wasefire/issues/new) if you encounter any
problem. This documentation could be improved.

After a bunch of compilation steps, you should see something that ends like:

```plaintext
"probe-run" "--chip=nRF52840_xxAA" "target/thumbv7em-none-eabi/release/runner-nordic"
(HOST) INFO flashing program (36 pages / 144.00 KiB)
(HOST) INFO success!
────────────────────────────────────────────────────────────────────────────────
3 ticks @ (1/100) hello world
└─ api_helper::debug::println @ crates/api-helper/src/debug.rs:9
".../wrapper.sh" "probe-rs" "run" "--chip=nRF52840_xxAA" "target/.../runner-nordic"
Erasing sectors ✔ [00:00:05] [################################]
Programming pages ✔ [00:00:04] [################################]
0.090527: hello world
```

The first line is from `cargo xtask`. The rest is from `probe-run`. The last 2
lines are triggered by the applet. Debugging output is prefixed by a timestamp
(number of 10ms ticks) and followed on the next line by code location.
The first line is from `cargo xtask`. The rest is from `probe-rs run`. The last
line is triggered by the applet. Debugging output is prefixed by a timestamp in
seconds.
21 changes: 5 additions & 16 deletions crates/xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ struct RunnerOptions {
#[clap(long)]
log: Option<String>,

/// Enables probe-run --measure-stack flag.
#[clap(long)]
measure_stack: bool,

/// Measures bloat after building.
// TODO: Make this a subcommand taking additional options for cargo bloat.
#[clap(long)]
Expand Down Expand Up @@ -538,19 +534,12 @@ impl RunnerOptions {
println!("JLinkGDBServer -device {chip} -if swd -speed 4000 -port 2331");
println!("gdb-multiarch -ex 'file {elf}' -ex 'target remote localhost:2331'");
}
let mut probe_run = wrap_command()?;
// TODO(https://crates.io/crates/probe-run > 0.3.10): Use a simpler flag (or no flag).
probe_run.args(["probe-run", "--log-format={t} {L} {s}\n└─ {m} @ {F}:{l}"]);
probe_run.arg(format!("--chip={chip}"));
if main.release {
probe_run.arg("--backtrace=never");
}
if self.measure_stack {
probe_run.arg("--measure-stack");
}
probe_run.arg(elf);
let mut probe_rs = wrap_command()?;
probe_rs.args(["probe-rs", "run"]);
probe_rs.arg(format!("--chip={chip}"));
probe_rs.arg(elf);
println!("Add --no-flash to the following command to rerun:");
replace_command(probe_run);
replace_command(probe_rs);
}

fn target(&self) -> &'static str {
Expand Down
30 changes: 19 additions & 11 deletions scripts/wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,25 @@ run() {
}

ensure_cargo() {
local g
local c
if [ $# -eq 4 ]; then
g=" ($3?rev=$4#.\{8\})"
c="--git=$3 --rev=$4"
local git_url
local git_commit
case "$1" in
# TODO(https://crates.io/crates/taplo-cli > 0.8.1): Remove.
taplo-cli)
git_url=https://github.com/tamasfe/taplo.git
git_commit=191852c018d142b99cd8f7b4987456a447b3afb7
;;
esac
local flags="$1@$2"
if [ -n "$git_url" ]; then
flags="$flags --git=$git_url --rev=$git_commit"
grep=" ($git_url?rev=$git_commit#.\{8\})"
fi
if ! cargo install --list --root="$CARGO_ROOT" | grep -q "^$1 v$2$g:\$"; then
if ! cargo install --list --root="$CARGO_ROOT" | grep -q "^$1 v$2$grep:\$"
then
[ "$1" = cargo-edit ] && ensure lib openssl
x cargo install --locked --root="$CARGO_ROOT" "$1@$2" $c
shift 2
x cargo install --locked --root="$CARGO_ROOT" $flags "$@"
fi
}

Expand All @@ -57,11 +67,9 @@ case "$1" in
esac
;;
mdbook) ensure_cargo mdbook 0.4.34 ;;
probe-run) ensure_cargo probe-run 0.3.10 ;;
probe-rs) ensure_cargo probe-rs 0.21.0 --features=cli ;;
rust-size) ensure_cargo cargo-binutils 0.3.6 ;;
taplo) ensure_cargo taplo-cli 0.8.1 \
https://github.com/tamasfe/taplo.git \
191852c018d142b99cd8f7b4987456a447b3afb7 ;;
taplo) ensure_cargo taplo-cli 0.8.1 ;;
twiggy) ensure_cargo twiggy 0.7.0 ;;
*) IS_CARGO=n ;;
esac
Expand Down