Build a C test using gcc?

Hi,

I want to build a Rust library that exposes a C API, and then write some tests in C for that API. Ideally cargo test would build and run those tests.

It looks like the gcc crate is only for building C libraries that are linked into Rust programs. I guess I could have a Rust program that links in a C library that links in a Rust library. Then the top-level Rust program would just call one function in the C library, to run all the tests.

Is there some simpler way?

Yeah, I think cargo test is just for testing Rust code. Your work-around sounds like it might work.

I personally just avoided that and wrote a simple compile script and a test runner in C and then hooked it up to travis. It's definitely not as convenient as just running cargo test though. :frowning:

2 Likes

Hm, gcc complains about an undefined symbol that should be coming from my Rust library, but I can't see a way to tell it to link that in, and I'm not sure if it's a good idea...

Just hardcoding a gcc command as you did might be simplest.

ETA: I ended up adding a makefile in a subdirectory similar to yours,. And, an integration test that runs make, so cargo test does the whole job.