-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_handmade.jai
74 lines (63 loc) · 2.54 KB
/
build_handmade.jai
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Thanks to https://github.com/colinbellino/jai-code-hot-reloading-example
#import "Basic";
#import "File";
#import "File_Utilities"; // for visit_files
#import "Compiler";
OUTPUT_PATH :: "build/";
OUPUT_EXECUTABLE_NAME :: "handmade";
#run {
set_build_options_dc(.{ do_output = false });
make_directory_if_it_does_not_exist(OUTPUT_PATH, recursive = true);
// Since the build can generate a lot debug and temporary files if you use it a lot,
// we do some clean up to not keep too much garbage.
visit_files(OUTPUT_PATH, recursive = false, null, delete_app_files_visitor, visit_files = true, visit_directories = true);
log("Compiling app. | OS: % | CPU: %", OS, CPU);
w := compiler_create_workspace("Build handmade");
options := get_build_options(w);
copy_commonly_propagated_fields(get_build_options(), *options);
options.output_path = OUTPUT_PATH;
options.output_executable_name = OUPUT_EXECUTABLE_NAME;
options.output_type = .DYNAMIC_LIBRARY; // Important!
options.os_target = OS;
options.cpu_target = CPU;
//options.backend = .X64;
set_optimization(*options, .DEBUG);
set_build_options(options, w);
compiler_begin_intercept(w);
// HANDMADE_INTERNAL indicates when we're trying to do something that we'de only want to do internally
// (e.g., specify allocator pointer positions)
// HANDMADE_DEBUG indicates something we'd only want in debug builds (e.g., asserts) -- there might be a better way to do this,
// or I think assert already does an #if ASSERT
build_constants := tprint(#string STRING
HANDMADE_INTERNAL :: %;
HANDMADE_DEBUG :: %;
STRING,
true,
true,
);
add_build_string(build_constants, w);
add_build_file("src/handmade.jai", w);
while true {
message := compiler_wait_for_message();
if message.kind == {
case .COMPLETE; {
message_complete := (cast(*Message_Complete) message);
if message_complete.error_code != .NONE {
exit(1);
}
break;
}
}
}
compiler_end_intercept(w);
};
delete_app_files_visitor :: (info: *File_Visit_Info, user_data: *void) {
#import "String";
if starts_with(info.short_name, "handmade.") {
if info.is_directory {
delete_directory(info.full_name);
} else {
file_delete(info.full_name);
}
}
}