Skip to content

Commit 0365155

Browse files
committed
3.1.70.4bi
1 parent 0677db6 commit 0365155

File tree

3 files changed

+91
-55
lines changed

3 files changed

+91
-55
lines changed

emsdk-cc

Lines changed: 86 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ def dbg(*argv, **kw):
1010
return print(*argv, **kw)
1111

1212

13-
SDKROOT = Path(os.environ.get("SDKROOT","/opt/python-wasm-sdk"))
14-
EMSDK = Path(os.environ.get("EMSDK","/opt/python-wasm-sdk/emsdk"))
15-
PREFIX = Path(os.environ.get("PREFIX","/opt/python-wasm-sdk/devices/emsdk/usr"))
13+
SDKROOT = Path(os.environ.get("SDKROOT", "/opt/python-wasm-sdk"))
14+
EMSDK = Path(os.environ.get("EMSDK", "/opt/python-wasm-sdk/emsdk"))
15+
PREFIX = Path(os.environ.get("PREFIX", "/opt/python-wasm-sdk/devices/emsdk/usr"))
1616

1717
sys.argv.pop(0)
1818

@@ -120,8 +120,12 @@ COPTS = env("COPTS", "-O0 -g3")
120120

121121

122122
MAIN_MODULE = LINKING = False
123-
EXE = ""
123+
124+
EXE = False
125+
HTML = False
126+
124127
MODE = ""
128+
AOUT = ""
125129

126130
SKIP = False
127131
COMPILE = False
@@ -136,20 +140,17 @@ for argc, arg in enumerate(sys.argv):
136140
break
137141

138142
if arg.startswith("CMakeFiles/"):
139-
# SKIP = True
140-
# break
141143
CMAKE = True
142144

143-
if arg.startswith('--preload-file') or arg.startswith('--embed-file'):
145+
if arg.startswith("--preload-file") or arg.startswith("--embed-file"):
144146
USE_RAWFS = False
145147

146148
if arg.find("MAIN_MODULE") > 0:
147149
MAIN_MODULE = True
148-
elif EXE.endswith(".cjs") or EXE.endswith(".js") or EXE.endswith(".html"):
149-
MAIN_MODULE = True
150150

151151
if arg == "-sENVIRONMENT=web":
152152
EXE = False
153+
HTML = True
153154

154155
if arg.lower() in ("-fpic", "-latomic"):
155156
continue
@@ -177,11 +178,11 @@ for argc, arg in enumerate(sys.argv):
177178
COMPILE = True
178179
# TODO maybe add node runner for a .cjs
179180
elif arg == "-o":
180-
EXE_POS = argc + 1
181+
out_pos = argc + 1
181182
if IS_SHARED:
182-
SHARED_TARGET = sys.argv[EXE_POS]
183-
elif EXE=="":
184-
EXE = sys.argv[EXE_POS]
183+
SHARED_TARGET = sys.argv[out_pos]
184+
elif not AOUT:
185+
AOUT = sys.argv[out_pos]
185186

186187
elif arg.endswith(".so") or arg == "-shared" or arg.find("SIDE_MODULE") > 0:
187188
IS_SHARED = True
@@ -197,15 +198,18 @@ for argc, arg in enumerate(sys.argv):
197198
continue
198199

199200
if arg.startswith("-l"):
200-
LINKING = True
201-
202-
# prevent duplicates objects/archives files on cmdline when linking
203-
if not CMAKE and (LINKING or MODE == "-o"):
204-
if arg.endswith(".a") or arg.endswith(".o") or arg.startswith("-l"):
205-
if arg in out:
206-
continue
207-
208-
# that is for some very bad setup.py behaviour regarding cross compiling.
201+
LINKING = True
202+
203+
# duplicates can happen on cmake but they are expected to be handled correctly so skip
204+
if not CMAKE:
205+
# prevent duplicates objects/archives files on cmdline when linking
206+
if LINKING or MODE == "-o":
207+
if arg.endswith(".a") or arg.endswith(".o") or arg.startswith("-l"):
208+
if arg in out:
209+
continue
210+
211+
# FAILSAFE
212+
# that is for some very bad known setup.py behaviour regarding cross compiling and some old codebases.
209213
# should not be needed ..
210214
if arg.startswith("-I/usr/"):
211215
continue
@@ -251,48 +255,76 @@ if CONFIGURE and len(out) == 1:
251255
if SKIP:
252256
final.extend(sys.argv)
253257
else:
254-
# should not happen
255-
if EXE:
256-
if EXE.endswith('.o') and '-c' not in out:
257-
final.append('-c')
258+
if AOUT:
259+
# should not happen
260+
if AOUT.endswith(".o") and "-c" not in out:
261+
final.append("-c")
258262
EXE = False
259263
MAIN_MODULE = False
260-
elif EXE.endswith('.html'):
264+
elif AOUT.endswith(".html"):
265+
MAIN_MODULE = True
266+
EXE = False
267+
HTML = True
268+
269+
# emscripten aware build
270+
elif AOUT.endswith(".cjs") or AOUT.endswith(".js"):
271+
MAIN_MODULE = True
272+
EXE = True
273+
# a.out, could be a standalone from config/cmake
274+
elif not CONFIGURE and not CMAKE and "-c" not in out:
275+
EXE = True
276+
else:
261277
EXE = False
262-
263278
if EXE:
264-
if EXE.endswith(".cjs") or EXE.endswith(".js"):
279+
if AOUT.endswith(".cjs") or AOUT.endswith(".js"):
280+
265281
def make_exe(*argv, **kw):
266-
global CONFIGURE
267-
if os.path.isfile(EXE) and not CONFIGURE:
268-
with open(EXE, "r") as file:
269-
bin = file.read()
270-
with open(EXE, "w") as file:
271-
file.write("#!/usr/bin/env node\n")
272-
file.write(bin)
273-
os.chmod(EXE, 0o766)
282+
global AOUT, CONFIGURE
283+
if os.path.isfile(AOUT) and not CONFIGURE:
284+
try:
285+
with open(AOUT, "r") as file:
286+
bin = file.read()
287+
with open(AOUT, "w") as file:
288+
file.write("#!/usr/bin/env node\n")
289+
file.write(bin)
290+
os.chmod(AOUT, 0o766)
291+
except Exception as e:
292+
dbg("ERROR: 292", e)
293+
274294
# the build system is old and exe has no suffix from cmake or configure
275295
else:
296+
276297
def make_exe(*argv, **kw):
277-
global CONFIGURE
278-
if os.path.isfile(EXE) and os.path.isfile(EXE+'.wasm') and not CONFIGURE:
279-
os.rename(EXE, EXE+".cjs")
280-
with open(EXE, "w") as file:
281-
file.write("#!/usr/bin/env bash\n")
282-
file.write('node $0.cjs "$@"\n')
283-
os.chmod(EXE, 0o766)
298+
global AOUT, CONFIGURE
299+
if os.path.isfile(AOUT) and os.path.isfile(AOUT + ".wasm") and not CONFIGURE:
300+
os.rename(AOUT, AOUT + ".cjs")
301+
try:
302+
with open(AOUT, "w") as file:
303+
file.write("#!/usr/bin/env bash\n")
304+
file.write('node $0.cjs "$@"\n')
305+
except Exception as e:
306+
dbg("ERROR: 306", e)
307+
os.rename(AOUT + ".cjs", AOUT)
308+
return
309+
try:
310+
os.chmod(AOUT, 0o766)
311+
except Exception as e:
312+
dbg("ERROR: 312", e)
284313

