I have some code that uses the
nix crate and I need to use the
nix::sys::stat::utimensat function provided by it. This function is just a wrapper over the
Now the problem is that not all systems implement the
utimensat system call. In particular, macOS 10.13 does not, and I have to support this system (because that's what I get on Travis CI when I have to use OSXFUSE). When building on those systems, my code fails at link time with an
undefined symbol error: https://travis-ci.org/jmmv/sandboxfs/jobs/647291509
So I'd like my code to conditionally use
utimensat if I know is present or fall back to
utimes if not.
My first instinct was to go for
#[cfg] and check for the OS name... but then found out that there is no way to check the version (right?). Regardless, even if this were possible, it'd still be a suboptimal way of going about this because I'd rather not make assumptions about what features are present based on the OS name+version pair.
So in the C world, I'd just write an
autoconf check to test for the presence of
utimensat and then make my code conditional on that. How can I do something similar in Rust? I can imagine some
build.rs magic? Is there a better way?