Skip to content

Commit

Permalink
4.0.0bi
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Jan 18, 2025
1 parent 5ac5707 commit aae1349
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 267 deletions.
6 changes: 3 additions & 3 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export PYDK_SYSCONFIG_PLATFORM=$(echo -n $PYDK_PYTHON_HOST_PLATFORM|cut -d- -f1)
# ============== wasi sdk ===============

# stable
export WASI_SDK=${WASI_SDK:-24.0}
export WASI_SDK=${WASI_SDK:-25.0}
export WASI_SDK_MAJOR=$(echo ${WASI_SDK}|cut -d. -f1)
export WASI_SDK_MINOR=$(echo ${WASI_SDK}|cut -d. -f2)
export WASI_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_MAJOR}/wasi-sdk-${WASI_SDK}-$(arch)-linux.tar.gz
Expand All @@ -89,8 +89,8 @@ NIM_VERSION=nim-2.0.8
NIM_VERSION=nim-2.2.0
NIM_URL=https://nim-lang.org/download/${NIM_VERSION}-linux_x64.tar.xz

NIM_VERSION=nim-git
NIM_URL=https://github.com/nim-lang/Nim
#NIM_VERSION=nim-git
#NIM_URL=https://github.com/nim-lang/Nim

export NIM_VERSION NIM_URL
export NIMSDK=${NIMSDK:-"${SDKROOT}/nimsdk"}
Expand Down
52 changes: 34 additions & 18 deletions emsdk-cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ if not sys.argv[0].endswith(".py"):
else:
EXEC = sys.argv.pop(0)

args = sys.argv


