run_make_support/external_deps/
rustdoc.rsuse std::ffi::OsStr;
use std::path::Path;
use crate::command::Command;
use crate::env::{env_var, env_var_os};
use crate::util::set_host_rpath;
#[track_caller]
pub fn bare_rustdoc() -> Rustdoc {
Rustdoc::bare()
}
#[track_caller]
pub fn rustdoc() -> Rustdoc {
Rustdoc::new()
}
#[derive(Debug)]
#[must_use]
pub struct Rustdoc {
cmd: Command,
}
crate::macros::impl_common_helpers!(Rustdoc);
#[track_caller]
fn setup_common() -> Command {
let rustdoc = env_var("RUSTDOC");
let mut cmd = Command::new(rustdoc);
set_host_rpath(&mut cmd);
cmd
}
impl Rustdoc {
#[track_caller]
pub fn bare() -> Self {
let cmd = setup_common();
Self { cmd }
}
#[track_caller]
pub fn new() -> Self {
let mut cmd = setup_common();
let target_rpath_dir = env_var_os("TARGET_RPATH_DIR");
cmd.arg(format!("-L{}", target_rpath_dir.to_string_lossy()));
Self { cmd }
}
pub fn extern_<P: AsRef<Path>>(&mut self, crate_name: &str, path: P) -> &mut Self {
assert!(
!crate_name.contains(|c: char| c.is_whitespace() || c == '\\' || c == '/'),
"crate name cannot contain whitespace or path separators"
);
let path = path.as_ref().to_string_lossy();
self.cmd.arg("--extern");
self.cmd.arg(format!("{crate_name}={path}"));
self
}
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg(path.as_ref());
self
}
#[doc(alias = "output")]
pub fn out_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg("--out-dir").arg(path.as_ref());
self
}
pub fn arg_file<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg(format!("@{}", path.as_ref().display()));
self
}
pub fn stdin_buf<I: AsRef<[u8]>>(&mut self, input: I) -> &mut Self {
self.cmd.stdin_buf(input);
self
}
pub fn edition(&mut self, edition: &str) -> &mut Self {
self.cmd.arg("--edition");
self.cmd.arg(edition);
self
}
pub fn target<S: AsRef<str>>(&mut self, target: S) -> &mut Self {
let target = target.as_ref();
self.cmd.arg(format!("--target={target}"));
self
}
pub fn crate_type(&mut self, crate_type: &str) -> &mut Self {
self.cmd.arg("--crate-type");
self.cmd.arg(crate_type);
self
}
pub fn crate_name<S: AsRef<OsStr>>(&mut self, name: S) -> &mut Self {
self.cmd.arg("--crate-name");
self.cmd.arg(name.as_ref());
self
}
pub fn library_search_path<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg("-L");
self.cmd.arg(path.as_ref());
self
}
pub fn output_format(&mut self, format: &str) -> &mut Self {
self.cmd.arg("--output-format");
self.cmd.arg(format);
self
}
}