Skip to content
Open
29 changes: 18 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ TESTABLE_APPS := bash coreutils curl git grep lmbench sed tinycc
APP ?= $(TESTABLE_APPS)

# -------- Phonies -------------------------------------------------------------
.PHONY: all preflight dirs print-config check-build libtirpc gnulib zlib openssl libcxx merge-base-sysroot merge-sysroot lmbench bash nginx coreutils cpython git curl grep sed gcc binutils postgres clean clean-all rebuild-libs rebuild-sysroot test install-bash install-nginx install-git install-curl install-grep install-sed install-lmbench install-coreutils install-gcc install-binutils install
.PHONY: all preflight dirs print-config check-build libtirpc gnulib zlib openssl libcxx merge-base-sysroot merge-sysroot lmbench bash nginx coreutils cpython git curl grep sed gcc binutils clang postgres clean clean-all rebuild-libs rebuild-sysroot install-bash install-nginx install-git install-curl install-grep install-sed install-lmbench install-coreutils install-gcc install-binutils install-clang install

all: preflight libtirpc gnulib merge-sysroot lmbench bash

Expand Down Expand Up @@ -79,24 +79,20 @@ check-build:
done

clean:
@if [[ -z "$(strip $(APP))" ]]; then \
echo "ERROR: no apps selected; set APP to one or more of: $(TESTABLE_APPS)"; \
exit 1; \
fi
@# Per-app clean scripts (optional — skips apps without clean.sh)
@for app in $(APP); do \
case " $(TESTABLE_APPS) " in \
*" $$app "*) ;; \
*) echo "ERROR: unsupported clean app '$$app'; supported apps: $(TESTABLE_APPS)"; exit 1 ;; \
*) continue ;; \
esac; \
if [[ -x '$(APPS_ROOT)/'"$$app"'/clean.sh' ]]; then \
'$(APPS_ROOT)/'"$$app"'/clean.sh' "$$app"; \
else \
echo "[SKIP] $$app: missing $(APPS_ROOT)/$$app/clean.sh"; \
fi; \
done
@# Infrastructure: stamps, sysroot, overlay, toolchain env
-rm -rf '$(APPS_OVERLAY)' '$(MERGED_SYSROOT)' '$(APPS_BIN_DIR)' '$(APPS_LIB_DIR)' '$(TOOL_ENV)'
-rm -f '$(LIBTIRPC_STAMP)' '$(GNULIB_STAMP)' '$(ZLIB_STAMP)' '$(OPENSSL_STAMP)'
-rm -f '$(MERGE_BASE_STAMP)' '$(MERGE_TIRPC_STAMP)' '$(MERGE_GNULIB_STAMP)' '$(MERGE_ZLIB_STAMP)' '$(MERGE_OPENSSL_STAMP)' '$(MERGE_ALL_STAMP)'
-rm -f '$(LIBTIRPC_STAMP)' '$(GNULIB_STAMP)' '$(ZLIB_STAMP)' '$(OPENSSL_STAMP)' '$(LIBCXX_STAMP)'
-rm -f '$(MERGE_BASE_STAMP)' '$(MERGE_TIRPC_STAMP)' '$(MERGE_GNULIB_STAMP)' '$(MERGE_ZLIB_STAMP)' '$(MERGE_OPENSSL_STAMP)' '$(MERGE_LIBCXX_STAMP)' '$(MERGE_ALL_STAMP)'

print-config:
@echo "LIND_WASM_ROOT=$(LIND_WASM_ROOT)"
Expand Down Expand Up @@ -329,6 +325,14 @@ binutils: $(MERGE_ZLIB_STAMP)
. '$(TOOL_ENV)'
JOBS='$(JOBS)' '$(APPS_ROOT)/binutils/compile_binutils.sh'

# ---------------- clang (WASM build) -------------------------------------------
# Uses llvm-project/compile_clang.sh to cross-compile clang and lld as
# wasm32-wasi binaries. Requires libc++ in the merged sysroot (C++ source).
# Stages artifacts under build/clang/usr/local/bin.
clang: $(MERGE_LIBCXX_STAMP)
. '$(TOOL_ENV)'
JOBS='$(JOBS)' '$(APPS_ROOT)/llvm-project/compile_clang.sh'

