Post-processing of compiled binaries

How can I run additional on a binary created from building? I need to run a few commands to convert the ELF binary to a specific format for my no_std target. Currently, I'm using cargo-make with a hacky Makefile.toml to run the commands. However, this isn't great, and has a lot of boilerplate between projects. I'm thinking that creating a new cargo subcommand would be the best way to do this. Are there any examples I can check out? I tried to write my own before, but I ran into troubles with workspaces, which I'd like to support.

Unfortunately Cargo can't do it, and currently external build systems are recommended for this.

Yeah, that's what I was thinking. What build systems are good for this that work well with workspaces? cargo-make does weird stuff with workspaces (you need a main Makefile.toml in the root directory), and I'd like to switch to something else. As this will be required for all projects using my target, not just one project, is it worth creating a cargo subcommand to do this? And if so, are there similar projects? Or is just or another build system a better option?

This may or may not be less hacky, depending on how you look at it: https://github.com/matklad/cargo-xtask

I like the cargo-xtask pattern because it doesn't require installing another package or tool. YMMV. :slight_smile:

you don't need a makefile.toml in your workspace root with cargo-make.
you can put it there only if you want to share common setups/tasks with member crates or write custom tasks for workspace directory. otherwise, remove it.

as for

cargo-make does weird stuff with workspaces

any additional info would be helpful. but feel free to open an issue in cargo-make repo directly.

FWIW I had the same challenge when targeting Nintendo 64, so I wrote a cargo subcommand: cargo-n64.

When I run a command in the root of the workspace, I get:

❱ cargo make dev                                           
[cargo-make] INFO - cargo make 0.30.6
[cargo-make] INFO - External file not found or is not a file, skipping.
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: dev
[cargo-make] INFO - Profile: development
[cargo-make] ERROR - Task not found: dev
[cargo-make] WARN - Build Failed.

I need to add a Makefile.toml to the root of the directory with the tasks that I want to be able to run directly:

[tasks.dev]
[tasks.release]

This looks like it is the opposite solution, where the root Makefile.toml takes the place of individual files within each crate within the workspace, but I don't like that it's harder to break apart these demos if one wanted.

I'm running the latest version, cargo-make 0.30.6, but this problem has been around for a year. I can't believe that this error is unintentional, as this seems like such a simple problem to encounter.

That's a great starting point—parsing the last JSON message was the step that I was mssing, I was trying to use cargo_metadata, which you reimplemented with Serde, but instead just parsing the output of cargo metadata. Parsing the last line though was the last thing I was missing. I'll have to do something to handle workspaces, but thanks for providing that.

1 Like

sounds like a bug :slight_smile: will fix it.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.