]> git.proxmox.com Git - rustc.git/blame - src/tools/cargo/tests/testsuite/multitarget.rs
New upstream version 1.75.0+dfsg1
[rustc.git] / src / tools / cargo / tests / testsuite / multitarget.rs
CommitLineData
0a29b90c
FG
1//! Tests for multiple `--target` flags to subcommands
2
3use cargo_test_support::{basic_manifest, cross_compile, project, rustc_host};
4
5#[cargo_test]
6fn simple_build() {
7 if cross_compile::disabled() {
8 return;
9 }
10 let t1 = cross_compile::alternate();
11 let t2 = rustc_host();
12 let p = project()
13 .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
14 .file("src/main.rs", "fn main() {}")
15 .build();
16
17 p.cargo("build")
18 .arg("--target")
19 .arg(&t1)
20 .arg("--target")
21 .arg(&t2)
22 .run();
23
24 assert!(p.target_bin(t1, "foo").is_file());
25 assert!(p.target_bin(t2, "foo").is_file());
26}
27
28#[cargo_test]
29fn simple_build_with_config() {
30 if cross_compile::disabled() {
31 return;
32 }
33 let t1 = cross_compile::alternate();
34 let t2 = rustc_host();
35 let p = project()
36 .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
37 .file("src/main.rs", "fn main() {}")
38 .file(
39 ".cargo/config.toml",
40 &format!(
41 r#"
42 [build]
43 target = ["{t1}", "{t2}"]
44 "#
45 ),
46 )
47 .build();
48
49 p.cargo("build").run();
50
51 assert!(p.target_bin(t1, "foo").is_file());
52 assert!(p.target_bin(t2, "foo").is_file());
53}
54
55#[cargo_test]
56fn simple_test() {
57 if !cross_compile::can_run_on_host() {
58 return;
59 }
60 let t1 = cross_compile::alternate();
61 let t2 = rustc_host();
62 let p = project()
63 .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
64 .file("src/lib.rs", "fn main() {}")
65 .build();
66
67 p.cargo("test")
68 .arg("--target")
69 .arg(&t1)
70 .arg("--target")
71 .arg(&t2)
72 .with_stderr_contains(&format!("[RUNNING] [..]{}[..]", t1))
73 .with_stderr_contains(&format!("[RUNNING] [..]{}[..]", t2))
74 .run();
75}
76
77#[cargo_test]
78fn simple_run() {
79 let p = project()
80 .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
81 .file("src/main.rs", "fn main() {}")
82 .build();
83
84 p.cargo("run --target a --target b")
85 .with_stderr("[ERROR] only one `--target` argument is supported")
86 .with_status(101)
87 .run();
88}
89
90#[cargo_test]
91fn simple_doc() {
92 if cross_compile::disabled() {
93 return;
94 }
95 let t1 = cross_compile::alternate();
96 let t2 = rustc_host();
97 let p = project()
98 .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
99 .file("src/lib.rs", "//! empty lib")
100 .build();
101
102 p.cargo("doc")
103 .arg("--target")
104 .arg(&t1)
105 .arg("--target")
106 .arg(&t2)
107 .run();
108
109 assert!(p.build_dir().join(&t1).join("doc/foo/index.html").is_file());
110 assert!(p.build_dir().join(&t2).join("doc/foo/index.html").is_file());
111}
112
ed00b5ec
FG
113#[cargo_test]
114fn simple_doc_open() {
115 if cross_compile::disabled() {
116 return;
117 }
118 let t1 = cross_compile::alternate();
119 let t2 = rustc_host();
120 let p = project()
121 .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
122 .file("src/lib.rs", "//! empty lib")
123 .build();
124
125 p.cargo("doc")
126 .arg("--open")
127 .arg("--target")
128 .arg(&t1)
129 .arg("--target")
130 .arg(&t2)
131 .with_stderr(
132 "\
133[DOCUMENTING] foo v1.0.0 ([..])
134[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
135[ERROR] only one `--target` argument is supported",
136 )
137 .with_status(101)
138 .run();
139}
140
0a29b90c
FG
141#[cargo_test]
142fn simple_check() {
143 if cross_compile::disabled() {
144 return;
145 }
146 let t1 = cross_compile::alternate();
147 let t2 = rustc_host();
148 let p = project()
149 .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
150 .file("src/main.rs", "fn main() {}")
151 .build();
152
153 p.cargo("check")
154 .arg("--target")
155 .arg(&t1)
156 .arg("--target")
157 .arg(&t2)
158 .run();
159}
160
161#[cargo_test]
162fn same_value_twice() {
163 if cross_compile::disabled() {
164 return;
165 }
166 let t = rustc_host();
167 let p = project()
168 .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
169 .file("src/main.rs", "fn main() {}")
170 .build();
171
172 p.cargo("build")
173 .arg("--target")
174 .arg(&t)
175 .arg("--target")
176 .arg(&t)
177 .run();
178
179 assert!(p.target_bin(t, "foo").is_file());
180}
181
182#[cargo_test]
183fn same_value_twice_with_config() {
184 if cross_compile::disabled() {
185 return;
186 }
187 let t = rustc_host();
188 let p = project()
189 .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
190 .file("src/main.rs", "fn main() {}")
191 .file(
192 ".cargo/config.toml",
193 &format!(
194 r#"
195 [build]
196 target = ["{t}", "{t}"]
197 "#
198 ),
199 )
200 .build();
201
202 p.cargo("build").run();
203
204 assert!(p.target_bin(t, "foo").is_file());
205}
206
207#[cargo_test]
208fn works_with_config_in_both_string_or_list() {
209 if cross_compile::disabled() {
210 return;
211 }
212 let t = rustc_host();
213 let p = project()
214 .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
215 .file("src/main.rs", "fn main() {}")
216 .file(
217 ".cargo/config.toml",
218 &format!(
219 r#"
220 [build]
221 target = "{t}"
222 "#
223 ),
224 )
225 .build();
226
227 p.cargo("build").run();
228
229 assert!(p.target_bin(t, "foo").is_file());
230
231 p.cargo("clean").run();
232
233 p.change_file(
234 ".cargo/config.toml",
235 &format!(
236 r#"
237 [build]
238 target = ["{t}"]
239 "#
240 ),
241 );
242
243 p.cargo("build").run();
244
245 assert!(p.target_bin(t, "foo").is_file());
246}
247
248#[cargo_test]
249fn works_with_env() {
250 let t = rustc_host();
251 let p = project()
252 .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
253 .file("src/main.rs", "fn main() {}")
254 .build();
255
256 p.cargo("build").env("CARGO_BUILD_TARGET", t).run();
257
258 assert!(p.target_bin(t, "foo").is_file());
259}