Skip to content

Commit 629b4a1

Browse files
committed
4.0.4pre
1 parent 4c2b77e commit 629b4a1

File tree

7 files changed

+328
-9
lines changed

7 files changed

+328
-9
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
rustsdk: false
2727
nimsdk: false
2828
COPTS: -O2 -g3
29-
EMFLAVOUR: 3.1.61
29+
EMFLAVOUR: 4.0.4
3030

3131
steps:
3232
- uses: actions/checkout@v4.2.2

emsdk-cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ COPTS = env("COPTS", "-O2 -g3")
137137
LOPTS = env("LOPTS", COPTS)
138138

139139

140-
SIZEOPT = "-Os" in LOPTS
140+
SIZEOPT = ("-Os" in LOPTS) or ("-Oz" in LOPTS)
141+
141142

142143
MAIN_MODULE = LINKING = STATIC = False
143144

@@ -294,8 +295,9 @@ else:
294295
dbg("WARNING maybe should use static here :", arg)
295296
# raise SystemExit(666)
296297

297-
# TODO check is -shared implies -sSIDE_MODULE=1
298298
elif arg == "-shared":
299+
# to get -sSIDE_MODULE=1
300+
LINKING = True
299301
IS_SHARED = True
300302
MAIN_MODULE = False
301303
continue
@@ -485,7 +487,7 @@ if EMCC_TRACE:
485487

486488
sys.argv.append(arg)
487489

488-
# for debugging configure, as cmake has its own very detailed log.
490+
# only for debugging configure, as cmake has its own very detailed log.
489491
if os.path.isfile("conftest.c"):
490492
__import__("shutil").copy("conftest.c", SDKROOT / "emcc.c")
491493
if DEBUG_PATTERN not in (False, True):

python-wasi-sdk.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,12 @@ END
216216
fi
217217

218218
# use ./ or emsdk will pollute env
219-
./scripts/emsdk-fetch.sh
219+
if echo $EMFLAVOUR|grep -q ^3\\.
220+
then
221+
./scripts/emsdk-fetch.sh
222+
else
223+
./scripts/emsdk-fetch4.sh
224+
fi
220225
# > /dev/null
221226

222227
echo " ---------- building cpython wasm support ${PYBUILD} ${CIVER} -----------" 1>&2

python-wasm-sdk.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,12 @@ END
216216
fi
217217

218218
# use ./ or emsdk will pollute env
219-
./scripts/emsdk-fetch.sh
219+
if echo $EMFLAVOUR|grep -q ^3\\.
220+
then
221+
./scripts/emsdk-fetch.sh
222+
else
223+
./scripts/emsdk-fetch4.sh
224+
fi
220225
# > /dev/null
221226

222227
echo " ---------- building cpython wasm support ${PYBUILD} ${CIVER} -----------" 1>&2

sources.wasm/8000-sdl_image.sh renamed to scripts/emsdk-fetch-sdl2.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/bin/bash
22

3-
. ${CONFIG:-config}
4-
5-
. scripts/emsdk-fetch.sh
3+
# . ${CONFIG:-config}
4+
# . scripts/emsdk-fetch.sh
65

76

87
cd ${ROOT}/src

scripts/emsdk-fetch-sdl3.sh

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
. ${SDKROOT}/config
4+
5+
sdl_get () {
6+
wget -c -q $1/$2
7+
tar xfz $2 && rm $2
8+
}
9+
10+
if [ -d ${SDKROOT}/src/SDL3-3.2.4 ]
11+
then
12+
echo using local files SDKROOT=$SDKROOT PREFIX=$PREFIX
13+
else
14+
mkdir -p ${SDKROOT}/src
15+
pushd ${SDKROOT}/src
16+
sdl_get https://github.com/libsdl-org/SDL/releases/download/release-3.2.4 SDL3-3.2.4.tar.gz
17+
sdl_get https://github.com/libsdl-org/SDL_image/releases/download/release-3.2.0 SDL3_image-3.2.0.tar.gz
18+
sdl_get https://github.com/libsdl-org/SDL_ttf/releases/download/prerelease-3.1.2 SDL3_ttf-3.1.2.tar.gz
19+
popd
20+
fi
21+
22+
. ${SDKROOT}/emsdk/emsdk_env.sh
23+
24+
export SDL3_DIR=${SDKROOT}/build/SDL3
25+
mkdir -p ${SDL3_DIR}
26+
pushd ${SDL3_DIR}
27+
28+
# embuilder --pic sdl3
29+
# "SDL", "SDL_image", "SDL_mixer", "SDL_ttf", "SDL_rtf", "SDL_net"
30+
31+
32+
if ( emcmake cmake -DEMSCRIPTEN=1 -DSDL_VIDEO_DRIVER_DUMMY=1 \
33+
-DCMAKE_INSTALL_PREFIX=${PREFIX} \
34+
-DSDL_STATIC_PIC=True \
35+
-DCMAKE_POSITION_INDEPENDENT_CODE=True \
36+
../../src/SDL3-3.?.? && emmake make install )
37+
then
38+
mkdir -p ${SDKROOT}/build/SDL3_image
39+
pushd ${SDKROOT}/build/SDL3_image
40+
41+
if emcmake cmake -DSDL3_DIR=${SDL3_DIR} \
42+
-DCMAKE_INSTALL_PREFIX=${PREFIX} \
43+
-DSDL_STATIC_PIC=True \
44+
-DCMAKE_POSITION_INDEPENDENT_CODE=True \
45+
../../src/SDL3_image-3.?.?
46+
then
47+
emmake make install
48+
fi
49+
50+
popd
51+
52+
53+
mkdir -p ${SDKROOT}/build/SDL3_ttf
54+
pushd ${SDKROOT}/build/SDL3_ttf
55+
56+
if emcmake cmake -DSDL3_DIR=${SDL3_DIR} \
57+
-DCMAKE_INSTALL_PREFIX=${PREFIX} \
58+
-DSDL_STATIC_PIC=True \
59+
-DCMAKE_POSITION_INDEPENDENT_CODE=True \
60+
../../src/SDL3_ttf-3.?.?
61+
then
62+
EMCC_CFLAGS="-lz" emmake make install
63+
fi
64+
65+
popd
66+
else
67+
echo ERROR
68+
exit 66
69+
fi
70+
popd
71+

