From: Brendan Hansen Date: Thu, 16 Nov 2023 03:51:39 +0000 (-0600) Subject: changed: completely changed build process X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=1acd5a5142e619586bf27d5c90d5fe91ad9c292c;p=onyx.git changed: completely changed build process --- diff --git a/.github/workflows/onyx-build.yml b/.github/workflows/onyx-build.yml index 336bc14f..23b9da0f 100644 --- a/.github/workflows/onyx-build.yml +++ b/.github/workflows/onyx-build.yml @@ -2,15 +2,68 @@ name: Build and Test on: push: - branches: [ master ] + branches: [ master, dev ] pull_request: - branches: [ master ] + branches: [ master, dev ] + workflow_dispatch: + inputs: + release: + description: 'Make release' jobs: build: + name: Building on ${{ matrix.build }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - build: linux-amd64 + os: ubuntu-20.04 + artifact_name: 'onyx-linux-amd64' + - build: windows-amd64 + os: windows-latest + artifact_name: 'onyx-windows-amd64' + steps: + - uses: actions/checkout@v3 + - name: Setup directory for building + if: matrix.build == 'linux-amd64' + run: | + chmod +x build.sh + mkdir -p build + + - name: Build Onyx for ${{ matrix.build }} + if: matrix.build == 'linux-amd64' + run: | + ./build.sh compile package + env: + ONYX_CC: gcc + ONYX_ARCH: x86_64 + ONYX_RUNTIME_LIBRARY: ovmwasm + ONYX_INCLUDE_DIR: shared/include + ONYX_LIBRARY_DIR: shared/lib/linux_x86_64/lib + + - name: Install Windows building dependencies + if: matrix.build == 'windows-amd64' + uses: ilammy/mscv-dev-cmd@v1 + + - name: Build Onyx for ${{ matrix.build }} + if: matrix.build == 'windows-amd64' + run: | + cmd.exe /c 'build.bat dist' + + - name: Upload Artifacts + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.artifact_name }} + path: dist + if-no-files-found: error + retention-days: 5 + + - runs-on: ubuntu-latest + steps: - uses: actions/checkout@v2 - name: make build.sh executable diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml deleted file mode 100644 index bea4613c..00000000 --- a/.github/workflows/windows-build.yml +++ /dev/null @@ -1,46 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: Build on Windows - -# Controls when the action will run. -on: - # Triggers the workflow on push or pull request events but only for the master branch - push: - branches: [ master ] - pull_request: - branches: [ master ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: windows-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - # Lets us use CL.exe - - uses: ilammy/msvc-dev-cmd@v1 - - # Runs a single command using the runners shell - - name: Build a release build - run: cmd.exe /c 'build.bat' - - - name: Upload executable file - uses: actions/upload-artifact@v2 - with: - name: executable - path: | - core - examples - shared/lib/windows_x86_64/lib/wasmer.dll - misc - onyx_runtime.dll - tests - onyx.exe diff --git a/.gitignore b/.gitignore index 14426751..f161288c 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,9 @@ tmp/ dist/ **/node_modules/ onyx-lsp.ini -shared/lib/linux_x86_64/lib/libovmwasm.so +shared/lib/linux_x86_64/lib/libovmwasm.a bin/onyx-run bin/onyx releases/ +compiler/onyx +runtime/onyx_runtime.so diff --git a/build.bat b/build.bat index 455de157..05646677 100644 --- a/build.bat +++ b/build.bat @@ -27,3 +27,15 @@ cl /MT /std:c17 /TC /I compiler/include /I shared/include /D_USRDLL /D_WINDLL ru del onyx_runtime.obj del onyx_runtime.lib del onyx_runtime.exp + +if "%1" == "dist" ( + mkdir dist + mkdir dist\shared\lib\windows_x86_64\lib + copy shared\lib\windows_x86_64\lib\wasmer.dll dist\shared\lib\windows_x86_64\lib\wasmer.dll + xcopy core dist\core /s /e /h /I + xcopy examples dist\examples /s /e /h /I + @REM xcopy misc dist\misc /s /e /h /I + xcopy onyx_runtime.dll dist\onyx_runtime.dll /s /e /h /I + xcopy tests dist\tests /s /e /h /I + xcopy onyx.exe dist\onyx.exe /s /e /h /I +) diff --git a/build.sh b/build.sh index 59854bab..e38c6e40 100755 --- a/build.sh +++ b/build.sh @@ -1,55 +1,71 @@ #!/bin/sh -[ ! $UID = 0 ] \ - && echo "Please run this script as root." \ - && exit 1 +DIST_DIR="./dist" +ONYX_INSTALL_DIR="$HOME/.onyx" -. ./settings.sh +compile_all() { + if [ "$ONYX_RUNTIME_LIBRARY" = "ovmwasm" ]; then + cd interpreter + ./build.sh $1 + cd .. + fi -echo "Installing on '$(uname -a)'" - -echo "Installing core libs" -[ -d "$CORE_DIR/core" ] && rm -r "$CORE_DIR/core" -mkdir -p "$CORE_DIR" -cp -r ./core/ "$CORE_DIR" - - -mkdir -p "$CORE_DIR/tools" -mkdir -p "$CORE_DIR/tools/pkg_templates" -cp ./scripts/onyx-pkg.onyx "$CORE_DIR/tools" -cp ./scripts/default.json "$CORE_DIR/tools/pkg_templates" - -# This is a development feature to allow for quickly reinstalling core libraries -# without have to recompile the entire compiler -[ "$1" = "core" ] && exit 0 - -if [ "$RUNTIME_LIBRARY" = "ovmwasm" ]; then - cd interpreter + cd compiler ./build.sh $1 cd .. -fi - -if [ ! -f "$CORE_DIR/lib/lib$RUNTIME_LIBRARY.so" ] || true; then - echo "Copying lib$RUNTIME_LIBRARY to $CORE_DIR/lib (first install)" - - mkdir -p "$CORE_DIR/lib" - mkdir -p "$CORE_DIR/include" - - cp "$WASMER_LIBRARY_DIR/lib$RUNTIME_LIBRARY.so" "$CORE_DIR/lib/lib$RUNTIME_LIBRARY.so" - - cp "shared/include/onyx_library.h" "$CORE_DIR/include/onyx_library.h" - cp "$WASMER_INCLUDE_DIR/wasm.h" "$CORE_DIR/include/wasm.h" -fi - -cd compiler -./build.sh $1 -cd .. - -cd runtime -./build.sh $1 -cd .. - + cd runtime + ./build.sh $1 + cd .. +} + +package_all() { + mkdir -p "$DIST_DIR" + + echo "Installing on '$(uname -a)'" + echo "Installing core libs" + [ -d "$DIST_DIR/core" ] && rm -r "$DIST_DIR/core" + cp -r ./core/ "$DIST_DIR" + + echo "Installing core tools" + mkdir -p "$DIST_DIR/bin" + cp compiler/onyx "$DIST_DIR/bin/" + + mkdir -p "$DIST_DIR/tools" + mkdir -p "$DIST_DIR/tools/pkg_templates" + cp ./scripts/onyx-pkg.onyx "$DIST_DIR/tools" + cp ./scripts/default.json "$DIST_DIR/tools/pkg_templates" + + echo "Installing runtime library '$ONYX_RUNTIME_LIBRARY'" + mkdir -p "$DIST_DIR/lib" + mkdir -p "$DIST_DIR/include" + + cp runtime/onyx_runtime.so "$DIST_DIR/lib/" + cp "shared/include/onyx_library.h" "$DIST_DIR/include/onyx_library.h" + cp "shared/include/wasm.h" "$DIST_DIR/include/wasm.h" + + cp -r "tests" "$DIST_DIR/" + cp -r "examples" "$DIST_DIR/" +} + +install_all() { + package_all + + mkdir -p "$ONYX_INSTALL_DIR" + cp -r "$DIST_DIR/." "$ONYX_INSTALL_DIR" +} + +for arg in $@; do + case "$arg" in + compile) compile_all ;; + package) package_all ;; + install) install_all ;; + clean) + rm -f compiler/onyx 2>/dev/null + rm -f runtime/onyx_runtime.so 2>/dev/null + ;; + esac +done # Otherwise the prompt ends on the same line printf "\n" diff --git a/compiler/build.sh b/compiler/build.sh index eff0031d..d10bc371 100755 --- a/compiler/build.sh +++ b/compiler/build.sh @@ -1,15 +1,7 @@ #!/bin/sh -. ../settings.sh - -# Enable Dynamic call -USE_DYNCALL=1 - -# Temporary flag -ENABLE_DEBUG_INFO=1 - C_FILES="onyx astnodes builtins checker clone doc entities errors lex parser symres types utils wasm_emit wasm_runtime " -LIBS="-L$CORE_DIR/lib -l$RUNTIME_LIBRARY -Wl,-rpath=$CORE_DIR/lib:./ -lpthread -ldl -lm" +LIBS="-L$ONYX_LIBRARY_DIR -lpthread -ldl -lm" INCLUDES="-I./include -I../shared/include -I../shared/include/dyncall" WARNINGS='-Wimplicit -Wmisleading-indentation -Wparentheses -Wsequence-point -Wreturn-type -Wshift-negative-value -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wmaybe-uninitialized -Wsign-compare -Wstrict-overflow -Wduplicated-branches -Wduplicated-cond -Wtrigraphs -Waddress -Wlogical-op' @@ -20,42 +12,24 @@ else FLAGS="$WARNINGS -O3" fi -if [ "$RUNTIME_LIBRARY" = "ovmwasm" ]; then - FLAGS="$FLAGS -DUSE_OVM_DEBUGGER" +if [ ! -z ${ONYX_RUNTIME_LIBRARY+x} ]; then + FLAGS="$FLAGS -DENABLE_RUN_WITH_WASMER" + LIBS="$LIBS -l$ONYX_RUNTIME_LIBRARY" fi -if [ "$ENABLE_DEBUG_INFO" = "1" ]; then - FLAGS="$FLAGS -DENABLE_DEBUG_INFO" +if [ "$ONYX_RUNTIME_LIBRARY" = "ovmwasm" ]; then + FLAGS="$FLAGS -DUSE_OVM_DEBUGGER" fi -FLAGS="$FLAGS -DENABLE_RUN_WITH_WASMER" +FLAGS="$FLAGS -DENABLE_DEBUG_INFO" -if [ "$USE_DYNCALL" = "1" ] && [ "$RUNTIME_LIBRARY" = "ovmwasm" ]; then - LIBS="$LIBS ../shared/lib/linux_$ARCH/lib/libdyncall_s.a ../shared/lib/linux_$ARCH/lib/libdyncallback_s.a" +if [ "$ONYX_USE_DYNCALL" = "1" ] && [ "$ONYX_RUNTIME_LIBRARY" = "ovmwasm" ]; then + LIBS="$LIBS ../shared/lib/linux_$ONYX_ARCH/lib/libdyncall_s.a ../shared/lib/linux_$ONYX_ARCH/lib/libdyncallback_s.a" FLAGS="$FLAGS -DUSE_DYNCALL" fi -mkdir -p "$BIN_DIR" - -echo "Compiling onyx..." -$CC -o "../bin/onyx" \ - $FLAGS \ - "-DCORE_INSTALLATION=\"$CORE_DIR\"" \ - $INCLUDES \ +echo "Compiling onyx" +$ONYX_CC -o "onyx" \ + $FLAGS $INCLUDES \ $(echo "$C_FILES" | sed 's/ /\n/g;s/\([a-zA-Z_0-9]*\)\n/src\/\1.c\n/g;s/\n/ /g') \ $LIBS - -echo "Installing onyx executable" -cp "../bin/onyx" "$BIN_DIR/onyx" - -C_FILES="onyxrun wasm_runtime " - -echo "Compiling onyx-run..." -$CC -o "../bin/onyx-run" \ - $FLAGS \ - $INCLUDES \ - $(echo "$C_FILES" | sed 's/ /\n/g;s/\([a-zA-Z_0-9]*\)\n/src\/\1.c\n/g;s/\n/ /g') \ - $LIBS - -echo "Installing onyx-run executable" -cp "../bin/onyx-run" "$BIN_DIR/onyx-run" diff --git a/compiler/src/onyx.c b/compiler/src/onyx.c index a73dc0a9..444a5342 100644 --- a/compiler/src/onyx.c +++ b/compiler/src/onyx.c @@ -127,15 +127,20 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg bh_arr_new(alloc, options.included_folders, 2); bh_arr_new(alloc, options.defined_variables, 2); - char* core_installation; + char* core_installation = NULL; #ifdef _BH_LINUX - core_installation = CORE_INSTALLATION; + core_installation = getenv("ONYX_PATH"); #endif #ifdef _BH_WINDOWS core_installation = bh_alloc_array(alloc, u8, 512); GetEnvironmentVariableA("ONYX_PATH", core_installation, 512); #endif + if (core_installation == NULL) { + bh_printf("Error: ONYX_PATH environment variable is not set. Please set this to the location of your Onyx installation.\n"); + exit(0); + } + // NOTE: Add the current folder bh_arr_push(options.included_folders, core_installation); bh_arr_push(options.included_folders, "."); diff --git a/compiler/src/wasm_runtime.c b/compiler/src/wasm_runtime.c index 1fcfbbe9..d423d01a 100644 --- a/compiler/src/wasm_runtime.c +++ b/compiler/src/wasm_runtime.c @@ -146,6 +146,11 @@ static WasmFuncDefinition** onyx_load_library(LinkLibraryContext *ctx, char *nam static void lookup_and_load_custom_libraries(LinkLibraryContext *ctx, bh_arr(WasmFuncDefinition **)* p_out) { bh_arr(WasmFuncDefinition **) out = *p_out; + char *onyx_path = getenv("ONYX_PATH"); + if (onyx_path) { + bh_arr_push(ctx->library_paths, bh_aprintf(bh_heap_allocator(), "%s/lib", onyx_path)); + } + bh_buffer wasm_bytes = ctx->wasm_bytes; i32 cursor = 8; // skip the magic number and version @@ -558,11 +563,6 @@ void onyx_run_initialize(b32 debug_enabled) { printf("Warning: --debug does nothing if libovmwasm.so is not being used!\n"); } - // Prefer the LLVM compile because it is faster. This should be configurable from the command line and/or a top-level directive. - if (wasmer_is_compiler_available(LLVM)) { - wasm_config_set_compiler(wasm_config, LLVM); - } - wasmer_features_t* features = wasmer_features_new(); wasmer_features_simd(features, 1); wasmer_features_threads(features, 1); diff --git a/interpreter/build.sh b/interpreter/build.sh index d1ab9254..1552b415 100755 --- a/interpreter/build.sh +++ b/interpreter/build.sh @@ -1,15 +1,19 @@ #!/bin/sh -. ../settings.sh - # FLAGS="-g3 -O2 -DOVM_DEBUG=1 -fno-stack-protector" # FLAGS="-g3 -DOVM_VERBOSE=1" FLAGS="-Ofast -fno-stack-protector" LIBS="-pthread" -TARGET="../shared/lib/linux_$(uname -m)/lib/libovmwasm.so" +TARGET="../shared/lib/linux_$(uname -m)/lib/libovmwasm.a" C_FILES="src/ovmwasm.c src/vm/*.c src/wasm/*.c src/debug/*.c" INCLUDES="-I../shared/include -Iinclude" -echo "Compiling libovmwasm.so" -$CC $FLAGS $INCLUDES -shared -fPIC -o $TARGET $C_FILES $LIBS $WARNINGS +mkdir -p "build_tmp" + +for c_file in $C_FILES; do + $ONYX_CC $FLAGS $INCLUDES -fPIC -o $(mktemp -p build_tmp -t XXXXXXX.o) -c $c_file $LIBS +done + +ar cr "$TARGET" build_tmp/*.o +rm -r "build_tmp" diff --git a/runtime/build.sh b/runtime/build.sh index fa1ab04c..263ccffc 100755 --- a/runtime/build.sh +++ b/runtime/build.sh @@ -1,12 +1,8 @@ #!/bin/sh -. ../settings.sh - -$CC -shared -fpic -w -O2 \ - -o ../bin/onyx_runtime.so \ +echo "Compiling onyx_runtime.so" +$ONYX_CC -shared -fpic -w -O2 \ + -o onyx_runtime.so \ -I ../shared/include -I ../compiler/include \ ./onyx_runtime.c \ -lpthread - -echo "Installing onyx_runtime.so" -mv "../bin/onyx_runtime.so" "$CORE_DIR/lib/onyx_runtime.so" diff --git a/scripts/run_tests.onyx b/scripts/run_tests.onyx index 25042d1b..e8f59db6 100644 --- a/scripts/run_tests.onyx +++ b/scripts/run_tests.onyx @@ -110,7 +110,7 @@ main :: (args) => { switch runtime.compiler_os { case .Linux { - exec_context.onyx_cmd = "./bin/onyx"; + exec_context.onyx_cmd = "./dist/bin/onyx"; if settings.debug do exec_context.onyx_cmd = "./bin/onyx-debug"; } case .Windows do exec_context.onyx_cmd = "onyx.exe"; diff --git a/settings.sh b/settings.sh index 1b1ad45f..b9afc986 100644 --- a/settings.sh +++ b/settings.sh @@ -1,24 +1,15 @@ -# The base path for the installation. -# This is typcially /usr or /usr/local. -INSTALL_DIR="/usr" - -# Where the core libraries for Onyx will go. -CORE_DIR="$INSTALL_DIR/share/onyx" - -# Where the onyx executable will be placed. -BIN_DIR="$INSTALL_DIR/bin" - # The compiler to use. Only GCC and TCC have been tested. -CC='gcc' +export ONYX_CC='gcc' # The architecture of your system. If your not sure, leave this alone. -ARCH="$(uname -m)" +export ONYX_ARCH="$(uname -m)" + +export ONYX_RUNTIME_LIBRARY="ovmwasm" +# export ONYX_RUNTIME_LIBRARY=":libwasmer.a" -RUNTIME_LIBRARY="ovmwasm" -# RUNTIME_LIBRARY="wasmer" +export ONYX_INCLUDE_DIR="$(pwd)/shared/include" +export ONYX_LIBRARY_DIR="$(pwd)/shared/lib/linux_$ONYX_ARCH/lib" -# Where the Wasmer library files can be found. -# They are bundled with the project, but if a different version is available, these can be changed. -WASMER_INCLUDE_DIR="$(pwd)/shared/include" -WASMER_LIBRARY_DIR="$(pwd)/shared/lib/linux_$ARCH/lib" +# Enable Dynamic call +export ONYX_USE_DYNCALL=1 diff --git a/shared/lib/linux_x86_64/lib/libwasmer.so b/shared/lib/linux_x86_64/lib/libwasmer.so deleted file mode 100755 index f6f99098..00000000 Binary files a/shared/lib/linux_x86_64/lib/libwasmer.so and /dev/null differ