stage1: make get_native_target go through self-hosted

master
Andrew Kelley 2020-02-28 02:00:20 -05:00
parent 3683ba87ac
commit d45ea4d89d
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
6 changed files with 110 additions and 105 deletions

View File

@ -1,5 +1,5 @@
const std = @import("std");
pub fn main() anyerror!void {
std.debug.warn("All your base are belong to us.\n", .{});
std.debug.warn("All your codebase are belong to us.\n", .{});
}

View File

@ -1215,8 +1215,8 @@ pub const Target = struct {
.uefi,
.windows,
.emscripten,
.other,
.wasi,
.other,
=> return null,
// TODO go over each item in this list and either move it to the above list, or

View File

@ -500,7 +500,10 @@ static int main0(int argc, char **argv) {
os_path_join(get_zig_special_dir(zig_lib_dir), buf_create_from_str("build_runner.zig"), build_runner_path);
ZigTarget target;
get_native_target(&target);
if ((err = target_parse_triple(&target, "native", nullptr))) {
fprintf(stderr, "Unable to get native target: %s\n", err_str(err));
return EXIT_FAILURE;
}
Buf *build_file_buf = buf_create_from_str((build_file != nullptr) ? build_file : "build.zig");
Buf build_file_abs = os_path_resolve(&build_file_buf, 1);
@ -1337,7 +1340,10 @@ static int main0(int argc, char **argv) {
return main_exit(root_progress_node, EXIT_SUCCESS);
} else if (cmd == CmdTest) {
ZigTarget native;
get_native_target(&native);
if ((err = target_parse_triple(&native, "native", nullptr))) {
fprintf(stderr, "Unable to get native target: %s\n", err_str(err));
return EXIT_FAILURE;
}
g->enable_cache = get_cache_opt(enable_cache, output_dir == nullptr);
codegen_build_and_link(g);

View File

@ -91,6 +91,106 @@ void stage2_progress_complete_one(Stage2ProgressNode *node) {}
void stage2_progress_disable_tty(Stage2Progress *progress) {}
void stage2_progress_update_node(Stage2ProgressNode *node, size_t completed_count, size_t estimated_total_items){}
static Os get_zig_os_type(ZigLLVM_OSType os_type) {
switch (os_type) {
case ZigLLVM_UnknownOS:
return OsFreestanding;
case ZigLLVM_Ananas:
return OsAnanas;
case ZigLLVM_CloudABI:
return OsCloudABI;
case ZigLLVM_DragonFly:
return OsDragonFly;
case ZigLLVM_FreeBSD:
return OsFreeBSD;
case ZigLLVM_Fuchsia:
return OsFuchsia;
case ZigLLVM_IOS:
return OsIOS;
case ZigLLVM_KFreeBSD:
return OsKFreeBSD;
case ZigLLVM_Linux:
return OsLinux;
case ZigLLVM_Lv2:
return OsLv2;
case ZigLLVM_Darwin:
case ZigLLVM_MacOSX:
return OsMacOSX;
case ZigLLVM_NetBSD:
return OsNetBSD;
case ZigLLVM_OpenBSD:
return OsOpenBSD;
case ZigLLVM_Solaris:
return OsSolaris;
case ZigLLVM_Win32:
return OsWindows;
case ZigLLVM_Haiku:
return OsHaiku;
case ZigLLVM_Minix:
return OsMinix;
case ZigLLVM_RTEMS:
return OsRTEMS;
case ZigLLVM_NaCl:
return OsNaCl;
case ZigLLVM_CNK:
return OsCNK;
case ZigLLVM_AIX:
return OsAIX;
case ZigLLVM_CUDA:
return OsCUDA;
case ZigLLVM_NVCL:
return OsNVCL;
case ZigLLVM_AMDHSA:
return OsAMDHSA;
case ZigLLVM_PS4:
return OsPS4;
case ZigLLVM_ELFIAMCU:
return OsELFIAMCU;
case ZigLLVM_TvOS:
return OsTvOS;
case ZigLLVM_WatchOS:
return OsWatchOS;
case ZigLLVM_Mesa3D:
return OsMesa3D;
case ZigLLVM_Contiki:
return OsContiki;
case ZigLLVM_AMDPAL:
return OsAMDPAL;
case ZigLLVM_HermitCore:
return OsHermitCore;
case ZigLLVM_Hurd:
return OsHurd;
case ZigLLVM_WASI:
return OsWASI;
case ZigLLVM_Emscripten:
return OsEmscripten;
}
zig_unreachable();
}
static void get_native_target(ZigTarget *target) {
// first zero initialize
*target = {};
ZigLLVM_OSType os_type;
ZigLLVM_ObjectFormatType oformat; // ignored; based on arch/os
ZigLLVMGetNativeTarget(
&target->arch,
&target->vendor,
&os_type,
&target->abi,
&oformat);
target->os = get_zig_os_type(os_type);
target->is_native = true;
if (target->abi == ZigLLVM_UnknownEnvironment) {
target->abi = target_default_abi(target->arch, target->os);
}
if (target_is_glibc(target)) {
target->glibc_version = heap::c_allocator.create<ZigGLibCVersion>();
target_init_default_glibc_version(target);
}
}
Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, const char *mcpu) {
Error err;

View File

@ -287,83 +287,6 @@ ZigLLVM_OSType get_llvm_os_type(Os os_type) {
zig_unreachable();
}
static Os get_zig_os_type(ZigLLVM_OSType os_type) {
switch (os_type) {
case ZigLLVM_UnknownOS:
return OsFreestanding;
case ZigLLVM_Ananas:
return OsAnanas;
case ZigLLVM_CloudABI:
return OsCloudABI;
case ZigLLVM_DragonFly:
return OsDragonFly;
case ZigLLVM_FreeBSD:
return OsFreeBSD;
case ZigLLVM_Fuchsia:
return OsFuchsia;
case ZigLLVM_IOS:
return OsIOS;
case ZigLLVM_KFreeBSD:
return OsKFreeBSD;
case ZigLLVM_Linux:
return OsLinux;
case ZigLLVM_Lv2:
return OsLv2;
case ZigLLVM_Darwin:
case ZigLLVM_MacOSX:
return OsMacOSX;
case ZigLLVM_NetBSD:
return OsNetBSD;
case ZigLLVM_OpenBSD:
return OsOpenBSD;
case ZigLLVM_Solaris:
return OsSolaris;
case ZigLLVM_Win32:
return OsWindows;
case ZigLLVM_Haiku:
return OsHaiku;
case ZigLLVM_Minix:
return OsMinix;
case ZigLLVM_RTEMS:
return OsRTEMS;
case ZigLLVM_NaCl:
return OsNaCl;
case ZigLLVM_CNK:
return OsCNK;
case ZigLLVM_AIX:
return OsAIX;
case ZigLLVM_CUDA:
return OsCUDA;
case ZigLLVM_NVCL:
return OsNVCL;
case ZigLLVM_AMDHSA:
return OsAMDHSA;
case ZigLLVM_PS4:
return OsPS4;
case ZigLLVM_ELFIAMCU:
return OsELFIAMCU;
case ZigLLVM_TvOS:
return OsTvOS;
case ZigLLVM_WatchOS:
return OsWatchOS;
case ZigLLVM_Mesa3D:
return OsMesa3D;
case ZigLLVM_Contiki:
return OsContiki;
case ZigLLVM_AMDPAL:
return OsAMDPAL;
case ZigLLVM_HermitCore:
return OsHermitCore;
case ZigLLVM_Hurd:
return OsHurd;
case ZigLLVM_WASI:
return OsWASI;
case ZigLLVM_Emscripten:
return OsEmscripten;
}
zig_unreachable();
}
const char *target_os_name(Os os_type) {
switch (os_type) {
case OsFreestanding:
@ -447,29 +370,6 @@ Error target_parse_glibc_version(ZigGLibCVersion *glibc_ver, const char *text) {
return ErrorNone;
}
void get_native_target(ZigTarget *target) {
// first zero initialize
*target = {};
ZigLLVM_OSType os_type;
ZigLLVM_ObjectFormatType oformat; // ignored; based on arch/os
ZigLLVMGetNativeTarget(
&target->arch,
&target->vendor,
&os_type,
&target->abi,
&oformat);
target->os = get_zig_os_type(os_type);
target->is_native = true;
if (target->abi == ZigLLVM_UnknownEnvironment) {
target->abi = target_default_abi(target->arch, target->os);
}
if (target_is_glibc(target)) {
target->glibc_version = heap::c_allocator.create<ZigGLibCVersion>();
target_init_default_glibc_version(target);
}
}
void target_init_default_glibc_version(ZigTarget *target) {
*target->glibc_version = {2, 17, 0};
}

View File

@ -73,7 +73,6 @@ ZigLLVM_ObjectFormatType target_oformat_enum(size_t index);
const char *target_oformat_name(ZigLLVM_ObjectFormatType oformat);
ZigLLVM_ObjectFormatType target_object_format(const ZigTarget *target);
void get_native_target(ZigTarget *target);
void target_triple_llvm(Buf *triple, const ZigTarget *target);
void target_triple_zig(Buf *triple, const ZigTarget *target);