-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.jai
More file actions
387 lines (334 loc) · 12.3 KB
/
Copy pathgenerate.jai
File metadata and controls
387 lines (334 loc) · 12.3 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
//
//idk how to include a folder using build_cpp procedure.
box3d_dir :: "box3d-0.1.0";
cmake_build_dir :: #run tprint("%/build", box3d_dir);
BOX3D_MAIN_HEADER_FILE_RELATIVE_PATH :: "-I\\box3d-0.1.0\\include";
BOX3D_INCLUDE_FILES :: string.[
"./box3d-0.1.0/include/box3d/box3d.h",
"./box3d-0.1.0/include/box3d/base.h",
"./box3d-0.1.0/include/box3d/collision.h",
"./box3d-0.1.0/include/box3d/config.h",
"./box3d-0.1.0/include/box3d/constants.h",
"./box3d-0.1.0/include/box3d/id.h",
"./box3d-0.1.0/include/box3d/math_functions.h",
"./box3d-0.1.0/include/box3d/types.h",
];
//this is copied and sligthly modified from "./src/CMakeLists.txt"
BOX3D_SOURCE_FILES :: string.[
"./box3d-0.1.0/src/aabb.c",
"./box3d-0.1.0/src/aabb.h",
"./box3d-0.1.0/src/algorithm.h",
"./box3d-0.1.0/src/arena_allocator.c",
"./box3d-0.1.0/src/arena_allocator.h",
"./box3d-0.1.0/src/bitset.c",
"./box3d-0.1.0/src/bitset.h",
"./box3d-0.1.0/src/block_allocator.c",
"./box3d-0.1.0/src/block_allocator.h",
"./box3d-0.1.0/src/body.c",
"./box3d-0.1.0/src/body.h",
"./box3d-0.1.0/src/broad_phase.c",
"./box3d-0.1.0/src/broad_phase.h",
"./box3d-0.1.0/src/capsule.c",
"./box3d-0.1.0/src/compound.c",
"./box3d-0.1.0/src/compound.h",
"./box3d-0.1.0/src/constraint_graph.c",
"./box3d-0.1.0/src/constraint_graph.h",
"./box3d-0.1.0/src/contact.c",
"./box3d-0.1.0/src/contact.h",
"./box3d-0.1.0/src/contact_solver.c",
"./box3d-0.1.0/src/contact_solver.h",
"./box3d-0.1.0/src/container.h",
"./box3d-0.1.0/src/convex_manifold.c",
"./box3d-0.1.0/src/core.c",
"./box3d-0.1.0/src/core.h",
"./box3d-0.1.0/src/ctz.h",
"./box3d-0.1.0/src/distance.c",
"./box3d-0.1.0/src/distance_joint.c",
"./box3d-0.1.0/src/dynamic_tree.c",
"./box3d-0.1.0/src/height_field.c",
"./box3d-0.1.0/src/hull.c",
"./box3d-0.1.0/src/id_pool.c",
"./box3d-0.1.0/src/id_pool.h",
"./box3d-0.1.0/src/island.c",
"./box3d-0.1.0/src/island.h",
"./box3d-0.1.0/src/joint.c",
"./box3d-0.1.0/src/joint.h",
"./box3d-0.1.0/src/manifold.c",
"./box3d-0.1.0/src/manifold.h",
"./box3d-0.1.0/src/math_functions.c",
"./box3d-0.1.0/src/math_internal.h",
"./box3d-0.1.0/src/mesh.c",
"./box3d-0.1.0/src/mesh_contact.c",
"./box3d-0.1.0/src/motor_joint.c",
"./box3d-0.1.0/src/mover.c",
"./box3d-0.1.0/src/parallel_for.c",
"./box3d-0.1.0/src/parallel_for.h",
"./box3d-0.1.0/src/parallel_joint.c",
"./box3d-0.1.0/src/physics_world.c",
"./box3d-0.1.0/src/physics_world.h",
"./box3d-0.1.0/src/platform.h",
"./box3d-0.1.0/src/prismatic_joint.c",
"./box3d-0.1.0/src/qsort.h",
"./box3d-0.1.0/src/recording.c",
"./box3d-0.1.0/src/recording.h",
"./box3d-0.1.0/src/recording_ops.inl",
"./box3d-0.1.0/src/recording_replay.c",
"./box3d-0.1.0/src/recording_replay.h",
"./box3d-0.1.0/src/world_snapshot.c",
"./box3d-0.1.0/src/world_snapshot.h",
"./box3d-0.1.0/src/revolute_joint.c",
"./box3d-0.1.0/src/scheduler.c",
"./box3d-0.1.0/src/scheduler.h",
"./box3d-0.1.0/src/sensor.c",
"./box3d-0.1.0/src/sensor.h",
"./box3d-0.1.0/src/shape.c",
"./box3d-0.1.0/src/shape.h",
"./box3d-0.1.0/src/simd.c",
"./box3d-0.1.0/src/simd.h",
"./box3d-0.1.0/src/solver.c",
"./box3d-0.1.0/src/solver.h",
"./box3d-0.1.0/src/solver_set.c",
"./box3d-0.1.0/src/solver_set.h",
"./box3d-0.1.0/src/sphere.c",
"./box3d-0.1.0/src/spherical_joint.c",
"./box3d-0.1.0/src/table.c",
"./box3d-0.1.0/src/table.h",
"./box3d-0.1.0/src/timer.c",
"./box3d-0.1.0/src/triangle_manifold.c",
"./box3d-0.1.0/src/types.c",
"./box3d-0.1.0/src/verstable.h",
"./box3d-0.1.0/src/weld_joint.c",
"./box3d-0.1.0/src/wheel_joint.c",
"./box3d-0.1.0/src/box3d.natvis",
];
AT_COMPILE_TIME :: true;
PS5_SUPPORT :: false;
NINTENDO_SUPPORT :: #run to_string(getenv("NINTENDO_SDK_ROOT")) != "";
LIB_BASE_NAME :: "box3d";
#if AT_COMPILE_TIME {
#run,stallable {
set_build_options_dc(.{do_output=false});
options := get_build_options();
args := options.compile_time_command_line;
if !generate_bindings(args, options.minimum_os_version) {
compiler_set_workspace_status(.FAILED);
}
}
} else {
#import "System";
main :: () {
set_working_directory(path_strip_filename(get_path_of_running_executable()));
if !generate_bindings(get_command_line_arguments(), #run get_build_options().minimum_os_version) {
exit(1);
}
}
}
generate_bindings :: (args: [] string, minimum_os_version: type_of(Build_Options.minimum_os_version)) -> bool {
using BG;
target_android := array_find(args, "-android");
target_ps5 := array_find(args, "-ps5");
target_x64 := array_find(args, "-x64");
target_arm := array_find(args, "-arm64");
compile := array_find(args, "-compile") | array_find(args, "--compile");
compile_debug := array_find(args, "-debug");
os_target := OS;
cpu_target := CPU;
if target_android os_target = .ANDROID;
if target_ps5 os_target = .PS5;
if target_x64 cpu_target = .X64;
if target_arm cpu_target = .ARM64;
build_dynamic_lib := true;
lib_directory: string;
cmake_preset: string;
build_preset: string;
lib_file_pattern: string;
if os_target == {
case .WINDOWS;
lib_directory = "windows";
cmake_preset = "windows";
build_preset = "windows-release";
lib_file_pattern = "box3d.lib";
case .LINUX;
lib_directory = "linux";
cmake_preset = "linux-release";
build_preset = "linux-release";
lib_file_pattern = "box3d.a";
case .MACOS;
lib_directory = "macos";
cmake_preset = "macos";
build_preset = "macos-release";
lib_file_pattern = "box3d.a";
case .ANDROID;
lib_directory = ifx cpu_target == .X64 then "android/x64" else "android/arm64";
cmake_preset = "linux-release";
build_preset = "linux-release";
lib_file_pattern = "box3d.a";
case .PS5;
build_dynamic_lib = false;
lib_directory = "ps5";
cmake_preset = "ps5";
build_preset = "ps5-release";
lib_file_pattern = "box3d.a";
case;
assert(false);
}
if compile {
make_directory_if_it_does_not_exist(lib_directory, recursive = true);
success := compile_with_cmake(lib_directory, cmake_preset, build_preset, compile_debug, os_target);
if !success return false;
}
options: Generate_Bindings_Options;
options.os = os_target;
options.cpu = cpu_target;
{
using options;
try_to_preserve_comments = false;
array_add(*library_search_paths, lib_directory);
array_add(*libraries, .{filename=LIB_BASE_NAME});
array_add(*source_files, ..BOX3D_INCLUDE_FILES);
header = tprint(HEADER_TEMPLATE, LIB_BASE_NAME);
generate_library_declarations = false;
footer = tprint(FOOTER_TEMPLATE, LIB_BASE_NAME);
auto_detect_enum_prefixes = true;
log_stripped_declarations = false;
generate_compile_time_struct_checks = false;
//here the thingy to replace definitons, just dont forget to also add them in HADER, FOOTER is canpsualted in #scope_file
visitor = (decl: *Declaration, parent_decl: *Declaration) -> Declaration_Visit_Result {
if decl.kind == .STRUCT && (
decl.name == "b3Vec2"
|| decl.name == "b3Vec3"
|| decl.name == "b3Quat"
|| decl.name == "b3Matrix3"
) {
decl.decl_flags |= .OMIT_FROM_OUTPUT;
return .STOP;
}
return .RECURSE;
};
}
output_filename := "bindings.jai";
return generate_bindings(options, output_filename);
}
HEADER_TEMPLATE :: #string END
//from core.h
B3_SECRET_COOKIE :: 1152023;
//from core.c
// This allows the user to change the length units at runtime
// b3_lengthUnitsPerMeter: float = 1.0;
b3Vec2 :: Vector2;
b3Vec3 :: Vector3;
b3Quat :: Quaternion;
b3Matrix3 :: Matrix3;
b3Quat_identity :b3Quat: { 0.0, 0.0, 0.0, 1.0 };
END
FOOTER_TEMPLATE :: #string END
#if OS == .WINDOWS {
%1 :: #library,no_dll "windows/%1";
} else #if OS == .LINUX {
%1 :: #library,no_dll "linux/%1";
} else #if OS == .MACOS {
%1 :: #library,no_dll "macos/%1";
} else #if OS == .ANDROID {
#if CPU == .X64 {
%1 :: #library,no_dll "android/x64/%1";
} else #if CPU == .ARM64 {
%1 :: #library,no_dll "android/arm64/%1";
}
} else #if OS == .PS5 {
%1 :: #library,no_dll "ps5/%1";
} else {
#assert false;
}
END
compile_with_cmake :: (lib_directory: string, cmake_preset: string, build_preset: string, debug: bool, os_target: type_of(OS)) -> bool {
old_dir := get_working_directory();
defer set_working_directory(old_dir);
set_working_directory(box3d_dir);
// Run cmake configure step
print("Running CMake configure with preset: %\n", cmake_preset);
configure_cmd := tprint("cmake --preset %", cmake_preset);
#import "String";
arr_configure_cmd := split(configure_cmd, " "); // Split the command into an array of strings
run_or_exit(arr_configure_cmd, get_working_directory()) ;
// Run cmake build step
print("Running CMake build with preset: %\n", build_preset);
build_cmd := tprint("cmake --build --preset %", build_preset);
arr_build_cmd := split(build_cmd, " "); // Split the command into an array of strings
run_or_exit(arr_build_cmd, get_working_directory());
// Go back to original directory for copying
set_working_directory(old_dir);
// Copy the compiled library to the destination directory
print("Copying compiled library to %\n", lib_directory);
if !copy_compiled_library(box3d_dir, lib_directory, os_target, debug) {
print("ERROR: Failed to copy compiled library\n");
return false;
}
print("Successfully compiled and copied box3d library\n");
return true;
}
run_or_exit :: (command: [] string, working_directory: string) {
// Enable this to see the commands being executed.
// print("Executing command \"%\" in directory \"%\"\n", join(..command, separator = " "), working_directory);
result, output_string, error_string := run_command(..command, working_directory = working_directory, capture_and_return_output = true, print_captured_output = true);
defer {
free(output_string);
free(error_string);
}
if result.exit_code != 0 {
log_error("Could not run command \"%\" in directory \"%\". Exit code: %\nError:\n%", get_quoted_command_string(command), working_directory, result.exit_code, error_string);
exit(1);
}
}
execute_command :: (command: string) -> Process_Result {
Process :: #import "Process";
return Process.run_command(command);
}
copy_compiled_library :: (box3d_dir: string, dest_dir: string, os_target: type_of(OS), debug: bool) -> bool {
source_path: string;
if os_target == {
case .WINDOWS;
source_path = tprint("%/src/Release/box3d.lib", cmake_build_dir);
case .LINUX;
source_path = tprint("%/src/Release/box3d.a", cmake_build_dir);
case .MACOS;
source_path = tprint("%/src/Release/box3d.a", cmake_build_dir);
case .ANDROID;
source_path = tprint("%/src/Release/box3d.a", cmake_build_dir);
case .PS5;
source_path = tprint("%/src/Release/box3d.a", cmake_build_dir);
case;
print("ERROR: Unknown OS target\n");
return false;
}
dest_path := tprint("%/box3d.lib", dest_dir);
if os_target != .WINDOWS {
if debug {
dest_path = tprint("%/box3d_d.a", dest_dir);
} else {
dest_path = tprint("%/box3d.a", dest_dir);
}
}
print("Copying from: %\n", source_path);
print("Copying to: %\n", dest_path);
if !file_exists(source_path) {
print("ERROR: Source library not found at: %\n", source_path);
return false;
}
if !copy_file(source_path, dest_path) {
print("ERROR: Failed to copy file from % to %\n", source_path, dest_path);
return false;
}
return true;
}
#import "Basic";
BG :: #import "Bindings_Generator"(NINTENDO_SUPPORT = NINTENDO_SUPPORT);
#import "Compiler";
#import "File";
#import "File_Utilities";
#import "Android/Toolchain";
#import "Process";
#if OS == .WINDOWS {
#import "Windows";
} else {
#import "POSIX";
}