@@ -3189,3 +3189,77 @@ fn check_transitive_artifact_dependency_with_different_target() {
3189
3189
. with_status ( 101 )
3190
3190
. run ( ) ;
3191
3191
}
3192
+
3193
+ #[ cargo_test]
3194
+ fn build_only_specified_artifact_library ( ) {
3195
+ // Create a project with:
3196
+ // - A crate `bar` with both `staticlib` and `cdylib` as crate-types.
3197
+ // - A crate `foo` which depends on either the `staticlib` or `cdylib` artifact of bar,
3198
+ // whose build-script simply checks which library artifacts are present.
3199
+ let create_project = |artifact_lib| {
3200
+ project ( )
3201
+ . file (
3202
+ "bar/Cargo.toml" ,
3203
+ r#"
3204
+ [package]
3205
+ name = "bar"
3206
+ version = "1.0.0"
3207
+
3208
+ [lib]
3209
+ crate-type = ["staticlib", "cdylib"]
3210
+ "# ,
3211
+ )
3212
+ . file ( "bar/src/lib.rs" , "" )
3213
+ . file (
3214
+ "Cargo.toml" ,
3215
+ & format ! (
3216
+ r#"
3217
+ [package]
3218
+ name = "foo"
3219
+ version = "1.0.0"
3220
+
3221
+ [build-dependencies]
3222
+ bar = {{ path = "bar", artifact = "{artifact_lib}" }}
3223
+ "# ) ,
3224
+ )
3225
+ . file ( "src/lib.rs" , "" )
3226
+ . file (
3227
+ "build.rs" ,
3228
+ r#"
3229
+ fn main() {
3230
+ println!("cdylib present: {}", std::env::var_os("CARGO_CDYLIB_FILE_BAR").is_some());
3231
+ println!("staticlib present: {}", std::env::var_os("CARGO_STATICLIB_FILE_BAR").is_some());
3232
+ }
3233
+ "# ,
3234
+ )
3235
+ . build ( )
3236
+ } ;
3237
+
3238
+ let cdylib = create_project ( "cdylib" ) ;
3239
+ cdylib
3240
+ . cargo ( "build -Z bindeps" )
3241
+ . masquerade_as_nightly_cargo ( & [ "bindeps" ] )
3242
+ . run ( ) ;
3243
+ match_exact (
3244
+ "cdylib present: true\n staticlib present: true" ,
3245
+ & build_script_output_string ( & cdylib, "foo" ) ,
3246
+ "build script output" ,
3247
+ "" ,
3248
+ None ,
3249
+ )
3250
+ . unwrap ( ) ;
3251
+
3252
+ let staticlib = create_project ( "staticlib" ) ;
3253
+ staticlib
3254
+ . cargo ( "build -Z bindeps" )
3255
+ . masquerade_as_nightly_cargo ( & [ "bindeps" ] )
3256
+ . run ( ) ;
3257
+ match_exact (
3258
+ "cdylib present: true\n staticlib present: true" ,
3259
+ & build_script_output_string ( & staticlib, "foo" ) ,
3260
+ "build script output" ,
3261
+ "" ,
3262
+ None ,
3263
+ )
3264
+ . unwrap ( ) ;
3265
+ }
0 commit comments