ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.79k stars 2.54k forks source link

`error: MS-style inline assembly is not available: Unable to find target for this triple (no targets are registered)` when cross compiling from x64-windows to x86-windows-msvc and including `windows.h` #20842

Open giuliano-macedo opened 3 months ago

giuliano-macedo commented 3 months ago

Zig Version

0.13.0

System information

windows: Version 10.0.19045.4529 64-bit
msvc build tools: 16.11.38

Steps to Reproduce and Observed Behavior

src/main.zig

pub fn main() void {
    _ = @cImport(@cInclude("windows.h"));
}

build.zig

const std = @import("std");
pub fn build(b: *std.Build) void {
    b.installArtifact(b.addExecutable(.{
        .name = "zig-windows",
        .root_source_file = b.path("src/main.zig"),
        .target = b.standardTargetOptions(.{ .default_target = .{ .cpu_arch = .x86, .os_tag = .windows, .abi = .msvc } }),
        .optimize = b.standardOptimizeOption(.{}),
        .link_libc = true,
    }));
}

zig build --verbose-cc output:

install
└─ install zig-windows
   └─ zig build-exe zig-windows Debug x86-windows-msvc 4 errors
src\main.zig:2:9: error: C import failed
    _ = @cImport(@cInclude("windows.h"));
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    callMain: C:\zig\lib\std\start.zig:514:17
    callMainWithArgs: C:\zig\lib\std\start.zig:482:12
    remaining reference traces hidden; use '-freference-trace' to see all reference traces
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um/winnt.h:1010:5: error: MS-style inline assembly is not available: Unable to find target for this triple (no targets are registered)
    __asm    {
    ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um/winnt.h:1026:5: error: MS-style inline assembly is not available: Unable to find target for this triple (no targets are registered)
    __asm {
    ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um/winnt.h:1042:5: error: MS-style inline assembly is not available: Unable to find target for this triple (no targets are registered)
    __asm    {
    ^
error: clang -x c --no-default-config -fno-caret-diagnostics -target i386-unknown-windows-msvc -nostdinc -fno-spell-checking -isystem C:\zig\lib\include -isystem C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt -isystem C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include -isystem C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\atlmfc\include -isystem C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um -isystem C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared -Xclang -target-cpu -Xclang pentium4 -Xclang -target-feature -Xclang -16bit-mode -Xclang -target-feature -Xclang +32bit-mode -Xclang -target-feature -Xclang -3dnow -Xclang -target-feature -Xclang -3dnowa -Xclang -target-feature -Xclang -64bit -Xclang -target-feature -Xclang -adx -Xclang -target-feature -Xclang -aes -Xclang -target-feature -Xclang -allow-light-256-bit -Xclang -target-feature -Xclang -amx-bf16 -Xclang -target-feature -Xclang -amx-complex -Xclang -target-feature -Xclang -amx-fp16 -Xclang -target-feature -Xclang -amx-int8 -Xclang -target-feature -Xclang -amx-tile -Xclang -target-feature -Xclang -avx -Xclang -target-feature -Xclang -avx10.1-256 -Xclang -target-feature -Xclang -avx10.1-512 -Xclang -target-feature -Xclang -avx2 -Xclang -target-feature -Xclang -avx512bf16 -Xclang -target-feature -Xclang -avx512bitalg -Xclang -target-feature -Xclang -avx512bw -Xclang -target-feature -Xclang -avx512cd -Xclang -target-feature -Xclang 
-avx512dq -Xclang -target-feature -Xclang -avx512er -Xclang -target-feature -Xclang -avx512f -Xclang -target-feature -Xclang -avx512fp16 -Xclang -target-feature -Xclang -avx512ifma -Xclang -target-feature -Xclang -avx512pf -Xclang -target-feature -Xclang -avx512vbmi -Xclang -target-feature -Xclang -avx512vbmi2 -Xclang -target-feature -Xclang -avx512vl -Xclang -target-feature -Xclang -avx512vnni -Xclang -target-feature -Xclang -avx512vp2intersect -Xclang -target-feature -Xclang -avx512vpopcntdq -Xclang -target-feature -Xclang -avxifma -Xclang -target-feature -Xclang -avxneconvert -Xclang -target-feature -Xclang -avxvnni -Xclang -target-feature -Xclang -avxvnniint16 -Xclang -target-feature -Xclang -avxvnniint8 -Xclang -target-feature -Xclang -bmi -Xclang -target-feature -Xclang -bmi2 -Xclang -target-feature -Xclang -branchfusion -Xclang -target-feature -Xclang -ccmp -Xclang -target-feature -Xclang -cf -Xclang -target-feature -Xclang -cldemote -Xclang -target-feature -Xclang -clflushopt -Xclang -target-feature -Xclang -clwb -Xclang -target-feature -Xclang -clzero -Xclang -target-feature -Xclang +cmov -Xclang -target-feature -Xclang -cmpccxadd -Xclang -target-feature -Xclang -crc32 -Xclang -target-feature -Xclang -cx16 -Xclang -target-feature -Xclang +cx8 -Xclang -target-feature -Xclang -egpr -Xclang -target-feature -Xclang -enqcmd -Xclang -target-feature -Xclang -ermsb -Xclang -target-feature -Xclang -evex512 -Xclang -target-feature -Xclang -f16c -Xclang -target-feature -Xclang -false-deps-getmant -Xclang -target-feature -Xclang -false-deps-lzcnt-tzcnt -Xclang -target-feature -Xclang -false-deps-mulc -Xclang -target-feature -Xclang -false-deps-mullq -Xclang -target-feature -Xclang -false-deps-perm -Xclang -target-feature -Xclang -false-deps-popcnt -Xclang -target-feature -Xclang -false-deps-range -Xclang -target-feature -Xclang -fast-11bytenop -Xclang -target-feature -Xclang -fast-15bytenop -Xclang -target-feature -Xclang -fast-7bytenop -Xclang -target-feature -Xclang -fast-bextr -Xclang -target-feature -Xclang -fast-gather -Xclang -target-feature -Xclang -fast-hops -Xclang -target-feature -Xclang -fast-lzcnt -Xclang -target-feature -Xclang -fast-movbe -Xclang -target-feature -Xclang -fast-scalar-fsqrt -Xclang -target-feature -Xclang -fast-scalar-shift-masks -Xclang -target-feature -Xclang -fast-shld-rotate -Xclang -target-feature -Xclang -fast-variable-crosslane-shuffle -Xclang -target-feature -Xclang -fast-variable-perlane-shuffle -Xclang -target-feature -Xclang -fast-vector-fsqrt -Xclang -target-feature -Xclang -fast-vector-shift-masks -Xclang -target-feature -Xclang -faster-shift-than-shuffle -Xclang -target-feature -Xclang -fma -Xclang -target-feature -Xclang -fma4 -Xclang -target-feature -Xclang -fsgsbase -Xclang -target-feature -Xclang -fsrm -Xclang -target-feature -Xclang +fxsr -Xclang -target-feature -Xclang -gfni -Xclang -target-feature -Xclang -harden-sls-ijmp -Xclang -target-feature -Xclang -harden-sls-ret -Xclang -target-feature -Xclang -hreset -Xclang -target-feature -Xclang -idivl-to-divb -Xclang -target-feature -Xclang -idivq-to-divl -Xclang -target-feature -Xclang -invpcid -Xclang -target-feature -Xclang -kl -Xclang -target-feature -Xclang -lea-sp -Xclang -target-feature -Xclang -lea-uses-ag -Xclang -target-feature -Xclang -lvi-cfi -Xclang -target-feature -Xclang -lvi-load-hardening -Xclang -target-feature -Xclang -lwp -Xclang -target-feature -Xclang -lzcnt -Xclang -target-feature -Xclang -macrofusion -Xclang -target-feature -Xclang +mmx -Xclang -target-feature -Xclang -movbe -Xclang -target-feature -Xclang -movdir64b -Xclang -target-feature -Xclang -movdiri -Xclang -target-feature -Xclang -mwaitx -Xclang -target-feature -Xclang -ndd -Xclang -target-feature -Xclang -no-bypass-delay -Xclang -target-feature -Xclang -no-bypass-delay-blend -Xclang -target-feature -Xclang -no-bypass-delay-mov -Xclang -target-feature -Xclang -no-bypass-delay-shuffle -Xclang -target-feature -Xclang +nopl -Xclang -target-feature -Xclang -pad-short-functions -Xclang -target-feature -Xclang -pclmul -Xclang -target-feature -Xclang -pconfig -Xclang -target-feature -Xclang -pku -Xclang -target-feature -Xclang -popcnt -Xclang -target-feature -Xclang -ppx -Xclang -target-feature -Xclang -prefer-128-bit -Xclang -target-feature -Xclang -prefer-256-bit -Xclang -target-feature -Xclang -prefer-mask-registers -Xclang -target-feature -Xclang -prefer-movmsk-over-vtest -Xclang -target-feature -Xclang -prefer-no-gather -Xclang -target-feature -Xclang -prefer-no-scatter -Xclang -target-feature -Xclang -prefetchi -Xclang -target-feature -Xclang -prefetchwt1 -Xclang -target-feature -Xclang -prfchw -Xclang -target-feature -Xclang -ptwrite -Xclang -target-feature -Xclang -push2pop2 -Xclang -target-feature -Xclang -raoint -Xclang -target-feature -Xclang -rdpid -Xclang -target-feature -Xclang -rdpru -Xclang -target-feature -Xclang -rdrnd -Xclang -target-feature -Xclang -rdseed -Xclang -target-feature -Xclang -retpoline -Xclang -target-feature -Xclang -retpoline-external-thunk -Xclang -target-feature -Xclang -retpoline-indirect-branches -Xclang -target-feature -Xclang -retpoline-indirect-calls -Xclang -target-feature -Xclang -rtm -Xclang -target-feature -Xclang -sahf -Xclang -target-feature -Xclang -sbb-dep-breaking -Xclang -target-feature -Xclang -serialize -Xclang -target-feature -Xclang -seses -Xclang -target-feature -Xclang -sgx -Xclang -target-feature -Xclang -sha -Xclang -target-feature -Xclang -sha512 -Xclang -target-feature -Xclang -shstk -Xclang -target-feature -Xclang -slow-3ops-lea -Xclang -target-feature -Xclang -slow-incdec -Xclang -target-feature -Xclang -slow-lea -Xclang -target-feature -Xclang -slow-pmaddwd -Xclang -target-feature -Xclang -slow-pmulld -Xclang -target-feature -Xclang -slow-shld -Xclang -target-feature -Xclang -slow-two-mem-ops -Xclang -target-feature -Xclang +slow-unaligned-mem-16 -Xclang -target-feature -Xclang -slow-unaligned-mem-32 -Xclang -target-feature -Xclang -sm3 -Xclang -target-feature -Xclang -sm4 -Xclang -target-feature -Xclang -soft-float -Xclang -target-feature -Xclang +sse -Xclang -target-feature -Xclang +sse2 -Xclang -target-feature -Xclang -sse3 -Xclang -target-feature -Xclang -sse4.1 -Xclang -target-feature -Xclang -sse4.2 -Xclang -target-feature -Xclang -sse4a -Xclang -target-feature -Xclang -sse-unaligned-mem -Xclang -target-feature -Xclang -ssse3 -Xclang -target-feature -Xclang -tagged-globals -Xclang -target-feature -Xclang -tbm -Xclang -target-feature -Xclang -tsxldtrk -Xclang -target-feature -Xclang -tuning-fast-imm-vector-shift -Xclang -target-feature -Xclang -uintr -Xclang -target-feature -Xclang -use-glm-div-sqrt-costs -Xclang -target-feature -Xclang -use-slm-arith-costs -Xclang -target-feature -Xclang -usermsr -Xclang -target-feature -Xclang -vaes -Xclang -target-feature -Xclang -vpclmulqdq -Xclang -target-feature -Xclang +vzeroupper -Xclang -target-feature -Xclang -waitpkg -Xclang -target-feature -Xclang -wbnoinvd -Xclang -target-feature -Xclang -widekl -Xclang -target-feature -Xclang +x87 -Xclang -target-feature -Xclang -xop -Xclang -target-feature -Xclang -xsave -Xclang -target-feature -Xclang -xsavec -Xclang -target-feature -Xclang -xsaveopt -Xclang -target-feature -Xclang -xsaves -fsanitize=undefined -fsanitize-trap=undefined -fno-sanitize=function -mred-zone -fno-omit-frame-pointer -fstack-protector-strong --param ssp-buffer-size=4 -D_DEBUG -O0 -funwind-tables -g -gcodeview -MD -MV -MF C:\Users\i5-10300h\Documents\zig-windows\.zig-cache\o\7c5c331ea40f41b25aa2b5254c7c8835\cimport.h.d -Xclang -detailed-preprocessing-record C:\Users\i5-10300h\Documents\zig-windows\.zig-cache\o\7c5c331ea40f41b25aa2b5254c7c8835\cimport.h

error: the following command failed with 4 compilation errors:
C:\zig\zig.exe build-exe -ODebug -target x86-windows-msvc -mcpu baseline -Mroot=C:\Users\i5-10300h\Documents\zig-windows\src\main.zig -lc --verbose-cc --cache-dir C:\Users\i5-10300h\Documents\zig-windows\.zig-cache --global-cache-dir C:\Users\i5-10300h\AppData\Local\zig --name zig-windows --listen=-
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install zig-windows transitive failure
   └─ zig build-exe zig-windows Debug x86-windows-msvc 4 errors
error: the following build command failed with exit code 1:
C:\Users\i5-10300h\Documents\zig-windows\.zig-cache\o\75d424a412e6bcd7b2aab2710f42cbcd\build.exe C:\zig\zig.exe C:\Users\i5-10300h\Documents\zig-windows C:\Users\i5-10300h\Documents\zig-windows\.zig-cache C:\Users\i5-10300h\AppData\Local\zig --seed 0xa3771c3f -Z5d71784d24f61e85 --verbose-cc

Expected Behavior

Successfully compiling

giuliano-macedo commented 3 months ago

It seems to be ~an issue with clang-tidy~, and can be fixed with the patch described here however the binary size would increase as stated by jcageman in this Caphyon issue.

Correction: it seems to be an LLVM issue that affected clang-tidy as well and it fixed by the patch in the PR.

squeek502 commented 3 months ago

Unrelated to your issue, but note that the x86-windows target currently has a known (and wide-ranging) miscompilation: https://github.com/ziglang/zig/issues/20047