added: custom sub-commands; `onyx pkg sync --skip-native`
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 26 Jun 2023 22:19:26 +0000 (17:19 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 26 Jun 2023 22:19:26 +0000 (17:19 -0500)
compiler/src/onyx.c
scripts/onyx-pkg.onyx

index af2819f0973cba550d5a20395e7f313bc5be697f..dd01aa15cdb7a35c2de0cdb31e7a163e5347f16d 100644 (file)
@@ -19,7 +19,7 @@ extern struct bh_allocator global_heap_allocator;
 #include "wasm_emit.h"
 #include "doc.h"
 
-#define VERSION "v0.1.4"
+#define VERSION "v0.1.5"
 
 
 Context context;
@@ -160,6 +160,7 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg
         arg_parse_start = argc;
 
         bh_arr_push(options.files, bh_aprintf(alloc, "%s/tools/onyx-pkg.onyx", core_installation));
+        goto skip_parsing_arguments;
     }
     #ifdef ENABLE_RUN_WITH_WASMER
     else if (!strcmp(argv[1], "run")) {
@@ -174,6 +175,16 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg
     }
     #endif
     else {
+        char *script_filename = bh_aprintf(alloc, "%s/tools/%s.wasm", core_installation, argv[1]);
+        if (bh_file_exists(script_filename)) {
+            options.action = ONYX_COMPILE_ACTION_RUN_WASM;
+            options.target_file = script_filename;
+
+            options.passthrough_argument_count = argc - 2;
+            options.passthrough_argument_data  = &argv[2];
+            goto skip_parsing_arguments;
+        }
+
         bh_printf("Unknown subcommand: '%s'\n", argv[1]);
         bh_printf("Run \"onyx help\" for valid subcommands.\n");
         exit(1);
@@ -308,6 +319,8 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg
         }
     }
 
+  skip_parsing_arguments:
+
     // NOTE: Always enable multi-threading for the Onyx runtime.
     if (options.runtime == Runtime_Onyx) {
         options.use_multi_threading = 1;
index fcb101a9e14b21e1b7864d527bb465ab159c5705..c88003acad4e3ee31cca236eb6d26ccb54bef317 100644 (file)
@@ -260,12 +260,17 @@ run_update_command :: (args: [] cstr) {
 """
 --clean          Remove directories of unneeded dependencies. This is not the default
                  behavior, as it could break builds.
+
+--skip-native    Skips compiling native libraries during synchronization.
 """
 }
 run_sync_command :: (args: [] cstr) {
     Sync_Options :: struct {
         #tag "--clean"
         clean := false;
+
+        #tag "--skip-native"
+        skip_native := false;
     }
     options: Sync_Options;
     arg_parse.arg_parse(args, &options);
@@ -301,7 +306,7 @@ run_sync_command :: (args: [] cstr) {
             continue;
         }
 
-        success, installed_folder := install_package(to_install.pack, to_install.downgrade_if_necessary);
+        success, installed_folder := install_package(to_install.pack, to_install.downgrade_if_necessary, options.skip_native);
         if !success {
             error_print("Aborting sync.\n");
             return;
@@ -601,7 +606,7 @@ run_new_command :: (args: [] cstr) {
 }
 
 
-install_package :: (pack: Package, downgrade_if_necessary := false) -> (bool, installed_folder: str) {
+install_package :: (pack: Package, downgrade_if_necessary := false, skip_native_compilation := false) -> (bool, installed_folder: str) {
     package_folder := get_install_path_of_repo(pack.repo);
 
     if os.file_exists(package_folder) {
@@ -627,6 +632,8 @@ install_package :: (pack: Package, downgrade_if_necessary := false) -> (bool, in
         error_print("Failed to fetch {} version {}.\n", pack.repo, pack.version);
         return false, "";
     }
+    
+    if skip_native_compilation do return true, package_folder;
 
     install_success := run_native_library_installation(package_folder);
     return install_success, package_folder;
@@ -772,6 +779,10 @@ run_command_and_forward_output :: (cmd: str) => {
 }
 
 build_package_file_to_load :: () {
+    if !os.dir_exists(config.config.lib_source_directory) {
+        os.dir_create(config.config.lib_source_directory);
+    }
+
     filepath := os.path_join(config.config.lib_source_directory, "packages.onyx");
 
     if os.file_exists(filepath) {