40
40
//! but not gcc's. As a result rustc cannot link with C++ static libraries (#36710)
41
41
//! when linking in self-contained mode.
42
42
43
- use crate :: spec:: LinkOutputKind ;
43
+ use crate :: spec:: { LinkOutputKind , MaybeLazy } ;
44
44
use std:: borrow:: Cow ;
45
45
use std:: collections:: BTreeMap ;
46
46
47
- pub type CrtObjects = BTreeMap < LinkOutputKind , Vec < Cow < ' static , str > > > ;
47
+ pub type CrtObjectsData = BTreeMap < LinkOutputKind , Vec < Cow < ' static , str > > > ;
48
+ pub type CrtObjects = MaybeLazy < CrtObjectsData > ;
48
49
49
- pub ( super ) fn new ( obj_table : & [ ( LinkOutputKind , & [ & ' static str ] ) ] ) -> CrtObjects {
50
+ pub ( super ) fn new ( obj_table : & [ ( LinkOutputKind , & [ & ' static str ] ) ] ) -> CrtObjectsData {
50
51
obj_table. iter ( ) . map ( |( z, k) | ( * z, k. iter ( ) . map ( |b| ( * b) . into ( ) ) . collect ( ) ) ) . collect ( )
51
52
}
52
53
53
- pub ( super ) fn all ( obj : & ' static str ) -> CrtObjects {
54
+ pub ( super ) fn all ( obj : & ' static str ) -> CrtObjectsData {
54
55
new ( & [
55
56
( LinkOutputKind :: DynamicNoPicExe , & [ obj] ) ,
56
57
( LinkOutputKind :: DynamicPicExe , & [ obj] ) ,
@@ -62,62 +63,70 @@ pub(super) fn all(obj: &'static str) -> CrtObjects {
62
63
}
63
64
64
65
pub ( super ) fn pre_musl_self_contained ( ) -> CrtObjects {
65
- new ( & [
66
- ( LinkOutputKind :: DynamicNoPicExe , & [ "crt1.o" , "crti.o" , "crtbegin.o" ] ) ,
67
- ( LinkOutputKind :: DynamicPicExe , & [ "Scrt1.o" , "crti.o" , "crtbeginS.o" ] ) ,
68
- ( LinkOutputKind :: StaticNoPicExe , & [ "crt1.o" , "crti.o" , "crtbegin.o" ] ) ,
69
- ( LinkOutputKind :: StaticPicExe , & [ "rcrt1.o" , "crti.o" , "crtbeginS.o" ] ) ,
70
- ( LinkOutputKind :: DynamicDylib , & [ "crti.o" , "crtbeginS.o" ] ) ,
71
- ( LinkOutputKind :: StaticDylib , & [ "crti.o" , "crtbeginS.o" ] ) ,
72
- ] )
66
+ MaybeLazy :: lazy ( || {
67
+ new ( & [
68
+ ( LinkOutputKind :: DynamicNoPicExe , & [ "crt1.o" , "crti.o" , "crtbegin.o" ] ) ,
69
+ ( LinkOutputKind :: DynamicPicExe , & [ "Scrt1.o" , "crti.o" , "crtbeginS.o" ] ) ,
70
+ ( LinkOutputKind :: StaticNoPicExe , & [ "crt1.o" , "crti.o" , "crtbegin.o" ] ) ,
71
+ ( LinkOutputKind :: StaticPicExe , & [ "rcrt1.o" , "crti.o" , "crtbeginS.o" ] ) ,
72
+ ( LinkOutputKind :: DynamicDylib , & [ "crti.o" , "crtbeginS.o" ] ) ,
73
+ ( LinkOutputKind :: StaticDylib , & [ "crti.o" , "crtbeginS.o" ] ) ,
74
+ ] )
75
+ } )
73
76
}
74
77
75
78
pub ( super ) fn post_musl_self_contained ( ) -> CrtObjects {
76
- new ( & [
77
- ( LinkOutputKind :: DynamicNoPicExe , & [ "crtend.o" , "crtn.o" ] ) ,
78
- ( LinkOutputKind :: DynamicPicExe , & [ "crtendS.o" , "crtn.o" ] ) ,
79
- ( LinkOutputKind :: StaticNoPicExe , & [ "crtend.o" , "crtn.o" ] ) ,
80
- ( LinkOutputKind :: StaticPicExe , & [ "crtendS.o" , "crtn.o" ] ) ,
81
- ( LinkOutputKind :: DynamicDylib , & [ "crtendS.o" , "crtn.o" ] ) ,
82
- ( LinkOutputKind :: StaticDylib , & [ "crtendS.o" , "crtn.o" ] ) ,
83
- ] )
79
+ MaybeLazy :: lazy ( || {
80
+ new ( & [
81
+ ( LinkOutputKind :: DynamicNoPicExe , & [ "crtend.o" , "crtn.o" ] ) ,
82
+ ( LinkOutputKind :: DynamicPicExe , & [ "crtendS.o" , "crtn.o" ] ) ,
83
+ ( LinkOutputKind :: StaticNoPicExe , & [ "crtend.o" , "crtn.o" ] ) ,
84
+ ( LinkOutputKind :: StaticPicExe , & [ "crtendS.o" , "crtn.o" ] ) ,
85
+ ( LinkOutputKind :: DynamicDylib , & [ "crtendS.o" , "crtn.o" ] ) ,
86
+ ( LinkOutputKind :: StaticDylib , & [ "crtendS.o" , "crtn.o" ] ) ,
87
+ ] )
88
+ } )
84
89
}
85
90
86
91
pub ( super ) fn pre_mingw_self_contained ( ) -> CrtObjects {
87
- new ( & [
88
- ( LinkOutputKind :: DynamicNoPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
89
- ( LinkOutputKind :: DynamicPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
90
- ( LinkOutputKind :: StaticNoPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
91
- ( LinkOutputKind :: StaticPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
92
- ( LinkOutputKind :: DynamicDylib , & [ "dllcrt2.o" , "rsbegin.o" ] ) ,
93
- ( LinkOutputKind :: StaticDylib , & [ "dllcrt2.o" , "rsbegin.o" ] ) ,
94
- ] )
92
+ MaybeLazy :: lazy ( || {
93
+ new ( & [
94
+ ( LinkOutputKind :: DynamicNoPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
95
+ ( LinkOutputKind :: DynamicPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
96
+ ( LinkOutputKind :: StaticNoPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
97
+ ( LinkOutputKind :: StaticPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
98
+ ( LinkOutputKind :: DynamicDylib , & [ "dllcrt2.o" , "rsbegin.o" ] ) ,
99
+ ( LinkOutputKind :: StaticDylib , & [ "dllcrt2.o" , "rsbegin.o" ] ) ,
100
+ ] )
101
+ } )
95
102
}
96
103
97
104
pub ( super ) fn post_mingw_self_contained ( ) -> CrtObjects {
98
- all ( "rsend.o" )
105
+ MaybeLazy :: lazy ( || all ( "rsend.o" ) )
99
106
}
100
107
101
108
pub ( super ) fn pre_mingw ( ) -> CrtObjects {
102
- all ( "rsbegin.o" )
109
+ MaybeLazy :: lazy ( || all ( "rsbegin.o" ) )
103
110
}
104
111
105
112
pub ( super ) fn post_mingw ( ) -> CrtObjects {
106
- all ( "rsend.o" )
113
+ MaybeLazy :: lazy ( || all ( "rsend.o" ) )
107
114
}
108
115
109
116
pub ( super ) fn pre_wasi_self_contained ( ) -> CrtObjects {
110
117
// Use crt1-command.o instead of crt1.o to enable support for new-style
111
118
// commands. See https://reviews.llvm.org/D81689 for more info.
112
- new ( & [
113
- ( LinkOutputKind :: DynamicNoPicExe , & [ "crt1-command.o" ] ) ,
114
- ( LinkOutputKind :: DynamicPicExe , & [ "crt1-command.o" ] ) ,
115
- ( LinkOutputKind :: StaticNoPicExe , & [ "crt1-command.o" ] ) ,
116
- ( LinkOutputKind :: StaticPicExe , & [ "crt1-command.o" ] ) ,
117
- ( LinkOutputKind :: WasiReactorExe , & [ "crt1-reactor.o" ] ) ,
118
- ] )
119
+ MaybeLazy :: lazy ( || {
120
+ new ( & [
121
+ ( LinkOutputKind :: DynamicNoPicExe , & [ "crt1-command.o" ] ) ,
122
+ ( LinkOutputKind :: DynamicPicExe , & [ "crt1-command.o" ] ) ,
123
+ ( LinkOutputKind :: StaticNoPicExe , & [ "crt1-command.o" ] ) ,
124
+ ( LinkOutputKind :: StaticPicExe , & [ "crt1-command.o" ] ) ,
125
+ ( LinkOutputKind :: WasiReactorExe , & [ "crt1-reactor.o" ] ) ,
126
+ ] )
127
+ } )
119
128
}
120
129
121
130
pub ( super ) fn post_wasi_self_contained ( ) -> CrtObjects {
122
- new ( & [ ] )
131
+ MaybeLazy :: lazy ( || new ( & [ ] ) )
123
132
}
0 commit comments