Logo

index : stringpad-jai

---

  • summary
  • about
  • tree
  • log
  • branches
<< path: root/public/stringpad-jai.git/html/build.jai blob: 803665040ce53b7dc01ce2c05fc4636f5b4be308 [raw] [clear marker]

        
0#import "Basic";
1#import "Compiler";
2#import "File";
3#import "Autorun";
4
5
6build :: () {
7 args := get_build_options().compile_time_command_line;
8
9 // args
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");
15
16
17 // program args
18 program_args := program_args_collect(args);
19 defer array_free(program_args);
20
21 // -----------------------------------------
22
23 w := compiler_create_workspace();
24
25 if !w {
26 log("Workspace creation failed.");
27 return;
28 }
29
30 set_build_options_dc(.{ do_output = false });
31
32 if args_help {
33 args_help_print();
34 return;
35 }
36
37
38 print("The workspace w is %\n", w);
39 make_directory_if_it_does_not_exist("bin");
40
41 target_options := get_build_options(w);
42 target_options.output_executable_name = "program";
43 target_options.output_path = "bin";
44
45 import_path: [..] string;
46 array_add(*import_path, ..target_options.import_path);
47 array_add(*import_path, ".");
48 target_options.import_path = import_path;
49
50
51 if args_compiler_silent target_options.text_output_flags = 0;
52
53 if args_build_release {
54 build_release(w, *target_options);
55 } else {
56 build_debug(w, *target_options);
57 }
58
59
60 compiler_begin_intercept(w);
61 add_build_file(tprint("%test/test.jai", #filepath), w);
62
63 add_build_string(tprint("MEMORY_DEBUGGER_ENABLED :: %;", args_memory_debug), w);
64
65 compiler_response := message_loop();
66 compiler_end_intercept(w);
67
68 if !compiler_response {
69 log("Compiler response failed.");
70 return;
71 }
72
73 if args_program_run run_build_result(w, program_args);
74}
75
76build_debug :: (w: Workspace, target_options: *Build_Options) {
77 log("Choosing debug options...");
78 target_options.backend =.X64;
79 set_optimization(target_options, Optimization_Type.DEBUG, true);
80 set_build_options(target_options.*, w);
81}
82
83build_release :: (w: Workspace, target_options: *Build_Options) {
84 log("Choosing release options...");
85 target_options.backend = .LLVM;
86 set_optimization(target_options, Optimization_Type.VERY_OPTIMIZED);
87 set_build_options(target_options.*, w);
88}
89
90
91args_help_print :: () {
92 help_message := #string _END_
93Usage: jai build.jai - [OPTIONS] :: [PROGRAM ARGS]
94
95Options:
96 help Prints this help menu.
97 silent Disables compiler/linker statistics.
98 run Runs your program afterwards.
99 release Builds with release options. If omitted, it builds a debug build.
100 memory Enables the memory leak detector.
101
102Passing Args to your Program:
103 If you want to supply args to your program, pass it like that:
104
105 `jai build.jai - run :: my_arg1 foo bar abc ABC`
106
107 Everything after the `::` get's forwarded to your program.
108
109_END_;
110 log(help_message);
111}
112
113program_args_collect :: (args: []string, divider: string = "::") -> [..]string {
114 buf: [..]string;
115
116 success, match := array_find(args, divider);
117 if success for i: match+1..args.count-1 array_add(*buf, args[i]);
118
119 return buf;
120}
121
122message_loop :: () -> success: bool {
123 while true {
124 message := compiler_wait_for_message();
125 if !message break;
126 if message.kind == {
127 case .COMPLETE;
128 message_complete := cast(*Message_Complete) message;
129 return message_complete.error_code == 0;
130 }
131 }
132 return false;
133}
134
135#placeholder MEMORY_DEBUGGER_ENABLED;
136
137
138main :: () {}
139
140#run build();
141
142
Copyright 2026  E766CB298A6D1E64 | Git-Thing heavily inspired by cgit