Logo

index : jinit

---

  • summary
  • about
  • tree
  • log
  • branches
<< path: root/public/jinit.git/html/templates/lib/template.jai blob: 848976bb864652db555f972acc51e9cec8278a7e [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 make_directory_if_it_does_not_exist("bin/debug");
41 make_directory_if_it_does_not_exist("bin/release");
42
43 target_options := get_build_options(w);
44 target_options.output_executable_name = "program";
45
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;
50
51
52 if args_compiler_silent target_options.text_output_flags = 0;
53
54 if args_build_release {
55 build_release(w, *target_options);
56 } else {
57 build_debug(w, *target_options);
58 }
59
60
61 compiler_begin_intercept(w);
62 add_build_file(tprint("%test/test.jai", #filepath), w);
63
64 add_build_string(tprint("MEMORY_DEBUGGER_ENABLED :: %;", args_memory_debug), w);
65
66 compiler_response := message_loop();
67 compiler_end_intercept(w);
68
69 if !compiler_response {
70 log("Compiler response failed.");
71 return;
72 }
73
74 if args_program_run run_build_result_of_workspace(w, program_args);
75}
76
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);
83}
84
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);
91}
92
93
94args_help_print :: () {
95 help_message := #string _END_
96Usage: jai build.jai - [OPTIONS] :: [PROGRAM ARGS]
97
98Options:
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.
104
105Passing Args to your Program:
106 If you want to supply args to your program, pass it like that:
107
108 `jai build.jai - run :: my_arg1 foo bar abc ABC`
109
110 Everything after the `::` get's forwarded to your program.
111
112_END_;
113 log(help_message);
114}
115
116program_args_collect :: (args: []string, divider: string = "::") -> [..]string {
117 buf: [..]string;
118
119 success, match := array_find(args, divider);
120 if success for i: match+1..args.count-1 array_add(*buf, args[i]);
121
122 return buf;
123}
124
125message_loop :: () -> success: bool {
126 while true {
127 message := compiler_wait_for_message();
128 if !message break;
129 if message.kind == {
130 case .COMPLETE;
131 message_complete := cast(*Message_Complete) message;
132 return message_complete.error_code == 0;
133 }
134 }
135 return false;
136}
137
138#placeholder MEMORY_DEBUGGER_ENABLED;
139
140
141main :: () {}
142
143#run build();
144
145
Copyright 2026  E766CB298A6D1E64 | Git-Thing heavily inspired by cgit