Skip to content

Commit 845f221

Browse files
committed
zig test on 64-bit windows runs 32-bit tests
1 parent d43204c commit 845f221

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ else()
129129
add_library(embedded_lld_elf ${EMBEDDED_LLD_ELF_SOURCES})
130130
add_library(embedded_lld_coff ${EMBEDDED_LLD_COFF_SOURCES})
131131
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")
133133
else()
134134
set(ZIG_LLD_COMPILE_FLAGS "-std=c++11 -fno-exceptions -fno-rtti -Wno-comment")
135135
endif()

src/main.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,7 @@ int main(int argc, char **argv) {
711711
codegen_build(g);
712712
codegen_link(g, buf_ptr(test_exe_name));
713713

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)) {
717715
fprintf(stderr, "Created %s but skipping execution because it is non-native.\n",
718716
buf_ptr(test_exe_name));
719717
return 0;

src/target.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,3 +640,28 @@ Buf *target_dynamic_linker(ZigTarget *target) {
640640
return buf_create_from_str("/lib64/ld-linux-x86-64.so.2");
641641
}
642642
}
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,7 @@ const char *target_exe_file_ext(ZigTarget *target);
7777

7878
Buf *target_dynamic_linker(ZigTarget *target);
7979

80+
bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target);
81+
8082

8183
#endif

0 commit comments

Comments
 (0)