mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
build_dll replace with -build-mode=dll
This commit is contained in:
@@ -12,6 +12,8 @@ struct BuildContext {
|
|||||||
i64 word_size; // Size of a pointer, must be >= 4
|
i64 word_size; // Size of a pointer, must be >= 4
|
||||||
i64 max_align; // max alignment, must be >= 1 (and typically >= word_size)
|
i64 max_align; // max alignment, must be >= 1 (and typically >= word_size)
|
||||||
|
|
||||||
|
String command;
|
||||||
|
|
||||||
String opt_flags;
|
String opt_flags;
|
||||||
String llc_flags;
|
String llc_flags;
|
||||||
String link_flags;
|
String link_flags;
|
||||||
|
|||||||
+1
-1
@@ -7750,7 +7750,7 @@ bool ir_gen_init(irGen *s, Checker *c) {
|
|||||||
int dir_pos = cast(int)string_extension_position(init_fullpath);
|
int dir_pos = cast(int)string_extension_position(init_fullpath);
|
||||||
s->output_name = filename_from_path(init_fullpath);
|
s->output_name = filename_from_path(init_fullpath);
|
||||||
s->output_base = make_string(init_fullpath.text, pos);
|
s->output_base = make_string(init_fullpath.text, pos);
|
||||||
gbFileError err = gb_file_create(&s->output_file, gb_bprintf("%.*s.ll", pos, init_fullpath.text));
|
gbFileError err = gb_file_create(&s->output_file, gb_bprintf("%.*s.ll", LIT(s->output_base)));
|
||||||
if (err != gbFileError_None) {
|
if (err != gbFileError_None) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
+71
-50
@@ -171,42 +171,6 @@ void usage(String argv0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum BuildFlagKind {
|
|
||||||
BuildFlag_Invalid,
|
|
||||||
|
|
||||||
BuildFlag_OptimizationLevel,
|
|
||||||
BuildFlag_ShowTimings,
|
|
||||||
BuildFlag_ThreadCount,
|
|
||||||
BuildFlag_KeepTempFiles,
|
|
||||||
BuildFlag_Collection,
|
|
||||||
|
|
||||||
BuildFlag_COUNT,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum BuildFlagParamKind {
|
|
||||||
BuildFlagParam_None,
|
|
||||||
|
|
||||||
BuildFlagParam_Boolean,
|
|
||||||
BuildFlagParam_Integer,
|
|
||||||
BuildFlagParam_Float,
|
|
||||||
BuildFlagParam_String,
|
|
||||||
|
|
||||||
BuildFlagParam_COUNT,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BuildFlag {
|
|
||||||
BuildFlagKind kind;
|
|
||||||
String name;
|
|
||||||
BuildFlagParamKind param_kind;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void add_flag(Array<BuildFlag> *build_flags, BuildFlagKind kind, String name, BuildFlagParamKind param_kind) {
|
|
||||||
BuildFlag flag = {kind, name, param_kind};
|
|
||||||
array_add(build_flags, flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool string_is_valid_identifier(String str) {
|
bool string_is_valid_identifier(String str) {
|
||||||
if (str.len <= 0) return false;
|
if (str.len <= 0) return false;
|
||||||
|
|
||||||
@@ -237,6 +201,41 @@ bool string_is_valid_identifier(String str) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum BuildFlagKind {
|
||||||
|
BuildFlag_Invalid,
|
||||||
|
|
||||||
|
BuildFlag_OptimizationLevel,
|
||||||
|
BuildFlag_ShowTimings,
|
||||||
|
BuildFlag_ThreadCount,
|
||||||
|
BuildFlag_KeepTempFiles,
|
||||||
|
BuildFlag_Collection,
|
||||||
|
BuildFlag_BuildMode,
|
||||||
|
|
||||||
|
BuildFlag_COUNT,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum BuildFlagParamKind {
|
||||||
|
BuildFlagParam_None,
|
||||||
|
|
||||||
|
BuildFlagParam_Boolean,
|
||||||
|
BuildFlagParam_Integer,
|
||||||
|
BuildFlagParam_Float,
|
||||||
|
BuildFlagParam_String,
|
||||||
|
|
||||||
|
BuildFlagParam_COUNT,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BuildFlag {
|
||||||
|
BuildFlagKind kind;
|
||||||
|
String name;
|
||||||
|
BuildFlagParamKind param_kind;
|
||||||
|
};
|
||||||
|
|
||||||
|
void add_flag(Array<BuildFlag> *build_flags, BuildFlagKind kind, String name, BuildFlagParamKind param_kind) {
|
||||||
|
BuildFlag flag = {kind, name, param_kind};
|
||||||
|
array_add(build_flags, flag);
|
||||||
|
}
|
||||||
|
|
||||||
bool parse_build_flags(Array<String> args) {
|
bool parse_build_flags(Array<String> args) {
|
||||||
Array<BuildFlag> build_flags = {};
|
Array<BuildFlag> build_flags = {};
|
||||||
array_init(&build_flags, heap_allocator(), BuildFlag_COUNT);
|
array_init(&build_flags, heap_allocator(), BuildFlag_COUNT);
|
||||||
@@ -245,6 +244,7 @@ bool parse_build_flags(Array<String> args) {
|
|||||||
add_flag(&build_flags, BuildFlag_ThreadCount, str_lit("thread-count"), BuildFlagParam_Integer);
|
add_flag(&build_flags, BuildFlag_ThreadCount, str_lit("thread-count"), BuildFlagParam_Integer);
|
||||||
add_flag(&build_flags, BuildFlag_KeepTempFiles, str_lit("keep-temp-files"), BuildFlagParam_None);
|
add_flag(&build_flags, BuildFlag_KeepTempFiles, str_lit("keep-temp-files"), BuildFlagParam_None);
|
||||||
add_flag(&build_flags, BuildFlag_Collection, str_lit("collection"), BuildFlagParam_String);
|
add_flag(&build_flags, BuildFlag_Collection, str_lit("collection"), BuildFlagParam_String);
|
||||||
|
add_flag(&build_flags, BuildFlag_BuildMode, str_lit("build-mode"), BuildFlagParam_String);
|
||||||
|
|
||||||
|
|
||||||
Array<String> flag_args = args;
|
Array<String> flag_args = args;
|
||||||
@@ -391,7 +391,8 @@ bool parse_build_flags(Array<String> args) {
|
|||||||
} else {
|
} else {
|
||||||
build_context.thread_count = count;
|
build_context.thread_count = count;
|
||||||
}
|
}
|
||||||
} break;
|
break;
|
||||||
|
}
|
||||||
case BuildFlag_KeepTempFiles:
|
case BuildFlag_KeepTempFiles:
|
||||||
GB_ASSERT(value.kind == ExactValue_Invalid);
|
GB_ASSERT(value.kind == ExactValue_Invalid);
|
||||||
build_context.keep_temp_files = true;
|
build_context.keep_temp_files = true;
|
||||||
@@ -459,7 +460,30 @@ bool parse_build_flags(Array<String> args) {
|
|||||||
|
|
||||||
// NOTE(bill): Allow for multiple library collections
|
// NOTE(bill): Allow for multiple library collections
|
||||||
continue;
|
continue;
|
||||||
} break;
|
}
|
||||||
|
|
||||||
|
case BuildFlag_BuildMode: {
|
||||||
|
GB_ASSERT(value.kind == ExactValue_String);
|
||||||
|
String str = value.value_string;
|
||||||
|
|
||||||
|
if (build_context.command != "build") {
|
||||||
|
gb_printf_err("'build-mode' can only be used with the 'build' command\n");
|
||||||
|
bad_flags = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str == "dll") {
|
||||||
|
build_context.is_dll = true;
|
||||||
|
} else if (str == "exe") {
|
||||||
|
build_context.is_dll = false;
|
||||||
|
} else {
|
||||||
|
gb_printf_err("Unknown build mode '%.*s'\n", LIT(str));
|
||||||
|
bad_flags = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -559,29 +583,24 @@ int main(int arg_count, char **arg_ptr) {
|
|||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
|
|
||||||
|
String command = args[1];
|
||||||
|
|
||||||
String init_filename = {};
|
String init_filename = {};
|
||||||
bool run_output = false;
|
bool run_output = false;
|
||||||
if (args[1] == "run") {
|
if (command == "run") {
|
||||||
if (args.count < 3) {
|
if (args.count < 3) {
|
||||||
usage(args[0]);
|
usage(args[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
init_filename = args[2];
|
init_filename = args[2];
|
||||||
run_output = true;
|
run_output = true;
|
||||||
} else if (args[1] == "build_dll") {
|
} else if (command == "build") {
|
||||||
if (args.count < 3) {
|
if (args.count < 3) {
|
||||||
usage(args[0]);
|
usage(args[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
init_filename = args[2];
|
init_filename = args[2];
|
||||||
build_context.is_dll = true;
|
} else if (command == "docs") {
|
||||||
} else if (args[1] == "build") {
|
|
||||||
if (args.count < 3) {
|
|
||||||
usage(args[0]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
init_filename = args[2];
|
|
||||||
} else if (args[1] == "docs") {
|
|
||||||
if (args.count < 3) {
|
if (args.count < 3) {
|
||||||
usage(args[0]);
|
usage(args[0]);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -593,7 +612,7 @@ int main(int arg_count, char **arg_ptr) {
|
|||||||
print_usage_line(0, "Documentation generation is not yet supported");
|
print_usage_line(0, "Documentation generation is not yet supported");
|
||||||
return 1;
|
return 1;
|
||||||
#endif
|
#endif
|
||||||
} else if (args[1] == "version") {
|
} else if (command == "version") {
|
||||||
gb_printf("%.*s version %.*s\n", LIT(args[0]), LIT(ODIN_VERSION));
|
gb_printf("%.*s version %.*s\n", LIT(args[0]), LIT(ODIN_VERSION));
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -601,11 +620,14 @@ int main(int arg_count, char **arg_ptr) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
build_context.command = command;
|
||||||
|
|
||||||
if (!parse_build_flags(args)) {
|
if (!parse_build_flags(args)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// NOTE(bill): add 'shared' directory if it is not already set
|
// NOTE(bill): add 'shared' directory if it is not already set
|
||||||
if (!find_library_collection_path(str_lit("shared"), nullptr)) {
|
if (!find_library_collection_path(str_lit("shared"), nullptr)) {
|
||||||
add_library_collection(str_lit("shared"),
|
add_library_collection(str_lit("shared"),
|
||||||
@@ -686,7 +708,6 @@ int main(int arg_count, char **arg_ptr) {
|
|||||||
|
|
||||||
String output_name = ir_gen.output_name;
|
String output_name = ir_gen.output_name;
|
||||||
String output_base = ir_gen.output_base;
|
String output_base = ir_gen.output_base;
|
||||||
int base_name_len = cast(int)output_base.len;
|
|
||||||
|
|
||||||
build_context.optimization_level = gb_clamp(build_context.optimization_level, 0, 3);
|
build_context.optimization_level = gb_clamp(build_context.optimization_level, 0, 3);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user