<<
path:
root/public/track.git/html/build.jai
blob: ecba41450f5c6256650673755127a7b14b5aeb22
[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 = "track";
47 if args_compiler_silent target_options.text_output_flags = 0;
49 if args_build_release {
50 build_release(w, *target_options);
52 build_debug(w, *target_options);
56 compiler_begin_intercept(w);
57 add_build_file(tprint("%src/main.jai", #filepath), w);
59 add_build_string(tprint("MEMORY_DEBUGGER_ENABLED :: %;", args_memory_debug), w);
61 compiler_response := message_loop();
62 compiler_end_intercept(w);
64 if !compiler_response {
65 log("Compiler response failed.");
69 if args_program_run run_build_result(w, program_args);
72build_debug :: (w: Workspace, target_options: *Build_Options) {
73 log("Choosing debug options...");
74 target_options.backend =.X64;
75 target_options.output_path = "bin/debug";
76 set_optimization(target_options, Optimization_Type.DEBUG, true);
77 set_build_options(target_options.*, w);
80build_release :: (w: Workspace, target_options: *Build_Options) {
81 log("Choosing release options...");
82 target_options.backend = .LLVM;
83 target_options.output_path = "bin/release";
84 set_optimization(target_options, Optimization_Type.VERY_OPTIMIZED);
85 set_build_options(target_options.*, w);
89args_help_print :: () {
90 help_message := #string _END_
91Usage: jai build.jai - [OPTIONS] :: [PROGRAM ARGS]
94 help Prints this help menu.
95 silent Disables compiler/linker statistics.
96 run Runs your program afterwards.
97 release Builds with release options. If omitted, it builds a debug build.
98 memory Enables the memory leak detector.
100Passing Args to your Program:
101 If you want to supply args to your program, pass it like that:
103 `jai build.jai - run :: my_arg1 foo bar abc ABC`
105 Everything after the `::` get's forwarded to your program.
111program_args_collect :: (args: []string, divider: string = "::") -> [..]string {
114 success, match := array_find(args, divider);
115 if success for i: match+1..args.count-1 array_add(*buf, args[i]);
120message_loop :: () -> success: bool {
122 message := compiler_wait_for_message();
126 message_complete := cast(*Message_Complete) message;
127 return message_complete.error_code == 0;
133#placeholder MEMORY_DEBUGGER_ENABLED;