-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't build docs for my crate (⇒ add ability to set environment variables?) #191
Comments
I would also like environment variables to be configurable. In the meantime, I worked around it as follows: In Cargo.toml [package.metadata.docs.rs]
rustc-args = ["--cfg", "<name>_docs_rs"]
rustdoc-args = ["--cfg", "<name>_docs_rs"] In build script: #[cfg(<name>_docs_rs)]
fn detect_version() -> String {
String::from("5.5")
}
#[cfg(not(<name>_docs_rs))]
fn detect_version() -> String {
// Use environment variables
} |
That's clever! But definitely kludgey :-) |
This is still a problem, and I don't think a general 'clean' work-around exists. My package bundles a file |
I think you should be able to set env vars in your |
Thank you, I tried with |
Is this a command you're calling in |
All right, the project is https://gitlab.com/glts/milter. It requires libmilter-dev (Debian/Ubuntu), and it bundles a milter.pc file. Then
Then doing exactly what the error message tells me, |
@glts the following patch makes the docker build succeed for me: diff --git a/build.rs b/build.rs
index 6f5ef92..1e5f22a 100644
--- a/build.rs
+++ b/build.rs
@@ -1,4 +1,5 @@
fn main() {
+ std::env::set_var("PKG_CONFIG_PATH", ".");
// Hack to make the build work on docs.rs, where PKG_CONFIG_PATH can’t be
// set. Remove once pkg-config file lands in distro.
if cfg!(milter_sys_docs_rs) { |
For everybody else on the issue: we now set |
@jyn514 All right, thank you for your help. (For me, it is still unfortunate [?] that I would have to hard-code the variable in |
Since we set |
Although it is possible to work around all these issues using the The reason this would be preferable is because we want to avoid special cases in our code for environments such as docs.rs, and solving it via configuration is a simple and declarative way to do this. |
I just uploaded a new crate, slurm-sys, which provides bindings to a C library called
libslurm
. However, my docs won't currently build on docs.rs (failure) because on Debian Jessie, the dev packages forlibslurm
don't include a pkg-config file, which mybuild.rs
expects to exist.If I could set environment variables in the docs.rs build environment, I could set
SLURM_NO_PKG_CONFIG
and I think everything would work; and I think this would be the appropriate thing for users to do when no pkg-config file is present. But as far as I can tell, it isn't possible to set this environment variable for the docs.rs build.Is that correct? Is there another workaround? It wouldn't be the most elegant, but if there were a way for my
build.rs
script to detect that it is running inside the docs.rs environment, I could add special-case code.The text was updated successfully, but these errors were encountered: