forked from farzher/clipman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
first.jai
122 lines (90 loc) · 3.44 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* -farzher September 13, 2021
Alternative to Ditto
i want an alternative so that i can encrypt the database file.
this code may not compile properly because i added a bunch of hacks
to built-in jai modules to support features like clipboard copy events
*/
RELEASE :: #run get_build_options().array_bounds_check == .OFF;
main_filepath :: "src/main.jai";
exe_icon_path :: "bin/tray.ico";
exe_name :: "clipman";
import_dir :: "src/modules";
#run build();
build :: () {
// seperate build options for debug vs release
build_options((options: *Build_Options) {
build_add_import_dir(options, import_dir);
options.output_executable_name = exe_name;
#if !RELEASE then options.output_path = "bin/";
#if !RELEASE then options.backend = .X64;
#if RELEASE then options.emit_debug_info = .NONE;
#if RELEASE then options.output_path = "release/";
#if RELEASE then #run Windows_Resources.disable_runtime_console();
});
// 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;
return 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_add_import_dir :: (options: *Build_Options, dir: string) {
import_path: [..] string;
array_add(*import_path, dir);
array_add(*import_path, ..options.import_path);
options.import_path = import_path;
}
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);
}