mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-30 01:44:36 +00:00
Merge pull request #430 from nakst/master
New Essence OS layer; cross-compiling improvements
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,24 +0,0 @@
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x100000;
|
||||
.text BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.text)
|
||||
}
|
||||
.rodata BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.rodata)
|
||||
}
|
||||
.data BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.data)
|
||||
}
|
||||
|
||||
.bss BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(COMMON)
|
||||
*(.bss)
|
||||
}
|
||||
}
|
||||
2
core/time/time_essence.odin
Normal file
2
core/time/time_essence.odin
Normal file
@@ -0,0 +1,2 @@
|
||||
package time
|
||||
IS_SUPPORTED :: false;
|
||||
@@ -56,8 +56,6 @@ TargetEndianKind target_endians[TargetArch_COUNT] = {
|
||||
|
||||
|
||||
String const ODIN_VERSION = str_lit("0.10.1");
|
||||
String cross_compile_target = str_lit("");
|
||||
String cross_compile_lib_dir = str_lit("");
|
||||
|
||||
|
||||
|
||||
@@ -66,6 +64,7 @@ struct TargetMetrics {
|
||||
TargetArchKind arch;
|
||||
isize word_size;
|
||||
isize max_align;
|
||||
String target_triplet;
|
||||
};
|
||||
|
||||
|
||||
@@ -109,6 +108,7 @@ struct BuildContext {
|
||||
bool has_resource;
|
||||
String opt_flags;
|
||||
String llc_flags;
|
||||
String target_triplet;
|
||||
String link_flags;
|
||||
bool is_dll;
|
||||
bool generate_docs;
|
||||
@@ -121,6 +121,7 @@ struct BuildContext {
|
||||
bool no_crt;
|
||||
bool use_lld;
|
||||
bool vet;
|
||||
bool cross_compiling;
|
||||
|
||||
QueryDataSetSettings query_data_set_settings;
|
||||
|
||||
@@ -135,18 +136,19 @@ struct BuildContext {
|
||||
gb_global BuildContext build_context = {0};
|
||||
|
||||
|
||||
|
||||
gb_global TargetMetrics target_windows_386 = {
|
||||
TargetOs_windows,
|
||||
TargetArch_386,
|
||||
4,
|
||||
8,
|
||||
str_lit("i686-pc-windows"),
|
||||
};
|
||||
gb_global TargetMetrics target_windows_amd64 = {
|
||||
TargetOs_windows,
|
||||
TargetArch_amd64,
|
||||
8,
|
||||
16,
|
||||
str_lit("x86_64-pc-windows-gnu"),
|
||||
};
|
||||
|
||||
gb_global TargetMetrics target_linux_386 = {
|
||||
@@ -154,12 +156,14 @@ gb_global TargetMetrics target_linux_386 = {
|
||||
TargetArch_386,
|
||||
4,
|
||||
8,
|
||||
str_lit("i686-pc-linux-gnu"),
|
||||
};
|
||||
gb_global TargetMetrics target_linux_amd64 = {
|
||||
TargetOs_linux,
|
||||
TargetArch_amd64,
|
||||
8,
|
||||
16,
|
||||
str_lit("x86_64-pc-linux-gnu"),
|
||||
};
|
||||
|
||||
gb_global TargetMetrics target_osx_amd64 = {
|
||||
@@ -167,10 +171,32 @@ gb_global TargetMetrics target_osx_amd64 = {
|
||||
TargetArch_amd64,
|
||||
8,
|
||||
16,
|
||||
str_lit("x86_64-apple-darwin"),
|
||||
};
|
||||
|
||||
gb_global TargetMetrics target_essence_amd64 = {
|
||||
TargetOs_essence,
|
||||
TargetArch_amd64,
|
||||
8,
|
||||
16,
|
||||
str_lit("x86_64-pc-none-elf"),
|
||||
};
|
||||
|
||||
struct NamedTargetMetrics {
|
||||
String name;
|
||||
TargetMetrics *metrics;
|
||||
};
|
||||
|
||||
gb_global NamedTargetMetrics named_targets[] = {
|
||||
{ str_lit("essence_amd64"), &target_essence_amd64 },
|
||||
{ str_lit("macos_amd64"), &target_osx_amd64 },
|
||||
{ str_lit("linux_386"), &target_linux_386 },
|
||||
{ str_lit("linux_amd64"), &target_linux_amd64 },
|
||||
{ str_lit("windows_386"), &target_windows_386 },
|
||||
{ str_lit("windows_amd64"), &target_windows_amd64 },
|
||||
};
|
||||
|
||||
NamedTargetMetrics *selected_target_metrics;
|
||||
|
||||
TargetOsKind get_target_os_from_string(String str) {
|
||||
for (isize i = 0; i < TargetOs_COUNT; i++) {
|
||||
@@ -522,7 +548,7 @@ String get_fullpath_core(gbAllocator a, String path) {
|
||||
|
||||
|
||||
|
||||
void init_build_context(void) {
|
||||
void init_build_context(TargetMetrics *cross_target) {
|
||||
BuildContext *bc = &build_context;
|
||||
|
||||
gb_affinity_init(&bc->affinity);
|
||||
@@ -554,8 +580,9 @@ void init_build_context(void) {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (cross_compile_target.len) {
|
||||
bc->ODIN_OS = cross_compile_target;
|
||||
if (cross_target) {
|
||||
metrics = *cross_target;
|
||||
bc->cross_compiling = true;
|
||||
}
|
||||
|
||||
GB_ASSERT(metrics.os != TargetOs_Invalid);
|
||||
@@ -573,6 +600,7 @@ void init_build_context(void) {
|
||||
bc->max_align = metrics.max_align;
|
||||
bc->link_flags = str_lit(" ");
|
||||
bc->opt_flags = str_lit(" ");
|
||||
bc->target_triplet = metrics.target_triplet;
|
||||
|
||||
|
||||
gbString llc_flags = gb_string_make_reserve(heap_allocator(), 64);
|
||||
|
||||
@@ -10964,12 +10964,14 @@ void ir_gen_tree(irGen *s) {
|
||||
// main :: proc(argc: i32, argv: ^^u8) -> i32
|
||||
String name = str_lit("main");
|
||||
|
||||
#if 0
|
||||
if (str_eq_ignore_case(cross_compile_target, str_lit("Essence"))) {
|
||||
// This is a bit hacky,
|
||||
// because this makes this function the first function run in the executable
|
||||
// so it won't actually have the argc/argv arguments.
|
||||
name = str_lit("ProgramEntry");
|
||||
}
|
||||
#endif
|
||||
|
||||
Type *proc_params = alloc_type_tuple();
|
||||
Type *proc_results = alloc_type_tuple();
|
||||
|
||||
92
src/main.cpp
92
src/main.cpp
@@ -75,7 +75,7 @@ i32 system_exec_command_line_app(char *name, char *fmt, ...) {
|
||||
va_end(va);
|
||||
cmd = make_string(cast(u8 *)&cmd_line, cmd_len-1);
|
||||
|
||||
//printf("do: %s\n", cmd_line);
|
||||
// printf("do: %s\n", cmd_line);
|
||||
exit_code = system(&cmd_line[0]);
|
||||
|
||||
// pid_t pid = fork();
|
||||
@@ -210,9 +210,8 @@ enum BuildFlagKind {
|
||||
BuildFlag_Collection,
|
||||
BuildFlag_Define,
|
||||
BuildFlag_BuildMode,
|
||||
BuildFlag_Target,
|
||||
BuildFlag_Debug,
|
||||
BuildFlag_CrossCompile,
|
||||
BuildFlag_CrossLibDir,
|
||||
BuildFlag_NoBoundsCheck,
|
||||
BuildFlag_NoCRT,
|
||||
BuildFlag_UseLLD,
|
||||
@@ -298,9 +297,8 @@ bool parse_build_flags(Array<String> args) {
|
||||
add_flag(&build_flags, BuildFlag_Collection, str_lit("collection"), BuildFlagParam_String);
|
||||
add_flag(&build_flags, BuildFlag_Define, str_lit("define"), BuildFlagParam_String);
|
||||
add_flag(&build_flags, BuildFlag_BuildMode, str_lit("build-mode"), BuildFlagParam_String);
|
||||
add_flag(&build_flags, BuildFlag_Target, str_lit("target"), BuildFlagParam_String);
|
||||
add_flag(&build_flags, BuildFlag_Debug, str_lit("debug"), BuildFlagParam_None);
|
||||
add_flag(&build_flags, BuildFlag_CrossCompile, str_lit("cross-compile"), BuildFlagParam_String);
|
||||
add_flag(&build_flags, BuildFlag_CrossLibDir, str_lit("cross-lib-dir"), BuildFlagParam_String);
|
||||
add_flag(&build_flags, BuildFlag_NoBoundsCheck, str_lit("no-bounds-check"), BuildFlagParam_None);
|
||||
add_flag(&build_flags, BuildFlag_NoCRT, str_lit("no-crt"), BuildFlagParam_None);
|
||||
add_flag(&build_flags, BuildFlag_UseLLD, str_lit("lld"), BuildFlagParam_None);
|
||||
@@ -478,33 +476,6 @@ bool parse_build_flags(Array<String> args) {
|
||||
build_context.keep_temp_files = true;
|
||||
break;
|
||||
|
||||
case BuildFlag_CrossCompile: {
|
||||
GB_ASSERT(value.kind == ExactValue_String);
|
||||
cross_compile_target = value.value_string;
|
||||
#if defined(GB_SYSTEM_UNIX) && defined(GB_ARCH_64_BIT)
|
||||
if (str_eq_ignore_case(cross_compile_target, str_lit("Essence"))) {
|
||||
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
gb_printf_err("Unsupported cross compilation target '%.*s'\n", LIT(cross_compile_target));
|
||||
gb_printf_err("Currently supported targets: Essence (from 64-bit Unixes only)\n");
|
||||
bad_flags = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case BuildFlag_CrossLibDir: {
|
||||
GB_ASSERT(value.kind == ExactValue_String);
|
||||
if (cross_compile_lib_dir.len) {
|
||||
gb_printf_err("Multiple cross compilation library directories\n");
|
||||
bad_flags = true;
|
||||
} else {
|
||||
cross_compile_lib_dir = concatenate_strings(heap_allocator(), str_lit("-L"), value.value_string);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case BuildFlag_Collection: {
|
||||
GB_ASSERT(value.kind == ExactValue_String);
|
||||
String str = value.value_string;
|
||||
@@ -623,7 +594,25 @@ bool parse_build_flags(Array<String> args) {
|
||||
break;
|
||||
}
|
||||
|
||||
case BuildFlag_Target: {
|
||||
String str = value.value_string;
|
||||
bool found = false;
|
||||
|
||||
for (int i = 0; i < sizeof(named_targets) / sizeof(named_targets[0]); i++) {
|
||||
if (str_eq_ignore_case(str, named_targets[i].name)) {
|
||||
found = true;
|
||||
selected_target_metrics = named_targets + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
gb_printf_err("Unknown target '%.*s'\n", LIT(str));
|
||||
bad_flags = true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case BuildFlag_BuildMode: {
|
||||
GB_ASSERT(value.kind == ExactValue_String);
|
||||
@@ -889,8 +878,8 @@ i32 exec_llvm_opt(String output_base) {
|
||||
}
|
||||
|
||||
i32 exec_llvm_llc(String output_base) {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
// For more arguments: http://llvm.org/docs/CommandGuide/llc.html
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
return system_exec_command_line_app("llvm-llc",
|
||||
"\"%.*sbin\\llc\" \"%.*s.bc\" -filetype=obj -O%d "
|
||||
"-o \"%.*s.obj\" "
|
||||
@@ -903,21 +892,19 @@ i32 exec_llvm_llc(String output_base) {
|
||||
LIT(build_context.llc_flags));
|
||||
#else
|
||||
// NOTE(zangent): Linux / Unix is unfinished and not tested very well.
|
||||
// For more arguments: http://llvm.org/docs/CommandGuide/llc.html
|
||||
return system_exec_command_line_app("llc",
|
||||
"llc \"%.*s.bc\" -filetype=obj -relocation-model=pic -O%d "
|
||||
"%.*s "
|
||||
"%s"
|
||||
"",
|
||||
"%s%.*s",
|
||||
LIT(output_base),
|
||||
build_context.optimization_level,
|
||||
LIT(build_context.llc_flags),
|
||||
str_eq_ignore_case(cross_compile_target, str_lit("Essence")) ? "-mtriple=x86_64-pc-none-elf" : "");
|
||||
build_context.cross_compiling ? "-mtriple=" : "",
|
||||
(int) (build_context.cross_compiling ? build_context.target_triplet.len : 0),
|
||||
build_context.target_triplet.text);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int arg_count, char **arg_ptr) {
|
||||
if (arg_count < 2) {
|
||||
usage(make_string_c(arg_ptr[0]));
|
||||
@@ -1026,7 +1013,7 @@ int main(int arg_count, char **arg_ptr) {
|
||||
}
|
||||
|
||||
|
||||
init_build_context();
|
||||
init_build_context(selected_target_metrics ? selected_target_metrics->metrics : nullptr);
|
||||
if (build_context.word_size == 4) {
|
||||
print_usage_line(0, "%s 32-bit is not yet supported", args[0]);
|
||||
return 1;
|
||||
@@ -1121,6 +1108,17 @@ int main(int arg_count, char **arg_ptr) {
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
if (build_context.cross_compiling) {
|
||||
if (0) {
|
||||
#ifdef GB_SYSTEM_UNIX
|
||||
} else if (selected_target_metrics->metrics == &target_essence_amd64) {
|
||||
system_exec_command_line_app("linker", "x86_64-essence-gcc \"%.*s.o\" -o \"%.*s\" %.*s",
|
||||
LIT(output_base), LIT(output_base), LIT(build_context.link_flags));
|
||||
#endif
|
||||
} else {
|
||||
gb_printf_err("Don't know how to cross compile to selected target.\n");
|
||||
}
|
||||
} else {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
timings_start_section(&timings, str_lit("msvc-link"));
|
||||
|
||||
@@ -1309,11 +1307,7 @@ int main(int arg_count, char **arg_ptr) {
|
||||
// It probably has to do with including the entire CRT, but
|
||||
// that's quite a complicated issue to solve while remaining distro-agnostic.
|
||||
// Clang can figure out linker flags for us, and that's good enough _for now_.
|
||||
if (str_eq_ignore_case(cross_compile_target, str_lit("Essence"))) {
|
||||
linker = "x86_64-elf-gcc -T core/sys/essence_linker_userland64.ld -ffreestanding -nostdlib -lgcc -g -z max-page-size=0x1000 -Wno-unused-command-line-argument";
|
||||
} else {
|
||||
linker = "clang -Wno-unused-command-line-argument";
|
||||
}
|
||||
linker = "clang -Wno-unused-command-line-argument";
|
||||
#endif
|
||||
|
||||
exit_code = system_exec_command_line_app("ld-link",
|
||||
@@ -1321,7 +1315,6 @@ int main(int arg_count, char **arg_ptr) {
|
||||
" %s "
|
||||
" %.*s "
|
||||
" %s "
|
||||
" %.*s "
|
||||
#if defined(GB_SYSTEM_OSX)
|
||||
// This sets a requirement of Mountain Lion and up, but the compiler doesn't work without this limit.
|
||||
// NOTE: If you change this (although this minimum is as low as you can go with Odin working)
|
||||
@@ -1332,11 +1325,9 @@ int main(int arg_count, char **arg_ptr) {
|
||||
#endif
|
||||
, linker, LIT(output_base), LIT(output_base), LIT(output_ext),
|
||||
lib_str,
|
||||
str_eq_ignore_case(cross_compile_target, str_lit("Essence")) ? "-lfreetype -lglue" : "-lc -lm",
|
||||
"-lc -lm",
|
||||
LIT(build_context.link_flags),
|
||||
link_settings,
|
||||
LIT(cross_compile_lib_dir)
|
||||
);
|
||||
link_settings);
|
||||
if (exit_code != 0) {
|
||||
return exit_code;
|
||||
}
|
||||
@@ -1369,6 +1360,7 @@ int main(int arg_count, char **arg_ptr) {
|
||||
return system_exec_command_line_app("odin run", "\"%.*s\" %.*s", LIT(complete_path), LIT(run_args_string));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user