@@ -20,8 +20,6 @@ use std::sync::{Once, ONCE_INIT};
20
20
type LLVMBool = libc:: c_uint ;
21
21
const LLVMTrue : LLVMBool = 1 ;
22
22
const LLVMFalse : LLVMBool = 0 ;
23
- pub enum LLVMPassRegistry_opaque { }
24
- pub type LLVMPassRegistryRef = * mut LLVMPassRegistry_opaque ;
25
23
#[ allow( missing_copy_implementations) ]
26
24
enum LLVMContext_opaque { }
27
25
type LLVMContextRef = * mut LLVMContext_opaque ;
@@ -32,75 +30,15 @@ type LLVMMemoryBufferRef = *mut LLVMMemoryBuffer_opaque;
32
30
enum LLVMModule_opaque { }
33
31
type LLVMModuleRef = * mut LLVMModule_opaque ;
34
32
#[ allow( missing_copy_implementations) ]
35
- pub enum LLVMTarget_opaque { }
36
- pub type LLVMTargetRef = * mut LLVMTarget_opaque ;
37
- pub enum LLVMTargetMachine_opaque { }
38
- pub type LLVMTargetMachineRef = * mut LLVMTargetMachine_opaque ;
39
- pub enum LLVMArchive_opaque { }
40
- pub type LLVMArchiveRef = * mut LLVMArchive_opaque ;
41
- pub enum LLVMArchiveIterator_opaque { }
42
- pub type LLVMArchiveIteratorRef = * mut LLVMArchiveIterator_opaque ;
43
- pub enum LLVMArchiveChild_opaque { }
44
- pub type LLVMArchiveChildRef = * mut LLVMArchiveChild_opaque ;
33
+ enum LLVMTarget_opaque { }
34
+ type LLVMTargetRef = * mut LLVMTarget_opaque ;
35
+ enum LLVMTargetMachine_opaque { }
36
+ type LLVMTargetMachineRef = * mut LLVMTargetMachine_opaque ;
37
+ enum LLVMArchiveChild_opaque { }
38
+ type LLVMArchiveChildRef = * mut LLVMArchiveChild_opaque ;
45
39
#[ allow( missing_copy_implementations) ]
46
- pub enum LLVMRustArchiveMember_opaque { }
47
- pub type LLVMRustArchiveMemberRef = * mut LLVMRustArchiveMember_opaque ;
48
-
49
-
50
-
51
- #[ derive( Copy , Clone , PartialEq , Debug ) ]
52
- #[ repr( C ) ]
53
- pub enum RelocMode {
54
- Default = 0 ,
55
- Static = 1 ,
56
- PIC = 2 ,
57
- DynamicNoPic = 3 ,
58
- }
59
-
60
- #[ repr( C ) ]
61
- #[ derive( Copy , Clone , Debug ) ]
62
- pub enum CodeGenModel {
63
- Default = 0 ,
64
- JITDefault = 1 ,
65
- Small = 2 ,
66
- Kernel = 3 ,
67
- Medium = 4 ,
68
- Large = 5 ,
69
- }
70
-
71
- #[ derive( Copy , Clone , PartialEq , Debug ) ]
72
- #[ repr( C ) ]
73
- pub enum CodeGenOptLevel {
74
- O0 = 0 ,
75
- O1 = 1 ,
76
- O2 = 2 ,
77
- O3 = 3 ,
78
- }
79
-
80
- #[ allow( dead_code) ]
81
- #[ repr( C ) ]
82
- enum VerifierFailureAction {
83
- AbortProcess = 0 ,
84
- PrintMessage = 1 ,
85
- ReturnStatus = 2 ,
86
- }
87
-
88
- #[ allow( dead_code) ]
89
- #[ repr( C ) ]
90
- enum CodeGenFileType {
91
- Assembly = 0 ,
92
- Object = 1 ,
93
- }
94
-
95
- #[ allow( dead_code) ]
96
- #[ repr( C ) ]
97
- #[ derive( Copy , Clone ) ]
98
- pub enum ArchiveKind {
99
- K_GNU ,
100
- K_MIPS64 ,
101
- K_BSD ,
102
- K_COFF ,
103
- }
40
+ enum LLVMRustArchiveMember_opaque { }
41
+ type LLVMRustArchiveMemberRef = * mut LLVMRustArchiveMember_opaque ;
104
42
105
43
extern {
106
44
fn LLVMContextCreate ( ) -> LLVMContextRef ;
@@ -119,9 +57,9 @@ extern {
119
57
triple : * const libc:: c_char ,
120
58
cpu : * const libc:: c_char ,
121
59
features : * const libc:: c_char ,
122
- lvl : CodeGenOptLevel ,
123
- reloc : RelocMode ,
124
- cm : CodeGenModel ) -> LLVMTargetMachineRef ;
60
+ lvl : Optimisation ,
61
+ reloc : Relocations ,
62
+ cm : CodegenModel ) -> LLVMTargetMachineRef ;
125
63
fn LLVMDisposeTargetMachine ( _: LLVMTargetMachineRef ) ;
126
64
fn LLVMTargetMachineEmitToFile ( _: LLVMTargetMachineRef ,
127
65
_: LLVMModuleRef ,
@@ -147,6 +85,87 @@ extern {
147
85
Kind : ArchiveKind ) -> libc:: c_int ;
148
86
}
149
87
88
+ #[ allow( dead_code) ]
89
+ #[ repr( C ) ]
90
+ enum VerifierFailureAction {
91
+ AbortProcess = 0 ,
92
+ PrintMessage = 1 ,
93
+ ReturnStatus = 2 ,
94
+ }
95
+
96
+ #[ allow( dead_code) ]
97
+ #[ repr( C ) ]
98
+ enum CodeGenFileType {
99
+ Assembly = 0 ,
100
+ Object = 1 ,
101
+ }
102
+
103
+
104
+ /// Relocation mode
105
+ ///
106
+ /// This option decides how relocations are handled.
107
+ #[ derive( Copy , Clone , PartialEq , Debug ) ]
108
+ #[ repr( C ) ]
109
+ pub enum Relocations {
110
+ /// Target default relocation model
111
+ Default = 0 ,
112
+ /// Non-relocatable code
113
+ Static = 1 ,
114
+ /// Fully relocatable, position independent code
115
+ PIC = 2 ,
116
+ /// Relocatable external references, non-relocatable code
117
+ DynamicNoPic = 3 ,
118
+ }
119
+
120
+ /// Codegen model
121
+ #[ repr( C ) ]
122
+ #[ derive( Copy , Clone , Debug ) ]
123
+ pub enum CodegenModel {
124
+ /// Target default code model
125
+ Default = 0 ,
126
+ /// Small code model
127
+ Small = 2 ,
128
+ /// Kernel code model
129
+ Kernel = 3 ,
130
+ /// Medium code model
131
+ Medium = 4 ,
132
+ /// Large code model
133
+ Large = 5 ,
134
+ }
135
+
136
+ /// Codegen optimisation level
137
+ #[ derive( Copy , Clone , PartialEq , Debug ) ]
138
+ #[ repr( C ) ]
139
+ pub enum Optimisation {
140
+ /// No codegen optimisation
141
+ ///
142
+ /// Corresponds to the -O0 option of `llc`
143
+ O0 = 0 ,
144
+ /// Some codegen optimisations
145
+ ///
146
+ /// Corresponds to the -O1 option of `llc`
147
+ O1 = 1 ,
148
+ /// Considerable codegen optimisations
149
+ ///
150
+ /// Corresponds to the -O2 option of `llc`
151
+ O2 = 2 ,
152
+ /// Heavy codegen optimisations
153
+ ///
154
+ /// Corresponds to the -O3 option of `llc`
155
+ O3 = 3 ,
156
+ }
157
+
158
+ /// The format of generated archive file
159
+ #[ allow( dead_code) ]
160
+ #[ repr( C ) ]
161
+ #[ derive( Copy , Clone ) ]
162
+ pub enum ArchiveKind {
163
+ Gnu ,
164
+ Mips64 ,
165
+ Bsd ,
166
+ Coff ,
167
+ }
168
+
150
169
#[ derive( Debug ) ]
151
170
pub struct BuildOptions {
152
171
pub triple : String ,
@@ -160,13 +179,19 @@ pub struct BuildOptions {
160
179
161
180
impl Default for BuildOptions {
162
181
fn default ( ) -> BuildOptions {
182
+ use std:: env:: var;
163
183
BuildOptions {
164
- triple : :: std :: env :: var ( "TARGET" ) . unwrap_or ( String :: new ( ) ) ,
184
+ triple : var ( "TARGET" ) . unwrap_or ( String :: new ( ) ) ,
165
185
cpu : String :: new ( ) ,
166
186
attr : String :: new ( ) ,
167
- model : CodeGenModel :: Default ,
168
- reloc : RelocMode :: Default ,
169
- opt : CodeGenOptLevel :: O0 ,
187
+ model : CodegenModel :: Default ,
188
+ reloc : Relocations :: Default ,
189
+ opt : match var ( "OPT_LEVEL" ) . ok ( ) . and_then ( |v| v. parse ( ) . ok ( ) ) . unwrap_or ( 0u64 ) {
190
+ 0 => Optimisation :: O0 ,
191
+ 1 => Optimisation :: O1 ,
192
+ 2 => Optimisation :: O2 ,
193
+ 3 | _ => Optimisation :: O3 ,
194
+ } ,
170
195
ar_section_name : String :: new ( ) ,
171
196
}
172
197
}
@@ -311,7 +336,7 @@ where P: AsRef<Path>, I: IntoIterator<Item=&'a (P, BuildOptions)>
311
336
members. len ( ) as libc:: size_t ,
312
337
members. as_ptr ( ) ,
313
338
true ,
314
- ArchiveKind :: K_GNU ) ;
339
+ ArchiveKind :: Gnu ) ;
315
340
fail_if ! ( r != 0 , "{:?}" , {
316
341
let err = LLVMRustGetLastError ( ) ;
317
342
if err. is_null( ) {
0 commit comments