Skip to content

Commit d1043c9

Browse files
committed
Work around rustdoc bugs for proc-macros
Use documentation in /target/doc if /target/$target/doc doesn't exist. Partially addresses rust-lang#422. Note: this does _not_ fix the issue mentioned above, it doesn't link to the right CSS files. See https://cdn.discordapp.com/attachments/541978667522195476/649031211913838592/unknown.png for an example.
1 parent a6e6aa9 commit d1043c9

File tree

1 file changed

+50
-37
lines changed

1 file changed

+50
-37
lines changed

src/docbuilder/rustwide_builder.rs

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl RustwideBuilder {
267267
.build(&self.toolchain, &krate, sandbox)
268268
.run(|build| {
269269
let mut files_list = None;
270-
let mut has_docs = false;
270+
let (mut has_docs, mut in_target) = (false, false);
271271
let mut successful_targets = Vec::new();
272272

273273
// Do an initial build and then copy the sources in the database
@@ -281,54 +281,43 @@ impl RustwideBuilder {
281281
build.host_source_dir(),
282282
)?);
283283

284-
has_docs = res
285-
.cargo_metadata
286-
.root()
287-
.library_name()
288-
.map(|name| {
289-
build
290-
.host_target_dir()
291-
.join(&res.target)
292-
.join("doc")
293-
.join(name)
294-
.is_dir()
295-
})
296-
.unwrap_or(false);
284+
if let Some(name) = res
285+
.cargo_metadata
286+
.root()
287+
.library_name() {
288+
let host_target = build.host_target_dir();
289+
if host_target.join(&res.target)
290+
.join("doc")
291+
.join(&name)
292+
.is_dir() {
293+
has_docs = true;
294+
in_target = true;
295+
// hack for proc-macro documentation:
296+
// it really should be in target/$target/doc,
297+
// but rustdoc has a bug and puts it in target/doc
298+
} else if host_target.join("doc").join(name).is_dir() {
299+
has_docs = true;
300+
}
301+
}
297302
}
298303

299304
if has_docs {
300305
debug!("adding documentation for the default target to the database");
301306
self.copy_docs(
302307
&build.host_target_dir(),
303308
local_storage.path(),
304-
&res.target,
309+
if in_target { &res.target } else { "" },
305310
true,
306311
)?;
312+
successful_targets.push(DEFAULT_TARGET.to_string());
307313

308-
// Then build the documentation for all the targets
309-
for target in TARGETS {
310-
debug!("building package {} {} for {}", name, version, target);
311-
let target_res = self.execute_build(Some(target), &build, &limits)?;
312-
if target_res.successful {
313-
// Cargo is not giving any error and not generating documentation of some crates
314-
// when we use a target compile options. Check documentation exists before
315-
// adding target to successfully_targets.
316-
if build.host_target_dir().join(target).join("doc").is_dir() {
317-
debug!(
318-
"adding documentation for target {} to the database",
319-
target
320-
);
321-
self.copy_docs(
322-
&build.host_target_dir(),
323-
local_storage.path(),
324-
target,
325-
false,
326-
)?;
327-
successful_targets.push(target.to_string());
328-
}
314+
if in_target {
315+
// Then build the documentation for all the targets
316+
for target in TARGETS {
317+
debug!("building package {} {} for {}", name, version, target);
318+
self.build_target(target, &build, &limits, &local_storage.path(), &mut successful_targets)?;
329319
}
330320
}
331-
332321
self.upload_docs(&conn, name, version, local_storage.path())?;
333322
}
334323

@@ -362,6 +351,30 @@ impl RustwideBuilder {
362351
Ok(res.successful)
363352
}
364353

354+
fn build_target(&self, target: &str, build: &Build, limits: &Limits,
355+
local_storage: &Path, successful_targets: &mut Vec<String>) -> Result<()> {
356+
let target_res = self.execute_build(Some(target), build, limits)?;
357+
if target_res.successful {
358+
// Cargo is not giving any error and not generating documentation of some crates
359+
// when we use a target compile options. Check documentation exists before
360+
// adding target to successfully_targets.
361+
if build.host_target_dir().join(target).join("doc").is_dir() {
362+
debug!(
363+
"adding documentation for target {} to the database",
364+
target,
365+
);
366+
self.copy_docs(
367+
&build.host_target_dir(),
368+
local_storage,
369+
target,
370+
false,
371+
)?;
372+
successful_targets.push(target.to_string());
373+
}
374+
}
375+
Ok(())
376+
}
377+
365378
fn execute_build(
366379
&self,
367380
target: Option<&str>,

0 commit comments

Comments
 (0)