rebuild-libs:
rm -f '$(LIBTIRPC_STAMP)' '$(GNULIB_STAMP)' '$(ZLIB_STAMP)' '$(OPENSSL_STAMP)' '$(LIBCXX_STAMP)' \
'$(MERGE_TIRPC_STAMP)' '$(MERGE_GNULIB_STAMP)' '$(MERGE_ZLIB_STAMP)' '$(MERGE_OPENSSL_STAMP)' '$(MERGE_LIBCXX_STAMP)' '$(MERGE_ALL_STAMP)'
Expand Down Expand Up @@ -376,4 +380,7 @@ install-gcc:
install-binutils:
'$(APPS_ROOT)/scripts/post_install.sh' '$(LINDFS_ROOT)' '$(APPS_BUILD)' binutils

install: install-bash install-nginx install-git install-curl install-grep install-sed install-lmbench install-coreutils install-gcc install-binutils
install-clang:
'$(APPS_ROOT)/scripts/post_install.sh' '$(LINDFS_ROOT)' '$(APPS_BUILD)' clang

install: install-bash install-nginx install-git install-curl install-grep install-sed install-lmbench install-coreutils install-gcc install-binutils install-clang
56 changes: 56 additions & 0 deletions llvm-project/Toolchain-WASI-LLVM.cmake.in
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this different from the other cmake file thats in the llvm repo?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

different from another one. This one has additional flags (ie: -D_linux)

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Auto-generated CMake toolchain for cross-compiling LLVM to wasm32-wasi
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR wasm32)

# Compiler and tools
set(CMAKE_C_COMPILER "@CLANG@")
set(CMAKE_CXX_COMPILER "@CLANGXX@")
set(CMAKE_AR "@AR@")
set(CMAKE_NM "@NM@")
set(CMAKE_RANLIB "@RANLIB@")
set(CMAKE_SYSROOT "@BASE_SYSROOT@")
set(CMAKE_LINKER "@LD@")

# Target configuration
set(CMAKE_C_COMPILER_TARGET wasm32-unknown-wasi)
set(CMAKE_CXX_COMPILER_TARGET wasm32-unknown-wasi)

# Force CMake to accept compilers without try-run (can't run wasm on host)
set(CMAKE_C_COMPILER_WORKS TRUE)
set(CMAKE_CXX_COMPILER_WORKS TRUE)
set(CMAKE_EXECUTABLE_SUFFIX ".wasm")

# WASM C flags — use -Os to minimize binary size (clang is huge)
# Use CACHE FORCE so nothing can override these (not even a stale CMakeCache)
# WASI uses glibc headers — define __linux__ so LLVM uses <endian.h>,
# Linux-style struct fields, etc. (WASI is not Linux, but its glibc
# sysroot matches the Linux ABI for these purposes.)
set(CMAKE_C_FLAGS "-Os -pthread -matomics -mbulk-memory -fno-exceptions -fno-unwind-tables -D__linux__" CACHE STRING "" FORCE)

# WASM C++ flags — use libc++, no exceptions/RTTI/unwind to reduce binary size
set(CMAKE_CXX_FLAGS "-Os -pthread -matomics -mbulk-memory -fno-exceptions -fno-unwind-tables -fno-rtti -D__linux__ -nostdinc++ -isystem $LIBCXX_INCLUDE -include $SCRIPT_DIR/fix_std_maxmin.h" CACHE STRING "" FORCE)

# Linker flags
set(CMAKE_EXE_LINKER_FLAGS "\
-L$MERGED_SYSROOT/lib/wasm32-wasi \
-L$MERGED_SYSROOT/usr/lib/wasm32-wasi \
-Wl,--export=__stack_pointer,--export=__stack_low \
-Wl,--import-memory,--export-memory \
-Wl,--max-memory=67108864 \
-lm " CACHE STRING "" FORCE)

# Don't pass -rpath to the linker
set(CMAKE_SKIP_RPATH TRUE)
set(CMAKE_SKIP_INSTALL_RPATH TRUE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)

# Prevent try-run errors
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

# Skip old toolchain warnings
set(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN ON CACHE BOOL "" FORCE)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Loading