Search code examples
rustcompilationrust-cargo

How to get Cargo to use my custom runner?


I'm trying to specify a custom runner for cargo, but it just refuses to use it. I've tried using both my own custom target triple after target. and I've tried using the cfg option you see below:

[target.'cfg(all(target_os = "none"))']
runner = "qemu-system-riscv64 -machine virt -kernel "

but in both cases, it says I have an unused manifest key when compiling:

warning: unused manifest key: target.cfg(all(target_os = "none")).runner

When using the cargo run it always just runs the normal binary instead of my custom runner.

My case is special as I'm using the config.toml file under the .cargo folder to specify my custom target triple:

[unstable]
build-std-features = ["compiler-builtins-mem"]
build-std = ["core", "compiler_builtins"]

[build]
target = "compilation_targets/riscv-unknown-kadrix.json"

Since this is a kernel there are some over special things about it:

  • Doesn't use the standard library
  • Doesn't use a main function, its entry point is _start
  • Uses a custom .start section for the _start function instead of .text
  • Uses a custom test framework

Not sure if any of those bullet points are relevant but better safe than sorry. The code is here if you want to inspect further.


Solution

  • The [target.'cfg'] runner = needs to be in .cargo/config.toml and not Cargo.toml.