changed: completely changed build process
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 16 Nov 2023 03:51:39 +0000 (21:51 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 16 Nov 2023 03:51:39 +0000 (21:51 -0600)
13 files changed:
.github/workflows/onyx-build.yml
.github/workflows/windows-build.yml [deleted file]
.gitignore
build.bat
build.sh
compiler/build.sh
compiler/src/onyx.c
compiler/src/wasm_runtime.c
interpreter/build.sh
runtime/build.sh
scripts/run_tests.onyx
settings.sh
shared/lib/linux_x86_64/lib/libwasmer.so [deleted file]

index 336bc14f82ac93c1e157dbfceb172a0c378f4235..23b9da0fe30229a6c89d7a4237377af670ab0225 100644 (file)
@@ -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 (file)
index bea4613..0000000
+++ /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
index 14426751e083dc370992e1a7490cb71deab00271..f161288c9c2705dc45883259782215cd45d23b0c 100644 (file)
@@ -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
index 455de1572b416effe9cfc3bf7754a01b39594751..056466771f8feb1248123bbe161ccf034e52c326 100644 (file)
--- 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
+)
index 59854bab9045b32096a23ba91344293bbafae13e..e38c6e4060faad55794ecf1de5141c575f2a9545 100755 (executable)
--- 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"
index eff0031d33c4a2d4e2fd75dbbb0c8101ef7e15b5..d10bc3718e042ecce9ca44009e5a24d570c16d06 100755 (executable)
@@ -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"
index a73dc0a9c1e059027d92db35e9c297a3c17b67ad..444a5342833908fdb4f896659ca11a696738c003 100644 (file)
@@ -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, ".");
index 1fcfbbe9b7ae50a8f3d2cf55cdf0368361d92168..d423d01a8cc18f38fd924a3e6579b04e94f8063f 100644 (file)
@@ -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);
index d1ab9254694045ebb326fcade919e00446a5c6c6..1552b41508f537821987ed8912327c79d8076e70 100755 (executable)
@@ -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"
index fa1ab04c2740ed0dcda3f6c94e00bdccfd884ddd..263ccffc2cbf4b4c567c79e92f6edd0459823448 100755 (executable)
@@ -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"
index 25042d1b0a8bf6183f9339c55310bb123b649f4e..e8f59db61419333824cbeb2b28aa2a2dea9b46f1 100644 (file)
@@ -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";
index 1b1ad45fec5b35837bf50f33f7814a0c8954d69e..b9afc986f1eed19e04d00e6c3e89cb656884741e 100644 (file)
@@ -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 (executable)
index f6f9909..0000000
Binary files a/shared/lib/linux_x86_64/lib/libwasmer.so and /dev/null differ