Skip to content

Commit 03a0eb0

Browse files
CopilotSteveL-MSFT
andcommitted
Add DEB package support to build system
Co-authored-by: SteveL-MSFT <11859881+SteveL-MSFT@users.noreply.github.com>
1 parent f55bb83 commit 03a0eb0

2 files changed

Lines changed: 88 additions & 1 deletion

File tree

build.ps1

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ param(
99
$architecture = 'current',
1010
[switch]$Clippy,
1111
[switch]$SkipBuild,
12-
[ValidateSet('msix','msix-private','msixbundle','tgz','zip','rpm')]
12+
[ValidateSet('msix','msix-private','msixbundle','tgz','zip','rpm','deb')]
1313
$packageType,
1414
[switch]$Test,
1515
[switch]$GetPackageVersion,
@@ -936,6 +936,81 @@ if ($packageType -eq 'msixbundle') {
936936
Copy-Item $builtRpm.FullName $finalRpmPath -Force
937937

938938
Write-Host -ForegroundColor Green "`nRPM package is created at $finalRpmPath"
939+
} elseif ($packageType -eq 'deb') {
940+
if (!$IsLinux) {
941+
throw "DEB package creation is only supported on Linux"
942+
}
943+
944+
# Check if dpkg-deb is available
945+
if ($null -eq (Get-Command dpkg-deb -ErrorAction Ignore)) {
946+
throw "dpkg-deb not found. Please install dpkg package (e.g., 'sudo apt install dpkg' or 'sudo dnf install dpkg')"
947+
}
948+
949+
$debTarget = Join-Path $PSScriptRoot 'bin' $architecture 'deb'
950+
if (Test-Path $debTarget) {
951+
Remove-Item $debTarget -Recurse -ErrorAction Stop -Force
952+
}
953+
954+
New-Item -ItemType Directory $debTarget > $null
955+
956+
# Create DEB package structure
957+
$debBuildRoot = Join-Path $debTarget 'dsc'
958+
$debDirs = @('DEBIAN', 'opt/dsc', 'usr/bin')
959+
foreach ($dir in $debDirs) {
960+
New-Item -ItemType Directory -Path (Join-Path $debBuildRoot $dir) -Force > $null
961+
}
962+
963+
# Copy files to the package directory
964+
$filesForPackage = $filesForLinuxPackage
965+
$stagingDir = Join-Path $debBuildRoot 'opt' 'dsc'
966+
967+
foreach ($file in $filesForPackage) {
968+
if ((Get-Item "$target\$file") -is [System.IO.DirectoryInfo]) {
969+
Copy-Item "$target\$file" "$stagingDir\$file" -Recurse -ErrorAction Stop
970+
} else {
971+
Copy-Item "$target\$file" $stagingDir -ErrorAction Stop
972+
}
973+
}
974+
975+
# Create symlink in usr/bin
976+
$symlinkPath = Join-Path $debBuildRoot 'usr' 'bin' 'dsc'
977+
New-Item -ItemType SymbolicLink -Path $symlinkPath -Target '/opt/dsc/dsc' -Force > $null
978+
979+
# Determine DEB architecture
980+
$debArch = if ($architecture -eq 'aarch64-unknown-linux-musl' -or $architecture -eq 'aarch64-unknown-linux-gnu') {
981+
'arm64'
982+
} elseif ($architecture -eq 'x86_64-unknown-linux-musl' -or $architecture -eq 'x86_64-unknown-linux-gnu') {
983+
'amd64'
984+
} else {
985+
throw "Unsupported architecture for DEB: $architecture"
986+
}
987+
988+
# Read the control template and replace placeholders
989+
$controlTemplate = Get-Content "$PSScriptRoot/packaging/deb/control" -Raw
990+
$controlContent = $controlTemplate.Replace('VERSION_PLACEHOLDER', $productVersion).Replace('ARCH_PLACEHOLDER', $debArch)
991+
$controlFile = Join-Path $debBuildRoot 'DEBIAN' 'control'
992+
Set-Content -Path $controlFile -Value $controlContent
993+
994+
Write-Verbose -Verbose "Building DEB package"
995+
$debPackageName = "dsc_$productVersion-1_$debArch.deb"
996+
997+
# Build the DEB
998+
dpkg-deb --build $debBuildRoot
999+
1000+
if ($LASTEXITCODE -ne 0) {
1001+
throw "Failed to create DEB package"
1002+
}
1003+
1004+
# Move the DEB to the bin directory with the correct name
1005+
$builtDeb = "$debBuildRoot.deb"
1006+
if (!(Test-Path $builtDeb)) {
1007+
throw "DEB package was not created"
1008+
}
1009+
1010+
$finalDebPath = Join-Path $PSScriptRoot 'bin' $debPackageName
1011+
Move-Item $builtDeb $finalDebPath -Force
1012+
1013+
Write-Host -ForegroundColor Green "`nDEB package is created at $finalDebPath"
9391014
}
9401015

9411016
$env:RUST_BACKTRACE=1

packaging/deb/control

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Package: dsc
2+
Version: VERSION_PLACEHOLDER
3+
Section: utils
4+
Priority: optional
5+
Architecture: ARCH_PLACEHOLDER
6+
Maintainer: Microsoft Corporation
7+
Homepage: https://github.com/PowerShell/DSC
8+
Description: DesiredStateConfiguration v3
9+
DSCv3 is the latest iteration of Microsoft's Desired State Configuration
10+
platform. DSCv3 is an open source command line application that abstracts
11+
the management of software components declaratively and idempotently.
12+
DSCv3 runs on Linux, macOS, and Windows without any external dependencies.

0 commit comments

Comments
 (0)