def env(k, default):
if default is false:
Expand Down Expand Up @@ -58,6 +56,8 @@ COMMON = arglist(
-Wno-unused-command-line-argument
-Wno-unreachable-code-fallthrough
-Wno-unused-function
-Wno-invalid-noreturn
-Wno-declaration-after-statement
""",
os.environ.get("PYDK_CFLAGS", ""),
)
Expand Down Expand Up @@ -102,6 +102,7 @@ if MVP:
-D_FILE_OFFSET_BITS=64
-sSUPPORT_LONGJMP=emscripten
-mno-bulk-memory
-mno-bulk-memory-opt
-mnontrapping-fptoint
-mno-reference-types
-mno-sign-ext
Expand All @@ -126,7 +127,7 @@ WASM_EXTRA = env("WASM_EXTRA", "") + " " + env("WASM_OPTS", "")
# the only sane default for now
COPTS = env("COPTS", "-O2 -g3")

SIZEOPT = '-Os' in COPTS
SIZEOPT = "-Os" in COPTS

MAIN_MODULE = LINKING = STATIC = False

Expand Down Expand Up @@ -169,7 +170,7 @@ for argc, arg in enumerate(sys.argv):
if arg.find("MAIN_MODULE") > 0:
MAIN_MODULE = True

if arg == '-static':
if arg == "-static":
STATIC = True

if arg.startswith("-sENVIRONMENT"):
Expand All @@ -192,6 +193,10 @@ for argc, arg in enumerate(sys.argv):
if arg in ("-g0", "-g1", "-g2", "-g3", "-g4"):
continue

if arg.endswith("/libpq/libpq.so"):
arg = "-lpq"
# for wasm-ld
sys.argv[argc] = arg

if not MAIN_MODULE:
# https://github.com/emscripten-core/emscripten/issues/22742
Expand Down Expand Up @@ -252,20 +257,31 @@ for argc, arg in enumerate(sys.argv):
AOUT = sys.argv[out_pos]

elif not STATIC:
if arg.endswith(".so") and arg.startswith("/usr/lib"):
arg = f"-l{arg.rsplit('/',1)[-1][3:-3]}"
if arg in ('-lportmidi','-lporttime'):
continue
elif arg.endswith(".so") or arg == "-shared" or arg.find("SIDE_MODULE") > 0:
IS_SHARED = True
if arg == "-shared":
pass
elif arg.endswith(".so"):
if arg.find("wasm32-emscripten.so") > 0 or arg.find("abi3.so") > 0:
PY_MODULE = true
if arg.endswith(".so"):
if arg.startswith("/usr/lib"):
arg = f"-l{arg.rsplit('/',1)[-1][3:-3]}"
if arg in ("-lportmidi", "-lporttime"):
continue

if arg.find("wasm32-emscripten.so") > 0 or arg.find("abi3.so") > 0:
PY_MODULE = true
SHARED_TARGET = arg
out.append(arg)

# FIX linking .so when it should have been .a for final exe without MAIN_MODULE set
# should be "LINKING" state
# is this arg the -o ? if yes do not even try static
elif out_pos != argc:
# if there is no static version let wasm-ld handle it.
if os.path.isfile(arg[:3] + ".a"):
arg = arg[:3] + ".a"
sys.argv[argc] = arg
elif IS_SHARED:
dbg("WARNING maybe should use static here :", arg)
# raise SystemExit(666)

# TODO check is -shared implies -sSIDE_MODULE=1
elif arg == "-shared":
IS_SHARED = True
SHARED = f"-shared -sASSERTIONS=0 -sSIDE_MODULE=1 -L{os.environ['PREFIX']}/lib"
continue

Expand All @@ -278,7 +294,7 @@ for argc, arg in enumerate(sys.argv):
continue

# fix sysroot is not default to PIC
arg = arg.replace("/lib/wasm32-emscripten/lib","/lib/wasm32-emscripten/pic/lib")
arg = arg.replace("/lib/wasm32-emscripten/lib", "/lib/wasm32-emscripten/pic/lib")

out.append(arg)

Expand Down Expand Up @@ -363,7 +379,7 @@ else:
try:
with open(AOUT, "w") as file:
file.write("#!/usr/bin/env bash\n")
file.write(os.environ.get('SYS_NODE', '/usr/bin/node')+' $0.cjs "$@"\n')
file.write(os.environ.get("SYS_NODE", "/usr/bin/node") + ' $0.cjs "$@"\n')
except Exception as e:
dbg("ERROR: 306", e)
os.rename(AOUT + ".cjs", AOUT)
Expand Down
243 changes: 2 additions & 241 deletions scripts/emsdk-fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -255,248 +255,9 @@ unset _EMCC_CCACHE
unset _PYTHON_SYSCONFIGDATA_NAME
unset PYTHONHOME
unset PYTHONPATH
# if \${PYDK_CC:-false}
if true
then
$EMSDK_PYTHON -E $SDKROOT/emsdk-cc \$0.py "\$@"
exit \$?
fi
# -Wwarn-absolute-paths
# --valid-abspath ${SDKROOT}
# COMMON="-Wno-unsupported-floating-point-opt"
COMMON="-Wno-limited-postlink-optimizations -Wno-unused-command-line-argument -Wno-unreachable-code-fallthrough -Wno-unused-function"
SHARED=""
IS_SHARED=false
PY_MODULE=false
MVP=\${MVP:true}
WASM_PURE=\${WASM_PURE:true}
if \$MVP
then
# turn of wasm ex (https://github.com/emscripten-core/emscripten/pull/20536)
# -fno-wasm-exceptions -sEMSCRIPTEN_LONGJMP=0
# -mcpu=generic would activate those https://reviews.llvm.org/D125728
# https://github.com/emscripten-core/emscripten/pull/17689
# -fPIC not allowed with -mno-mutable-globals
# -mno-sign-ext not allowed with pthread
#WASMOPTS="-fno-wasm-exceptions -sSUPPORT_LONGJMP=emscripten"
#CPU="-mnontrapping-fptoint -mno-reference-types -mno-sign-ext -m32"
# -mno-bulk-memory <= this is problematic 2024-10-26
CPU="-D_FILE_OFFSET_BITS=64 -sSUPPORT_LONGJMP=emscripten -mno-bulk-memory -mnontrapping-fptoint -mno-reference-types -mno-sign-ext -m32"
else
CPU="-D_FILE_OFFSET_BITS=64 -mcpu=bleeding-edge -m64"
fi
# try to keep 32 but with 64 iface (bitint)
WASMEXTRA="$WASM_EXTRA \$WASMOPTS"
LINKING=\${LINKING:-false}
if echo "\$@ "|grep -q "\\.so "
then
LINKING=true
fi
declare -A seen=( )
for arg do
shift
if [ "\$arg" = "-v" ]
then
$EMSDK_PYTHON -E \$0.py -v
exit 0
fi
if [ "\$arg" = "--version" ]
then
$EMSDK_PYTHON -E \$0.py --version
exit 0
fi
if \$LINKING
then
# prevent duplicates objects/archives files on cmdline when linking shared
if echo \$arg|grep -q \\\\.o\$
then
[[ \${seen[\$arg]} ]] && continue
fi
if echo \$arg|grep -q \\\\.a\$
then
[[ \${seen[\$arg]} ]] && continue
fi
if echo \$arg|grep -q ^-l
then
[[ \${seen[\$arg]} ]] && continue
fi
seen[\$arg]=1
fi
arg_is_bad=false
for badarg in "-Wl,--as-needed" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-Wl,-znow" "-Wl,-zrelro" "-Wl,-zrelro,-znow"
do
if [ "\$arg" = "\$badarg" ]
then
arg_is_bad=true
break
fi
done
if \$arg_is_bad
then
continue
fi
if [ "\$arg" = "-c" ]
then
CPU_EXTRA=\$WASM_EXTRA
fi
if [ "\$arg" = "-o" ]
then
CPU_EXTRA=\$WASM_EXTRA
fi
if [ "\$arg" = "-fallow-argument-mismatch" ]
then
continue
fi
if [ "\$arg" = "-lutil" ]
then
continue
fi
if [ "\$arg" = "-O3" ]
then
continue
fi
if [ "\$arg" = "-g" ]
then
continue
fi
if [ "\$arg" = "-lgcc" ]
then
continue
fi
if [ "\$arg" = "-lgcc_s" ]
then
continue
fi
if [ "\$arg" = "-nomvp" ]
then
MVP=false
continue
fi
if [ "\$arg" = "-pthread" ]
then
if echo \$CPU|grep -q mno-sign-ext
then
continue
fi
fi
# that is for some very bad setup.py behaviour regarding cross compiling.
# should not be needed ..
[ "\$arg" = "-I/usr/include" ] && continue
[ "\$arg" = "-I/usr/include/SDL2" ] && continue
[ "\$arg" = "-L/usr/lib64" ] && continue
[ "\$arg" = "-L/usr/lib" ] && continue
[ "\$arg" = "-latomic" ] && continue
if [ "\$arg" = "-shared" ]
then
IS_SHARED=true
SHARED="\$SHARED -sSIDE_MODULE"
fi
if echo "\$arg"|grep -q wasm32-emscripten.so\$
then
PY_MODULE=true
SHARED_TARGET=\$arg
else
if echo "\$arg"|grep -q abi3.so\$
then
PY_MODULE=true
SHARED_TARGET=\$arg
fi
fi
if \$PY_MODULE
then
if \$IS_SHARED
then
true
else
IS_SHARED=true
SHARED="\$SHARED -shared -sSIDE_MODULE"
fi
else
if \$IS_SHARED
then
if echo "\$arg"|grep \\\\.so\$
then
PY_MODULE=true
SHARED_TARGET=\$arg
SHARED="-sSIDE_MODULE"
fi
fi
fi
set -- "\$@" "\$arg"
done
if \$IS_SHARED
then
# always pass CPU opts when linking
$EMSDK_PYTHON -E \$0.py \$SHARED $COPTS \$CPU \$WASM_EXTRA \$LDFLAGS -sSIDE_MODULE -gsource-map --source-map-base / "\$@" \$COMMON
if \$MVP
then
if \$WASM_PURE
then
SOTMP=\$(mktemp).so
mv \$SHARED_TARGET \$SOTMP
# --memory64-lowering --signext-lowering
$SDKROOT/emsdk/upstream/bin/wasm-emscripten-finalize -mvp \$SOTMP -o \$SHARED_TARGET
[ -f \$SHARED_TARGET.map ] && rm \$SHARED_TARGET.map
rm \$SOTMP
fi
fi
else
# do not pass WASM opts when -c/-o but always PIC
if echo $@|grep -q MAIN_MODULE
then
$EMSDK_PYTHON -E \$0.py $COPTS \$CPU \$CPU_EXTRA \$CPPFLAGS -DBUILD_STATIC "\$@" \$COMMON
else
$EMSDK_PYTHON -E \$0.py $COPTS \$CPU_EXTRA \$CPPFLAGS -DBUILD_STATIC "\$@" \$COMMON
fi
fi
#else
# unset _EMCC_CCACHE
# exec ccache "\$0" "\$@"
#fi
$EMSDK_PYTHON -E $SDKROOT/emsdk-cc \$0.py "\$@"
exit \$?
END

rm emsdk/upstream/emscripten/em++
Expand Down
Loading

0 comments on commit aae1349

Please sign in to comment.