Is there a way to detect rustdoc from the build script?

I'd like to know whether it is currently possible to know from the build script which is the cargo command that triggered it, cargo doc vs cargo build for example.

It would be very useful for when there are some costly compilations that are only needed for the documentation.

I haven't tried it, but try checking whether the CARGO_CFG_DOC environment variable is set.

Thanks. I've just tried it but the variable is never set.

In fact the only result in google for CARGO_CFG_DOC is this thread. So it does seems that in fact is not possible yet.

I'm working on a workaround for my self, by employing features. I'll share here when it's working, in case it helps anybody else.

Since it is indeed possible to set the feature of a dependency, thankfully I've been able to solve this use case by using the combination of two features. For the curious

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.