1
- use std:: env;
2
- use std:: ffi:: OsStr ;
3
- use std:: fmt:: Write as _;
4
- use std:: fs;
5
- use std:: path:: { Path , PathBuf } ;
1
+ use std:: { env, ffi:: OsStr , fs, path:: PathBuf } ;
6
2
7
3
static WASM3_SOURCE : & str = "wasm3/source" ;
8
4
const WHITELIST_REGEX_FUNCTION : & str = "([A-Z]|m3_).*" ;
@@ -12,36 +8,12 @@ const PRIMITIVES: &[&str] = &[
12
8
"f64" , "f32" , "u64" , "i64" , "u32" , "i32" , "u16" , "i16" , "u8" , "i8" ,
13
9
] ;
14
10
15
- fn gen_wrapper ( out_path : & Path ) -> PathBuf {
16
- // TODO: we currently need the field definitions of the structs of wasm3. These aren't exposed
17
- // in the wasm3.h header so we have to generate bindings for more.
18
- let wrapper_file = out_path. join ( "wrapper.h" ) ;
19
-
20
- let mut buffer = String :: new ( ) ;
21
- fs:: read_dir ( WASM3_SOURCE )
22
- . unwrap_or_else ( |_| panic ! ( "failed to read {} directory" , WASM3_SOURCE ) )
23
- . filter_map ( Result :: ok)
24
- . map ( |entry| entry. path ( ) )
25
- . filter ( |path| path. extension ( ) . and_then ( OsStr :: to_str) == Some ( "h" ) )
26
- . for_each ( |path| {
27
- writeln ! (
28
- & mut buffer,
29
- "#include \" {}\" " ,
30
- path. file_name( ) . unwrap( ) . to_str( ) . unwrap( )
31
- )
32
- . unwrap ( )
33
- } ) ;
34
- fs:: write ( & wrapper_file, buffer) . expect ( "failed to create wasm3 wrapper file" ) ;
35
- wrapper_file
36
- }
37
-
38
11
fn gen_bindings ( ) {
39
12
let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
40
13
41
- let wrapper_file = gen_wrapper ( & out_path) ;
42
-
43
14
let mut bindgen = bindgen:: builder ( )
44
- . header ( wrapper_file. to_str ( ) . unwrap ( ) )
15
+ . header ( "wasm3/source/wasm3.h" )
16
+ . header ( "wasm3/source/m3_env.h" )
45
17
. use_core ( )
46
18
. ctypes_prefix ( "cty" )
47
19
. layout_tests ( false )
@@ -69,13 +41,8 @@ fn gen_bindings() {
69
41
) ,
70
42
& format ! (
71
43
"-Dd_m3HasFloat={}" ,
72
- if cfg!( feature = "floats" ) {
73
- 1
74
- } else {
75
- 0
76
- }
44
+ if cfg!( feature = "floats" ) { 1 } else { 0 }
77
45
) ,
78
- "-Dd_m3LogOutput=0" ,
79
46
"-Dd_m3VerboseErrorMessages=0" ,
80
47
"-Iwasm3/source" ,
81
48
]
@@ -101,13 +68,24 @@ fn main() {
101
68
) ;
102
69
103
70
cfg. cpp ( false )
104
- . define ( "d_m3LogOutput" , Some ( "0" ) )
105
71
. warnings ( false )
106
72
. extra_warnings ( false )
107
73
. include ( WASM3_SOURCE ) ;
108
74
75
+ let target_arch = env:: var ( "CARGO_CFG_TARGET_ARCH" ) . unwrap ( ) ;
76
+ let target_env = env:: var ( "CARGO_CFG_TARGET_ENV" ) . unwrap ( ) ;
77
+ let target_vendor = env:: var ( "CARGO_CFG_TARGET_VENDOR" ) . unwrap ( ) ;
78
+
79
+ // Set options specific for x86_64-fortanix-unknown-sgx target.
80
+ if target_arch == "x86_64" && target_env == "sgx" && target_vendor == "fortanix" {
81
+ // Disable the stack protector as the Fortanix ABI currently sets FS and GS bases to the
82
+ // same value and the stack protector assumes the canary value is at FS:0x28 but with the
83
+ // Fortanix ABI that contains a copy of RSP.
84
+ cfg. flag ( "-fno-stack-protector" ) ;
85
+ }
86
+
109
87
// Add any extra arguments from the environment to the CC command line.
110
- if let Ok ( extra_clang_args) = std :: env:: var ( "BINDGEN_EXTRA_CLANG_ARGS" ) {
88
+ if let Ok ( extra_clang_args) = env:: var ( "BINDGEN_EXTRA_CLANG_ARGS" ) {
111
89
// Try to parse it with shell quoting. If we fail, make it one single big argument.
112
90
if let Some ( strings) = shlex:: split ( & extra_clang_args) {
113
91
strings. iter ( ) . for_each ( |string| {
@@ -118,10 +96,6 @@ fn main() {
118
96
} ;
119
97
}
120
98
121
- if cfg ! ( feature = "wasi" ) {
122
- cfg. define ( "d_m3HasWASI" , None ) ;
123
- }
124
-
125
99
cfg. define (
126
100
"d_m3Use32BitSlots" ,
127
101
if cfg ! ( feature = "use-32bit-slots" ) {
0 commit comments