mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-08 16:48:18 +00:00
implemented foreign asm imports on linux/osx
This commit is contained in:
+1
-2
@@ -4733,8 +4733,7 @@ gb_internal void check_add_foreign_import_decl(CheckerContext *ctx, Ast *decl) {
|
||||
}
|
||||
|
||||
if (has_asm_extension(fullpath)) {
|
||||
if (build_context.metrics.arch != TargetArch_amd64 ||
|
||||
build_context.metrics.os != TargetOs_windows) {
|
||||
if (build_context.metrics.arch != TargetArch_amd64) {
|
||||
error(decl, "Assembly files are not yet supported on this platform: %.*s_%.*s",
|
||||
LIT(target_os_names[build_context.metrics.os]), LIT(target_arch_names[build_context.metrics.arch]));
|
||||
}
|
||||
|
||||
+49
-2
@@ -149,14 +149,20 @@ gb_internal i32 linker_stage(LinkerData *gen) {
|
||||
if (!string_set_update(&asm_files, lib)) {
|
||||
String asm_file = asm_files.entries[i].value;
|
||||
String obj_file = concatenate_strings(permanent_allocator(), asm_file, str_lit(".obj"));
|
||||
|
||||
String obj_format;
|
||||
#if defined(GB_ARCH_64_BIT)
|
||||
obj_format = str_lit("win64");
|
||||
#elif defined(GB_ARCH_32_BIT)
|
||||
obj_format = str_lit("win32");
|
||||
#endif // GB_ARCH_*_BIT
|
||||
result = system_exec_command_line_app("nasm",
|
||||
"\"%.*s\\bin\\nasm\\windows\\nasm.exe\" \"%.*s\" "
|
||||
"-f win64 "
|
||||
"-f \"%.*s\" "
|
||||
"-o \"%.*s\" "
|
||||
"%.*s "
|
||||
"",
|
||||
LIT(build_context.ODIN_ROOT), LIT(asm_file),
|
||||
LIT(obj_format),
|
||||
LIT(obj_file),
|
||||
LIT(build_context.extra_assembler_flags)
|
||||
);
|
||||
@@ -296,6 +302,10 @@ gb_internal i32 linker_stage(LinkerData *gen) {
|
||||
gbString lib_str = gb_string_make(heap_allocator(), "-L/");
|
||||
defer (gb_string_free(lib_str));
|
||||
|
||||
StringSet asm_files = {};
|
||||
string_set_init(&asm_files, 64);
|
||||
defer (string_set_destroy(&asm_files));
|
||||
|
||||
StringSet libs = {};
|
||||
string_set_init(&libs, 64);
|
||||
defer (string_set_destroy(&libs));
|
||||
@@ -307,6 +317,42 @@ gb_internal i32 linker_stage(LinkerData *gen) {
|
||||
if (lib.len == 0) {
|
||||
continue;
|
||||
}
|
||||
if (has_asm_extension(lib)) {
|
||||
if (string_set_update(&asm_files, lib)) {
|
||||
continue; // already handled
|
||||
}
|
||||
String asm_file = lib;
|
||||
String obj_file = concatenate_strings(permanent_allocator(), asm_file, str_lit(".o"));
|
||||
String obj_format;
|
||||
#if defined(GB_ARCH_64_BIT)
|
||||
if (is_osx) {
|
||||
obj_format = str_lit("macho64");
|
||||
} else {
|
||||
obj_format = str_lit("elf64");
|
||||
}
|
||||
#elif defined(GB_ARCH_32_BIT)
|
||||
if (is_osx) {
|
||||
obj_format = str_lit("macho32");
|
||||
} else {
|
||||
obj_format = str_lit("elf32");
|
||||
}
|
||||
#endif // GB_ARCH_*_BIT
|
||||
// Note(bumbread): I'm assuming nasm is installed on the host machine.
|
||||
// Shipping binaries on unix-likes gets into the weird territorry of
|
||||
// "which version of glibc" is it linked with.
|
||||
result = system_exec_command_line_app("nasm",
|
||||
"nasm \"%.*s\" "
|
||||
"-f \"%.*s\" "
|
||||
"-o \"%.*s\" "
|
||||
"%.*s "
|
||||
"",
|
||||
LIT(asm_file),
|
||||
LIT(obj_format),
|
||||
LIT(obj_file),
|
||||
LIT(build_context.extra_assembler_flags)
|
||||
);
|
||||
array_add(&gen->output_object_paths, obj_file);
|
||||
} else {
|
||||
if (string_set_update(&libs, lib)) {
|
||||
continue;
|
||||
}
|
||||
@@ -351,6 +397,7 @@ gb_internal i32 linker_stage(LinkerData *gen) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Entity *e : gen->foreign_libraries) {
|
||||
GB_ASSERT(e->kind == Entity_LibraryName);
|
||||
|
||||
Reference in New Issue
Block a user