Logo

index : raylib-jai

---

  • summary
  • about
  • tree
  • log
  • branches
<< path: root/public/raylib-jai.git/html/Raylib/generate.jai blob: 849494b08bcf48131815ed3d2adeb1fed3b32be0 [raw] [clear marker]

        
0
1UNIT_NAMES :: string.["raudio", "rcore", "rmodels", "rshapes", "rtext", "rtextures", "utils", "rglfw"];
2
3FILES_TO_COMPILE :: #run -> [UNIT_NAMES.count]string {
4 result: [UNIT_NAMES.count]string;
5
6 for UNIT_NAMES
7 result[it_index] = sprint("raylib/src/%.c", UNIT_NAMES[it_index]);
8
9 return result;
10}
11
12CFLAGS :: string.["-w", "-pipe", "-I./src", "-DPLATFORM_DESKTOP", "-D_GLFW_X11"];
13
14#run,stallable generate();
15generate :: () {
16 set_build_options_dc(.{do_output=false});
17
18 options := get_build_options();
19
20 args := options.compile_time_command_line;
21
22 remove_unneeded_cringe();
23
24 if array_find(args, "compile") {
25 success := build_cpp_static_lib("libraylib", ..FILES_TO_COMPILE, debug=true, extra = CFLAGS);
26
27 if !success {
28 log_error("Building raylib static library failed");
29 compiler_set_workspace_status(.FAILED);
30 return;
31 }
32
33 success = build_cpp_dynamic_lib("libraylib", ..FILES_TO_COMPILE, debug=true, extra = CFLAGS);
34
35 if !success {
36 log_error("Building raylib shared library failed");
37 compiler_set_workspace_status(.FAILED);
38 return;
39 }
40 }
41
42 generate_raylib_bindings(output_filename = "generated.jai");
43}
44
45generate_raylib_bindings :: (output_filename: string) {
46 using opts: Generate_Bindings_Options;
47
48 generate_library_declarations = false;
49
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");
56
57
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;
62
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 });
77
78 return table;
79 }
80
81
82 /* These clash with Jai's Math module. These are the same structs anyway. */
83 NAMES_TO_DISCARD :: string.["Vector2", "Vector3", "Quaternion", "Vector4", "PI"];
84
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 }
91
92 if decl.kind == .FUNCTION {
93 result := table_find_pointer(*STUPID_FUNCTION_TABLE, decl.name);
94
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 }
101
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 }
111
112 return .RECURSE;
113 };
114
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}
121
122remove_unneeded_cringe :: () {
123
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",
140
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",
150
151 "src/external/glfw/CMakeLists.txt",
152 "src/external/glfw/CONTRIBUTORS.md",
153 "src/external/glfw/README.md",
154 "src/external/glfw/.mailmap",
155 ];
156
157 FOLDER :: "raylib";
158
159 for FILES_TO_DELETE {
160 file_to_delete := tprint("%/%", FOLDER, it);
161
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 }
167
168 reset_temporary_storage();
169 }
170
171 FOLDERS_TO_DELETE :: string.[
172 ".git",
173 ".github",
174 "cmake",
175 "examples",
176 "logo",
177 "projects",
178 "tools",
179
180 "src/external/glfw/CMake",
181 ];
182
183 for FOLDERS_TO_DELETE {
184 file_to_delete := tprint("%/%", FOLDER, it);
185
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 }
191
192 reset_temporary_storage();
193 }
194}
195
196#import "Compiler";
197#import "Basic";
198#import "BuildCpp";
199#import "File_Utilities";
200#import "File";
201#import "Hash_Table";
202#import "Bindings_Generator";
203
Copyright 2026  E766CB298A6D1E64 | Git-Thing heavily inspired by cgit