'pre-hook' on cargo test?

#1

Short Question: Is there a way to add a shell command that gets executed before every invocation of “cargo tests”.

I do NOT want it to be invoked before every unit tests.
I want it to be invoked once before every “cargo test” command.

Long Version:
I have a Makefile which compiles a bunch of cuda files to ptx. Right now, my work flow is:

  1. edit some *.cu; 2. run make, 3. run rust unit test

Sometimes I forget 2. I would like it so that before every “cargo test” command, a pre-hook is executed to re-run the makefile.

Pre-Emptive Questions:

Why not just make a command lien shortcut?

Cargo test is being called via IntelliJ.

Rust Command specify cwd
#2

You can set an environment variable like CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER which will wrap all target commands, including tests. You could write a script here which does your setup, and then run the command it gave you as arguments.

1 Like
#3

Swap to fully use make, add a .PHONY: test and then write a test target that depends on building your visa stuff and then runs the tests.

#4

You can tell cargo to rebuild your project when *.cu files are changed using rerun-if-changed (see here). Then, you can execute make from the build script.

2 Likes
#5

@Riateche : I like this approach. I almost have it working: Rust Comamnd specify cwd

How do I tell Command how to set the cwd? (The makefile is not in crate-root/Makefile, but it is located in crate-root/cu/Makefile).