#import "Basic"; #import "Compiler"; #import "File"; #import "Autorun"; build :: () { args := get_build_options().compile_time_command_line; // args args_help := array_find(args, "help"); args_compiler_silent := array_find(args, "silent"); args_program_run := array_find(args, "run"); args_build_release := array_find(args, "release"); // ----------------------------------------- w := compiler_create_workspace(); if !w { log("Workspace creation failed."); return; } set_build_options_dc(.{ do_output = false }); if args_help { args_help_print(); return; } print("The workspace w is %\n", w); make_directory_if_it_does_not_exist("bin"); target_options := get_build_options(w); target_options.output_executable_name = "program"; target_options.output_path = "bin"; import_path: [..] string; array_add(*import_path, ..target_options.import_path); array_add(*import_path, "."); target_options.import_path = import_path; if args_compiler_silent target_options.text_output_flags = 0; if args_build_release { build_release(w, *target_options); } else { build_debug(w, *target_options); } compiler_begin_intercept(w); add_build_file(tprint("%test/test.jai", #filepath), w); jinit_compiler_response := jinit_compiler_intercept(); compiler_end_intercept(w); if !jinit_compiler_response { log("Compiler response failed."); return; } if args_program_run run_build_result(w); } // adapted from: https://github.com/Ivo-Balbaert/The_Way_to_Jai/blob/main/book/30B_Manipulating_the_build_process.md build_debug :: (w: Workspace, target_options: *Build_Options) { log("Choosing debug options..."); target_options.backend =.X64; set_optimization(target_options, Optimization_Type.DEBUG, true); set_build_options(target_options.*, w); } build_release :: (w: Workspace, target_options: *Build_Options) { log("Choosing release options..."); target_options.backend = .LLVM; set_optimization(target_options, Optimization_Type.VERY_OPTIMIZED); set_build_options(target_options.*, w); } args_help_print :: () { help_message := #string _END_ Usage: jai build.jai - [ARGS] Options: help Prints this help menu silent Disables compiler/linker statistics run Runs your program afterwards release Builds with release options. If omitted, it builds a debug build. _END_; log(help_message); } jinit_compiler_intercept :: () -> success: bool { while true { message := compiler_wait_for_message(); if !message break; if message.kind == { case .COMPLETE; message_complete := cast(*Message_Complete) message; return message_complete.error_code == 0; } } return false; } main :: () {} #run build();