-
Notifications
You must be signed in to change notification settings - Fork 0
update build script for lmbench #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| if command -v apt >/dev/null 2>&1; then | ||
| echo "[INFO] Installing autoconf, automake, libtool..." | ||
| apt update | ||
| apt install -y autoconf automake libtool | ||
| fi | ||
|
|
||
| if [ -f ./autogen.sh ]; then | ||
| chmod +x autogen.sh | ||
| ./autogen.sh | ||
| fi | ||
|
|
||
| export AR=/home/lind/lind-wasm/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin/llvm-ar | ||
| export CC="/home/lind/lind-wasm/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin/clang --target=wasm32-unknown-wasi" | ||
| export CXX="/home/lind/lind-wasm/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin/clang++ --target=wasm32-unknown-wasi" | ||
| export LD=/home/lind/lind-wasm/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin/wasm-ld | ||
|
|
||
| export SYSROOT="/home/lind/lind-wasm/src/glibc/sysroot" | ||
| export CFLAGS="--sysroot=$SYSROOT -g -O2" | ||
| export CXXFLAGS="--sysroot=$SYSROOT -g -O2" | ||
| export LDFLAGS="--sysroot=$SYSROOT -Wl,--import-memory,--export-memory,--max-memory=67108864,--export=__stack_pointer,--export=__stack_low" | ||
|
|
||
| ./configure --host=wasm32-unknown-wasi --disable-gssapi \ | ||
| --disable-shared \ | ||
| --enable-static \ | ||
| --with-pic \ | ||
| --sysconfdir=/etc \ | ||
| ac_cv_func_malloc_0_nonnull=yes \ | ||
| ac_cv_func_memset=yes \ | ||
| ac_cv_func_strchr=yes | ||
|
|
||
| make | ||
|
|
||
| echo "[INFO] Moving .o files to sysroot merge_tmp..." | ||
|
|
||
| mkdir -p /home/lind/lind-wasm/src/glibc/sysroot/lib/wasm32-wasi/merge_tmp | ||
|
||
| find src -name '*.o' -exec mv {} /home/lind/lind-wasm/src/glibc/sysroot/lib/wasm32-wasi/merge_tmp/ \; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| echo "[STEP 1] Copy TIRPC headers to sysroot..." | ||
| mkdir -p /home/lind/lind-wasm/src/glibc/sysroot/include/wasm32-wasi/rpc | ||
| sudo cp -r /usr/include/tirpc/rpc/* /home/lind/lind-wasm/src/glibc/sysroot/include/wasm32-wasi/rpc/ | ||
| sudo cp /usr/include/tirpc/netconfig.h /home/lind/lind-wasm/src/glibc/sysroot/include/wasm32-wasi/ | ||
|
|
||
| echo "[STEP 2] Ensure output directory is owned by current user..." | ||
| sudo mkdir -p /home/lind/lind-wasm/src/glibc/sysroot/lib/wasm32-wasi/merge_tmp | ||
| sudo chown -R "$(whoami)" /home/lind/lind-wasm/src/glibc/sysroot/lib/wasm32-wasi/merge_tmp | ||
|
|
||
| echo "[STEP 3] Compile lib_*.c and getopt.c to wasm .o files..." | ||
| SRC_DIR="/home/lind/lind-wasm/lind-wasm-apps/lmbench/src" | ||
| OUT_DIR="/home/lind/lind-wasm/src/glibc/sysroot/lib/wasm32-wasi/merge_tmp" | ||
| CLANG="/home/lind/lind-wasm/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin/clang" | ||
| SYSROOT="/home/lind/lind-wasm/src/glibc/sysroot" | ||
|
|
||
| for f in "$SRC_DIR"/lib_*.c "$SRC_DIR"/getopt.c; do | ||
| fname=$(basename "$f" .c) | ||
| echo "Compiling $fname.c ..." | ||
| if [[ "$fname" == "lib_sched" ]]; then | ||
| "$CLANG" --target=wasm32-unknown-wasi --sysroot="$SYSROOT" \ | ||
| -O2 -g -Wno-return-type -c "$f" -o "$OUT_DIR/$fname.o" | ||
| else | ||
| "$CLANG" --target=wasm32-unknown-wasi --sysroot="$SYSROOT" \ | ||
| -O2 -g -c "$f" -o "$OUT_DIR/$fname.o" | ||
| fi | ||
| done | ||
|
|
||
| echo "[STEP 4] Extract original libc.a objects into merge_tmp..." | ||
| LLVM_AR="/home/lind/lind-wasm/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin/llvm-ar" | ||
| LIBC_A="$SYSROOT/lib/wasm32-wasi/libc.a" | ||
|
|
||
| cd "$OUT_DIR" | ||
| "$LLVM_AR" x "$LIBC_A" | ||
|
|
||
| echo "[STEP 5] Delete current libc.a..." | ||
| sudo rm -f "$LIBC_A" | ||
| echo "Deleted libc.a" | ||
|
|
||
| echo "[STEP 6] Rebuild libc.a from all .o files..." | ||
| sudo "$LLVM_AR" rcs "$LIBC_A" "$OUT_DIR"/*.o | ||
|
|
||
| echo "[STEP 7] Run ranlib..." | ||
| sudo /home/lind/lind-wasm/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin/llvm-ranlib "$LIBC_A" | ||
|
|
||
| echo "[DONE] libc.a rebuilt with merged .o files." | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #!/bin/bash | ||
| set +e | ||
|
|
||
| CLANG="/home/lind/lind-wasm/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin/clang" | ||
| WASM_OPT="/home/lind/lind-wasm/tools/binaryen/bin/wasm-opt" | ||
| WASMTIME="/home/lind/lind-wasm/src/wasmtime/target/debug/wasmtime" | ||
| SYSROOT="/home/lind/lind-wasm/src/glibc/sysroot" | ||
|
|
||
| SRC_DIR="/home/lind/lind-wasm/lind-wasm-apps/lmbench/src" | ||
| OUT_DIR="/home/lind/lind-wasm/lind-wasm-apps/lmbench/src/wasm-bin" | ||
|
|
||
| mkdir -p "$OUT_DIR" | ||
|
|
||
| fail_count=0 | ||
| cfiles=$(find "$SRC_DIR" -maxdepth 1 -name "*.c" \ | ||
| ! -name "getopt.c" \ | ||
| ! -name "lat_usleep.c" \ | ||
| ! -name "lib_*.c") | ||
|
|
||
| for cfile in $cfiles; do | ||
| base=$(basename "$cfile" .c) | ||
| wasm_tmp="$SRC_DIR/$base.wasm" | ||
| ofile="$OUT_DIR/$base.cwasm" | ||
|
|
||
| echo "[*] Compiling $base.c → $ofile with clang -std=gnu89" | ||
|
|
||
| "$CLANG" -std=gnu89 -pthread --target=wasm32-unknown-wasi --sysroot="$SYSROOT" \ | ||
| -Wl,--import-memory,--export-memory,--max-memory=67108864,--export=__stack_pointer,--export=__stack_low \ | ||
| "$cfile" -g -O0 -o "$wasm_tmp" | ||
|
|
||
| if [ ! -f "$wasm_tmp" ]; then | ||
| echo "Failed to compile $base.c (clang error)" | ||
| ((fail_count++)) | ||
| continue | ||
| fi | ||
|
|
||
| "$WASM_OPT" --epoch-injection --asyncify -O2 --debuginfo "$wasm_tmp" -o "$wasm_tmp" | ||
|
|
||
| "$WASMTIME" compile "$wasm_tmp" -o "$ofile" | ||
|
|
||
| if [ ! -f "$ofile" ]; then | ||
| echo "Failed to compile $base.wasm to $base.cwasm" | ||
| ((fail_count++)) | ||
| continue | ||
| fi | ||
|
|
||
| rm -f "$wasm_tmp" | ||
| done | ||
|
|
||
| total_count=$(echo "$cfiles" | wc -l) | ||
| echo "" | ||
| echo "total number: $total_count" | ||
| echo "compile error number: $fail_count" | ||
| echo "all the compiled file in: $OUT_DIR" | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the script depends on several specific tools (clang, wasm-opt, wasmtime, and a specific SYSROOT), it might be a good idea to move all the path exports and environment variable setups to the top of the script using fallbacks like this:
This way you could modify them at the time you call the compile without having to edit the script, like this:
WASMTIME=$HOME/.cargo/bin/wasmtime ./compile_lmbench.shAnd if you later want to move it to the Makefile to adhere to the build contract style we talked about in Issue 10