added: `onyx version` subcommand
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 16 Nov 2023 20:40:38 +0000 (14:40 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 16 Nov 2023 20:40:38 +0000 (14:40 -0600)
.github/workflows/onyx-build.yml
compiler/include/astnodes.h
compiler/src/onyx.c
runtime/src/ort_os.h

index e1a4bb14fc739af85885b229a9179430d11d0051..5bf3ded677b1e6d91e56d4745b9cb1c31ec12d13 100644 (file)
@@ -4,7 +4,6 @@ on:
   push:
     branches: 
       - master
-      - dev
   pull_request:
     branches:
       - master
@@ -30,6 +29,10 @@ jobs:
             os: ubuntu-latest
             runtime_library: ':libwasmer.a'
             artifact_name: 'onyx-linux-wasmer-amd64'
+          - build: linux-amd64
+            os: ubuntu-latest
+            runtime_library: none
+            artifact_name: 'onyx-linux-none-amd64' 
           - build: windows-amd64
             os: windows-latest
             artifact_name: 'onyx-windows-amd64'
@@ -61,7 +64,7 @@ jobs:
         uses: ilammy/msvc-dev-cmd@v1
 
       - name: Build Onyx for ${{ matrix.build }}
-        if: matrix.build == 'linux-amd64'
+        if: (matrix.build == 'linux-amd64') && (matrix.runtime_library != 'none')
         run: |
           ./build.sh compile package
         env:
@@ -71,6 +74,15 @@ jobs:
           ONYX_INCLUDE_DIR: ../shared/include
           ONYX_LIBRARY_DIR: ${{ env.ONYX_LIBRARY_DIR }}
           ONYX_USE_DYNCALL: '1'
+          
+      - name: Build Onyx for ${{ matrix.build }}
+        if: (matrix.build == 'linux-amd64') && (matrix.runtime_library == 'none')
+        run: |
+          ./build.sh compile package
+        env:
+          ONYX_CC: gcc
+          ONYX_ARCH: x86_64
+          ONYX_INCLUDE_DIR: ../shared/include
 
       - name: Build Onyx for ${{ matrix.build }}
         if: matrix.build == 'windows-amd64'
index 21bed6344299d934fbfdf0990c237f8f85e90ab8..136ae2a3cdba442eee759602aaedc903d1cedea3 100644 (file)
@@ -1751,6 +1751,7 @@ enum CompileAction {
     ONYX_COMPILE_ACTION_WATCH,
     ONYX_COMPILE_ACTION_DOCUMENT,
     ONYX_COMPILE_ACTION_PRINT_HELP,
+    ONYX_COMPILE_ACTION_PRINT_VERSION
 };
 
 
index 96095e293d39c3dc648b6686924669363e47cd32..a7e1c14164482926ce4cf81674e418d062d63d47 100644 (file)
@@ -24,13 +24,15 @@ extern struct bh_allocator global_heap_allocator;
 
 Context context;
 
-#define DOCSTRING_HEADER "Onyx toolchain version " VERSION "\n" \
+#define VERSION_STRING "Onyx toolchain version " VERSION "\n" \
+    "Built on " __TIMESTAMP__ "\n"
+
+#define DOCSTRING_HEADER VERSION_STRING \
     "\n" \
     "The toolchain for the Onyx programming language, created by Brendan Hansen.\n" \
     "\n"
 
 
-
 static const char* top_level_docstring = DOCSTRING_HEADER
     "Usage:\n"
     "\tonyx <subcommand>\n"
@@ -43,7 +45,8 @@ static const char* top_level_docstring = DOCSTRING_HEADER
 #endif
     "\tcheck     Checks syntax and types of an Onyx program.\n"
     "\twatch     Continuously rebuilds an Onyx program on file changes.\n"
-    "\tpackage   Package manager\n";
+    "\tpackage   Package manager\n"
+    "\tversion   Prints version information\n";
     // "\tdoc <input files>\n"
 
 static const char *build_docstring = DOCSTRING_HEADER
@@ -132,8 +135,10 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg
     core_installation = getenv("ONYX_PATH");
     #endif
     #ifdef _BH_WINDOWS
-    core_installation = bh_alloc_array(alloc, u8, 512);
-    GetEnvironmentVariableA("ONYX_PATH", core_installation, 512);
+    char *tmp_core_installation = bh_alloc_array(alloc, u8, 512);
+    if (GetEnvironmentVariableA("ONYX_PATH", tmp_core_installation, 512) > 0) {
+        core_installation = tmp_core_installation;
+    }
     #endif
 
     if (core_installation == NULL) {
@@ -152,6 +157,10 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg
         options.action = ONYX_COMPILE_ACTION_PRINT_HELP;
         options.help_subcommand = argc > 2 ? argv[2] : NULL;
     }
+    else if (!strcmp(argv[1], "version")) {
+        options.action = ONYX_COMPILE_ACTION_PRINT_VERSION;
+        goto skip_parsing_arguments;
+    }
     else if (!strcmp(argv[1], "compile") || !strcmp(argv[1], "build")) {
         options.action = ONYX_COMPILE_ACTION_COMPILE;
         arg_parse_start = 2;
@@ -1154,6 +1163,11 @@ int main(int argc, char *argv[]) {
             return 1;
         }
 
+        case ONYX_COMPILE_ACTION_PRINT_VERSION: {
+            bh_printf(VERSION_STRING);
+            return 0;
+        }
+
         case ONYX_COMPILE_ACTION_CHECK:
             compiler_progress = do_compilation(&compile_opts);
             break;
index 93954a838889eab0c74c30ce851555ffa2f9ce26..e6ef5e88e8443afcd5cddf562d3a5fbc202e7d45 100644 (file)
@@ -149,7 +149,7 @@ ONYX_DEF(__random_get, (WASM_PTR, WASM_I32), ()) {
 ONYX_DEF(__futex_wait, (WASM_PTR, WASM_I32, WASM_I32), (WASM_I32)) {
     int *addr = ONYX_PTR(params->data[0].of.i32);
 
-    #if defined(_BH_LINUX) || defined(_BH_DARWIN)
+    #if defined(_BH_LINUX)
     struct timespec delay;
 
     struct timespec *t = NULL;
@@ -181,7 +181,7 @@ ONYX_DEF(__futex_wait, (WASM_PTR, WASM_I32, WASM_I32), (WASM_I32)) {
 ONYX_DEF(__futex_wake, (WASM_PTR, WASM_I32), (WASM_I32)) {
     int *addr = ONYX_PTR(params->data[0].of.i32);
 
-    #if defined(_BH_LINUX) || defined(_BH_DARWIN)
+    #if defined(_BH_LINUX)
     int res = syscall(SYS_futex, addr, FUTEX_WAKE, params->data[1].of.i32, NULL, NULL, 0);
 
     results->data[0] = WASM_I32_VAL(res);