|
| 1 | +# Rust 驱动构建脚本 - sysdemo |
| 2 | + |
| 3 | +$ErrorActionPreference = "Stop" |
| 4 | + |
| 5 | +$SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path |
| 6 | +Set-Location $SCRIPT_DIR |
| 7 | +$WDK_PATH = "E:\Program Files\Windows Kits\10" |
| 8 | +$EWDK_ISO_PATH = "D:\Admin\vs2022VC\EWDK_br_release_28000_251103-1709.iso" |
| 9 | +$EWDK_MOUNT_LETTER = "E:" |
| 10 | +$EWDK_BUILD_ENV = "$EWDK_MOUNT_LETTER\BuildEnv\SetupBuildEnv.cmd" |
| 11 | + |
| 12 | +Write-Host "=== sysdemo 驱动构建脚本 ===" -ForegroundColor Cyan |
| 13 | +Write-Host "" |
| 14 | +Write-Host "脚本目录: $SCRIPT_DIR" -ForegroundColor Green |
| 15 | +Write-Host "" |
| 16 | + |
| 17 | +# ============================================ |
| 18 | +# 注册表配置 |
| 19 | +# ============================================ |
| 20 | +Write-Host "配置注册表路径..." -ForegroundColor Yellow |
| 21 | + |
| 22 | +$regPath = "HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots" |
| 23 | +$regValue = Get-ItemProperty -Path $regPath -Name "KitsRoot10" -ErrorAction SilentlyContinue |
| 24 | + |
| 25 | +if ($null -eq $regValue) { |
| 26 | + New-ItemProperty -Path $regPath -Name "KitsRoot10" -Value "$WDK_PATH\\"" -PropertyType String -Force | Out-Null |
| 27 | +} else { |
| 28 | + Set-ItemProperty -Path $regPath -Name "KitsRoot10" -Value "$WDK_PATH\\"" -Force | Out-Null |
| 29 | +} |
| 30 | + |
| 31 | +$regPathWow = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows Kits\Installed Roots" |
| 32 | +$regValueWow = Get-ItemProperty -Path $regPathWow -Name "KitsRoot10" -ErrorAction SilentlyContinue |
| 33 | + |
| 34 | +if ($null -eq $regValueWow) { |
| 35 | + New-ItemProperty -Path $regPathWow -Name "KitsRoot10" -Value "$WDK_PATH\\"" -PropertyType String -Force | Out-Null |
| 36 | +} else { |
| 37 | + Set-ItemProperty -Path $regPathWow -Name "KitsRoot10" -Value "$WDK_PATH\\"" -Force | Out-Null |
| 38 | +} |
| 39 | + |
| 40 | +Write-Host "注册表配置完成" -ForegroundColor Green |
| 41 | +Write-Host "" |
| 42 | + |
| 43 | +# ============================================ |
| 44 | +# 设置 EWDK 构建环境 |
| 45 | +# ============================================ |
| 46 | +Write-Host "设置 EWDK 构建环境..." -ForegroundColor Yellow |
| 47 | + |
| 48 | +if (-not (Test-Path $EWDK_MOUNT_LETTER)) { |
| 49 | + Mount-DiskImage -ImagePath $EWDK_ISO_PATH -StorageType ISO -ErrorAction SilentlyContinue |
| 50 | +} |
| 51 | + |
| 52 | +& $EWDK_BUILD_ENV | Out-Null |
| 53 | + |
| 54 | +$WDK_VERSION = "10.0.28000.0" |
| 55 | +$WDK_BIN = "$WDK_PATH\bin\$WDK_VERSION" |
| 56 | +$MSVC_BIN = "E:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64" |
| 57 | + |
| 58 | +$env:WDKContentRoot = $WDK_PATH |
| 59 | +$env:PATH = "$WDK_BIN\x64;$MSVC_BIN;$env:PATH" |
| 60 | + |
| 61 | +Write-Host "" |
| 62 | + |
| 63 | +# ============================================ |
| 64 | +# 配置构建环境 |
| 65 | +# ============================================ |
| 66 | +Write-Host "配置构建环境..." -ForegroundColor Yellow |
| 67 | + |
| 68 | +$env:LIB = "$WDK_PATH\Lib\$WDK_VERSION\um\x64;$WDK_PATH\Lib\$WDK_VERSION\ucrt\x64;E:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\lib\x64" |
| 69 | +$env:RUSTFLAGS = "-C target-feature=+crt-static" |
| 70 | +$env:CARGO_CFG_TARGET_FEATURE = "cmpxchg16b,crt-static,fxsr,sse,sse2,sse3" |
| 71 | + |
| 72 | +Write-Host "" |
| 73 | + |
| 74 | +# ============================================ |
| 75 | +# 编译项目 |
| 76 | +# ============================================ |
| 77 | +Write-Host "=== 编译 sysdemo ===" -ForegroundColor Cyan |
| 78 | + |
| 79 | +cargo build --release --target x86_64-pc-windows-msvc |
| 80 | + |
| 81 | +if ($LASTEXITCODE -eq 0) { |
| 82 | + Write-Host "sysdemo 编译成功!" -ForegroundColor Green |
| 83 | + |
| 84 | + $workspaceTarget = "d:\ux\examples\hypedbg\rust-driver\target\x86_64-pc-windows-msvc\release" |
| 85 | + $dllPath = "$workspaceTarget\sysdemo.dll" |
| 86 | + $sysPath = "$workspaceTarget\sysdemo.sys" |
| 87 | + $localSysPath = "$SCRIPT_DIR\sysdemo.sys" |
| 88 | + |
| 89 | + if (Test-Path $dllPath) { |
| 90 | + if (Test-Path $sysPath) { |
| 91 | + Remove-Item -Path $sysPath -Force -ErrorAction SilentlyContinue |
| 92 | + } |
| 93 | + Rename-Item -Path $dllPath -NewName "sysdemo.sys" -Force |
| 94 | + Write-Host "重命名 sysdemo.dll 为 sysdemo.sys" -ForegroundColor Yellow |
| 95 | + |
| 96 | + if (Test-Path $localSysPath) { |
| 97 | + Remove-Item -Path $localSysPath -Force -ErrorAction SilentlyContinue |
| 98 | + } |
| 99 | + Copy-Item -Path $sysPath -Destination $localSysPath -Force |
| 100 | + Write-Host "复制 sysdemo.sys 到本地目录" -ForegroundColor Yellow |
| 101 | + } |
| 102 | + |
| 103 | + Write-Host "" |
| 104 | + Write-Host "=== 构建完成 ===" -ForegroundColor Green |
| 105 | + Write-Host "请等待驱动签名后再进行测试..." -ForegroundColor Yellow |
| 106 | +} else { |
| 107 | + Write-Error "sysdemo 编译失败" |
| 108 | + exit 1 |
| 109 | +} |
0 commit comments