<<
path:
root/public/gist.git/html/jai/hot_reload/build.jai
blob: 1686dcfe38746656c9e18d392113abc76e97bcf2
[raw]
[clear marker]
4args_compiler_silent: bool;
6args_build_release: bool;
7args_memory_debug: bool;
10args_rebuild_editor: bool;
13Release_Kind :: enum_flags {
27 set_build_options_dc(.{ do_output = false });
28 args := get_build_options().compile_time_command_line;
31 args_help = array_find(args, "help");
32 args_compiler_silent = array_find(args, "silent");
33 args_program_run = array_find(args, "run");
34 args_build_release = array_find(args, "release");
35 args_memory_debug = array_find(args, "memory");
36 args_ua_alloc = array_find(args, "ua");
37 args_hot_reload = array_find(args, "hotreload");
38 args_rebuild_editor = array_find(args, "rebuild");
42 program_args := program_args_collect(args);
46 workspace_host := create_workspace("host");
47 workspace_editor := create_workspace("editor");
54 make_directory_if_it_does_not_exist("bin");
55 make_directory_if_it_does_not_exist("bin/debug");
56 make_directory_if_it_does_not_exist("bin/release");
57 make_directory_if_it_does_not_exist("bin/debug_hot");
58 make_directory_if_it_does_not_exist("bin/release_hot");
60 release_as: Release_Kind = ifx args_build_release then .RELEASE else .DEBUG;
61 if args_hot_reload then release_as |= .SHARED;
63 should_run_program := args_program_run ^ (args_hot_reload & args_program_run);
66 workspace_setup(workspace_editor, run=should_run_program, release_as, #code {
67 add_build_string(tprint("IS_HOT_RELOAD :: %;", args_hot_reload), workspace);
68 add_build_file(tprint("%src/main.jai", #filepath), workspace);
71 if args_hot_reload && !args_rebuild_editor {
72 workspace_setup(workspace_host, run=true, .DEBUG, #code {
74 tprint("FP_EDITOR_SO :: \"%\";", "bin/debug_hot/editor.so"), workspace
76 add_build_file(tprint("%src/host.jai", #filepath), workspace);
81build_debug :: (w: Workspace, target_options: *Build_Options) {
82 log("Choosing debug options...");
83 target_options.backend =.X64;
84 target_options.output_path = "bin/debug";
85 set_optimization(target_options, Optimization_Type.DEBUG, true);
86 set_build_options(target_options.*, w);
89build_release :: (w: Workspace, target_options: *Build_Options) {
90 log("Choosing release options...");
91 target_options.backend = .LLVM;
92 target_options.output_path = "bin/release";
93 set_optimization(target_options, Optimization_Type.VERY_OPTIMIZED);
94 set_build_options(target_options.*, w);
97build_dynamic_debug :: (w: Workspace, target_options: *Build_Options) {
98 log("Choosing dyn debug options ...");
99 target_options.backend = .X64;
100 target_options.output_type = .DYNAMIC_LIBRARY;
101 target_options.output_path = "bin/debug_hot";
102 set_optimization(target_options, Optimization_Type.DEBUG, true);
103 set_build_options(target_options.*, w);
106build_dynamic_release :: (w: Workspace, target_options: *Build_Options) {
107 log("Choosing dyn release options ...");
108 target_options.backend = .LLVM;
109 target_options.output_type = .DYNAMIC_LIBRARY;
110 target_options.output_path = "bin/release_hot";
111 set_optimization(target_options, Optimization_Type.VERY_OPTIMIZED);
112 set_build_options(target_options.*, w);
116args_help_print :: () {
117 help_message := #string _END_
118Usage: jai build.jai - [OPTIONS] :: [PROGRAM ARGS]
121 help Prints this help menu.
122 silent Disables compiler/linker statistics.
123 run Runs your program afterwards.
124 release Builds with release options. If omitted, it builds a debug build.
125 memory Enables the memory leak detector.
127Passing Args to your Program:
128 If you want to supply args to your program, pass it like that:
130 `jai build.jai - run :: my_arg1 foo bar abc ABC`
132 Everything after the `::` get's forwarded to your program.
138program_args_collect :: (args: []string, divider: string = "::") -> [..]string {
141 success, match := array_find(args, divider);
142 if success for i: match+1..args.count-1 array_add(*buf, args[i]);
147message_loop :: () -> success: bool {
149 message := compiler_wait_for_message();
153 message_complete := cast(*Message_Complete) message;
154 return message_complete.error_code == 0;
160create_workspace :: (name: string) -> Program #expand {
161 w := compiler_create_workspace(name);
163 log("Workspace creation failed: %", name);
169workspace_setup :: (using program: Program, run: bool, release_kind: Release_Kind, $intercept: Code) #expand {
171 insert_constant :: (label: string, any: Any) #expand {
172 add_build_string(tprint("% :: %;", label, any), `workspace);
176 print("The workspace w is %\n", workspace);
177 target_options := get_build_options(workspace);
178 target_options.output_executable_name = name;
180 if args_compiler_silent target_options.text_output_flags = 0;
184 build_release(workspace, *target_options);
185 case (.SHARED | .RELEASE);
186 build_dynamic_release(workspace, *target_options);
187 case (.SHARED | .DEBUG);
188 build_dynamic_debug(workspace, *target_options);
190 build_debug(workspace, *target_options);
192 compiler_report("Unkown release kind");
195 compiler_begin_intercept(workspace);
197 #insert,scope() intercept;
199 insert_constant("IS_DEVELOPER", !args_build_release);
200 insert_constant("IS_UA_ALLOCATOR", args_ua_alloc);
201 insert_constant("MEMORY_DEBUGGER_ENABLED", args_memory_debug);
203 compiler_response := message_loop();
204 compiler_end_intercept(workspace);
206 if !compiler_response {
207 log("Compiler response failed.");
211 if run then run_build_result_of_workspace(workspace, program_args);