Add Windows Driver Kit (WDK) support for building KMDF/UMDF drivers

download --with-wdk fetches the WDK headers/libs/host-tools NuGet
packages (nuget.org has no vsman-manifest entry for this content) and
lays them out where the DriverKit.BuildTools PlatformToolset expects
them. msbuildEnv wires WDKContentRoot/WDKBuildFolder through
DisableRegistryUse the same way the SDK/toolset paths already are.

Two WDK-package fixups were needed for a real driver to actually
build under Wine: the bundled build-task assembly is versioned for an
older VisualStudioVersion than ours, and the package ships no x86
host-tools directory at all (only x64/arm64), which StampInf hardcodes
a path to.

Also force TZ=UTC for msbuild invocations: StampInf stamps DriverVer
using the local wall-clock date while Inf2Cat validates it against
UTC "now", so any timezone east of UTC sees a "postdated DriverVer"
failure for most of the day.

Verified against a real KMDF sample driver (microsoft/Windows-driver-
samples' echo_2): compiles, links, INF stamps and passes Inf2Cat's
signability check with SignMode=off.
This commit is contained in:
Cheviiot
2026-07-25 03:24:44 +10:00
parent 44fee57ddd
commit 8551d7fe99
4 changed files with 347 additions and 3 deletions
+23 -1
View File
@@ -1,6 +1,7 @@
package wrapper
import (
"os"
"path/filepath"
"regexp"
"strings"
@@ -19,12 +20,20 @@ var reToolsetDir = regexp.MustCompile(`^v(\d+)$`)
// Windows Registry.
func msbuildEnv(cfg *wineenv.Config, paths *wineenv.Paths) map[string]string {
env := map[string]string{
// WDK driver builds stamp the INF's DriverVer with StampInf (which
// uses the local wall-clock date) and then validate it with
// Inf2Cat (which checks against UTC "now"). For any timezone east
// of UTC, local-vs-UTC disagree on the calendar date for most of
// the day, so Inf2Cat rejects the just-stamped date as "postdated"
// (MSB6006, "DriverVer set to a date in the future"). Forcing both
// tools onto the same UTC clock removes the mismatch.
"TZ": "UTC",
"DisableRegistryUse": "true",
"VCToolsVersion": cfg.MSVCVer,
"VsInstallRoot": paths.BaseWin + `\`,
"VSInstallDir": paths.BaseWin + `\`,
"MicrosoftKitRoot": paths.BaseWin + `\`,
"SDKReferenceDirectoryRoot": paths.BaseWin + `\`,
"SDKExtensionDirectoryRoot": paths.BaseWin + `\`,
"MSBUILDSDKREFERENCEDIRECTORY": paths.BaseWin + `\`,
@@ -69,6 +78,19 @@ func msbuildEnv(cfg *wineenv.Config, paths *wineenv.Paths) map[string]string {
env["PreferredToolArchitecture"] = "x64"
}
// The WindowsKernelModeDriver10.0/WindowsUserModeDriver10.0
// PlatformToolsets (registered by `download --with-wdk`, see
// internal/download/wdk.go) resolve WDKContentRoot through the
// (nonexistent, under Wine) registry unless it's already set - same
// DisableRegistryUse workaround as WindowsSdkDir_10 above. WDKBuildFolder
// picks the per-SDK-build subtree (c/build/<ver>/...) the NuGet
// package's content is organized under.
wdkContentRoot := filepath.Join(paths.BaseUnix, "wdk", cfg.Arch, "c")
if fi, err := os.Stat(wdkContentRoot); err == nil && fi.IsDir() {
env["WDKContentRoot"] = wineenv.ToWinPath(wdkContentRoot) + `\`
env["WDKBuildFolder"] = cfg.SDKVer
}
return env
}