matklad / cargo-xtask

840 stars 23 forks source link

Is `xtask` compatible with `no_std`/cross-compilation target projects? #24

Closed U007D closed 1 year ago

U007D commented 1 year ago

I am building a (cross-compiled) RISC-V no_std project using cargo build on x86_64. It uses a .cargo/Config.toml in the crate root to specify a linker script (memory.lds) and to set the compilation target:

[build]
target = "riscv64gc-unknown-none-elf"

[target.riscv64gc-unknown-none-elf]
linker = "rust-lld"
runner = "riscv64-unknown-elf-gdb --command=gdb-runner.gdbs"
rustflags = ["-C", "link-arg=-Tmemory.lds"]

When I add xtask to this project (converting the project to a workspace), cargo attempts to build xtask as a RISC-V target. When I move the above .cargo/Config.toml out of the workspace root to the application root, cargo "forgets" (appears to ignore .cargo/Config.toml not in workspace root) to build my app as a RISC-V application, instead simply building it as a native application for my host CPU.

Is xtask compatible with no_std/foreign target projects?

matklad commented 1 year ago

If you are on nightly, you can use

https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#per-package-target

to move target from config.toml to cargo.toml.

Would

[alias]
xtask = "run --package xtask --target your-host-target --"

work?

U007D commented 1 year ago

Thanks, @matklad. I looked into this feature earlier this week (I'd tried it but found it did not appear to be working for me). I will need to specify cross-compilation targets with as anxtask build command parameter, so neither the .cargo/config.toml nor the per-package-target features will work for me. I'll pass the target information on the command line with my xtask build implementation.

Great project! This is something I was after years ago but this is much better thought out than what I had in mind. Thanks again!