@@ -116,7 +116,7 @@ else:
116116# try to keep 32 but maybe with 64 iface (bigint)
117117WASM_EXTRA = env ("WASM_EXTRA" , "" ) + " " + env ("WASM_OPTS" , "" )
118118
119- COPTS = env ("COPTS" , "-O0 -g3 " )
119+ COPTS = env ("COPTS" , "-O0" )
120120
121121
122122MAIN_MODULE = LINKING = False
@@ -132,6 +132,8 @@ COMPILE = False
132132
133133USE_RAWFS = True
134134CMAKE = False
135+ RUSTC = False
136+
135137
136138out = []
137139for argc , arg in enumerate (sys .argv ):
@@ -162,11 +164,6 @@ for argc, arg in enumerate(sys.argv):
162164 if arg in ("-Wl,--as-needed" , "-Wl,--eh-frame-hdr" , "-Wl,-znoexecstack" , "-Wl,-znow" , "-Wl,-zrelro" , "-Wl,-zrelro,-znow" ):
163165 continue
164166
165- if arg in ("-O1" , "-O2" , "-O3" ):
166- continue
167-
168- if arg in ("-g" , "-g2" , "-g3" , "-g4" ):
169- continue
170167
171168 if arg in ("-lgcc" , "-lgcc_s" , "-fallow-argument-mismatch" ):
172169 continue
@@ -175,7 +172,55 @@ for argc, arg in enumerate(sys.argv):
175172 if MVP :
176173 continue
177174
178- if arg in ("-o" , "-c" ):
175+ if arg in ("-O1" , "-O2" , "-O3" , "-Os" , "-Oz" ):
176+ continue
177+
178+ if arg in ("-g" , "-g0" , "-g1" , "-g2" , "-g3" , "-g4" ):
179+ continue
180+
181+
182+ # FAILSAFE
183+ # that is for some very bad known setup.py behaviour regarding cross compiling and some old codebases.
184+ # should not be needed ..
185+ if arg .startswith ("-I/" ):
186+ if arg .startswith ("-I/usr/" ):
187+ continue
188+ # remove dups
189+ if arg in out :
190+ continue
191+
192+ if arg .startswith ("-L/" ):
193+ if arg .startswith ("-L/usr/" ):
194+ continue
195+ # remove dups
196+ if arg in out :
197+ continue
198+
199+
200+ # https://github.com/emscripten-core/emscripten/issues/22742
201+ # https://github.com/hoodmane/emscripten/commit/34144634026c91a73bd3e1db85627132d3a37a6d
202+
203+ if arg .find ("ASSERTIONS" ) > 0 :
204+ continue
205+
206+
207+ if IS_SHARED :
208+ if arg == '-lc' :
209+ #continue
210+ pass
211+
212+
213+ # rustc has an habit of "-l" "c" instead of "-lc"
214+ if arg .startswith ("-l" ):
215+ if len (arg )> 2 :
216+ LINKING = True
217+ # prevent duplicate lib when linking
218+ if arg in out :
219+ continue
220+ else :
221+ RUSTC = True
222+
223+ elif arg in ("-o" , "-c" ):
179224 MODE = arg
180225 MODE_POS = argc
181226 if arg == "-c" :
@@ -201,26 +246,15 @@ for argc, arg in enumerate(sys.argv):
201246 SHARED = f"-shared -sSIDE_MODULE=1 -L{ os .environ ['PREFIX' ]} /lib"
202247 continue
203248
204- if arg .startswith ("-l" ):
205- LINKING = True
206249
207- # duplicates can happen on cmake but they are expected to be handled correctly so skip
208- if not CMAKE :
250+ # duplicates can happen on cmake/rustc but they are expected to be here for a reason so skip them
251+ if not ( CMAKE or RUSTC ) :
209252 # prevent duplicates objects/archives files on cmdline when linking
210253 if LINKING or MODE == "-o" :
211- if arg .endswith (".a" ) or arg .endswith (".o" ) or arg . startswith ( "-l" ) :
254+ if arg .endswith (".a" ) or arg .endswith (".o" ):
212255 if arg in out :
213256 continue
214257
215- # FAILSAFE
216- # that is for some very bad known setup.py behaviour regarding cross compiling and some old codebases.
217- # should not be needed ..
218- if arg .startswith ("-I/usr/" ):
219- continue
220-
221- if arg .startswith ("-L/usr/" ):
222- continue
223-
224258 out .append (arg )
225259
226260os .environ .pop ("_EMCC_CCACHE" , "" )
0 commit comments