forked from focus-editor/focus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst.jai
180 lines (145 loc) · 5.81 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
VERSION :: "0.2.0-dev";
RELEASE_DATE :: #run -> string {
current_time := to_calendar(current_time_consensus());
return calendar_to_string(current_time);
}
#run build();
build :: () {
options := get_build_options();
options.minimum_macos_version = .{12, 0};
args := options.compile_time_command_line;
import_path: [..] string;
array_add(*import_path, "modules");
array_add(*import_path, ..options.import_path);
options.import_path = import_path;
set_build_options_dc(.{do_output=false});
set_working_directory(#filepath);
optimized := false;
windows7 := false;
set_optimization(*options, .DEBUG);
// options.arithmetic_overflow_check = .FATAL; Try uncommenting this line in 0.1.072. Doesn't work correctly on 0.1.071.
build_dir := "build_debug";
options.output_executable_name = "focus";
for arg: args {
if arg == {
case "release";
optimized = true;
build_dir = "build_release";
set_optimization(*options, .VERY_OPTIMIZED);
options.llvm_options.enable_split_modules = false;
options.array_bounds_check = .ON;
options.null_pointer_check = .ON;
options.arithmetic_overflow_check = .OFF;
case "debug";
case "windows7";
windows7 = true;
options.output_executable_name = "focus_windows7";
case;
compiler_report(tprint("Command-line argument #%, '%', is invalid. Valid options are: 'debug', 'release'.\n", it_index+1, arg));
}
}
options.output_path = build_dir;
make_directory_if_it_does_not_exist(build_dir);
w := compiler_create_workspace(options.output_executable_name);
set_build_options(options, w);
#if OS == .WINDOWS {
// Disable runtime console
if optimized {
set_build_options_dc(.{append_linker_arguments=.["/SUBSYSTEM:windows", "/ENTRY:mainCRTStartup"]}, w);
// For tracing release builds use this:
// set_build_options_dc(.{append_linker_arguments=.["/SUBSYSTEM:windows", "/ENTRY:mainCRTStartup", "ws2_32.lib", "msvcprtd.lib"]}, w);
} else {
set_build_options_dc(.{append_linker_arguments=.["ws2_32.lib", "msvcprtd.lib"]}, w);
}
}
compiler_begin_intercept(w);
add_build_file("src/main.jai", w);
build_constants := tprint(#string STRING
VERSION :: "%";
RELEASE_DATE :: "%";
DEBUG :: %;
WINDOWS7 :: %;
STRING,
VERSION,
RELEASE_DATE,
ifx optimized then "false" else "true",
ifx windows7 then "true" else "false",
);
add_build_string(build_constants, w);
while true {
message := compiler_wait_for_message();
if message.workspace != w continue;
if message.kind == .COMPLETE break;
}
compiler_end_intercept(w);
#if OS == .WINDOWS {
exe_path := tprint("%/%.exe", build_dir, options.output_executable_name);
ico_data := create_ico_file_from_bitmap_filename("images/focus.png");
success := set_icon_by_data(exe_path, ico_data);
if !success {
log_error("ERROR: Couldn't set icon for '%'\n", exe_path);
}
manifest_options: Manifest_Options;
success = add_manifest_to_executable(exe_path, manifest_options);
if !success {
log_error("ERROR: Couldn't add manifest to executable '%'\n", exe_path);
}
} else #if OS == .MACOS {
if !optimized return; // When debugging, use the Unix program directly. This saves us compile time.
// Set up our temporary directory to turn into a .dmg disk image
DMG_DIR :: "dmg";
run_command("mkdir", DMG_DIR);
// Generate Focus.app inside our temporary directory
set_working_directory(DMG_DIR);
create_app_bundle("Focus", tprint("../build_release/%", options.output_executable_name), "../images/mac.png", "", true, true);
write_entire_file("Focus.app/Contents/Info.plist", tprint(INFO_PLIST_CONTENTS, VERSION, VERSION));
set_working_directory(#filepath);
// Create a symbolic link to /Applications (what all the cool kids do)
run_command("ln", "-s", "/Applications", DMG_DIR);
// Generate a .DMG using Disk Utility
run_command("hdiutil", "create", "-volname", tprint("Focus %", VERSION), "-srcfolder", DMG_DIR, "-ov", "-format", "UDZO", tprint("Focus-%-Intel.dmg", VERSION));
// Remove our temporary directory when we're done
run_command("rm", "-r", DMG_DIR);
#import "MacOS_Bundler";
#import "Process";
#import "File";
}
}
#import "Compiler";
#import "Basic";
#import "File";
#if OS == .WINDOWS {
#import "Ico_File";
#import "Windows_Resources";
} else #if OS == .MACOS {
INFO_PLIST_CONTENTS :: #string STRING
<?xml version="1.0" ?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist>
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en-US</string>
<key>CFBundleDisplayName</key>
<string>Focus</string>
<key>CFBundleExecutable</key>
<string>Focus</string>
<key>CFBundleIconFile</key>
<string>icon_data.icns</string>
<key>CFBundleIdentifier</key>
<string>dev.focus-editor</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Focus</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>%</string>
<key>CFBundleVersion</key>
<string>%</string>
<key>NSHumanReadableCopyright</key>
<string>© 2023 Ivan Ivanov</string>
</dict>
</plist>
STRING
}