Skip to content

Commit c3dbd3c

Browse files
committed
ninja fixes
1 parent 2b0e746 commit c3dbd3c

File tree

8 files changed

+286
-172
lines changed

8 files changed

+286
-172
lines changed

emsdk-cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ if SKIP:
308308
final.extend(sys.argv)
309309
else:
310310
if AOUT:
311-
if CMAKE or CONFIGURE:
311+
if CMAKE or NINJA or RUSTC or CONFIGURE:
312312
EXE = False
313313
# should not happen
314314
elif AOUT.endswith(".o") and "-c" not in out:

scripts/cpython-build-emsdk-prebuilt.sh

Lines changed: 92 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,105 @@ $HPIP install --force ninja
8383
# patch ninja for jobs limit and wrapper detection
8484
# https://github.com/ninja-build/ninja/issues/1482
8585

86-
cat > ${HOST_PREFIX}/bin/ninja <<END
87-
#!${HOST_PREFIX}/bin/python${PYBUILD}
86+
cat > ${HOST_PREFIX}/lib/python${PYBUILD}/site-packages/ninja/__init__.py <<END
87+
from __future__ import annotations
88+
89+
import os
90+
import subprocess
91+
import sys
92+
import sysconfig
93+
from collections.abc import Iterable
94+
from typing import NoReturn
95+
96+
from ._version import version as __version__
97+
from .ninja_syntax import Writer, escape, expand
98+
99+
__all__ = ["BIN_DIR", "DATA", "Writer", "__version__", "escape", "expand", "ninja"]
100+
101+
102+
def __dir__() -> list[str]:
103+
return __all__
104+
105+
106+
def _get_ninja_dir() -> str:
107+
ninja_exe = "ninja" + sysconfig.get_config_var("EXE")
108+
109+
# Default path
110+
path = os.path.join(sysconfig.get_path("scripts"), ninja_exe)
111+
if os.path.isfile(path):
112+
return os.path.dirname(path)
113+
114+
# User path
115+
if sys.version_info >= (3, 10):
116+
user_scheme = sysconfig.get_preferred_scheme("user")
117+
elif os.name == "nt":
118+
user_scheme = "nt_user"
119+
elif sys.platform.startswith("darwin") and getattr(sys, "_framework", None):
120+
user_scheme = "osx_framework_user"
121+
else:
122+
user_scheme = "posix_user"
123+
124+
path = sysconfig.get_path("scripts", scheme=user_scheme)
125+
126+
if os.path.isfile(os.path.join(path, ninja_exe)):
127+
return path
128+
129+
# Fallback to python location
130+
path = os.path.dirname(sys.executable)
131+
if os.path.isfile(os.path.join(path, ninja_exe)):
132+
return path
133+
134+
return ""
135+
136+
137+
BIN_DIR = _get_ninja_dir()
138+
139+
140+
def _program(name: str, args: Iterable[str]) -> int:
141+
cmd = os.path.join('${HOST_PREFIX}/bin', name)
142+
return subprocess.call([cmd, *args], close_fds=False)
143+
144+
def ninja() -> NoReturn:
145+
import os
146+
os.environ['NINJA'] = "1"
147+
if not sys.argv[-1] != "--version":
148+
sys.argv.insert(1,'1')
149+
sys.argv.insert(1,'-j')
150+
# import time
151+
# while os.path.isfile('/tmp/ninja'):
152+
# time.sleep(.5)
153+
# open('/tmp/ninja','w').close()
154+
155+
ret = _program('ninja.real', sys.argv[1:])
156+
# try:
157+
# os.unlink('/tmp/ninja')
158+
# except:
159+
# pass
160+
raise SystemExit(ret)
161+
162+
END
163+
164+
165+
166+
if [ -f $HOST_PREFIX/bin/ninja.real ]
167+
then
168+
echo ninja already patched
169+
else
170+
mv $HOST_PREFIX/bin/ninja $HOST_PREFIX/bin/ninja.real
171+
cat > $HOST_PREFIX/bin/ninja <<END
172+
#!/opt/python-wasm-sdk/devices/x86_64/usr/bin/python3
88173
# -*- coding: utf-8 -*-
89174
import re
90175
import sys
91-
sys.argv.insert(1,'1')
92-
sys.argv.insert(1,'-j')
93-
import os
94-
os.environ['NINJA']="1"
95176
from ninja import ninja
96177
if __name__ == '__main__':
97-
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?\$', '', sys.argv[0])
178+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
98179
sys.exit(ninja())
99180
END
181+
chmod +x $HOST_PREFIX/bin/ninja
182+
fi
183+
184+
100185

