diff --git a/.pipelines/build-stage.yml b/.pipelines/build-stage.yml index de7ab37..8785981 100644 --- a/.pipelines/build-stage.yml +++ b/.pipelines/build-stage.yml @@ -24,7 +24,7 @@ parameters: type: object default: - target: "wsl;libwsl;wslg;wslservice;wslhost;wslrelay;wslinstaller;wslinstall;initramfs;wslserviceproxystub;wslsettings;wslinstallerproxystub;testplugin" - pattern: "wsl.exe,libwsl.dll,wslg.exe,wslservice.exe,wslhost.exe,wslrelay.exe,wslinstaller.exe,wslinstall.dll,wslserviceproxystub.dll,wslsettings.dll,wslsettings.exe,wslinstallerproxystub.dll,wsldevicehost.dll,WSLDVCPlugin.dll,testplugin.dll,wsldeps.dll" + pattern: "wsl.exe,libwsl.dll,wslg.exe,wslservice.exe,wslhost.exe,wslrelay.exe,wslinstaller.exe,wslinstall.dll,wslserviceproxystub.dll,wslsettings/wslsettings.dll,wslsettings/wslsettings.exe,wslinstallerproxystub.dll,wsldevicehost.dll,WSLDVCPlugin.dll,testplugin.dll,wsldeps.dll" - target: "msixgluepackage" pattern: "gluepackage.msix" - target: "msipackage" @@ -120,6 +120,11 @@ stages: ob_sdl_codeSignValidation_excludes: -|**testbin\** Codeql.PublishDatabaseLog: true Codeql.SourceRoot: src + packageStagingDir: '$(Build.SourcesDirectory)\packageStagingDir' + ${{ if eq(parameters.isRelease, 'true') }}: + packageInputDirArg: '-DPACKAGE_INPUT_DIR=$(packageStagingDir)' + ${{ else }}: + packageInputDirArg: '' steps: @@ -166,7 +171,7 @@ stages: displayName: "CMake ${{ platform }}" inputs: workingDirectory: "." - cmakeArgs: . --fresh -A ${{ platform }} -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_VERSION=10.0.26100.0 -DPACKAGE_VERSION=$(version.WSL_PACKAGE_VERSION) -DWSL_NUGET_PACKAGE_VERSION=$(version.WSL_NUGET_PACKAGE_VERSION) -DSKIP_PACKAGE_SIGNING=${{ parameters.isRelease }} -DOFFICIAL_BUILD=${{ parameters.isRelease }} -DPIPELINE_BUILD_ID=$(Build.BuildId) -DVSO_ORG=${{ parameters.vsoOrg }} -DVSO_PROJECT=${{ parameters.vsoProject }} -DWSL_BUILD_WSL_SETTINGS=true + cmakeArgs: . --fresh -A ${{ platform }} -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_VERSION=10.0.26100.0 -DPACKAGE_VERSION=$(version.WSL_PACKAGE_VERSION) -DWSL_NUGET_PACKAGE_VERSION=$(version.WSL_NUGET_PACKAGE_VERSION) -DSKIP_PACKAGE_SIGNING=${{ parameters.isRelease }} -DOFFICIAL_BUILD=${{ parameters.isRelease }} -DPIPELINE_BUILD_ID=$(Build.BuildId) -DVSO_ORG=${{ parameters.vsoOrg }} -DVSO_PROJECT=${{ parameters.vsoProject }} -DWSL_BUILD_WSL_SETTINGS=true $(packageInputDirArg)\${{ platform }} # This additional Restore NuGet package task is added as a workaround for WSL Settings to have its packages restored properly. # Without this, building wsl settings may encounter the following error: @@ -196,7 +201,7 @@ stages: AuthSignCertName: ${{ parameters.esrp.AuthSignCertName }} AppRegistrationClientId: ${{ parameters.esrp.AppRegistrationClientId }} AppRegistrationTenantId: ${{ parameters.esrp.AppRegistrationTenantId }} - FolderPath: "bin\\${{ platform }}" + FolderPath: "bin\\${{ platform }}\\Release" Pattern: "${{ target.pattern }}" UseMSIAuthentication: true EsrpClientId: ${{ parameters.esrp.EsrpClientId }} @@ -224,20 +229,27 @@ stages: } ] - # Replace the intermediate wslsettings binaries file with the signed versions so that any future steps building wslsettings will use the signed versions - - task: PowerShell@2 - displayName: 'Replace wslsettings binaries in intermediate folder with signed versions' - condition: and(succeeded(), eq('${{ parameters.isRelease }}', true)) - inputs: - targetType: inline - script: | - $arch = '${{ platform }}' - $wslsettingsbinpath = "bin\$arch\release\wslsettings" - $wslsettingsobjpath = "src\windows\wslsettings\obj\$arch\release" - # Update the timestamp of wslsettings.exe so that it doesn't get rebuilt - (Get-Item $wslsettingsbinpath\wslsettings.exe).LastWriteTime = Get-Date - Copy-Item $wslsettingsbinpath\wslsettings.dll $wslsettingsobjpath\wslsettings.dll -Force - Copy-Item $wslsettingsbinpath\wslsettings.exe $wslsettingsobjpath\apphost.exe -Force + - task: PowerShell@2 + displayName: "Copy signed ${{ target.target }} to staging (${{ platform }})" + condition: and(succeeded(), eq('${{ parameters.isRelease }}', true)) + inputs: + targetType: inline + script: | + $arch = '${{ platform }}' + $pattern = '${{ target.pattern }}' + $inputDir = "bin\$arch\Release" + $outputDir = "$(packageStagingDir)\$arch" + New-Item -ItemType Directory -Path "$outputDir\wslsettings" -Force + foreach ($file in $pattern.Split(',')) { + $sourcePath = Join-Path $inputDir $file + if (Test-Path $sourcePath) { + $destPath = Join-Path $outputDir $file + Write-Host "Copying signed file: $sourcePath -> $destPath" + Copy-Item -Path $sourcePath -Destination $destPath -Force + } else { + Write-Warning "File not found: $sourcePath" + } + } - script: cmake --build . --config Release -- -m displayName: "Build installer msix and tests (${{ platform }})" @@ -411,3 +423,4 @@ stages: - task: CodeQL3000Finalize@0 condition: ${{ and(parameters.isNightly, eq(variables['Build.SourceBranch'], 'refs/heads/main'))}} + diff --git a/msipackage/CMakeLists.txt b/msipackage/CMakeLists.txt index 9f51362..6b4cb3d 100644 --- a/msipackage/CMakeLists.txt +++ b/msipackage/CMakeLists.txt @@ -1,16 +1,29 @@ set(BIN ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE}) + +# For pipeline builds, use PACKAGE_INPUT_DIR if specified (contains signed binaries) +# For local builds, use bin directory +if(DEFINED PACKAGE_INPUT_DIR) + message(STATUS "Using signed binaries from ${PACKAGE_INPUT_DIR} for MSI packaging") +else() + set(PACKAGE_INPUT_DIR ${BIN}) +endif() + set(OUTPUT_PACKAGE ${BIN}/wsl.msi) set(PACKAGE_WIX_IN ${CMAKE_CURRENT_LIST_DIR}/package.wix.in) set(PACKAGE_WIX ${BIN}/package.wix) set(CAB_CACHE ${BIN}/cab) -set(BINARIES wsl.exe;wslg.exe;wslhost.exe;wslrelay.exe;wslservice.exe;wslserviceproxystub.dll;init;initrd.img;wslinstall.dll) - +set(WINDOWS_BINARIES wsl.exe;wslg.exe;wslhost.exe;wslrelay.exe;wslservice.exe;wslserviceproxystub.dll;wslinstall.dll) if (WSL_BUILD_WSL_SETTINGS) - list(APPEND BINARIES_DEPENDENCIES "wslsettings/wslsettings.dll;wslsettings/wslsettings.exe;libwsl.dll") + list(APPEND WINDOWS_BINARIES "wslsettings/wslsettings.dll;wslsettings/wslsettings.exe;libwsl.dll") endif() set(BINARIES_DEPENDENCIES) -foreach(binary ${BINARIES}) +foreach(binary ${WINDOWS_BINARIES}) + list(APPEND BINARIES_DEPENDENCIES "${PACKAGE_INPUT_DIR}/${binary}") +endforeach() + +set(LINUX_BINARIES init;initrd.img) +foreach(binary ${LINUX_BINARIES}) list(APPEND BINARIES_DEPENDENCIES "${BIN}/${binary}") endforeach() diff --git a/msipackage/package.wix.in b/msipackage/package.wix.in index 732234d..330f7eb 100644 --- a/msipackage/package.wix.in +++ b/msipackage/package.wix.in @@ -1,4 +1,4 @@ - + @@ -19,21 +19,21 @@ - + - - - - - + + + + + - + @@ -223,7 +223,7 @@ - + @@ -292,7 +292,7 @@ - + @@ -323,7 +323,7 @@ - + @@ -350,7 +350,10 @@ - + + + + @@ -385,8 +388,8 @@ - - + + +