|
| 1 | +parameters: |
| 2 | + BuildCommand: '' |
| 3 | + StageName: 'Windows_Nodejs_Packaging' |
| 4 | + ArtifactName: 'drop-onnxruntime-nodejs-win' |
| 5 | + DoEsrp: 'false' |
| 6 | + BuildArch: 'x64' # Optional. Options: x86, x64 |
| 7 | + sln_platform: 'x64' # Options: Win32, x64, arm, arm64 |
| 8 | + AgentDemands: [] |
| 9 | + BuildConfigurations: ['RelWithDebInfo'] # Options: Debug, RelWithDebInfo |
| 10 | + EnableLto: true |
| 11 | + # Controls whether unreleased onnx opsets are allowed. Default is set to 1 |
| 12 | + AllowReleasedOpsetOnly: '0' |
| 13 | + IsReleaseBuild: false |
| 14 | + PublishWebGpuBuildTools: false |
| 15 | + WebGpuBuildToolsArtifactName: 'Windows_WebGPU_BuildTools_x64' |
| 16 | + DependsOnStageName: '' |
| 17 | + |
| 18 | +stages: |
| 19 | +- stage: ${{ parameters.StageName }} |
| 20 | + dependsOn: |
| 21 | + - Setup |
| 22 | + - ${{ if ne(parameters.DependsOnStageName, '') }}: |
| 23 | + - ${{ parameters.DependsOnStageName }} |
| 24 | + |
| 25 | + jobs: |
| 26 | + - job: ${{ parameters.StageName }} |
| 27 | + timeoutInMinutes: 200 |
| 28 | + strategy: |
| 29 | + maxParallel: 2 |
| 30 | + matrix: |
| 31 | + ${{ each BuildConfiguration in parameters.BuildConfigurations }}: |
| 32 | + ${{ BuildConfiguration }}: |
| 33 | + BuildConfig: ${{ BuildConfiguration }} |
| 34 | + workspace: |
| 35 | + clean: all |
| 36 | + pool: |
| 37 | + name: onnxruntime-Win-CPU-2022 |
| 38 | + demands: ${{ parameters.AgentDemands }} |
| 39 | + variables: |
| 40 | + buildDirectory: '$(Build.BinariesDirectory)' |
| 41 | + OnnxRuntimeBuildDirectory: '$(Build.BinariesDirectory)' |
| 42 | + runCodesignValidationInjection: ${{ parameters. DoEsrp}} #For the others, code sign is in a separated job |
| 43 | + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true |
| 44 | + ALLOW_RELEASED_ONNX_OPSET_ONLY: ${{ parameters.AllowReleasedOpsetOnly }} |
| 45 | + BuildDate : $[stageDependencies.Setup.Set_Variables.outputs['Set_Build_Date.BuildDate']] |
| 46 | + BuildTime : $[stageDependencies.Setup.Set_Variables.outputs['Set_Build_Time.BuildTime']] |
| 47 | + BuildCommandExtra: '' |
| 48 | + ${{ if eq(parameters.EnableLto, true) }}: |
| 49 | + build_py_lto_flag: --enable_lto |
| 50 | + |
| 51 | + steps: |
| 52 | + - checkout: self |
| 53 | + clean: true |
| 54 | + submodules: none |
| 55 | + |
| 56 | + - powershell: | |
| 57 | + if($env:TELEMETRYGUID) |
| 58 | + { |
| 59 | + $length = $env:TELEMETRYGUID.length |
| 60 | + $fileContent = "#define TraceLoggingOptionMicrosoftTelemetry() \ |
| 61 | + TraceLoggingOptionGroup("+$env:TELEMETRYGUID.substring(1, $length-2)+")" |
| 62 | + New-Item -Path "$(Build.SourcesDirectory)\include\onnxruntime\core\platform\windows\TraceLoggingConfigPrivate.h" -ItemType "file" -Value "$fileContent" -Force |
| 63 | + Write-Output "Enabling TELEMETRY" |
| 64 | + } |
| 65 | + displayName: 'Create TraceLoggingConfigPrivate.h For WinML Telemetry' |
| 66 | + env: |
| 67 | + TELEMETRYGUID: $(TELEMETRYGUID) |
| 68 | +
|
| 69 | + - task: NodeTool@0 |
| 70 | + inputs: |
| 71 | + versionSpec: '20.x' |
| 72 | + |
| 73 | + - task: UsePythonVersion@0 |
| 74 | + inputs: |
| 75 | + versionSpec: '3.12' |
| 76 | + addToPath: true |
| 77 | + architecture: ${{ parameters.BuildArch }} |
| 78 | + |
| 79 | + # need to set PROCESSOR_ARCHITECTURE so the x86 SDK is installed correctly |
| 80 | + - task: UseDotNet@2 |
| 81 | + inputs: |
| 82 | + version: 8.x |
| 83 | + env: |
| 84 | + PROCESSOR_ARCHITECTURE: ${{ parameters.BuildArch }} |
| 85 | + |
| 86 | + - task: BatchScript@1 |
| 87 | + displayName: 'Setup VS2022 env vars' |
| 88 | + inputs: |
| 89 | + filename: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat' |
| 90 | + arguments: ${{ parameters.BuildArch }} |
| 91 | + modifyEnvironment: true |
| 92 | + |
| 93 | + - ${{ if and(ne(parameters.WebGpuBuildToolsArtifactName, ''), eq(parameters.sln_platform, 'arm64')) }}: |
| 94 | + - task: DownloadPipelineArtifact@2 |
| 95 | + displayName: 'Download WebGPU build tools from x64 build' |
| 96 | + inputs: |
| 97 | + artifactName: '${{ parameters.WebGpuBuildToolsArtifactName }}' |
| 98 | + targetPath: '$(Build.BinariesDirectory)\${{ parameters.WebGpuBuildToolsArtifactName }}' |
| 99 | + - script: | |
| 100 | + @echo ##vso[task.setvariable variable=LLVM_TABLEGEN_PATH]$(Build.BinariesDirectory)\${{ parameters.WebGpuBuildToolsArtifactName }}\llvm-tblgen.exe |
| 101 | + @echo ##vso[task.setvariable variable=CLANG_TABLEGEN_PATH]$(Build.BinariesDirectory)\${{ parameters.WebGpuBuildToolsArtifactName }}\clang-tblgen.exe |
| 102 | + displayName: 'Set tablegen paths' |
| 103 | + - powershell: | |
| 104 | + Write-Host "Using LLVM_TABLEGEN_PATH: $(LLVM_TABLEGEN_PATH)" |
| 105 | + Write-Host "Using CLANG_TABLEGEN_PATH: $(CLANG_TABLEGEN_PATH)" |
| 106 | + Write-Host "##vso[task.setvariable variable=BuildCommandExtra]--cmake_extra_defines LLVM_TABLEGEN=$(LLVM_TABLEGEN_PATH) CLANG_TABLEGEN=$(CLANG_TABLEGEN_PATH)" |
| 107 | + displayName: 'Set build flags for WebGPU cross-compilation' |
| 108 | +
|
| 109 | + - powershell: | |
| 110 | + python tools\ci_build\build.py --build_dir $(Build.BinariesDirectory) ${{ parameters.BuildCommand }} $(BuildCommandExtra) --use_binskim_compliant_compile_flags --parallel --build --update --config $(BuildConfig) --msbuild_extra_options IncludeMobileTargets=false ${{ variables.build_py_lto_flag }} |
| 111 | +
|
| 112 | + - ${{ if notIn(parameters['sln_platform'], 'Win32', 'x64') }}: |
| 113 | + # Use cross-compiled protoc |
| 114 | + - script: | |
| 115 | + @echo ##vso[task.setvariable variable=ProtocDirectory]$(Build.BinariesDirectory)\installed\bin |
| 116 | +
|
| 117 | + # The Configuration variable is required to build C# |
| 118 | + - script: | |
| 119 | + @echo ##vso[task.setvariable variable=Configuration]$(BuildConfig) |
| 120 | + displayName: 'Set Configuration variable' |
| 121 | +
|
| 122 | + # Node.js Publish |
| 123 | + - task: BatchScript@1 |
| 124 | + displayName: 'Setup VS env vars' |
| 125 | + inputs: |
| 126 | + filename: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat' |
| 127 | + arguments: ${{ parameters.BuildArch }} |
| 128 | + modifyEnvironment: true |
| 129 | + - task: CopyFiles@2 |
| 130 | + displayName: 'Copy DirectML binaries to: $(Build.SourcesDirectory)\js\node\bin\napi-v3\win32\${{ parameters.sln_platform }}' |
| 131 | + inputs: |
| 132 | + SourceFolder: '$(Build.BinariesDirectory)\$(BuildConfig)\$(BuildConfig)' |
| 133 | + Contents: 'DirectML.dll' |
| 134 | + TargetFolder: '$(Build.SourcesDirectory)\js\node\bin\napi-v3\win32\${{ parameters.sln_platform }}' |
| 135 | + - powershell: | |
| 136 | + $dxcZipUrl = "https://github.com/microsoft/DirectXShaderCompiler/releases/download/v1.8.2502/dxc_2025_02_20.zip" |
| 137 | + $dxcZipPath = "$(Build.BinariesDirectory)\dxc.zip" |
| 138 | + $dxcExtractPath = "$(Build.BinariesDirectory)\dxc_extracted" |
| 139 | + $targetArch = "${{ parameters.sln_platform }}" |
| 140 | +
|
| 141 | + # Download the DXC package |
| 142 | + Write-Host "Downloading DXC release from $dxcZipUrl" |
| 143 | + Invoke-WebRequest -Uri $dxcZipUrl -OutFile $dxcZipPath |
| 144 | +
|
| 145 | + # Create extraction directory |
| 146 | + if (-not (Test-Path $dxcExtractPath)) { |
| 147 | + New-Item -Path $dxcExtractPath -ItemType Directory -Force |
| 148 | + } |
| 149 | +
|
| 150 | + # Extract the zip file |
| 151 | + Write-Host "Extracting DXC package to $dxcExtractPath" |
| 152 | + Expand-Archive -Path $dxcZipPath -DestinationPath $dxcExtractPath -Force |
| 153 | +
|
| 154 | + # Copy the necessary DLLs to the target directory |
| 155 | + $sourcePath = Join-Path $dxcExtractPath "bin\$targetArch" |
| 156 | + $targetPath = "$(Build.SourcesDirectory)\js\node\bin\napi-v3\win32\$targetArch" |
| 157 | +
|
| 158 | + Write-Host "Copying dxil.dll and dxcompiler.dll from $sourcePath to $targetPath" |
| 159 | + Copy-Item -Path "$sourcePath\dxil.dll" -Destination $targetPath -Force |
| 160 | + Copy-Item -Path "$sourcePath\dxcompiler.dll" -Destination $targetPath -Force |
| 161 | +
|
| 162 | + Write-Host "DXC DLLs successfully copied to the target directory" |
| 163 | + displayName: 'Download and Copy DXC Binaries' |
| 164 | + - template: ../templates/win-esrp-dll.yml |
| 165 | + parameters: |
| 166 | + FolderPath: '$(Build.SourcesDirectory)\js\node\bin\napi-v3\win32\${{ parameters.sln_platform }}' |
| 167 | + DisplayName: 'ESRP - Sign Node.js binding binaries' |
| 168 | + DoEsrp: ${{ parameters.DoEsrp }} |
| 169 | + Pattern: '*.dll,*.node' |
| 170 | + |
| 171 | + - script: | |
| 172 | + del /Q $(Build.SourcesDirectory)\js\node\bin\napi-v3\win32\${{ parameters.sln_platform }}\CodeSignSummary-*.* |
| 173 | + call npm pack |
| 174 | + copy $(Build.SourcesDirectory)\js\node\onnxruntime-*.tgz $(Build.ArtifactStagingDirectory) |
| 175 | + workingDirectory: '$(Build.SourcesDirectory)\js\node' |
| 176 | + displayName: 'Create NPM Package' |
| 177 | +
|
| 178 | + - task: 1ES.PublishPipelineArtifact@1 |
| 179 | + inputs: |
| 180 | + targetPath: '$(Build.SourcesDirectory)\js\node\bin\napi-v3\win32\${{ parameters.sln_platform }}' |
| 181 | + artifactName: ${{ parameters.ArtifactName }} |
| 182 | + |
| 183 | + - ${{ if and(eq(parameters.PublishWebGpuBuildTools, true), eq(parameters.sln_platform, 'x64')) }}: |
| 184 | + - script: | |
| 185 | + mkdir $(Build.ArtifactStagingDirectory)\${{ parameters.WebGpuBuildToolsArtifactName }} |
| 186 | + copy $(Build.BinariesDirectory)\$(BuildConfig)\_deps\dawn-build\third_party\dxc\RelWithDebInfo\bin\llvm-tblgen.exe $(Build.ArtifactStagingDirectory)\${{ parameters.WebGpuBuildToolsArtifactName }} |
| 187 | + copy $(Build.BinariesDirectory)\$(BuildConfig)\_deps\dawn-build\third_party\dxc\RelWithDebInfo\bin\clang-tblgen.exe $(Build.ArtifactStagingDirectory)\${{ parameters.WebGpuBuildToolsArtifactName }} |
| 188 | + displayName: 'Copy WebGPU build tools' |
| 189 | + - task: 1ES.PublishPipelineArtifact@1 |
| 190 | + inputs: |
| 191 | + targetPath: '$(Build.ArtifactStagingDirectory)\${{ parameters.WebGpuBuildToolsArtifactName }}' |
| 192 | + artifactName: ${{ parameters.WebGpuBuildToolsArtifactName }} |
0 commit comments