101186
echo "
102187
* cpython-build-emsdk-prebuilt pip==$PIP *

scripts/cpython-build-emsdk.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ export PYTHON_FOR_BUILD=${PYTHON_FOR_BUILD:-${HPY}}
1515

1616
. ./scripts/emsdk-fetch.sh
1717

18-
REBUILD_WASM=${REBUILD_WASMPY:-false}
19-
20-
if $REBUILD || $REBUILD_WASMPY
18+
if ${REBUILD_WASMPY:-false}
2119
then
2220
rm -rf build/cpython-wasm/ build/pycache/config.cache
2321
rm build/cpython-wasm/libpython${PYBUILD}.a 2>/dev/null
@@ -130,7 +128,7 @@ echo "
130128

131129

132130

133-
if [ -f build/cpython-wasm/libpython${PYBUILD}.a ]
131+
if [ -f ${SDKROOT}/build/cpython-wasm/libpython${PYBUILD}.a ]
134132
then
135133
echo "
136134
* not rebuilding cpython-wasm for [$PYDK_PYTHON_HOST_PLATFORM]

scripts/cpython-fetch.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,17 @@ fi
7979

8080
if echo $PYBUILD |grep -q 13$
8181
then
82-
wget -q -c https://www.python.org/ftp/python/3.13.1/Python-3.13.1.tar.xz
83-
tar xf Python-3.13.1.tar.xz
82+
if [ -d Python-3.13.1 ]
83+
then
84+
echo " * Using local cpython sources"
85+
else
86+
pwd
87+
ls
88+
echo " * fetching remote cpython sources"
89+
wget -q -c https://www.python.org/ftp/python/3.13.1/Python-3.13.1.tar.xz
90+
tar xf Python-3.13.1.tar.xz || exit 87
91+
fi
92+
8493
ln -s Python-3.13.1 cpython${PYBUILD}
8594

8695
sed -i 's|ProcessPoolExecutor = None|return True|g' cpython3.13/Lib/compileall.py

scripts/emsdk-fetch.sh

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,52 @@ then
66

77
. ${CONFIG:-config}
88

9+
10+
11+
# for full rebuild
12+
# rm emsdk/.complete
13+
914
if [ -d emsdk ]
1015
then
1116
echo "
1217
* using emsdk from $(realpath emsdk)
1318
with sys python $SYS_PYTHON
1419
" 1>&2
1520
else
16-
# emsdk could have been deleted for full rebuild
17-
rm emsdk/.complete
21+
git clone --no-tags --depth 1 --single-branch --branch main https://github.com/emscripten-core/emsdk.git
22+
pushd emsdk
23+
#git checkout 91f8563a9d1a4a0ec03bbb2be23485367d85a091
24+
./emsdk install ${EMFLAVOUR:-latest}
25+
./emsdk activate ${EMFLAVOUR:-latest}
26+
popd
27+
fi
1828

19-
if git clone --no-tags --depth 1 --single-branch --branch main https://github.com/emscripten-core/emsdk.git
20-
then
21-
pushd emsdk
22-
#git checkout 91f8563a9d1a4a0ec03bbb2be23485367d85a091
23-
./emsdk install ${EMFLAVOUR:-latest}
24-
./emsdk activate ${EMFLAVOUR:-latest}
2529

2630

27-
pushd upstream/emscripten
28-
echo "FIXME: applying stdio* are not const"
29-
sed -i 's|extern FILE \*const|extern FILE \*|g' cache/sysroot/include/stdio.h
3031

