-
Notifications
You must be signed in to change notification settings - Fork 3
/
first.jai
99 lines (73 loc) · 2.76 KB
/
first.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
RELEASE :: #run get_build_options().optimization_level == .RELEASE;
main_filepath :: "src/main.jai";
exe_icon_path :: "assets/bunny.ico";
#run build();
build :: () {
// seperate build options for debug vs release
build_options((options: *Build_Options) {
options.output_executable_name = "bunnymark";
#if !RELEASE then options.backend = .X64;
#if RELEASE then #run Windows_Resources.disable_runtime_console();
#if RELEASE then options.emit_debug_info = .NONE;
});
// wait for the exe to finish compiling, so we can set its icon
build_compile(main_filepath);
// set exe icon
exe_path := tprint("%1%2.exe", options.output_path, options.output_executable_name);
Windows_Resources.set_icon_by_filename(exe_path, exe_icon_path);
// update the readme with the jai compiler version we're using
#if RELEASE replace_autogenerated("README.md", "the_compiler", compiler_version_string);
}
// replaces occurances of #name(whatever) with #name(value) in the file
replace_autogenerated :: (filepath: string, name: string, value: string) {
filetext := File.read_entire_file(filepath);
assert(filetext != "");
index := find_index_from_left(filetext, tprint("#%(", name));
assert(index != -1);
index_end := find_index_from_left(filetext, ")", index);
assert(index_end != -1);
index_end += ")".count;
string_to_replace: string;
string_to_replace.data = *filetext[index];
string_to_replace.count = index_end - index;
newfiletext := replace(filetext, string_to_replace, tprint("#%(%)", name, value));
if newfiletext == filetext return;
File.write_entire_file(filepath, newfiletext);
}
compiler_version_string :: #run -> string {
compiler_version_info: Version_Info;
compiler_get_version_info(*compiler_version_info);
return tprint("v%.%.%", compiler_version_info.major, compiler_version_info.minor, compiler_version_info.micro);
};
#import "Basic";
#import "Compiler";
#import "String";
Windows_Resources :: #import "Windows_Resources";
File :: #import "File";
w: Workspace;
options: Build_Options;
build_inited := false;
build_ensure_init :: () {
if build_inited return; build_inited = true;
w = compiler_create_workspace();
options = get_build_options();
set_build_options_dc(.{do_output=false});
}
build_options :: (fn: (*Build_Options)) {
build_ensure_init();
fn(*options);
set_build_options(options, w);
}
build_compile :: (src_files: ..string) {
build_ensure_init();
compiler_begin_intercept(w);
for src_files add_build_file(it, w);
// actually compile the code, and wait for it to finish compiling
while true {
message := compiler_wait_for_message();
if !message continue;
if message.workspace != w continue;
if message.kind == .COMPLETE break;
}
compiler_end_intercept(w);
}