#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"); args_memory_debug := array_find(args, "memory"); // program args program_args := program_args_collect(args); defer array_free(program_args); // ----------------------------------------- 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"); make_directory_if_it_does_not_exist("bin/debug"); make_directory_if_it_does_not_exist("bin/release"); target_options := get_build_options(w); target_options.output_executable_name = "track"; 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("%src/main.jai", #filepath), w); add_build_string(tprint("MEMORY_DEBUGGER_ENABLED :: %;", args_memory_debug), w); compiler_response := message_loop(); compiler_end_intercept(w); if !compiler_response { log("Compiler response failed."); return; } if args_program_run run_build_result(w, program_args); } build_debug :: (w: Workspace, target_options: *Build_Options) { log("Choosing debug options..."); target_options.backend =.X64; target_options.output_path = "bin/debug"; 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; target_options.output_path = "bin/release"; 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 - [OPTIONS] :: [PROGRAM 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. memory Enables the memory leak detector. Passing Args to your Program: If you want to supply args to your program, pass it like that: `jai build.jai - run :: my_arg1 foo bar abc ABC` Everything after the `::` get's forwarded to your program. _END_; log(help_message); } program_args_collect :: (args: []string, divider: string = "::") -> [..]string { buf: [..]string; success, match := array_find(args, divider); if success for i: match+1..args.count-1 array_add(*buf, args[i]); return buf; } message_loop :: () -> 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; } #placeholder MEMORY_DEBUGGER_ENABLED; main :: () {} #run build();