-
Notifications
You must be signed in to change notification settings - Fork 0
/
python-nim-sdk.sh
executable file
·194 lines (140 loc) · 4.23 KB
/
python-nim-sdk.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/bash
SDKROOT=${SDKROOT:-/opt/python-wasm-sdk}
CONFIG=$(realpath ${CONFIG:-${SDKROOT}/config})
. $CONFIG
if [ -d ${NIMSDK} ]
then
echo "
will not overwrite existing working directory
NIMSDK=${NIMSDK}
"
else
mkdir ${NIMSDK}
fi
pushd ${NIMSDK}
if [ -d $NIM_VERSION/bin ]
then
echo "
will not overwrite existing Nim build found in
${NIMSDK}/$NIM_VERSION/bin
"
else
if echo $NIM_URL|grep -q nim-lang\.org
then
echo ERROR download/install release from $NIM_URL
else
$GITGET devel $NIM_URL $NIM_VERSION
pushd $NIM_VERSION
chmod +x *sh
CC=clang CXX=clang++ ./build_all.sh
rm -rf build csources_v2 nimcache
popd
fi
fi
# --usenimcache
mkdir -p ${NIMSDK}/nim
cat > ${NIMSDK}/nim/config.nims <<END
echo " ==== python-nim-sdk ======"
import std/strformat
var ARCH="$(arch)"
var SDKROOT = getEnv("SDKROOT","${SDKROOT}")
--colors:on
--define:release
echo fmt" ==== Panda3D: generic config {ARCH=} from {SDKROOT=} ===="
--cc:clang
--os:linux
--threads:off
#--noCppExceptions
--exceptions:quirky
--define:noCppExceptions
--define:usemalloc
# gc : bohem => need libgc.so.1
--mm:orc
#--define:noSignalHandler
#
--define:static
# better debug but optionnal/tweakable
--parallelBuild:1
--opt:none
--define:debug
when defined(wasi):
echo " ===== Panda3D: wasi build ======"
# overwrite
ARCH="wasisdk"
# needed for compiler
--cc:clang
--os:linux
--define:emscripten
--define:static
--cpu:wasm32
switch("clibdir", fmt"{SDKROOT}/devices/{ARCH}/usr/lib/wasm32-wasi")
# more compat but in the long term workaround Panda3D instead
# wasi emulations
switch("passC", "-D_GNU_SOURCE")
switch("passC", "-D_WASI_EMULATED_MMAN -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_GETPID")
switch("passL", "-lwasi-emulated-getpid -lwasi-emulated-mman -lwasi-emulated-signal -lwasi-emulated-process-clocks")
switch("passL","-lstdc++")
when defined(app):
echo " @@@@@ APP MODE @@@@@"
# switch("passL", "-Wl,--no-entry")
# switch("passL", "-Wl,--no-entry,--export-all -mexec-model=reactor")
--noMain
else:
# don't use _start/main but _initialize instead
switch("passL", "-Wl,--no-entry,--export-all -mexec-model=reactor")
# component model aka reactor
--noMain
# FIXME
switch("passC", fmt"-m32 -Djmp_buf=int")
# better debug but optionnal/tweakable
# switch("passC", "-O0 -g3 -mllvm -inline-threshold=1")
--parallelBuild:1
--opt:none
else:
echo fmt" ===== Panda3D: native {ARCH} build ======"
switch("passL", "-lfreetype -lharfbuzz")
# -lfftw3 -lassimp")
# static
switch("passL", "-lp3tinydisplay")
# common
switch("passL", "-lc -lz")
# only for script gen which does not pass cincludes
# --passC:-I/opt/python-wasm-sdk/devices/${ARCH}/usr/include/panda3d
# --passL:-L${SDKROOT}/devices/${ARCH}/usr/lib
switch("nimcache", fmt"{SDKROOT}/nimsdk/cache.{ARCH}")
switch("clibdir", fmt"{SDKROOT}/devices/{ARCH}/usr/lib")
switch("cincludes", fmt"{SDKROOT}/devices/{ARCH}/usr/include/panda3d")
switch("out", fmt"out.{ARCH}")
END
cat > nimsdk_env.sh <<END
if [[ -z \${NIMSDK_ENV+z} ]]
then
export NIMSDK_ENV=true
export SDKROOT=$SDKROOT
. $CONFIG
. $WASISDK/wasisdk_env.sh
export XDG_CONFIG_HOME=${NIMSDK}
export NIMBLE_DIR=${NIMSDK}/pkg
export PATH=${NIMSDK}/${NIM_VERSION}/bin:\$PATH
echo "
* using nimsdk from \$(realpath \${NIMSDK}/\${NIM_VERSION}/bin)
with sys python \$SYS_PYTHON and host python \$HPY
toolchain file CMAKE_TOOLCHAIN_FILE=\${CMAKE_TOOLCHAIN_FILE}
install prefix PREFIX=\${PREFIX}
Nim from $NIMSDK/$NIM_VERSION/bin
SDKROOT=$SDKROOT
NIMSDK=$NIMSDK
NIMBLE_DIR=\$NIMBLE_DIR
PATH=\$PATH
clang=\$(which clang)
clang++=\$(which clang++)
"
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="[PyDK:nim] \[\e[32m\]\w \[\e[91m\]\$(parse_git_branch)\[\e[00m\]\$ "
else
echo "nimsdk: config already set !" 1>&2
fi
END
popd