31-
echo "FIXME: Applying https://github.com/emscripten-core/emscripten/pull/20281 dylink.js : handle ** argument case"
32-
if [ -f test/other/test_em_js_side.c b/test/other/test_em_js_side.c ]
33-
then
34-
wget https://patch-diff.githubusercontent.com/raw/emscripten-core/emscripten/pull/20281.diff
35-
patch -p1 < 20281.diff
36-
else
37-
patch -p1 <<END
32+
33+
if [ -f emsdk/.complete ]
34+
then
35+
echo " * found emsdk/.complete : not patching/building emsdk"
36+
else
37+
pushd emsdk/upstream/emscripten
38+
39+
40+
41+
42+
echo "FIXME: applying stdio* are not const"
43+
sed -i 's|extern FILE \*const|extern FILE \*|g' cache/sysroot/include/stdio.h
44+
45+
46+
47+
48+
echo "FIXME: Applying https://github.com/emscripten-core/emscripten/pull/20281 dylink.js : handle ** argument case"
49+
if [ -f test/other/test_em_js_side.c b/test/other/test_em_js_side.c ]
50+
then
51+
wget https://patch-diff.githubusercontent.com/raw/emscripten-core/emscripten/pull/20281.diff
52+
patch -p1 < 20281.diff
53+
else
54+
patch -p1 <<END
3855
diff --git a/src/library_dylink.js b/src/library_dylink.js
3956
index 632e20aa61e3..ebb13995d6c3 100644
4057
--- a/src/library_dylink.js
@@ -50,28 +67,30 @@ index 632e20aa61e3..ebb13995d6c3 100644
5067
var func = `(${jsArgs}) => ${body};`;
5168
END
5269

53-
fi
54-
echo "FIXME: Applying https://github.com/emscripten-core/emscripten/pull/17956 file corruption when using emscripten_run_preload_plugins with BrowserFS"
55-
wget https://patch-diff.githubusercontent.com/raw/emscripten-core/emscripten/pull/17956.diff
56-
57-
if patch -p1 < 17956.diff
58-
then
59-
echo applied https://github.com/emscripten-core/emscripten/pull/17956
60-
# 18941 has been merged
61-
else
62-
# deal with old version of emsdk for the above 3.1.45 patch
63-
sed -i 's|new Uint8Array(data.object.contents), true, true|FS.readFile(_file), true, true|g' src/library_browser.js
64-
# merged since 3.1.34 which quite the more stable atm
65-
#echo "MAYBE FIXME: Applying https://github.com/emscripten-core/emscripten/pull/18941"
66-
#wget https://patch-diff.githubusercontent.com/raw/emscripten-core/emscripten/pull/18941.diff
67-
#patch -p1 < 18941.diff
68-
fi
69-
popd
70+
fi
71+
72+
73+
echo "FIXME: Applying https://github.com/emscripten-core/emscripten/pull/17956 file corruption when using emscripten_run_preload_plugins with BrowserFS"
74+
wget https://patch-diff.githubusercontent.com/raw/emscripten-core/emscripten/pull/17956.diff
75+
76+
if patch -p1 < 17956.diff
77+
then
78+
echo applied https://github.com/emscripten-core/emscripten/pull/17956
79+
# 18941 has been merged
80+
else
81+
# deal with old version of emsdk for the above 3.1.45 patch
82+
sed -i 's|new Uint8Array(data.object.contents), true, true|FS.readFile(_file), true, true|g' src/library_browser.js
83+
# merged since 3.1.34 which quite the more stable atm
84+
#echo "MAYBE FIXME: Applying https://github.com/emscripten-core/emscripten/pull/18941"
85+
#wget https://patch-diff.githubusercontent.com/raw/emscripten-core/emscripten/pull/18941.diff
86+
#patch -p1 < 18941.diff
87+
fi
88+
popd # emsdk/upstream/emscripten
7089

7190
# wget https://raw.githubusercontent.com/paradust7/minetest-wasm/main/emsdk_emcc.patch
7291
# patch -p1 < emsdk_emcc.patch
7392

