|
9 | 9 | $architecture = 'current', |
10 | 10 | [switch]$Clippy, |
11 | 11 | [switch]$SkipBuild, |
12 | | - [ValidateSet('msix','msix-private','msixbundle','tgz','zip','rpm')] |
| 12 | + [ValidateSet('msix','msix-private','msixbundle','tgz','zip','rpm','deb')] |
13 | 13 | $packageType, |
14 | 14 | [switch]$Test, |
15 | 15 | [switch]$GetPackageVersion, |
@@ -936,6 +936,81 @@ if ($packageType -eq 'msixbundle') { |
936 | 936 | Copy-Item $builtRpm.FullName $finalRpmPath -Force |
937 | 937 |
|
938 | 938 | 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" |
939 | 1014 | } |
940 | 1015 |
|
941 | 1016 | $env:RUST_BACKTRACE=1 |
0 commit comments