<<
path:
root/public/jinit.git/html/templates/lib/template.jai
blob: 848976bb864652db555f972acc51e9cec8278a7e
[raw]
[clear marker]
7 args := get_build_options().compile_time_command_line;
10 args_help := array_find(args, "help");
11 args_compiler_silent := array_find(args, "silent");
12 args_program_run := array_find(args, "run");
13 args_build_release := array_find(args, "release");
14 args_memory_debug := array_find(args, "memory");
18 program_args := program_args_collect(args);
19 defer array_free(program_args);
21 // -----------------------------------------
23 w := compiler_create_workspace();
26 log("Workspace creation failed.");
30 set_build_options_dc(.{ do_output = false });
38 print("The workspace w is %\n", w);
39 make_directory_if_it_does_not_exist("bin");
40 make_directory_if_it_does_not_exist("bin/debug");
41 make_directory_if_it_does_not_exist("bin/release");
43 target_options := get_build_options(w);
44 target_options.output_executable_name = "program";
46 import_path: [..] string;
47 array_add(*import_path, ..target_options.import_path);
48 array_add(*import_path, ".");
49 target_options.import_path = import_path;
52 if args_compiler_silent target_options.text_output_flags = 0;
54 if args_build_release {
55 build_release(w, *target_options);
57 build_debug(w, *target_options);
61 compiler_begin_intercept(w);
62 add_build_file(tprint("%test/test.jai", #filepath), w);
64 add_build_string(tprint("MEMORY_DEBUGGER_ENABLED :: %;", args_memory_debug), w);
66 compiler_response := message_loop();
67 compiler_end_intercept(w);
69 if !compiler_response {
70 log("Compiler response failed.");
74 if args_program_run run_build_result_of_workspace(w, program_args);
77build_debug :: (w: Workspace, target_options: *Build_Options) {
78 log("Choosing debug options...");
79 target_options.backend =.X64;
80 target_options.output_path = "bin/debug";
81 set_optimization(target_options, Optimization_Type.DEBUG, true);
82 set_build_options(target_options.*, w);
85build_release :: (w: Workspace, target_options: *Build_Options) {
86 log("Choosing release options...");
87 target_options.backend = .LLVM;
88 target_options.output_path = "bin/release";
89 set_optimization(target_options, Optimization_Type.VERY_OPTIMIZED);
90 set_build_options(target_options.*, w);
94args_help_print :: () {
95 help_message := #string _END_
96Usage: jai build.jai - [OPTIONS] :: [PROGRAM ARGS]
99 help Prints this help menu.
100 silent Disables compiler/linker statistics.
101 run Runs your program afterwards.
102 release Builds with release options. If omitted, it builds a debug build.
103 memory Enables the memory leak detector.
105Passing Args to your Program:
106 If you want to supply args to your program, pass it like that:
108 `jai build.jai - run :: my_arg1 foo bar abc ABC`
110 Everything after the `::` get's forwarded to your program.
116program_args_collect :: (args: []string, divider: string = "::") -> [..]string {
119 success, match := array_find(args, divider);
120 if success for i: match+1..args.count-1 array_add(*buf, args[i]);
125message_loop :: () -> success: bool {
127 message := compiler_wait_for_message();
131 message_complete := cast(*Message_Complete) message;
132 return message_complete.error_code == 0;
138#placeholder MEMORY_DEBUGGER_ENABLED;