|
1 | 1 | //! Tests for the new feature resolver.
|
2 | 2 |
|
| 3 | +use cargo_test_support::cross_compile::{self, alternate}; |
3 | 4 | use cargo_test_support::paths::CargoPathExt;
|
4 | 5 | use cargo_test_support::registry::{Dependency, Package};
|
5 |
| -use cargo_test_support::{basic_manifest, project}; |
| 6 | +use cargo_test_support::{basic_manifest, project, rustc_host}; |
6 | 7 |
|
7 | 8 | #[cargo_test]
|
8 | 9 | fn inactivate_targets() {
|
@@ -183,6 +184,49 @@ fn inactive_target_optional() {
|
183 | 184 | .run();
|
184 | 185 | }
|
185 | 186 |
|
| 187 | +#[cargo_test] |
| 188 | +fn itarget_proc_macro() { |
| 189 | + // itarget inside a proc-macro while cross-compiling |
| 190 | + if cross_compile::disabled() { |
| 191 | + return; |
| 192 | + } |
| 193 | + Package::new("hostdep", "1.0.0").publish(); |
| 194 | + Package::new("pm", "1.0.0") |
| 195 | + .proc_macro(true) |
| 196 | + .target_dep("hostdep", "1.0", &rustc_host()) |
| 197 | + .file("src/lib.rs", "extern crate hostdep;") |
| 198 | + .publish(); |
| 199 | + let p = project() |
| 200 | + .file( |
| 201 | + "Cargo.toml", |
| 202 | + r#" |
| 203 | + [package] |
| 204 | + name = "foo" |
| 205 | + version = "0.1.0" |
| 206 | +
|
| 207 | + [dependencies] |
| 208 | + pm = "1.0" |
| 209 | + "#, |
| 210 | + ) |
| 211 | + .file("src/lib.rs", "") |
| 212 | + .build(); |
| 213 | + |
| 214 | + p.cargo("check").run(); |
| 215 | + p.cargo("check -Zfeatures=itarget") |
| 216 | + .masquerade_as_nightly_cargo() |
| 217 | + .run(); |
| 218 | + p.cargo("check --target").arg(alternate()).run(); |
| 219 | + p.cargo("check -Zfeatures=itarget --target") |
| 220 | + .arg(alternate()) |
| 221 | + .masquerade_as_nightly_cargo() |
| 222 | + .run(); |
| 223 | + // For good measure, just make sure things don't break. |
| 224 | + p.cargo("check -Zfeatures=all --target") |
| 225 | + .arg(alternate()) |
| 226 | + .masquerade_as_nightly_cargo() |
| 227 | + .run(); |
| 228 | +} |
| 229 | + |
186 | 230 | #[cargo_test]
|
187 | 231 | fn decouple_host_deps() {
|
188 | 232 | // Basic test for `host_dep` decouple.
|
@@ -1185,3 +1229,63 @@ fn has_dev_dep_for_test() {
|
1185 | 1229 | )
|
1186 | 1230 | .run();
|
1187 | 1231 | }
|
| 1232 | + |
| 1233 | +#[cargo_test] |
| 1234 | +fn build_dep_activated() { |
| 1235 | + // Build dependencies always match the host for [target.*.build-dependencies]. |
| 1236 | + if cross_compile::disabled() { |
| 1237 | + return; |
| 1238 | + } |
| 1239 | + Package::new("somedep", "1.0.0") |
| 1240 | + .file("src/lib.rs", "") |
| 1241 | + .publish(); |
| 1242 | + Package::new("targetdep", "1.0.0").publish(); |
| 1243 | + Package::new("hostdep", "1.0.0") |
| 1244 | + // Check that "for_host" is sticky. |
| 1245 | + .target_dep("somedep", "1.0", &rustc_host()) |
| 1246 | + .feature("feat1", &[]) |
| 1247 | + .file( |
| 1248 | + "src/lib.rs", |
| 1249 | + r#" |
| 1250 | + extern crate somedep; |
| 1251 | +
|
| 1252 | + #[cfg(not(feature="feat1"))] |
| 1253 | + compile_error!{"feat1 missing"} |
| 1254 | + "#, |
| 1255 | + ) |
| 1256 | + .publish(); |
| 1257 | + |
| 1258 | + let p = project() |
| 1259 | + .file( |
| 1260 | + "Cargo.toml", |
| 1261 | + &format!( |
| 1262 | + r#" |
| 1263 | + [package] |
| 1264 | + name = "foo" |
| 1265 | + version = "0.1.0" |
| 1266 | +
|
| 1267 | + # This should never be selected. |
| 1268 | + [target.'{}'.build-dependencies] |
| 1269 | + targetdep = "1.0" |
| 1270 | +
|
| 1271 | + [target.'{}'.build-dependencies] |
| 1272 | + hostdep = {{version="1.0", features=["feat1"]}} |
| 1273 | + "#, |
| 1274 | + alternate(), |
| 1275 | + rustc_host() |
| 1276 | + ), |
| 1277 | + ) |
| 1278 | + .file("src/lib.rs", "") |
| 1279 | + .file("build.rs", "fn main() {}") |
| 1280 | + .build(); |
| 1281 | + |
| 1282 | + p.cargo("check").run(); |
| 1283 | + p.cargo("check -Zfeatures=all") |
| 1284 | + .masquerade_as_nightly_cargo() |
| 1285 | + .run(); |
| 1286 | + p.cargo("check --target").arg(alternate()).run(); |
| 1287 | + p.cargo("check -Zfeatures=all --target") |
| 1288 | + .arg(alternate()) |
| 1289 | + .masquerade_as_nightly_cargo() |
| 1290 | + .run(); |
| 1291 | +} |
0 commit comments