File tree Expand file tree Collapse file tree 2 files changed +38
-6
lines changed Expand file tree Collapse file tree 2 files changed +38
-6
lines changed Original file line number Diff line number Diff line change @@ -73,16 +73,16 @@ fn needs_object(crate_types: &[CrateType]) -> bool {
73
73
74
74
/// Lto setting to use when this unit needs object code.
75
75
fn lto_when_needs_object(crate_types: &[CrateType]) -> Lto {
76
- if crate_types.iter().any(CrateType::can_lto) {
77
- // A mixed rlib/cdylib whose parent is running LTO. This
78
- // needs both, for bitcode in the rlib (for LTO) and the
79
- // cdylib requires object code.
80
- Lto::ObjectAndBitcode
81
- } else {
76
+ if crate_types.iter().all(|ct| *ct == CrateType::Dylib) {
82
77
// A dylib whose parent is running LTO. rustc currently
83
78
// doesn't support LTO with dylibs, so bitcode is not
84
79
// needed.
85
80
Lto::OnlyObject
81
+ } else {
82
+ // Mixed rlib with a dylib or cdylib whose parent is running LTO. This
83
+ // needs both: bitcode for the rlib (for LTO) and object code for the
84
+ // dylib.
85
+ Lto::ObjectAndBitcode
86
86
}
87
87
}
88
88
Original file line number Diff line number Diff line change @@ -746,3 +746,35 @@ fn doctest() {
746
746
.with_stderr_contains("[..]`rustdoc [..]-C lto[..]")
747
747
.run();
748
748
}
749
+
750
+ #[cargo_test]
751
+ fn dylib_rlib_bin() {
752
+ // dylib+rlib linked with a binary
753
+ let p = project()
754
+ .file(
755
+ "Cargo.toml",
756
+ r#"
757
+ [package]
758
+ name = "foo"
759
+ version = "0.1.0"
760
+
761
+ [lib]
762
+ crate-type = ["dylib", "rlib"]
763
+
764
+ [profile.release]
765
+ lto = true
766
+ "#,
767
+ )
768
+ .file("src/lib.rs", "pub fn foo() { println!(\"hi!\"); }")
769
+ .file("src/main.rs", "fn main() { foo::foo(); }")
770
+ .build();
771
+
772
+ let output = p.cargo("build --release -v").exec_with_output().unwrap();
773
+ verify_lto(
774
+ &output,
775
+ "foo",
776
+ "--crate-type dylib --crate-type rlib",
777
+ Lto::ObjectAndBitcode,
778
+ );
779
+ verify_lto(&output, "foo", "--crate-type bin", Lto::Run(None));
780
+ }
You can’t perform that action at this time.
0 commit comments