Logo

index : termcolors-jai

---

  • summary
  • about
  • tree
  • log
  • branches
<< path: root/public/termcolors-jai.git/html/build.jai blob: 2749bbb41247b83bfe06608381ca5d848323218c [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
15
16 // -----------------------------------------
17 w := compiler_create_workspace();
18
19 if !w {
20 log("Workspace creation failed.");
21 return;
22 }
23
24 set_build_options_dc(.{ do_output = false });
25
26 if args_help {
27 args_help_print();
28 return;
29 }
30
31
32 print("The workspace w is %\n", w);
33 make_directory_if_it_does_not_exist("bin");
34
35 target_options := get_build_options(w);
36 target_options.output_executable_name = "program";
37 target_options.output_path = "bin";
38
39 import_path: [..] string;
40 array_add(*import_path, ..target_options.import_path);
41 array_add(*import_path, ".");
42 target_options.import_path = import_path;
43
44 if args_compiler_silent target_options.text_output_flags = 0;
45
46 if args_build_release {
47 build_release(w, *target_options);
48 } else {
49 build_debug(w, *target_options);
50 }
51
52
53 compiler_begin_intercept(w);
54 add_build_file(tprint("%test/test.jai", #filepath), w);
55
56 jinit_compiler_response := jinit_compiler_intercept();
57 compiler_end_intercept(w);
58
59 if !jinit_compiler_response {
60 log("Compiler response failed.");
61 return;
62 }
63
64 if args_program_run run_build_result(w);
65}
66
67
68// adapted from: https://github.com/Ivo-Balbaert/The_Way_to_Jai/blob/main/book/30B_Manipulating_the_build_process.md
69
70build_debug :: (w: Workspace, target_options: *Build_Options) {
71 log("Choosing debug options...");
72 target_options.backend =.X64;
73 set_optimization(target_options, Optimization_Type.DEBUG, true);
74 set_build_options(target_options.*, w);
75}
76
77build_release :: (w: Workspace, target_options: *Build_Options) {
78 log("Choosing release options...");
79 target_options.backend = .LLVM;
80 set_optimization(target_options, Optimization_Type.VERY_OPTIMIZED);
81 set_build_options(target_options.*, w);
82}
83
84
85args_help_print :: () {
86 help_message := #string _END_
87Usage: jai build.jai - [ARGS]
88
89Options:
90 help Prints this help menu
91 silent Disables compiler/linker statistics
92 run Runs your program afterwards
93 release Builds with release options. If omitted, it builds a debug build.
94
95_END_;
96 log(help_message);
97}
98
99jinit_compiler_intercept :: () -> success: bool {
100 while true {
101 message := compiler_wait_for_message();
102 if !message break;
103 if message.kind == {
104 case .COMPLETE;
105 message_complete := cast(*Message_Complete) message;
106 return message_complete.error_code == 0;
107 }
108 }
109 return false;
110}
111
112main :: () {}
113
114#run build();
115
Copyright 2026  E766CB298A6D1E64 | Git-Thing heavily inspired by cgit