Author:ptrace Comitter:ptrace Date:2026-01-26 03:17:04 UTC Merge: 7f24ab21f049f98a0f422d1033ad99f843cdbaef 2cdf89378fdb0ea9e2e9817a1ef7102f5c6b4bf6

Merge pull request 'Added raylib template' (#8) from feature/added-template-raylib into main

Reviewed-on: https://codeberg.org/ptrace/jai-init/pulls/8

diff --git a/src/main.jai b/src/main.jai index 8784ef6..834b3df 100644 --- a/src/main.jai +++ b/src/main.jai @@ -24,7 +24,7 @@  */ /*     +Version: 2.3.0     +Version: 2.3.1 */ #import "Basic"; diff --git a/templates/raylib/rules_raylib.jai b/templates/raylib/rules_raylib.jai new file mode 100644 index 0000000..3b47bdb --- /dev/null +++ b/templates/raylib/rules_raylib.jai @@ -0,0 +1,57 @@ () -> Rules {     gitignore :: #string STR_END # Jai .build /bin     STR_END;     main_jai :: #string STR_END #import "Basic"()(     MEMORY_DEBUGGER = MEMORY_DEBUGGER_ENABLED ); #import "Math"; #import "raylib"; main :: () {     #if MEMORY_DEBUGGER_ENABLED defer report_memory_leaks();     log("Hello, Sailor!");     //SetTraceLogLevel(.LOG_NONE);     //SetConfigFlags(.FLAG_MSAA_4X_HINT);     InitWindow(800, 600, "Template");     defer CloseWindow();     SetTargetFPS(60);     while !WindowShouldClose() {         {             BeginDrawing();             defer EndDrawing();             ClearBackground({ 42, 42, 60, 255 });             DrawFPS(10, 10);             DrawText(TextFormat("Frame Time: %f s", GetFrameTime()), 10, 30, 20, WHITE);         }         //reset_temporary_storage()     } }     STR_END;     return .{         arg_name = "ray",         description = "Raylib starter template",         template = "templates/raylib/template.jai",         dirs_in_workplace = .[ "src", "modules" ],         files = .[             .{ ".gitignore", gitignore },             .{ "src/main.jai", main_jai },             .{ "README.md", "" },         ],     }; }(); diff --git a/templates/raylib/template.jai b/templates/raylib/template.jai new file mode 100644 index 0000000..b03b095 --- /dev/null +++ b/templates/raylib/template.jai @@ -0,0 +1,140 @@ #import "Basic"; #import "Compiler"; #import "File"; #import "Autorun"; build :: () {     args := get_build_options().compile_time_command_line;     // args     args_help               := array_find(args, "help");     args_compiler_silent    := array_find(args, "silent");     args_program_run        := array_find(args, "run");     args_build_release      := array_find(args, "release");     args_memory_debug       := array_find(args, "memory");     // program args     program_args := program_args_collect(args);     defer array_free(program_args);     // -----------------------------------------     w := compiler_create_workspace();     if !w {         log("Workspace creation failed.");         return;     }     set_build_options_dc(.{ do_output = false });     if args_help {         args_help_print();         return;     }     print("The workspace w is %\n", w);     make_directory_if_it_does_not_exist("bin");     make_directory_if_it_does_not_exist("bin/debug");     make_directory_if_it_does_not_exist("bin/release");     target_options := get_build_options(w);     target_options.output_executable_name = "program";     if args_compiler_silent  target_options.text_output_flags = 0;     if args_build_release {         build_release(w, *target_options);     } else {         build_debug(w, *target_options);     }     compiler_begin_intercept(w);     add_build_file(tprint("%src/main.jai", #filepath), w);     add_build_string(tprint("MEMORY_DEBUGGER_ENABLED :: %;", args_memory_debug), w);     compiler_response := message_loop();     compiler_end_intercept(w);     if !compiler_response {         log("Compiler response failed.");         return;     }     if args_program_run  run_build_result(w, program_args); } build_debug :: (w: Workspace, target_options: *Build_Options) {     log("Choosing debug options...");     target_options.backend =.X64;     target_options.output_path = "bin/debug";     set_optimization(target_options, Optimization_Type.DEBUG, true);     set_build_options(target_options.*, w); } build_release :: (w: Workspace, target_options: *Build_Options) {     log("Choosing release options...");     target_options.backend = .LLVM;     target_options.output_path = "bin/release";     set_optimization(target_options, Optimization_Type.VERY_OPTIMIZED);     set_build_options(target_options.*, w); } args_help_print :: () {     help_message := #string _END_ Usage:  jai build.jai - [OPTIONS] :: [PROGRAM ARGS] Options:     help        Prints this help menu.     silent      Disables compiler/linker statistics.     run         Runs your program afterwards.     release     Builds with release options. If omitted, it builds a debug build.     memory      Enables the memory leak detector. Passing Args to your Program:     If you want to supply args to your program, pass it like that:         `jai build.jai - run :: my_arg1 foo bar abc ABC`     Everything after the `::` get's forwarded to your program. _END_;     log(help_message); } program_args_collect :: (args: []string, divider: string = "::") -> [..]string {     buf: [..]string;     success, match := array_find(args, divider);     if success  for i: match+1..args.count-1  array_add(*buf, args[i]);     return buf; } message_loop :: () -> success: bool {     while true {         message := compiler_wait_for_message();         if !message break;         if message.kind == {         case .COMPLETE;             message_complete := cast(*Message_Complete) message;             return message_complete.error_code == 0;         }     }     return false; } #placeholder MEMORY_DEBUGGER_ENABLED; main :: () {} #run build();