@@ -62,11 +62,11 @@ SHARED_TARGET = SHARED = ""
62
62
MVP = env ("MVP" , true )
63
63
64
64
if env ("EMMAKEN_JUST_CONFIGURE" , false ):
65
- CONFIGURE = True
65
+ CONFIGURE = True
66
66
elif env ("CONFIG_SITE" , false ):
67
- CONFIGURE = True
67
+ CONFIGURE = True
68
68
else :
69
- CONFIGURE = env ("CONFIGURE" , false )
69
+ CONFIGURE = env ("CONFIGURE" , false )
70
70
71
71
72
72
if MVP :
@@ -82,6 +82,9 @@ if MVP:
82
82
# WASMOPTS="-fno-wasm-exceptions -sSUPPORT_LONGJMP=emscripten"
83
83
# CPU="-mnontrapping-fptoint -mno-reference-types -mno-sign-ext -m32"
84
84
85
+ # bulk and main/side
86
+ # https://github.com/emscripten-core/emscripten/issues/22161
87
+
85
88
CPU = arglist (
86
89
"""
87
90
-D_FILE_OFFSET_BITS=64
@@ -91,6 +94,15 @@ if MVP:
91
94
-mno-reference-types
92
95
-mno-sign-ext
93
96
-m32
97
+ -mno-extended-const
98
+ -mno-atomics
99
+ -mno-tail-call
100
+ -mno-fp16
101
+ -mno-multivalue
102
+ -mno-relaxed-simd
103
+ -mno-simd128
104
+ -mno-multimemory
105
+ -mno-exception-handling
94
106
"""
95
107
)
96
108
else :
@@ -100,7 +112,7 @@ else:
100
112
# try to keep 32 but maybe with 64 iface (bigint)
101
113
WASM_EXTRA = env ("WASM_EXTRA" , "" ) + " " + env ("WASM_OPTS" , "" )
102
114
103
- COPTS = env ("COPTS" , "-fPIC " )
115
+ COPTS = env ("COPTS" , "-O0 -g3 " )
104
116
105
117
106
118
MAIN_MODULE = LINKING = False
@@ -116,12 +128,11 @@ for argc, arg in enumerate(sys.argv):
116
128
SKIP = True
117
129
break
118
130
119
- if arg .startswith (' CMakeFiles/' ):
131
+ if arg .startswith (" CMakeFiles/" ):
120
132
SKIP = True
121
133
break
122
134
123
-
124
- if arg .find ("MAIN_MODULE" ):
135
+ if arg .find ("MAIN_MODULE" ) > 0 or EXE .endswith (".cjs" ) or EXE .endswith (".js" ):
125
136
MAIN_MODULE = True
126
137
127
138
if arg .lower () in ("-fpic" , "-latomic" ):
@@ -130,43 +141,49 @@ for argc, arg in enumerate(sys.argv):
130
141
if arg in ("-Wl,--as-needed" , "-Wl,--eh-frame-hdr" , "-Wl,-znoexecstack" , "-Wl,-znow" , "-Wl,-zrelro" , "-Wl,-zrelro,-znow" ):
131
142
continue
132
143
133
- if arg in ("-O3" , "-g" , "-lgcc" , "-lgcc_s" , "-fallow-argument-mismatch" ):
144
+ if arg in ("-O1" , "-O2" , "-O3" ):
145
+ continue
146
+
147
+ if arg in ("-g" , "-g2" , "-g3" , "-g4" ):
148
+ continue
149
+
150
+ if arg in ("-lgcc" , "-lgcc_s" , "-fallow-argument-mismatch" ):
134
151
continue
135
152
136
153
if arg == "-pthread" :
137
154
if MVP :
138
155
continue
139
156
140
157
if arg in ("-o" , "-c" ):
141
- CPU_EXTRA = WASM_EXTRA
142
158
MODE = arg
143
159
MODE_POS = argc
144
160
if arg == "-c" :
145
161
COMPILE = True
146
- # TODO maybe add node runner and compile to .cjs
162
+ # TODO maybe add node runner for a .cjs
147
163
elif arg == "-o" :
148
- EXE_POS = argc + 1
149
- EXE = sys .argv [EXE_POS ]
150
-
151
- elif arg .endswith (".so" ) or arg == "-shared" :
164
+ if IS_SHARED :
165
+ EXE_POS = argc + 1
166
+ SHARED_TARGET = sys .argv [EXE_POS ]
167
+ else :
168
+ EXE_POS = argc + 1
169
+ EXE = sys .argv [EXE_POS ]
170
+
171
+ elif arg .endswith (".so" ) or arg == "-shared" or arg .find ("SIDE_MODULE" ) > 0 :
152
172
LINKING = True
173
+ IS_SHARED = True
153
174
if arg == "-shared" :
154
- IS_SHARED = True
155
- elif arg .find ( "wasm32-emscripten .so" ) > 0 or arg . find ( "abi3.so" ) > 0 :
156
- IS_SHARED = True
157
- PY_MODULE = true
175
+ pass
176
+ elif arg .endswith ( " .so" ):
177
+ if arg . find ( "wasm32-emscripten.so" ) > 0 or arg . find ( "abi3.so" ) > 0 :
178
+ PY_MODULE = true
158
179
SHARED_TARGET = arg
159
-
160
- if IS_SHARED :
161
180
out .append (arg )
162
- SHARED = "-sSIDE_MODULE"
163
- if not SHARED in out :
164
- out .insert (0 , SHARED )
165
- out .append (f"-L{ os .environ ['PREFIX' ]} /lib" )
166
- continue
181
+
182
+ SHARED = f"-shared -sSIDE_MODULE=1 -L{ os .environ ['PREFIX' ]} /lib"
183
+ continue
167
184
168
185
# prevent duplicates objects/archives files on cmdline when linking
169
- if LINKING or MODE == "-o" :
186
+ if LINKING or MODE == "-o" :
170
187
if arg .endswith (".a" ) or arg .endswith (".o" ) or arg .startswith ("-l" ):
171
188
if arg in out :
172
189
continue
@@ -185,12 +202,6 @@ os.environ.pop("_EMCC_CCACHE", "")
185
202
186
203
187
204
"""
188
- if [ "\$arg" = "-lutil" ]
189
- then
190
- continue
191
- fi
192
-
193
-
194
205
if [ "\$arg" = "-nomvp" ]
195
206
then
196
207
MVP=false
@@ -214,53 +225,56 @@ os.environ.pop("_EMCC_CCACHE", "")
214
225
final = [EXEC ]
215
226
216
227
# a.out test misses fpic
217
- if CONFIGURE and len (out )== 1 :
218
- SKIP = out [0 ] == 'conftest.c'
219
- sys .argv .insert (0 ,"-fPIC" )
228
+ if CONFIGURE and len (out ) == 1 :
229
+ SKIP = out [0 ] == "conftest.c"
230
+ sys .argv .insert (0 , "-fPIC" )
231
+ sys .argv .extend (CPU )
220
232
221
233
222
234
if SKIP :
223
235
final .extend (sys .argv )
224
236
else :
225
- if EXE .endswith ('.cjs' ):
226
- def make_exe (* argv ,** kw ):
237
+ if EXE .endswith (".cjs" ) or EXE .endswith (".js" ):
238
+
239
+ def make_exe (* argv , ** kw ):
227
240
global CONFIGURE
228
241
if os .path .isfile (EXE ) and not CONFIGURE :
229
- with open (EXE ,'r' ) as file :
242
+ with open (EXE , "r" ) as file :
230
243
bin = file .read ()
231
- with open (EXE ,"w" ) as file :
244
+ with open (EXE , "w" ) as file :
232
245
file .write ("#!/usr/bin/env node\n " )
233
246
file .write (bin )
234
247
os .chmod (EXE , 0o766 )
235
248
236
- final .append ('-sENVIRONMENT=node' )
237
- final .append ('-sNODERAWFS' )
238
- final .append ("-L/lib/wasm32-emscripten/pic" )
249
+ final .append ("-sENVIRONMENT=node" )
250
+ final .append ("-sNODERAWFS" )
239
251
__import__ ("atexit" ).register (make_exe )
240
252
253
+ # do not pass WASM opts when -c/-o but always PIC and opt level
254
+ final .extend (arglist ("-fPIC" , SHARED , COPTS ))
241
255
242
- if IS_SHARED :
243
- final .extend (arglist (SHARED , COPTS ))
244
- final .extend (CPU )
245
- #, "-gsource-map --source-map-base /"))
246
- final .extend (arglist (WASM_EXTRA , env ("LDFLAGS" , "" )))
256
+ # prevent use of extended instr
257
+ final .extend (CPU )
247
258
248
- # do not pass WASM opts when -c/-o but always PIC
249
- elif MAIN_MODULE :
250
- final .extend (arglist (SHARED , COPTS ))
251
- final .extend (CPU )
252
- # -gsource-map --source-map-base /
253
- final .extend (arglist (env ("CPU_EXTRA" , "" ), env ("CPPFLAGS" , "" ), "-DBUILD_STATIC" ))
259
+ if IS_SHARED or LINKING :
260
+ # , "-gsource-map --source-map-base /"))
261
+ final .extend (arglist (WASM_EXTRA , env ("LDFLAGS" , "" )))
254
262
else :
255
- final .extend (arglist (SHARED , COPTS , env ("CPU_EXTRA" , "" ), env ("CPPFLAGS" , "" ), "-DBUILD_STATIC" ))
263
+ if MAIN_MODULE :
264
+ # TODO: module level
265
+ # -gsource-map --source-map-base /
266
+ pass
267
+ final .extend (arglist (WASM_EXTRA , "-DBUILD_STATIC" ))
268
+
256
269
final .extend (out )
257
270
final .extend (COMMON )
258
271
259
272
260
-
261
273
if env ("EMCC_TRACE" , false ):
274
+
262
275
def dump ():
263
- dbg (f"""
276
+ dbg (
277
+ f"""
264
278
265
279
{ COMMON = }
266
280
@@ -276,19 +290,20 @@ if env("EMCC_TRACE", false):
276
290
277
291
{ final = }
278
292
279
- """ )
293
+ """
294
+ )
295
+
280
296
dump ()
281
- if os .path .isfile (' conftest.c' ):
282
- __import__ ("shutil" ).copy ("conftest.c" , os .environ ["SDKROOT" ]+ "/emcc.c" )
297
+ if os .path .isfile (" conftest.c" ):
298
+ __import__ ("shutil" ).copy ("conftest.c" , os .environ ["SDKROOT" ] + "/emcc.c" )
283
299
284
300
285
301
sys .path .insert (0 , str (Path (EXEC ).parent ))
286
302
sys .argv .clear ()
287
303
while len (final ):
288
304
arg = final .pop (0 )
289
- #arg = arg.replace('"', '\\"')
305
+ # add debug filters here.
306
+
290
307
sys .argv .append (arg )
291
308
292
309
exec (open (EXEC , "r" ).read (), globals (), globals ())
293
-
294
-
0 commit comments