To do a basic and simple compiler message loop, create a workspace, call compiler_begin_intercept
, add all the files you want to compile, run the compiler message loop, call compiler_end_intercept
, and finally #run build()
.
The following build.jai
example code is the minimum code to run a basic compiler message loop:
#import "Basic";
#import "Compiler";
build :: () {
w := compiler_create_workspace();
if !w {
print("Workspace creation failed.\n");
return;
}
// modify build options here
target_options := get_build_options(w);
target_options.output_executable_name = "program";
set_build_options(target_options, w);
compiler_begin_intercept(w);
// add all the files
add_build_file(tprint("%/main.jai", #filepath), w);
while true {
// process compiler messages in this loop
message := compiler_wait_for_message();
if !message break;
if message.kind == {
case .COMPLETE;
break;
}
}
compiler_end_intercept(w);
set_build_options_dc(.{do_output=false});
}
#run build();
Create a basic “Hello World” main.jai
file.
#import "Basic";
main () {
print("Hello World!!!\n");
}
These two files, build.jai
and main.jai
are enough to get a basic compiler message loop up and running.
Learn more about the compiler messages being sent to your program here.
Learn more about the compiler build options here.