scripts/emsdk-fetch4.sh

+237
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
#!/bin/bash
2+
3+
if [[ -z ${EMSDK+z} ]]
4+
then
5+
pushd ${SDKROOT:-/opt/python-wasm-sdk}
6+
7+
. ${CONFIG:-config}
8+
9+
# for full rebuild
10+
# rm emsdk/.complete
11+
12+
if [ -d emsdk ]
13+
then
14+
echo "
15+
* using emsdk from $(realpath emsdk)
16+
with sys python $SYS_PYTHON
17+
" 1>&2
18+
else
19+
git clone --no-tags --depth 1 --single-branch --branch main https://github.com/emscripten-core/emsdk.git
20+
pushd emsdk
21+
./emsdk install ${EMFLAVOUR:-latest}
22+
./emsdk activate ${EMFLAVOUR:-latest}
23+
popd
24+
fi
25+
26+
27+
if [ -f emsdk/.complete ]
28+
then
29+
echo " * found emsdk/.complete : not patching/building emsdk"
30+
else
31+
pushd emsdk
32+
pushd upstream/emscripten
33+
popd # upstream/emscripten
34+
popd # emsdk
35+
fi # emsdk/.complete
36+
37+
export EMSDK_PYTHON=$SYS_PYTHON
38+
39+
if [ -f ${SDKROOT}/emsdk/emsdk_env.sh ]
40+
then
41+
echo "
42+
* activating emsdk via emsdk_env.sh with EMSDK_PYTHON=$EMSDK_PYTHON
43+
" 1>&2
44+
. ${SDKROOT}/emsdk/emsdk_env.sh
45+
46+
else
47+
echo "
48+
ERROR cannot find emsdk/emsdk_env.sh in $(pwd)
49+
" 1>&2
50+
exit 41
51+
fi
52+
53+
# EMSDK_PYTHON may have been cleared, restore it
54+
export EMSDK_PYTHON=$SYS_PYTHON
55+
56+
if [ -f emsdk/.complete ]
57+
then
58+
echo "
59+
* emsdk third parties ok
60+
" 1>&2
61+
else
62+
# sdl2_image is too old
63+
ALL="libembind libgl libal libhtml5 libstubs libnoexit libsockets"
64+
ALL="$ALL libc libdlmalloc libcompiler_rt libc++-noexcept libc++abi-noexcept"
65+
ALL="$ALL libfetch zlib bzip2 libpng libjpeg freetype harfbuzz"
66+
ALL="$ALL sqlite3 vorbis ogg"
67+
68+
if echo $EMFLAVOUR|grep -q tot
69+
then
70+
SDL3=true
71+
echo "
72+
* using SDL3
73+
"
74+
else
75+
SDL3=false
76+
echo "
77+
* using SDL2
78+
"
79+
ALL="$ALL sdl2 sdl2_mixer sdl2_gfx sdl2_ttf"
80+
fi
81+
82+
echo "
83+
* building third parties libraries for emsdk ( can take time ... )
84+
" 1>&2
85+
86+
for one in $ALL
87+
do
88+
echo "
89+
+ $done
90+
" 1>&2
91+
embuilder build $one
92+
embuilder --pic build $one
93+
done
94+
95+
96+
if $SDL3
97+
then
98+
#=============================================================================================================================
99+
./scripts/emsdk-fetch-sdl3.sh
100+
#=============================================================================================================================
101+
else
102+
#=============================================================================================================================
103+
./scripts/emsdk-fetch-sdl2.sh
104+
#=============================================================================================================================
105+
fi # SDL3
106+
107+
108+
echo "
109+
* building third parties done, mark is emsdk/.complete )
110+
" 1>&2
111+
112+
113+
export PATH=$(echo -n ${SDKROOT}/emsdk/node/??.??.*/bin):$PATH
114+
115+
cat > emsdk/upstream/emscripten/emcc <<END
116+
#!/bin/bash
117+
118+
EMCC_TRACE=\${EMCC_TRACE:-false}
119+
if \$EMCC_TRACE
120+
then
121+
echo "
122+
\$0 \$@" >> $SDKROOT/emcc.log
123+
fi
124+
125+
unset _EMCC_CCACHE
126+
unset _PYTHON_SYSCONFIGDATA_NAME
127+
unset PYTHONHOME
128+
unset PYTHONPATH
129+
130+
$SYS_PYTHON -E $SDKROOT/emsdk-cc \$0.py "\$@"
131+
exit \$?
132+
END
133+
134+
rm emsdk/upstream/emscripten/em++
135+
if ln emsdk/upstream/emscripten/emcc emsdk/upstream/emscripten/em++
136+
then
137+
# cmake usually wants cc
138+
ln emsdk/upstream/emscripten/emcc emsdk/upstream/emscripten/cc
139+
ln emsdk/upstream/emscripten/emcc.py emsdk/upstream/emscripten/cc.py
140+
else
141+
echo "
142+
143+
============ hard link not supported ==============
144+
145+
146+
"
147+
cat emsdk/upstream/emscripten/emcc > emsdk/upstream/emscripten/em++
148+
cat emsdk/upstream/emscripten/emcc > emsdk/upstream/emscripten/cc
149+
cat emsdk/upstream/emscripten/emcc.py > emsdk/upstream/emscripten/cc.py
150+
fi
151+
152+
cat > emsdk/upstream/emscripten/emar <<END
153+
#!/bin/bash
154+
155+
unset _PYTHON_SYSCONFIGDATA_NAME
156+
unset PYTHONHOME
157+
unset PYTHONPATH
158+
159+
$SYS_PYTHON -E \$0.py "\$@"
160+
END
161+
162+
cat emsdk/upstream/emscripten/emar > emsdk/upstream/emscripten/emcmake
163+
164+
cat > emsdk/upstream/emscripten/emconfigure <<END
165+
#!/bin/bash
166+
$SYS_PYTHON -E \$0.py "\$@"
167+
END
168+
169+
chmod +x emsdk/upstream/emscripten/em*
170+
touch emsdk/.complete
171+
fi
172+
173+
# EM_PKG_CONFIG_PATH ?
174+
# https://emscripten.org/docs/compiling/Building-Projects.html#pkg-config
175+
176+
# export PKG_CONFIG_SYSROOT_DIR="${SDKROOT}/devices/emsdk"
177+
export PKG_CONFIG_LIBDIR="${SDKROOT}/emsdk/upstream/emscripten/system/lib/pkgconfig"
178+
export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig:${HOST_PREFIX}/lib/pkgconfig"
179+
export EM_PKG_CONFIG_PATH=$PKG_CONFIG_PATH
180+
181+
if echo $PATH|grep -q $EMSDK/upstream/emscripten/system/bin
182+
then
183+
# emsdk env does not set it, but it's required for eg sdl2-config
184+
echo -n
185+
else
186+
export PATH=$(echo -n ${EMSDK}/node/??.??.*/bin):$EMSDK/upstream/emscripten/system/bin:$EMSDK/upstream/emscripten:$PATH
187+
fi
188+
189+
echo "
190+
* installing wasm-objdump (wasi)
191+
"
192+
mkdir -p ${SDKROOT}/devices/$(arch)/usr/bin/
193+
cp $SDKROOT/wasisdk/bin/wasm-objdump* ${SDKROOT}/devices/$(arch)/usr/bin/
194+
195+
196+
197+
198+
TRUE=$(which true)
199+
echo "
200+
* pointing readelf and ldconfig to ${TRUE}
201+
"
202+
for fix in readelf ldconfig
203+
do
204+
FIXED=$EMSDK/upstream/emscripten/system/bin/$fix
205+
[ -f $FIXED ] || cp $TRUE $FIXED
206+
done
207+
208+
209+
210+
# emsdk shipped node cannot run on alpine
211+
export SYS_NODE=$(echo -n $SDKROOT/emsdk/node/??.??.*/bin/node)
212+
if [ -f /alpine ]
213+
then
214+
if [ -f $SYS_NODE.glibc ]
215+
then
216+
echo "node alpine node version already selected"
217+
else
218+
mv $SYS_NODE $SYS_NODE.glibc
219+
cp -vf /usr/bin/node $SYS_NODE
220+
fi
221+
fi
222+
223+
export NPROC=1
224+
export EMSDK_NUM_CORES=$NPROC
225+
226+
mkdir -p src
227+
export SYSROOT=$EMSDK/upstream/emscripten/cache/sysroot
228+
popd # ${SDKROOT:-/opt/python-wasm-sdk}
229+
230+
echo "
231+
will use node = $SYS_NODE
232+
sysroot = $SYSROOT
233+
"
234+
else
235+
echo "emsdk: already fetched and config set !" 1>&2
236+
fi
237+

0 commit comments

Comments
 (0)