How to temporarily modify code of C sub-dependency built via cargo


#1

A unit test in my application exposes a bug in the C library it indirectly depends on, and I can’t reproduce the bug without my application, so I need to edit the C code while running Rust app’s tests.

I have:

A C library built with autotools » wrapped in rust-sys package (that clones the source from git to cargo’s OUT_DIR) » wrapped in higher-level Rust package » used by my application.

The usual way I use is to push code to git repository of the C code, and then bump version of all the packages along the way, but that’s way to much to do for every single line tweaked.

Ideally I’d like to modify cloned copy of the C code that sits in my app’s target directory, but I don’t know how to make Cargo notice it has changed and rebuild it (I can’t delete whole target dir, because that’s where the cloned C code is).

I found I can delete target/debug/build/*/build-script-build to make cargo say it’s compiling it, but I don’t think it really is. Cargo is a black box that hides all its build output, so I don’t know if it’s really rebuilding, or just relinking something cached.

How can I make Cargo completely rebuild (starting with re-running build.rs) a dependency of my apps’ dependency, but without deleting target/debug/build/*/out/? (or maybe there’s a better way to edit the C code quickly)


#2

cargo --verbose logs all the invocations of the compiler.


#3

Hm, I think that you can use override to override rust-sys package dependency to some locally cloned directory. So then the problem reduces to

A C library built with autotools » wrapped in rust-sys package (that clones the source from git to cargo’s OUT_DIR) http://doc.crates.io/specifying-dependencies.html#overriding-dependencies

And here you can tweak build.rs such that it does not clone, but instead uses local copy of C code.

EDIT: bad link for override, here is a better one


#4

That prints only the rust compiler invocations. I’m running C compiler via build.rs (that runs a makefile), and cargo silences that even in verbose mode :frowning:


#5

Overrides look very promising. Thanks for the tip!


#6

Sounds like a bug, perhaps you can report it? Looks like something that I’ll be able to fix :wink:


#7

I’ve found it’s been fixed recently! https://github.com/rust-lang/cargo/pull/2630 (I needed to switch from beta to nightly). So now I can see what the makefile is doing.