285314
final.append("-sENVIRONMENT=node")
286315

287316
# error: explicitly setting EXIT_RUNTIME not compatible with STANDALONE_WASM.
288317
# EXIT_RUNTIME will always be True for programs (with a main function) and False for reactors (not main function).
289-
#final.append("-sEXIT_RUNTIME")
318+
# final.append("-sEXIT_RUNTIME")
290319

291320
if USE_RAWFS:
292-
#final.append("-sASYNCIFY")
321+
# final.append("-sASYNCIFY")
293322
final.append("-sNODERAWFS")
294323

295324
__import__("atexit").register(make_exe)
325+
elif HTML:
326+
if "-sENVIRONMENT=web" not in out:
327+
final.append("-sENVIRONMENT=web")
296328

297329
# do not pass WASM opts when -c/-o but always PIC and opt level
298330
final.extend(arglist("-fPIC", SHARED, COPTS))
@@ -316,15 +348,16 @@ else:
316348
final.extend(COMMON)
317349

318350

319-
320351
sys.path.insert(0, str(Path(EXEC).parent))
321352
sys.argv.clear()
322353

323354
EMCC_TRACE = env("EMCC_TRACE", false)
324355
if EMCC_TRACE:
325356
DEBUG_PATTERN = env("DEBUG_PATTERN", "main")
357+
326358
def dump():
327-
dbg(f"""
359+
dbg(
360+
f"""
328361
{COMMON=}
329362
330363
{CPU=}
@@ -341,20 +374,20 @@ if EMCC_TRACE:
341374
342375
{' '.join(sys.argv)}
343376
"""
344-
)
377+
)
345378

346379
while len(final):
347380
arg = final.pop(0)
348381
# add debug filters here.
349382

350383
sys.argv.append(arg)
351384

352-
385+
# for debugging configure, cmake has its own very detailed log.
353386
if os.path.isfile("conftest.c"):
354387
__import__("shutil").copy("conftest.c", SDKROOT / "emcc.c")
355-
if DEBUG_PATTERN not in (False,True):
356-
with open("conftest.c","r") as file:
357-
if file.read().find(DEBUG_PATTERN)>0:
388+
if DEBUG_PATTERN not in (False, True):
389+
with open("conftest.c", "r") as file:
390+
if file.read().find(DEBUG_PATTERN) > 0:
358391
dump()
359392

360393
else:

scripts/cpython-build-emsdk.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,10 @@ then
366366
# emsdk_env already parsed
367367
echo -n
368368
else
369-
. ${SDKROOT}/config
370-
. ${SDKROOT}/emsdk/emsdk_env.sh
369+
pushd ${SDKROOT}
370+
. config
371+
. emsdk/emsdk_env.sh
372+
popd
371373
export PATH=$SDKROOT/emsdk/upstream/emscripten:$SDKROOT/emsdk/upstream/emscripten/system/bin:\$PATH
372374
export PKG_CONFIG_SYSROOT_DIR="${SDKROOT}/devices/emsdk"
373375
export PKG_CONFIG_LIBDIR="${SDKROOT}/emsdk/upstream/emscripten/system/lib/pkgconfig"

scripts/pack-sdk.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ tar -cpPR \
1919
${SDKROOT}/devices/* \
2020
${SDKROOT}/prebuilt/* \
2121
${SDKROOT}/native \
22+
${SDKROOT}/bun \
2223
> /tmp/sdk/python${PYBUILD}-${TAG}-sdk-${CIVER}.tar
2324
lz4 -c --favor-decSpeed --best /tmp/sdk/python${PYBUILD}-${TAG}-sdk-${CIVER}.tar \
2425
> /tmp/sdk/python${PYBUILD}-${TAG}-sdk-${CIVER}.tar.lz4

0 commit comments

Comments
 (0)