| author | |
| committer | |
| log | 845f22101b1efb2d8898d8ba7310cd78151a42d5 |
| tree | 214478004045621b4a089a7b381bb5934c355aaa |
| parent | d43204c950a24467a85e14fe5ba026e1eac2a19f |
4 files changed, 29 insertions(+), 4 deletions(-)
CMakeLists.txt+1-1| ... | ... | @@ -129,7 +129,7 @@ else() |
| 129 | 129 | add_library(embedded_lld_elf ${EMBEDDED_LLD_ELF_SOURCES}) |
| 130 | 130 | add_library(embedded_lld_coff ${EMBEDDED_LLD_COFF_SOURCES}) |
| 131 | 131 | if(MSVC) |
| 132 | set(ZIG_LLD_COMPILE_FLAGS "-std=c++11") | |
| 132 | set(ZIG_LLD_COMPILE_FLAGS "-std=c++11 -D_CRT_SECURE_NO_WARNINGS") | |
| 133 | 133 | else() |
| 134 | 134 | set(ZIG_LLD_COMPILE_FLAGS "-std=c++11 -fno-exceptions -fno-rtti -Wno-comment") |
| 135 | 135 | endif() |
src/main.cpp+1-3| ... | ... | @@ -711,9 +711,7 @@ int main(int argc, char **argv) { |
| 711 | 711 | codegen_build(g); |
| 712 | 712 | codegen_link(g, buf_ptr(test_exe_name)); |
| 713 | 713 | |
| 714 | bool is_native_target = target == nullptr || (target->os == native.os && | |
| 715 | target->arch.arch == native.arch.arch && target->arch.sub_arch == native.arch.sub_arch); | |
| 716 | if (!is_native_target) { | |
| 714 | if (!target_can_exec(&native, target)) { | |
| 717 | 715 | fprintf(stderr, "Created %s but skipping execution because it is non-native.\n", |
| 718 | 716 | buf_ptr(test_exe_name)); |
| 719 | 717 | return 0; |
src/target.cpp+25| ... | ... | @@ -640,3 +640,28 @@ Buf *target_dynamic_linker(ZigTarget *target) { |
| 640 | 640 | return buf_create_from_str("/lib64/ld-linux-x86-64.so.2"); |
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | ||
| 644 | bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target) { | |
| 645 | assert(host_target != nullptr); | |
| 646 | ||
| 647 | if (guest_target == nullptr) { | |
| 648 | // null guest target means that the guest target is native | |
| 649 | return true; | |
| 650 | } | |
| 651 | ||
| 652 | if (guest_target->os == host_target->os && guest_target->arch.arch == host_target->arch.arch && | |
| 653 | guest_target->arch.sub_arch == host_target->arch.sub_arch) | |
| 654 | { | |
| 655 | // OS, arch, and sub-arch match | |
| 656 | return true; | |
| 657 | } | |
| 658 | ||
| 659 | if (guest_target->os == ZigLLVM_Win32 && guest_target->os == ZigLLVM_Win32 && | |
| 660 | host_target->arch.arch == ZigLLVM_x86_64 && guest_target->arch.arch == ZigLLVM_x86) | |
| 661 | { | |
| 662 | // 64-bit windows can run 32-bit programs | |
| 663 | return true; | |
| 664 | } | |
| 665 | ||
| 666 | return false; | |
| 667 | } |
src/target.hpp+2| ... | ... | @@ -77,5 +77,7 @@ const char *target_exe_file_ext(ZigTarget *target); |
| 77 | 77 | |
| 78 | 78 | Buf *target_dynamic_linker(ZigTarget *target); |
| 79 | 79 | |
| 80 | bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target); | |
| 81 | ||
| 80 | 82 | |
| 81 | 83 | #endif |