74-
pushd upstream/emscripten
93+
pushd upstream/emscripten
7594
echo "FIXME: Applying https://github.com/emscripten-core/emscripten/pull/21472 glfw3: gl level version major/minor hints"
7695
wget https://patch-diff.githubusercontent.com/raw/emscripten-core/emscripten/pull/21472.diff
7796
patch -p1 < 21472.diff
@@ -94,12 +113,12 @@ fi
94113
#echo "FIXME: scriptDirectory workaround" MERGER
95114
#wget https://patch-diff.githubusercontent.com/raw/emscripten-core/emscripten/pull/22605.diff
96115
#patch -p1 < 22605.diff
97-
popd
116+
popd # upstream/emscripten
98117

99118

100119

101-
# https://github.com/paradust7/minetest-wasm/blob/main/emsdk_dirperms.patch
102-
patch -p1 <<END
120+
# https://github.com/paradust7/minetest-wasm/blob/main/emsdk_dirperms.patch
121+
patch -p1 <<END
103122
--- emsdk-orig/upstream/emscripten/system/lib/wasmfs/wasmfs.cpp 2022-07-29 17:22:28.000000000 +0000
104123
+++ emsdk/upstream/emscripten/system/lib/wasmfs/wasmfs.cpp 2022-08-06 02:07:24.098196400 +0000
105124
@@ -141,7 +141,7 @@
@@ -133,8 +152,8 @@ END
133152
#END
134153

135154

136-
# https://raw.githubusercontent.com/paradust7/minetest-wasm/main/emsdk_setlk.patch
137-
patch -p1 << END
155+
# https://raw.githubusercontent.com/paradust7/minetest-wasm/main/emsdk_setlk.patch
156+
patch -p1 << END
138157
--- emsdk-orig/upstream/emscripten/system/lib/wasmfs/syscalls.cpp 2022-07-29 17:22:28.000000000 +0000
139158
+++ emsdk/upstream/emscripten/system/lib/wasmfs/syscalls.cpp 2022-08-06 05:05:17.014502697 +0000
140159
@@ -1419,7 +1419,7 @@
@@ -148,12 +167,7 @@ END
148167
case F_SETOWN:
149168
END
150169

151-
152-
153-
154-
popd
155-
fi
156-
fi
170+
fi # emsdk/.complete
157171

158172
export EMSDK_PYTHON=$SYS_PYTHON
159173

sources.extra/1000-glib.sh renamed to sources.extra/1900-glib.sh

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55

66
. ${CONFIG:-config}
77

8-
if which meson
9-
then
10-
echo meson found $(which meson)
11-
else
12-
$HPY -m pip install meson
13-
fi
14-
158
. scripts/emsdk-fetch.sh
169

1710
if pushd ${ROOT}/src
@@ -46,8 +39,7 @@ then
4639
done
4740

4841
# Common compiler flags
49-
export CFLAGS="-O3"
50-
export CXXFLAGS="$CFLAGS"
42+
export COPTS="-Os -g0"
5143
export LDFLAGS="-L$PREFIX/lib"
5244

5345

@@ -138,14 +130,37 @@ cpu_family = 'wasm32'
138130
cpu = 'wasm32'
139131
endian = 'little'
140132
141-
[ninja]
133+
[backend]
142134
backend_max_links = 1
143135
144136
END
145137

146-
meson setup _build --prefix=$PREFIX --cross-file=emscripten-crossfile.meson --default-library=static --buildtype=release \
138+
echo "
139+
140+
141+
============ MESON SETUP $(which ninja) =========================
142+
143+
144+
"
145+
meson setup _build --reconfigure --prefix=$PREFIX --cross-file=emscripten-crossfile.meson --default-library=static --buildtype=minsize \
147146
--force-fallback-for=pcre2,gvdb -Dselinux=disabled -Dxattr=false -Dlibmount=disabled -Dnls=disabled \
148147
-Dtests=false -Dglib_assert=false -Dglib_checks=false
148+
echo "
149+
150+
151+
============ MESON COMPILE =========================
152+
153+
154+
"
155+
# meson compile _build -j 1
156+
echo "
157+
158+
159+
============ MESON INSTALL =========================
160+
161+
162+
"
163+
149164
meson install -C _build --tag devel
150165
popd # glib
151166
popd # src

0 commit comments

Comments
 (0)