QuxxyHis Holy Macroness•

I recently wrote the build-helper crate to help with this. It basically just defines functions to read the stuff Cargo exposes to build scripts, and to emit the information Cargo will read back.

24
CUVipernum · fedora•

Funny, I was just recently thinking of doing the same thing. Glad I learned of yours first!

2
ekse•

Thanks for that! I'm going to use it for my unicorn crate.

1
IshKebab•

Also I wish there was a standard way to say you want to link with C libraries statically. As it is you have to read the build script, and hope there is an environment variable that isn't ignored on Linux or whatever.

5
simukisOP•

Printing a cargo:rustc-link-lib=static=something will find and link libsomething.a in.

1
retep998rust · winapi · bunny•

Note that static has rather undesirable behavior. Specifically when you're building an rlib, rustc will be responsible for finding the library instead of the linker (thereby completely ignoring all the paths that the linker would search in), as well as bundling the static library into the rlib which will sometimes break things (most notably msvc libraries compiled with /GL but it affects other platforms too).

I highly recommend using the newer static-nobundle instead, either immediately if you use nightly, or as soon as it stabilizes otherwise. https://github.com/rust-lang/rust/pull/38426

2
IshKebab•

Yeah but if it's in a dependency I have to work out what magic I need to do so that their build.rs script prints that. There's no standard way to do it.

1