run_make_support/external_deps/
rustdoc.rs
1use std::ffi::OsStr;
2use std::path::Path;
3
4use crate::command::Command;
5use crate::env::{env_var, env_var_os};
6use crate::util::set_host_rpath;
7
8#[track_caller]
10pub fn bare_rustdoc() -> Rustdoc {
11 Rustdoc::bare()
12}
13
14#[track_caller]
16pub fn rustdoc() -> Rustdoc {
17 Rustdoc::new()
18}
19
20#[derive(Debug)]
21#[must_use]
22pub struct Rustdoc {
23 cmd: Command,
24}
25
26crate::macros::impl_common_helpers!(Rustdoc);
27
28#[track_caller]
29fn setup_common() -> Command {
30 let rustdoc = env_var("RUSTDOC");
31 let mut cmd = Command::new(rustdoc);
32 set_host_rpath(&mut cmd);
33 cmd
34}
35
36impl Rustdoc {
37 #[track_caller]
39 pub fn bare() -> Self {
40 let cmd = setup_common();
41 Self { cmd }
42 }
43
44 #[track_caller]
46 pub fn new() -> Self {
47 let mut cmd = setup_common();
48 cmd.arg("-L").arg(env_var_os("TARGET_RPATH_DIR"));
49 Self { cmd }
50 }
51
52 pub fn extern_<P: AsRef<Path>>(&mut self, crate_name: &str, path: P) -> &mut Self {
54 assert!(
55 !crate_name.contains(|c: char| c.is_whitespace() || c == '\\' || c == '/'),
56 "crate name cannot contain whitespace or path separators"
57 );
58
59 let path = path.as_ref().to_string_lossy();
60
61 self.cmd.arg("--extern");
62 self.cmd.arg(format!("{crate_name}={path}"));
63
64 self
65 }
66
67 pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
69 self.cmd.arg(path.as_ref());
70 self
71 }
72
73 #[doc(alias = "output")]
75 pub fn out_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
76 self.cmd.arg("--out-dir").arg(path.as_ref());
77 self
78 }
79
80 pub fn arg_file<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
83 self.cmd.arg(format!("@{}", path.as_ref().display()));
84 self
85 }
86
87 pub fn stdin_buf<I: AsRef<[u8]>>(&mut self, input: I) -> &mut Self {
89 self.cmd.stdin_buf(input);
90 self
91 }
92
93 pub fn edition(&mut self, edition: &str) -> &mut Self {
95 self.cmd.arg("--edition");
96 self.cmd.arg(edition);
97 self
98 }
99
100 pub fn target<S: AsRef<str>>(&mut self, target: S) -> &mut Self {
102 let target = target.as_ref();
103 self.cmd.arg(format!("--target={target}"));
104 self
105 }
106
107 pub fn crate_type(&mut self, crate_type: &str) -> &mut Self {
109 self.cmd.arg("--crate-type");
110 self.cmd.arg(crate_type);
111 self
112 }
113
114 pub fn crate_name<S: AsRef<OsStr>>(&mut self, name: S) -> &mut Self {
116 self.cmd.arg("--crate-name");
117 self.cmd.arg(name.as_ref());
118 self
119 }
120
121 pub fn library_search_path<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
124 self.cmd.arg("-L");
125 self.cmd.arg(path.as_ref());
126 self
127 }
128
129 pub fn output_format(&mut self, format: &str) -> &mut Self {
131 self.cmd.arg("--output-format");
132 self.cmd.arg(format);
133 self
134 }
135}