Skip to content

Commit fd4d7a0

Browse files
committed
Bring back rustc-args
But instead of passing it to cargo with ops::CompileOptions, crate RUSTFLAGS environment variable.
1 parent d1103b3 commit fd4d7a0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/docbuilder/metadata.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use error::Result;
2121
/// all-features = true
2222
/// no-default-features = true
2323
/// default-target = "x86_64-unknown-linux-gnu"
24+
/// rustc-args = [ "--example-rustc-arg" ]
2425
/// rustdoc-args = [ "--example-rustdoc-arg" ]
2526
/// dependencies = [ "example-system-dependency" ]
2627
/// ```
@@ -44,6 +45,9 @@ pub struct Metadata {
4445
/// is always built on this target. You can change default target by setting this.
4546
pub default_target: Option<String>,
4647

48+
/// List of command line arguments for `rustc`.
49+
pub rustc_args: Option<Vec<String>>,
50+
4751
/// List of command line arguments for `rustdoc`.
4852
pub rustdoc_args: Option<Vec<String>>,
4953

@@ -89,6 +93,7 @@ impl Metadata {
8993
all_features: false,
9094
no_default_features: false,
9195
default_target: None,
96+
rustc_args: None,
9297
rustdoc_args: None,
9398
dependencies: None,
9499
}
@@ -115,6 +120,8 @@ impl Metadata {
115120
.and_then(|v| v.as_bool()).unwrap_or(metadata.all_features);
116121
metadata.default_target = table.get("default-target")
117122
.and_then(|v| v.as_str()).map(|v| v.to_owned());
123+
metadata.rustc_args = table.get("rustc-args").and_then(|f| f.as_array())
124+
.and_then(|f| f.iter().map(|v| v.as_str().map(|v| v.to_owned())).collect());
118125
metadata.rustdoc_args = table.get("rustdoc-args").and_then(|f| f.as_array())
119126
.and_then(|f| f.iter().map(|v| v.as_str().map(|v| v.to_owned())).collect());
120127
metadata.dependencies = table.get("dependencies").and_then(|f| f.as_array())
@@ -164,6 +171,10 @@ mod test {
164171

165172
assert_eq!(metadata.default_target.unwrap(), "x86_64-unknown-linux-gnu".to_owned());
166173

174+
let rustc_args = metadata.rustc_args.unwrap();
175+
assert_eq!(rustc_args.len(), 1);
176+
assert_eq!(rustc_args[0], "--example-rustc-arg".to_owned());
177+
167178
let rustdoc_args = metadata.rustdoc_args.unwrap();
168179
assert_eq!(rustdoc_args.len(), 1);
169180
assert_eq!(rustdoc_args[0], "--example-rustdoc-arg".to_owned());

src/utils/build_doc.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ pub fn build_doc(name: &str, vers: Option<&str>, target: Option<&str>) -> CargoR
4646

4747
let metadata = Metadata::from_package(&pkg).map_err(|e| human(e.description()))?;
4848

49+
// This is only way to pass rustc_args to cargo.
50+
// CompileOptions::target_rustc_args is used only for the current crate,
51+
// and since docs.rs never runs rustc on the current crate, we assume rustc_args
52+
// will be used for the dependencies. That is why we are creating RUSTFLAGS environment
53+
// variable instead of using target_rustc_args.
54+
if let Some(rustc_args) = metadata.rustc_args {
55+
env::set_var("RUSTFLAGS", rustc_args.join(" "));
56+
}
57+
4958
let opts = ops::CompileOptions {
5059
config: &config,
5160
jobs: None,

0 commit comments

Comments
 (0)