allow user program to specify simplified build options
This commit is contained in:
parent
ca27aedae7
commit
ee1adc6803
3 changed files with 48 additions and 19 deletions
|
|
@ -87,6 +87,10 @@ G: *struct {
|
|||
#poke_name reload init;
|
||||
#poke_name reload setup;
|
||||
#poke_name reload teardown;
|
||||
#poke_name reload build_options;
|
||||
|
||||
// Use the default build options
|
||||
build_options :: () => reload.Simple_Build_Options.{};
|
||||
|
||||
reload :: #import "jx/reload";
|
||||
|
||||
|
|
|
|||
|
|
@ -55,5 +55,10 @@ else {
|
|||
#poke_name reload init;
|
||||
#poke_name reload setup;
|
||||
#poke_name reload teardown;
|
||||
|
||||
#poke_name reload build_options;
|
||||
|
||||
// Use the default build options
|
||||
build_options :: () => reload.Simple_Build_Options.{};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,11 +14,16 @@ Status :: enum {
|
|||
hard_reload;
|
||||
}
|
||||
|
||||
Simple_Build_Options :: struct {
|
||||
output_name: string;
|
||||
relative_output_path: string;
|
||||
}
|
||||
|
||||
Init_Proc :: #type (state: *void, allocator: Allocator, full_reset: bool);
|
||||
Setup_Proc :: #type ();
|
||||
Teardown_Proc :: #type ();
|
||||
Frame_Proc :: #type () -> Status;
|
||||
|
||||
Build_Options_Proc :: #type () -> Simple_Build_Options;
|
||||
|
||||
#scope_module;
|
||||
|
||||
|
|
@ -26,6 +31,7 @@ Frame_Proc :: #type () -> Status;
|
|||
#placeholder init;
|
||||
#placeholder setup;
|
||||
#placeholder teardown;
|
||||
#placeholder build_options;
|
||||
|
||||
#if !disabled {
|
||||
#load "reload_main.jai";
|
||||
|
|
@ -56,13 +62,30 @@ Frame_Proc :: #type () -> Status;
|
|||
#assert (type_of(setup) == Setup_Proc) "setup was the wrong type!";
|
||||
#assert (type_of(teardown) == Teardown_Proc) "teardown was the wrong type!";
|
||||
#assert (type_of(frame) == Frame_Proc) "frame was the wrong type!";
|
||||
#assert (type_of(build_options) == Build_Options_Proc) "build_options was the wrong type!";
|
||||
}
|
||||
|
||||
file_path :: #run loc.fully_pathed_filename;
|
||||
proj_path :: #run path_strip_filename(file_path);
|
||||
temp_path :: #run tprint("%/.build/tmp.jai", proj_path);
|
||||
temp_exists :: #run file_exists(temp_path);
|
||||
lib_name :: #run tprint("%_lib", path_basename(file_path));
|
||||
lib_name :: #run tprint("%_lib", user_options.output_name);
|
||||
|
||||
user_options :: #run -> Simple_Build_Options {
|
||||
opts := build_options();
|
||||
|
||||
if opts.relative_output_path.count == 0 {
|
||||
opts.relative_output_path = proj_path;
|
||||
} else {
|
||||
opts.relative_output_path = tprint("%/%", proj_path, opts.relative_output_path);
|
||||
}
|
||||
|
||||
if opts.output_name.count == 0 {
|
||||
opts.output_name = path_strip_extension(path_filename(file_path));
|
||||
}
|
||||
|
||||
return opts;
|
||||
}
|
||||
|
||||
// only run the build when we the module importing us is compiled
|
||||
#if !(disabled || temp_exists) #run {
|
||||
|
|
@ -70,9 +93,6 @@ lib_name :: #run tprint("%_lib", path_basename(file_path));
|
|||
|
||||
make_directory_if_it_does_not_exist(".build");
|
||||
|
||||
out_path := path_strip_extension(proj_path);
|
||||
out_name := path_strip_extension(path_filename(file_path));
|
||||
|
||||
// build host executable
|
||||
{
|
||||
ws := compiler_create_workspace(file_path);
|
||||
|
|
@ -80,9 +100,9 @@ lib_name :: #run tprint("%_lib", path_basename(file_path));
|
|||
|
||||
opts := get_build_options(ws);
|
||||
opts.text_output_flags = 0;
|
||||
opts.output_path = out_path;
|
||||
opts.output_path = user_options.relative_output_path;
|
||||
opts.output_type = .EXECUTABLE;
|
||||
opts.output_executable_name = out_name;
|
||||
opts.output_executable_name = user_options.output_name;
|
||||
|
||||
// create a temporary file that contains the hijacked main.
|
||||
// we need to #load our program library so the #placeholders
|
||||
|
|
@ -116,7 +136,7 @@ lib_name :: #run tprint("%_lib", path_basename(file_path));
|
|||
defer compiler_destroy_workspace(ws);
|
||||
|
||||
opts := get_build_options(ws);
|
||||
opts.output_path = out_path;
|
||||
opts.output_path = user_options.relative_output_path;
|
||||
opts.output_type = .DYNAMIC_LIBRARY;
|
||||
opts.output_executable_name = lib_name;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue