@@ -7,7 +7,7 @@ use std::sync::Arc;
7
7
use std:: sync:: Mutex ;
8
8
#[ cfg( feature = "compiler" ) ]
9
9
use wasmer_compiler:: Compiler ;
10
- use wasmer_compiler:: { CompileError , Target } ;
10
+ use wasmer_compiler:: { CompileError , Target , Triple } ;
11
11
use wasmer_engine:: { Artifact , DeserializeError , Engine , EngineId , Tunables } ;
12
12
#[ cfg( feature = "compiler" ) ]
13
13
use wasmer_types:: Features ;
@@ -29,9 +29,22 @@ impl NativeEngine {
29
29
/// Create a new `NativeEngine` with the given config
30
30
#[ cfg( feature = "compiler" ) ]
31
31
pub fn new ( compiler : Box < dyn Compiler + Send > , target : Target , features : Features ) -> Self {
32
- if let Err ( _) = which ( "gcc" ) . or_else ( |_| which ( "clang-10" ) ) {
33
- panic ! ( "gcc/clang is not found, it is required for using the `NativeEngine`" ) ;
34
- }
32
+ let host_target = Triple :: host ( ) ;
33
+ let is_cross_compiling = target. triple ( ) != & host_target;
34
+
35
+ let linker = if is_cross_compiling {
36
+ which ( Into :: < & ' static str > :: into ( Linker :: Clang10 ) )
37
+ . map ( |_| Linker :: Clang10 )
38
+ . or_else ( |_| {
39
+ which ( Into :: < & ' static str > :: into ( Linker :: Clang ) )
40
+ . map ( |_| Linker :: Clang )
41
+ } )
42
+ . expect ( "Nor `clang-10` or `clang` has been found, at least one of them is required for the `NativeEngine`" )
43
+ } else {
44
+ which ( Into :: < & ' static str > :: into ( Linker :: Gcc ) )
45
+ . map ( |_| Linker :: Gcc )
46
+ . expect ( "`gcc` has not been found, it is required for the `NativeEngine`" )
47
+ } ;
35
48
36
49
Self {
37
50
inner : Arc :: new ( Mutex :: new ( NativeEngineInner {
@@ -40,6 +53,8 @@ impl NativeEngine {
40
53
signatures : SignatureRegistry :: new ( ) ,
41
54
prefixer : None ,
42
55
features,
56
+ is_cross_compiling,
57
+ linker,
43
58
} ) ) ,
44
59
target : Arc :: new ( target) ,
45
60
engine_id : EngineId :: default ( ) ,
@@ -69,6 +84,8 @@ impl NativeEngine {
69
84
trampolines : HashMap :: new ( ) ,
70
85
signatures : SignatureRegistry :: new ( ) ,
71
86
prefixer : None ,
87
+ is_cross_compiling : false ,
88
+ linker : Linker :: None ,
72
89
} ) ) ,
73
90
target : Arc :: new ( Target :: default ( ) ) ,
74
91
engine_id : EngineId :: default ( ) ,
@@ -178,6 +195,25 @@ impl Engine for NativeEngine {
178
195
}
179
196
}
180
197
198
+ #[ derive( Clone , Copy ) ]
199
+ pub ( crate ) enum Linker {
200
+ None ,
201
+ Clang10 ,
202
+ Clang ,
203
+ Gcc ,
204
+ }
205
+
206
+ impl Into < & ' static str > for Linker {
207
+ fn into ( self ) -> & ' static str {
208
+ match self {
209
+ Self :: None => "" ,
210
+ Self :: Clang10 => "clang-10" ,
211
+ Self :: Clang => "clang" ,
212
+ Self :: Gcc => "gcc" ,
213
+ }
214
+ }
215
+ }
216
+
181
217
/// The inner contents of `NativeEngine`
182
218
pub struct NativeEngineInner {
183
219
/// The compiler
@@ -195,6 +231,10 @@ pub struct NativeEngineInner {
195
231
/// the functions in the shared object generated by the `NativeEngine`,
196
232
/// so we can assure no collisions.
197
233
prefixer : Option < Box < dyn Fn ( & [ u8 ] ) -> String + Send > > ,
234
+ /// Whether the native engine will cross-compile.
235
+ is_cross_compiling : bool ,
236
+ /// The linker to use.
237
+ linker : Linker ,
198
238
}
199
239
200
240
impl NativeEngineInner {
@@ -255,4 +295,12 @@ impl NativeEngineInner {
255
295
// where they belong become unallocated.
256
296
self . trampolines . insert ( index, trampoline) ;
257
297
}
298
+
299
+ pub ( crate ) fn is_cross_compiling ( & self ) -> bool {
300
+ self . is_cross_compiling
301
+ }
302
+
303
+ pub ( crate ) fn linker ( & self ) -> Linker {
304
+ self . linker
305
+ }
258
306
}
0 commit comments