1UNIT_NAMES :: string.["raudio", "rcore", "rmodels", "rshapes", "rtext", "rtextures", "utils", "rglfw"];
3FILES_TO_COMPILE :: #run -> [UNIT_NAMES.count]string {
4 result: [UNIT_NAMES.count]string;
6 for UNIT_NAMES
7 result[it_index] = sprint("raylib/src/%.c", UNIT_NAMES[it_index]);
9 return result;
10}
12CFLAGS :: string.["-w", "-pipe", "-I./src", "-DPLATFORM_DESKTOP", "-D_GLFW_X11"];
14#run,stallable generate();
15generate :: () {
16 set_build_options_dc(.{do_output=false});
18 options := get_build_options();
20 args := options.compile_time_command_line;
22 remove_unneeded_cringe();
24 if array_find(args, "compile") {
25 success := build_cpp_static_lib("libraylib", ..FILES_TO_COMPILE, debug=true, extra = CFLAGS);
27 if !success {
28 log_error("Building raylib static library failed");
29 compiler_set_workspace_status(.FAILED);
30 return;
31 }
33 success = build_cpp_dynamic_lib("libraylib", ..FILES_TO_COMPILE, debug=true, extra = CFLAGS);
35 if !success {
36 log_error("Building raylib shared library failed");
37 compiler_set_workspace_status(.FAILED);
38 return;
39 }
40 }
42 generate_raylib_bindings(output_filename = "generated.jai");
43}
45generate_raylib_bindings :: (output_filename: string) {
46 using opts: Generate_Bindings_Options;
48 generate_library_declarations = false;
50 array_add(*library_search_paths,"./");
51 array_add(*libraries, { filename = "libraylib" });
52 array_add(*include_paths, "raylib/src/external/glfw/include");
53 array_add(*source_files, "raylib/src/raylib.h");
54 array_add(*source_files, "raylib/src/rlgl.h");
55 array_add(*source_files, "raylib/src/raymath.h");
58 /* Raylib for some reason loves using `int` instead of the actual enum type. */
59 Stupid_Table :: #type Table(string, struct { #as using type: CType; argument_position: s64; });
60 STUPID_FUNCTION_TABLE :: #run -> Stupid_Table {
61 table: Stupid_Table;
63 table_add(*table, "SetConfigFlags", { hardcoded_jai_string = "ConfigFlags", argument_position = 0 });
64 table_add(*table, "IsKeyDown", { hardcoded_jai_string = "KeyboardKey", argument_position = 0 });
65 table_add(*table, "IsKeyPressed", { hardcoded_jai_string = "KeyboardKey", argument_position = 0 });
66 table_add(*table, "IsKeyPressedRepeat", { hardcoded_jai_string = "KeyboardKey", argument_position = 0 });
67 table_add(*table, "IsMouseButtonDown", { hardcoded_jai_string = "MouseButton", argument_position = 0 });
68 table_add(*table, "IsMouseButtonUp", { hardcoded_jai_string = "MouseButton", argument_position = 0 });
69 table_add(*table, "IsMouseButtonReleased", { hardcoded_jai_string = "MouseButton", argument_position = 0 });
70 table_add(*table, "IsMouseButtonPressed", { hardcoded_jai_string = "MouseButton", argument_position = 0 });
71 table_add(*table, "SetMouseCursor", { hardcoded_jai_string = "MouseCursor", argument_position = 0 });
72 table_add(*table, "SetShaderValue", { hardcoded_jai_string = "ShaderUniformDataType", argument_position = 3 });
73 table_add(*table, "SetTraceLogLevel", { hardcoded_jai_string = "TraceLogLevel", argument_position = 0 });
74 table_add(*table, "UpdateCamera", { hardcoded_jai_string = "CameraMode", argument_position = 1 });
75 table_add(*table, "LoadFontData", { hardcoded_jai_string = "FontType", argument_position = 5 });
76 table_add(*table, "SetTextureFilter", { hardcoded_jai_string = "TextureFilter", argument_position = 1 });
78 return table;
79 }
82 /* These clash with Jai's Math module. These are the same structs anyway. */
83 NAMES_TO_DISCARD :: string.["Vector2", "Vector3", "Quaternion", "Vector4", "PI"];
85 visitor = (decl: *Declaration, parent_decl: *Declaration) -> Declaration_Visit_Result {
86 if array_find(NAMES_TO_DISCARD, decl.name) {
87 log("Discarded raylib's %", decl.name);
88 decl.decl_flags |= .OMIT_FROM_OUTPUT;
89 return .STOP;
90 }
92 if decl.kind == .FUNCTION {
93 result := table_find_pointer(*STUPID_FUNCTION_TABLE, decl.name);
95 if result != null {
96 /* Replace the argument type at the position with a hardcoded string. For example: u32 -> ConfigFlags */
97 cast(*Function, decl).type.type_of_function.arguments[result.argument_position].type = result;
98 log("Fixed the type of stupid function '%'", decl.name);
99 }
100 }
102 if parent_decl && parent_decl.kind == .STRUCT {
103 if parent_decl.name == "Camera3D"
104 && decl.name == "projection"
105 && decl.kind == .DECLARATION
106 && decl.type.number_flags == ._32BIT | .SIGNED {
107 change_type_to_enum(decl, "CameraProjection");
108 log("Changed the type of '%(%)'", parent_decl.name, parent_decl.kind);
109 }
110 }
112 return .RECURSE;
113 };
115 if !generate_bindings(opts, output_filename) {
116 log_error("Failed to generated raylib bindings");
117 compiler_set_workspace_status(.FAILED);
118 return;
119 }
120}
122remove_unneeded_cringe :: () {
124 FILES_TO_DELETE :: string.[
125 ".gitignore",
126 "BINDINGS.md",
127 "CHANGELOG",
128 "CMakeLists.txt",
129 "CMakeOptions.txt",
130 "CONTRIBUTING.md",
131 "CONVENTIONS.md",
132 "FAQ.md",
133 "HISTORY.md",
134 "README.md",
135 "ROADMAP.md",
136 "SECURITY.md",
137 "build.zig",
138 "build.zig.zon",
139 "raylib.pc.in",
141 "src/CMakeLists.txt",
142 "src/Makefile",
143 "src/minshell.html",
144 "src/raylib.dll.rc",
145 "src/raylib.dll.rc.data",
146 "src/raylib.ico",
147 "src/raylib.rc",
148 "src/raylib.rc.data",
149 "src/shell.html",
151 "src/external/glfw/CMakeLists.txt",
152 "src/external/glfw/CONTRIBUTORS.md",
153 "src/external/glfw/README.md",
154 "src/external/glfw/.mailmap",
155 ];
157 FOLDER :: "raylib";
159 for FILES_TO_DELETE {
160 file_to_delete := tprint("%/%", FOLDER, it);
162 if file_exists(file_to_delete) {
163 assert(!is_directory(file_to_delete));
164 file_delete(file_to_delete);
165 log("Deleted cringe file - %", file_to_delete);
166 }
168 reset_temporary_storage();
169 }
171 FOLDERS_TO_DELETE :: string.[
172 ".git",
173 ".github",
174 "cmake",
175 "examples",
176 "logo",
177 "projects",
178 "tools",
180 "src/external/glfw/CMake",
181 ];
183 for FOLDERS_TO_DELETE {
184 file_to_delete := tprint("%/%", FOLDER, it);
186 if file_exists(file_to_delete) {
187 assert(is_directory(file_to_delete));
188 delete_directory(file_to_delete);
189 log("Deleted cringe directory - %", file_to_delete);
190 }
192 reset_temporary_storage();
193 }
194}
196#import "Compiler";
197#import "Basic";
198#import "BuildCpp";
199#import "File_Utilities";
200#import "File";
201#import "Hash_Table";
202#import "Bindings_Generator";
index : raylib-jai
---