From 8d7e8c3a11b15f83d575dc47775fd1867cd29b92 Mon Sep 17 00:00:00 2001 From: modeco80 Date: Sun, 16 Jul 2023 21:10:59 -0400 Subject: [PATCH] add scripts for building llvm (for inclusion in addon root) --- .gitignore | 8 ++++++++ build_llvm.sh | 42 +++++++++++++++++++++++++++++++++++++++ ideas.md | 20 +++++++++++-------- lua/autorun/lcpu_load.lua | 6 ++++++ 4 files changed, 68 insertions(+), 8 deletions(-) create mode 100755 build_llvm.sh diff --git a/.gitignore b/.gitignore index 18168a7..1f97ab3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,11 @@ native/projects/riscv/ref .cache/ .vscode/ + + +# temporary +llvm_src/ +llvm_build/ + +# pre-'mv' filenames +llvm-project-*/ diff --git a/build_llvm.sh b/build_llvm.sh new file mode 100755 index 0000000..ae637f3 --- /dev/null +++ b/build_llvm.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# this script builds llvm components + +LLVM_VERSION=16.0.0 +LLVM_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION/llvm-project-$LLVM_VERSION.src.tar.xz" +LLVM_FILENAME="llvm-project-$LLVM_VERSION.src.tar.xz" + + +# download/extract LLVM (if need be) +[[ ! -d 'llvm_src' ]] && { + curl -LO $LLVM_URL + tar xf $LLVM_FILENAME + mv llvm-project-$LLVM_VERSION.src llvm_src/ + rm $LLVM_FILENAME +}; + +# Configure LLVM. THis is a mouthful, but it's only a mouthful because we specialize things we don't +# want in our minimal build of the LLVM project/clang. +# -DLLVM_ENABLE_LTO=Thin +cmake -GNinja -S llvm_src/llvm -B llvm_build \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DCMAKE_INSTALL_PREFIX="$PWD/lua/bin/llvm" \ + -DLLVM_USE_LINKER=lld \ + -DLLVM_INCLUDE_TESTS=OFF \ + -DLLVM_ENABLE_PROJECTS="clang;lld" \ + -DLLVM_TARGETS_TO_BUILD="RISCV" \ + -DLLVM_DEFAULT_TARGET_TRIPLE="riscv32-none-gnu" + +# TODO: Configure and build compiler-rt with our toolchain. +#cmake -GNinja -S llvm_src/compiler-rt \ +# -DCOMPILER_RT_BUILD_SANITIZERS=OFF \ +# -DCOMPILER_RT_BUILD_LIBFUZZER=OFF \ +# -DCOMPILER_RT_BUILD_PROFILE=OFF \ +# -DCOMPILER_RT_BUILD_MEMPROF=OFF \ +# -DCOMPILER_RT_BUILD_ORC=OFF \ +# -DCOMPILER_RT_BAREMETAL_BUILD=ON + +# Build it +cmake --build llvm_build -j $(($(nproc) + 1)) diff --git a/ideas.md b/ideas.md index db94100..729ae70 100644 --- a/ideas.md +++ b/ideas.md @@ -8,6 +8,7 @@ This is basically the working ideas for the LCPU project. - RISC-V rv32ima core - Would supporting more than one CPU core type be worthwhile? If so, the project is relatively setup for such workflow... - Controllable paramaters (RAM size, ...) +- Our own frambuffer screen SENT (since wiremod decided to go stupid mode and saw off the gpu) ## Code upload/project workflow @@ -17,12 +18,16 @@ This is basically the working ideas for the LCPU project. ### Integrated simple project workflow +### LLVM integration +- LLVM assembler (llvm-mc) is used + - clang for C code? (if it's not prohibitively expensive) + - In all cases (as/clang), the tools will all be firewalled to the given project data directory. + In the case of clang, an addional path will be allowed (clang freestanding headers), but that's the only exception. + + - LLVM tools integrated into server library? Or installed in lua/bin? + - Write assembly/maybe C code using a tiny project system (data for them would go in server data folder ?) - - LLVM assembler is used - - Integrated clang for C code? (if it's not prohibitively expensive) - - In all cases (as/clang), the tools will all be firewalled to the given project data directory. - In the case of clang, an addional path will be allowed (clang freestanding headers), but that's the only exception. - + - Text editor used to edit project source files - Some example projects? @@ -33,9 +38,9 @@ This is basically the working ideas for the LCPU project. - possibly override for "respectful" users and admins (admins probably wouldn't even count)? - Admin controlled per-user max LCPU entity count (default 8) - - admins can override/do not count? + - Admins don't count -- Admin controled global (affects all placed LCPUs) scheduler timeslice. +- Admin controled global (affects all placed LCPUs) scheduler cycle rate. - Couldn't be faster than tickrate though or we might block source (and.. well, i dont think i have to explain) - I decided not to go with the cpu thread stuff just because its annoying, and would require more state tracking. just ticking in lua using `ENTITY:Think` should be more than good enough (even if theres a risk of hitching source, but I don't think it's that big of a problem...) - Project compilations however will definitely end up in a different thread though. Running them in the engine thread would undoubtably cause issues. @@ -45,4 +50,3 @@ This is basically the working ideas for the LCPU project. - Wiremod interopability - Wiremod GPIO (which uses normal wire stuff) - Console Screen - - Wire GPU (if it's not painful to do so)? diff --git a/lua/autorun/lcpu_load.lua b/lua/autorun/lcpu_load.lua index 8b89532..04fafa5 100644 --- a/lua/autorun/lcpu_load.lua +++ b/lua/autorun/lcpu_load.lua @@ -2,3 +2,9 @@ -- this will contain files later on in life. print("hello world?") + +-- detect if wiremod is installed +if not istable(WireLib) then + print("[LCPU] we need wiremod..") + return +end