Logo

index : jinit

---

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