Skip to content

Commit 6206129

Browse files
committed
Updated tinycc compile script to remove some errors, added documentation and copying to build folder of app repo
1 parent e8e4284 commit 6206129

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

tinycc/compile_tinycc.sh

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,60 @@
11
#!/bin/bash
22

3+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
APPS_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
5+
6+
# Default LIND_WASM_ROOT to parent directory (layout: lind-wasm/lind-wasm-apps)
7+
if [[ -z "${LIND_WASM_ROOT:-}" ]]; then
8+
LIND_WASM_ROOT="$(cd "$APPS_ROOT/.." && pwd)"
9+
fi
10+
SYSROOT="${LIND_WASM_ROOT}/build/sysroot"
11+
LINDFS="${LIND_WASM_ROOT}/lindfs"
12+
LIND_BOOT="${LIND_WASM_ROOT}/src/lind-boot/target/debug/lind-boot"
13+
14+
CLANG_BIN="${LIND_WASM_ROOT}/clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04/bin/clang"
15+
16+
CFLAGS_WASM="--target=wasm32-wasi -g -O0 --sysroot=$SYSROOT -pthread -matomics -mbulk-memory -fno-pie -fvisibility=default -fno-builtin"
17+
18+
LDFLAGS_WASM="--target=wasm32-wasi -g -O0 --sysroot=$SYSROOT -static -Wl,--import-memory,--export-memory,--shared-memory,--max-memory=67108864,--export="__stack_pointer",--export=__stack_low,--export=__tls_base"
19+
20+
cd $SCRIPT_DIR
21+
322
./configure \
423
--cpu=i386 \
5-
--cc="/home/lind/lind-wasm/clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04/bin/clang" \
6-
--extra-cflags="--target=wasm32-wasi -g -O0 --sysroot=/home/lind/lind-wasm/build/sysroot -pthread -matomics -mbulk-memory -fno-pie -fvisibility=default -fno-builtin" \
7-
--extra-ldflags="--target=wasm32-wasi -g -O0 --sysroot=/home/lind/lind-wasm/build/sysroot -static -Wl,--import-memory,--export-memory,--shared-memory,--max-memory=67108864,--export="__stack_pointer",--export=__stack_low,--export=__tls_base" \
24+
--cc=$CLANG_BIN \
25+
--extra-cflags="$CFLAGS_WASM" \
26+
--extra-ldflags="$LDFLAGS_WASM" \
827
--enable-static --enable-cross --extra-libs=""
928

1029
echo "CONFIG_ldl=no" >> config.mak
1130

12-
make
31+
make tcc
32+
33+
if [ -f "tcc" ]; then
34+
mv tcc tcc.wasm
35+
else
36+
echo "Error: tcc binary was not generated!"
37+
exit 1
38+
fi
1339

1440
# use gcc to compile libtcc1.c to object file, then archive it into a static library
41+
# `libtcc1` is used by tinycc wasm binary for compiling C programs. Hence `libtcc1` is compiled as an x86 ELF binary in align with the target architecture of tinycc
1542
gcc -m32 -O2 -DTCC_TARGET_I386 -c lib/libtcc1.c -o libtcc1.o
1643
ar rcs libtcc1.a libtcc1.o
1744

1845
# opt and precompile
19-
lind_compile --opt-only tcc.wasm -o tcc.cwasm
20-
lind_compile --precompile-only tcc.wasm -o tcc.cwasm
46+
echo "Precompiling"
47+
lind_compile --opt-only tcc.wasm -o tcc.opt.wasm
48+
if [ -s "tcc.opt.wasm" ]; then
49+
echo "Generating cwasm from opt.wasm"
50+
lind_compile --precompile-only tcc.opt.wasm -o tcc.cwasm
51+
else
52+
echo "Generating cwasm from wasm"
53+
lind_compile --precompile-only tcc.wasm -o tcc.cwasm
54+
fi
2155

22-
# copy
23-
mkdir -p /home/lind/lind-wasm/lindfs/usr/local/lib/tcc/
24-
cp tcc.cwasm ../lindfs/
25-
cp libtcc1.a /home/lind/lind-wasm/lindfs/usr/local/lib/tcc/
56+
# copy to app build folder preserving the directory structure
57+
mkdir -p $APPS_ROOT/build/tinycc/bin
58+
mkdir -p $APPS_ROOT/build/usr/local/bin/tcc/
59+
cp tcc.cwasm $APPS_ROOT/build/tinycc/bin
60+
cp libtcc1.a $APPS_ROOT/build/usr/local/bin/tcc/

0 commit comments

Comments
 (0)