Skip to content

Commit f47ede6

Browse files
committed
test: capture linker selection for host artifacts
1 parent 9582e30 commit f47ede6

2 files changed

Lines changed: 386 additions & 0 deletions

File tree

‎tests/testsuite/build_script.rs‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,117 @@ Caused by:
11321132
.run();
11331133
}
11341134

1135+
#[cargo_test]
1136+
fn target_cfg_linker_build_script() {
1137+
let p = project()
1138+
.file(
1139+
".cargo/config.toml",
1140+
r#"
1141+
[target.'cfg(all())']
1142+
linker = "/path/to/cfg/linker"
1143+
"#,
1144+
)
1145+
.file("build.rs", "fn main() {}")
1146+
.file("src/lib.rs", "")
1147+
.build();
1148+
1149+
p.cargo("build -v")
1150+
.with_status(101)
1151+
.with_stderr_data(str![[r#"
1152+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1153+
[RUNNING] `rustc --crate-name build_script_build [..]--crate-type bin [..]-C linker=[..]/path/to/cfg/linker [..]`
1154+
[ERROR] linker `[..]/path/to/cfg/linker` not found
1155+
...
1156+
"#]])
1157+
.run();
1158+
}
1159+
1160+
#[cargo_test]
1161+
fn target_cfg_linker_build_script_with_target() {
1162+
let target = rustc_host();
1163+
let p = project()
1164+
.file(
1165+
".cargo/config.toml",
1166+
r#"
1167+
[target.'cfg(all())']
1168+
linker = "/path/to/cfg/linker"
1169+
"#,
1170+
)
1171+
.file("build.rs", "fn main() {}")
1172+
.file("src/lib.rs", "")
1173+
.build();
1174+
1175+
p.cargo("build -v --target")
1176+
.arg(&target)
1177+
.with_stderr_data(str![[r#"
1178+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1179+
[RUNNING] `rustc --crate-name build_script_build [..]--crate-type bin [..]`
1180+
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
1181+
[RUNNING] `rustc --crate-name foo [..]-C linker=[..]/path/to/cfg/linker [..]`
1182+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1183+
1184+
"#]])
1185+
.run();
1186+
}
1187+
1188+
#[cargo_test]
1189+
fn target_linker_build_script_with_target() {
1190+
let target = rustc_host();
1191+
let p = project()
1192+
.file(
1193+
".cargo/config.toml",
1194+
&format!(
1195+
r#"
1196+
[target.{target}]
1197+
linker = "/path/to/target/linker"
1198+
"#,
1199+
),
1200+
)
1201+
.file("build.rs", "fn main() {}")
1202+
.file("src/lib.rs", "")
1203+
.build();
1204+
1205+
p.cargo("build -v --target")
1206+
.arg(&target)
1207+
.with_status(101)
1208+
.with_stderr_data(str![[r#"
1209+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1210+
[RUNNING] `rustc --crate-name build_script_build [..]--crate-type bin [..]-C linker=[..]/path/to/target/linker [..]`
1211+
[ERROR] linker `[..]/path/to/target/linker` not found
1212+
...
1213+
"#]])
1214+
.run();
1215+
}
1216+
1217+
#[cargo_test]
1218+
fn target_cfg_linker_build_script_with_host_config_and_target() {
1219+
let target = rustc_host();
1220+
let p = project()
1221+
.file(
1222+
".cargo/config.toml",
1223+
r#"
1224+
[target.'cfg(all())']
1225+
linker = "/path/to/cfg/linker"
1226+
"#,
1227+
)
1228+
.file("build.rs", "fn main() {}")
1229+
.file("src/lib.rs", "")
1230+
.build();
1231+
1232+
p.cargo("build -v -Ztarget-applies-to-host -Zhost-config --target")
1233+
.arg(&target)
1234+
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
1235+
.with_stderr_data(str![[r#"
1236+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1237+
[RUNNING] `rustc --crate-name build_script_build [..]--crate-type bin [..]`
1238+
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
1239+
[RUNNING] `rustc --crate-name foo [..]-C linker=[..]/path/to/cfg/linker [..]`
1240+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1241+
1242+
"#]])
1243+
.run();
1244+
}
1245+
11351246
#[cargo_test]
11361247
fn custom_build_script_wrong_rustc_flags() {
11371248
let p = project()

‎tests/testsuite/tool_paths.rs‎

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,281 @@ running 1 test
779779
.run();
780780
}
781781

782+
#[cargo_test]
783+
fn target_cfg_linker_proc_macro_with_target() {
784+
let target = rustc_host();
785+
let p = proc_macro_package();
786+
p.change_file(
787+
".cargo/config.toml",
788+
r#"
789+
[target.'cfg(all())']
790+
linker = "/path/to/cfg/linker"
791+
"#,
792+
);
793+
794+
p.cargo("build -v --target")
795+
.arg(&target)
796+
.with_stderr_data(str![[r#"
797+
[COMPILING] foo v0.0.0 ([ROOT]/foo)
798+
[RUNNING] `rustc --crate-name foo [..]--crate-type proc-macro [..]`
799+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
800+
801+
"#]])
802+
.run();
803+
}
804+
805+
#[cargo_test]
806+
fn host_linker_proc_macro() {
807+
let target = rustc_host();
808+
let p = proc_macro_package();
809+
p.change_file(
810+
".cargo/config.toml",
811+
&format!(
812+
r#"
813+
[host]
814+
linker = "/path/to/host/linker"
815+
[target.{target}]
816+
linker = "/path/to/target/linker"
817+
"#,
818+
),
819+
);
820+
821+
p.cargo("build -v -Ztarget-applies-to-host -Zhost-config --target")
822+
.arg(&target)
823+
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
824+
.with_status(101)
825+
.with_stderr_data(str![[r#"
826+
[COMPILING] foo v0.0.0 ([ROOT]/foo)
827+
[RUNNING] `rustc --crate-name foo [..]--crate-type proc-macro [..]-C linker=[..]/path/to/host/linker [..]`
828+
[ERROR] linker `[..]/path/to/host/linker` not found
829+
...
830+
"#]])
831+
.run();
832+
}
833+
834+
#[cargo_test]
835+
fn target_linker_proc_macro_test() {
836+
let target = rustc_host();
837+
let p = proc_macro_package();
838+
p.change_file(
839+
".cargo/config.toml",
840+
&format!(
841+
r#"
842+
[target.{target}]
843+
linker = "/path/to/target/linker"
844+
"#,
845+
),
846+
);
847+
848+
p.cargo("test --lib -v")
849+
.with_status(101)
850+
.with_stderr_data(str![[r#"
851+
[COMPILING] foo v0.0.0 ([ROOT]/foo)
852+
[RUNNING] `rustc --crate-name foo [..]--test [..]-C linker=[..]/path/to/target/linker [..]`
853+
[ERROR] linker `[..]/path/to/target/linker` not found
854+
...
855+
"#]])
856+
.run();
857+
}
858+
859+
#[cargo_test]
860+
fn target_cfg_linker_proc_macro_test() {
861+
let p = proc_macro_package();
862+
p.change_file(
863+
".cargo/config.toml",
864+
r#"
865+
[target.'cfg(all())']
866+
linker = "/path/to/cfg/linker"
867+
"#,
868+
);
869+
870+
p.cargo("test --lib -v")
871+
.with_status(101)
872+
.with_stderr_data(str![[r#"
873+
[COMPILING] foo v0.0.0 ([ROOT]/foo)
874+
[RUNNING] `rustc --crate-name foo [..]--test [..]-C linker=[..]/path/to/cfg/linker [..]`
875+
[ERROR] linker `[..]/path/to/cfg/linker` not found
876+
...
877+
"#]])
878+
.run();
879+
}
880+
881+
#[cargo_test]
882+
fn target_linker_proc_macro_test_with_target() {
883+
let target = rustc_host();
884+
let p = proc_macro_package();
885+
p.change_file(
886+
".cargo/config.toml",
887+
&format!(
888+
r#"
889+
[target.{target}]
890+
linker = "/path/to/target/linker"
891+
"#,
892+
),
893+
);
894+
895+
p.cargo("test --lib -v --target")
896+
.arg(&target)
897+
.with_status(101)
898+
.with_stderr_data(str![[r#"
899+
[COMPILING] foo v0.0.0 ([ROOT]/foo)
900+
[RUNNING] `rustc --crate-name foo [..]--test [..]-C linker=[..]/path/to/target/linker [..]`
901+
[ERROR] linker `[..]/path/to/target/linker` not found
902+
...
903+
"#]])
904+
.run();
905+
}
906+
907+
#[cargo_test]
908+
fn target_cfg_linker_proc_macro_test_with_target() {
909+
let target = rustc_host();
910+
let p = proc_macro_package();
911+
p.change_file(
912+
".cargo/config.toml",
913+
r#"
914+
[target.'cfg(all())']
915+
linker = "/path/to/cfg/linker"
916+
"#,
917+
);
918+
919+
p.cargo("test --lib -v --target")
920+
.arg(&target)
921+
.with_stderr_data(str![[r#"
922+
[COMPILING] foo v0.0.0 ([ROOT]/foo)
923+
[RUNNING] `rustc --crate-name foo [..]--test [..]`
924+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
925+
[RUNNING] `[ROOT]/foo/target/debug/deps/foo-[HASH][EXE]`
926+
927+
"#]])
928+
.with_stdout_data(str![[r#"
929+
...
930+
running 1 test
931+
...
932+
"#]])
933+
.run();
934+
}
935+
936+
#[cargo_test]
937+
fn host_linker_proc_macro_test() {
938+
let target = rustc_host();
939+
let p = proc_macro_package();
940+
p.change_file(
941+
".cargo/config.toml",
942+
&format!(
943+
r#"
944+
[host]
945+
linker = "/path/to/host/linker"
946+
[target.{target}]
947+
linker = "/path/to/target/linker"
948+
"#,
949+
),
950+
);
951+
952+
p.cargo("test --lib -v -Ztarget-applies-to-host -Zhost-config --target")
953+
.arg(&target)
954+
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
955+
.with_status(101)
956+
.with_stderr_data(str![[r#"
957+
[COMPILING] foo v0.0.0 ([ROOT]/foo)
958+
[RUNNING] `rustc --crate-name foo [..]--test [..]-C linker=[..]/path/to/host/linker [..]`
959+
[ERROR] linker `[..]/path/to/host/linker` not found
960+
...
961+
"#]])
962+
.run();
963+
}
964+
965+
#[cargo_test]
966+
fn target_cfg_linker_proc_macro_test_with_host_config() {
967+
let target = rustc_host();
968+
let p = proc_macro_package();
969+
p.change_file(
970+
".cargo/config.toml",
971+
r#"
972+
[host]
973+
linker = "/path/to/host/linker"
974+
[target.'cfg(all())']
975+
linker = "/path/to/cfg/linker"
976+
"#,
977+
);
978+
979+
p.cargo("test --lib -v -Ztarget-applies-to-host -Zhost-config --target")
980+
.arg(&target)
981+
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
982+
.with_status(101)
983+
.with_stderr_data(str![[r#"
984+
[COMPILING] foo v0.0.0 ([ROOT]/foo)
985+
[RUNNING] `rustc --crate-name foo [..]--test [..]-C linker=[..]/path/to/host/linker [..]`
986+
[ERROR] linker `[..]/path/to/host/linker` not found
987+
...
988+
"#]])
989+
.run();
990+
}
991+
992+
#[cargo_test]
993+
fn target_linker_proc_macro_test_with_cross_target() {
994+
if cross_compile_disabled() {
995+
return;
996+
}
997+
let target = rustc_host();
998+
let alternate = cross_compile_alternate();
999+
let p = proc_macro_package();
1000+
p.change_file(
1001+
".cargo/config.toml",
1002+
&format!(
1003+
r#"
1004+
[target.{target}]
1005+
linker = "/path/to/target/linker"
1006+
"#,
1007+
),
1008+
);
1009+
1010+
p.cargo("test --lib -v --target")
1011+
.arg(alternate)
1012+
.with_status(101)
1013+
.with_stderr_data(str![[r#"
1014+
[COMPILING] foo v0.0.0 ([ROOT]/foo)
1015+
[RUNNING] `rustc --crate-name foo [..]--test [..]-C linker=[..]/path/to/target/linker [..]`
1016+
[ERROR] linker `[..]/path/to/target/linker` not found
1017+
...
1018+
"#]])
1019+
.run();
1020+
}
1021+
1022+
#[cargo_test]
1023+
fn target_linker_proc_macro_test_with_cross_target_host_config() {
1024+
if cross_compile_disabled() {
1025+
return;
1026+
}
1027+
let target = rustc_host();
1028+
let alternate = cross_compile_alternate();
1029+
let p = proc_macro_package();
1030+
p.change_file(
1031+
".cargo/config.toml",
1032+
&format!(
1033+
r#"
1034+
[host]
1035+
linker = "/path/to/host/linker"
1036+
[target.{target}]
1037+
linker = "/path/to/target/linker"
1038+
[target.'cfg(all())']
1039+
linker = "/path/to/cfg/linker"
1040+
"#,
1041+
),
1042+
);
1043+
1044+
p.cargo("test --lib -v -Ztarget-applies-to-host -Zhost-config --target")
1045+
.arg(alternate)
1046+
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
1047+
.with_status(101)
1048+
.with_stderr_data(str![[r#"
1049+
[COMPILING] foo v0.0.0 ([ROOT]/foo)
1050+
[RUNNING] `rustc --crate-name foo [..]--test [..]-C linker=[..]/path/to/host/linker [..]`
1051+
[ERROR] linker `[..]/path/to/host/linker` not found
1052+
...
1053+
"#]])
1054+
.run();
1055+
}
1056+
7821057
#[cargo_test]
7831058
fn custom_linker_env() {
7841059
let p = project().file("src/main.rs", "fn main() {}").build();

0 commit comments

Comments
 (0)