Sal.h missing when compiling windows project

I don’t know anything about windows, but I am attempting to compile a portion of npcap with this build.zig

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const upstream = b.dependency("npcap", .{});
    const packet = b.addStaticLibrary(.{
        .name = "Packet",
        .target = target,
        .optimize = optimize,
    });
    packet.linkLibCpp(); // needs #include <string>
    packet.linkLibC(); // needs assert.h
    // work-around _Post_invalid_ being missing? something about sal.h headers.
    // https://github.com/xmake-io/xmake-repo/pull/5390
    packet.root_module.addCMacro("_Post_invalid_", "");
    packet.addIncludePath(upstream.path("Common"));
    packet.addIncludePath(upstream.path("packetWin7/Dll"));
    packet.addCSourceFiles(.{
        .root = upstream.path(""),
        .files = &.{
            // "Common/Packet32.h",
            // "Common/WpcapNames.h",
            "packetWin7/Dll/AdInfo.cpp",
            // "Packet.def", tf is a def file?
            "packetWin7/Dll/Packet32-Int.h",
            "packetWin7/Dll/Packet32.cpp",
            "packetWin7/Dll/debug.h",
            // "version.rc", and WTF are these?
            // "version.rc2",
        },
    });
    b.installArtifact(packet);
}
error: 'sal.h' file not found
#include <sal.h>

I’m pretty sure this should be provided by linkLibC but I don’t really know what I’m doing here so figured it would ask.

has some mentions of sal.h

The file is included in zig libc distribution: lib/libc/include/any-windows-any/sal.h
What is your target triple?

I’m not sure what target triple to use honestly.

zig build -Dtarget=x86_64-windows-msvc produces

error: 'sal.h' file not found

and
zig build -Dtarget=x86_64-windows-gnu produces a lot more errors.

missing identifier GAA_FLAG_SKIP_DNS_INFO on zig build -Dtarget=x86_64-windows-gnu

The -gnu libc is shipped by zig, sal.h is included but as you discovered GAA_FLAG_SKIP_DNS_INFO is missing.

The -msvc libc is shipped by Microsoft Visual Studio. It includes sal.h and:

include/um/IPTypes.h
413:#define GAA_FLAG_SKIP_DNS_INFO                  0x0800

When running zig libc is sys_include_dir= populated? (sal.h must be in this folder)

If zig libc output for include and lib is not populated, run Visual Studio Installer and select from “Individual Components”:

  • “MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest)” (or VS 2019)
    and
  • “Windows 10 SDK (10.0.20348.0)” (or later)

I am on a linux host, compiling for windows.

I believe -msvc relies on system installed msvc headers? The “windows SDK”. (disgusted).

So I will continue down the -gnu path.

I can workaround the missing GAA_FLAG_SKIP_DNS_INFO by adding this to my build.zig:

packet.root_module.addCMacro("GAA_FLAG_SKIP_DNS_INFO", "0x800");
2 Likes