|
9 | 9 | $architecture = 'current', |
10 | 10 | [switch]$Clippy, |
11 | 11 | [switch]$SkipBuild, |
12 | | - [ValidateSet('msix','msix-private','msixbundle','tgz','zip')] |
| 12 | + [ValidateSet('msix','msix-private','msixbundle','tgz','zip','rpm','deb')] |
13 | 13 | $packageType, |
14 | 14 | [switch]$Test, |
15 | 15 | [switch]$GetPackageVersion, |
@@ -857,6 +857,176 @@ if ($packageType -eq 'msixbundle') { |
857 | 857 | } |
858 | 858 |
|
859 | 859 | Write-Host -ForegroundColor Green "`ntar.gz file is created at $tarFile" |
| 860 | +} elseif ($packageType -eq 'rpm') { |
| 861 | + if (!$IsLinux) { |
| 862 | + throw "RPM package creation is only supported on Linux" |
| 863 | + } |
| 864 | + |
| 865 | + # Check if rpmbuild is available |
| 866 | + if ($null -eq (Get-Command rpmbuild -ErrorAction Ignore)) { |
| 867 | + throw "rpmbuild not found. Please install rpm-build package (e.g., 'sudo apt install rpm build-essential' or 'sudo dnf install rpm-build')" |
| 868 | + } |
| 869 | + |
| 870 | + $rpmTarget = Join-Path $PSScriptRoot 'bin' $architecture 'rpm' |
| 871 | + if (Test-Path $rpmTarget) { |
| 872 | + Remove-Item $rpmTarget -Recurse -ErrorAction Stop -Force |
| 873 | + } |
| 874 | + |
| 875 | + New-Item -ItemType Directory $rpmTarget > $null |
| 876 | + |
| 877 | + # Create RPM build directories |
| 878 | + $rpmBuildRoot = Join-Path $rpmTarget 'rpmbuild' |
| 879 | + $rpmDirs = @('BUILD', 'RPMS', 'SOURCES', 'SPECS', 'SRPMS') |
| 880 | + foreach ($dir in $rpmDirs) { |
| 881 | + New-Item -ItemType Directory -Path (Join-Path $rpmBuildRoot $dir) -Force > $null |
| 882 | + } |
| 883 | + |
| 884 | + # Create a staging directory for the files |
| 885 | + $stagingDir = Join-Path $rpmBuildRoot 'SOURCES' 'dsc_files' |
| 886 | + New-Item -ItemType Directory $stagingDir > $null |
| 887 | + |
| 888 | + $filesForPackage = $filesForLinuxPackage |
| 889 | + |
| 890 | + foreach ($file in $filesForPackage) { |
| 891 | + if ((Get-Item "$target\$file") -is [System.IO.DirectoryInfo]) { |
| 892 | + Copy-Item "$target\$file" "$stagingDir\$file" -Recurse -ErrorAction Stop |
| 893 | + } else { |
| 894 | + Copy-Item "$target\$file" $stagingDir -ErrorAction Stop |
| 895 | + } |
| 896 | + } |
| 897 | + |
| 898 | + # Determine RPM architecture |
| 899 | + $rpmArch = if ($architecture -eq 'current') { |
| 900 | + # Detect current system architecture |
| 901 | + $currentArch = uname -m |
| 902 | + if ($currentArch -eq 'x86_64') { |
| 903 | + 'x86_64' |
| 904 | + } elseif ($currentArch -eq 'aarch64') { |
| 905 | + 'aarch64' |
| 906 | + } else { |
| 907 | + throw "Unsupported current architecture for RPM: $currentArch" |
| 908 | + } |
| 909 | + } elseif ($architecture -eq 'aarch64-unknown-linux-musl' -or $architecture -eq 'aarch64-unknown-linux-gnu') { |
| 910 | + 'aarch64' |
| 911 | + } elseif ($architecture -eq 'x86_64-unknown-linux-musl' -or $architecture -eq 'x86_64-unknown-linux-gnu') { |
| 912 | + 'x86_64' |
| 913 | + } else { |
| 914 | + throw "Unsupported architecture for RPM: $architecture" |
| 915 | + } |
| 916 | + |
| 917 | + # Read the spec template and replace placeholders |
| 918 | + $specTemplate = Get-Content "$PSScriptRoot/packaging/rpm/dsc.spec" -Raw |
| 919 | + $specContent = $specTemplate.Replace('VERSION_PLACEHOLDER', $productVersion.Replace('-','~')).Replace('ARCH_PLACEHOLDER', $rpmArch) |
| 920 | + $specFile = Join-Path $rpmBuildRoot 'SPECS' 'dsc.spec' |
| 921 | + Set-Content -Path $specFile -Value $specContent |
| 922 | + |
| 923 | + Write-Verbose -Verbose "Building RPM package" |
| 924 | + $rpmPackageName = "dsc-$productVersion-1.$rpmArch.rpm" |
| 925 | + |
| 926 | + # Build the RPM |
| 927 | + rpmbuild -v -bb --define "_topdir $rpmBuildRoot" --buildroot "$rpmBuildRoot/BUILDROOT" $specFile 2>&1 > $rpmTarget/rpmbuild.log |
| 928 | + |
| 929 | + if ($LASTEXITCODE -ne 0) { |
| 930 | + Write-Error (Get-Content $rpmTarget/rpmbuild.log -Raw) |
| 931 | + throw "Failed to create RPM package" |
| 932 | + } |
| 933 | + |
| 934 | + # Copy the RPM to the bin directory |
| 935 | + $builtRpm = Get-ChildItem -Path (Join-Path $rpmBuildRoot 'RPMS') -Recurse -Filter '*.rpm' | Select-Object -First 1 |
| 936 | + if ($null -eq $builtRpm) { |
| 937 | + throw "RPM package was not created" |
| 938 | + } |
| 939 | + |
| 940 | + $finalRpmPath = Join-Path $PSScriptRoot 'bin' $builtRpm.Name |
| 941 | + Copy-Item $builtRpm.FullName $finalRpmPath -Force |
| 942 | + |
| 943 | + Write-Host -ForegroundColor Green "`nRPM package is created at $finalRpmPath" |
| 944 | +} elseif ($packageType -eq 'deb') { |
| 945 | + if (!$IsLinux) { |
| 946 | + throw "DEB package creation is only supported on Linux" |
| 947 | + } |
| 948 | + |
| 949 | + # Check if dpkg-deb is available |
| 950 | + if ($null -eq (Get-Command dpkg-deb -ErrorAction Ignore)) { |
| 951 | + throw "dpkg-deb not found. Please install dpkg package (e.g., 'sudo apt install dpkg' or 'sudo dnf install dpkg')" |
| 952 | + } |
| 953 | + |
| 954 | + $debTarget = Join-Path $PSScriptRoot 'bin' $architecture 'deb' |
| 955 | + if (Test-Path $debTarget) { |
| 956 | + Remove-Item $debTarget -Recurse -ErrorAction Stop -Force |
| 957 | + } |
| 958 | + |
| 959 | + New-Item -ItemType Directory $debTarget > $null |
| 960 | + |
| 961 | + # Create DEB package structure |
| 962 | + $debBuildRoot = Join-Path $debTarget 'dsc' |
| 963 | + $debDirs = @('DEBIAN', 'opt/dsc', 'usr/bin') |
| 964 | + foreach ($dir in $debDirs) { |
| 965 | + New-Item -ItemType Directory -Path (Join-Path $debBuildRoot $dir) -Force > $null |
| 966 | + } |
| 967 | + |
| 968 | + # Copy files to the package directory |
| 969 | + $filesForPackage = $filesForLinuxPackage |
| 970 | + $stagingDir = Join-Path $debBuildRoot 'opt' 'dsc' |
| 971 | + |
| 972 | + foreach ($file in $filesForPackage) { |
| 973 | + if ((Get-Item "$target\$file") -is [System.IO.DirectoryInfo]) { |
| 974 | + Copy-Item "$target\$file" "$stagingDir\$file" -Recurse -ErrorAction Stop |
| 975 | + } else { |
| 976 | + Copy-Item "$target\$file" $stagingDir -ErrorAction Stop |
| 977 | + } |
| 978 | + } |
| 979 | + |
| 980 | + # Create symlink in usr/bin |
| 981 | + $symlinkPath = Join-Path $debBuildRoot 'usr' 'bin' 'dsc' |
| 982 | + New-Item -ItemType SymbolicLink -Path $symlinkPath -Target '/opt/dsc/dsc' -Force > $null |
| 983 | + |
| 984 | + # Determine DEB architecture |
| 985 | + $debArch = if ($architecture -eq 'current') { |
| 986 | + # Detect current system architecture |
| 987 | + $currentArch = uname -m |
| 988 | + if ($currentArch -eq 'x86_64') { |
| 989 | + 'amd64' |
| 990 | + } elseif ($currentArch -eq 'aarch64') { |
| 991 | + 'arm64' |
| 992 | + } else { |
| 993 | + throw "Unsupported current architecture for DEB: $currentArch" |
| 994 | + } |
| 995 | + } elseif ($architecture -eq 'aarch64-unknown-linux-musl' -or $architecture -eq 'aarch64-unknown-linux-gnu') { |
| 996 | + 'arm64' |
| 997 | + } elseif ($architecture -eq 'x86_64-unknown-linux-musl' -or $architecture -eq 'x86_64-unknown-linux-gnu') { |
| 998 | + 'amd64' |
| 999 | + } else { |
| 1000 | + throw "Unsupported architecture for DEB: $architecture" |
| 1001 | + } |
| 1002 | + |
| 1003 | + # Read the control template and replace placeholders |
| 1004 | + $controlTemplate = Get-Content "$PSScriptRoot/packaging/deb/control" -Raw |
| 1005 | + $controlContent = $controlTemplate.Replace('VERSION_PLACEHOLDER', $productVersion).Replace('ARCH_PLACEHOLDER', $debArch) |
| 1006 | + $controlFile = Join-Path $debBuildRoot 'DEBIAN' 'control' |
| 1007 | + Set-Content -Path $controlFile -Value $controlContent |
| 1008 | + |
| 1009 | + Write-Verbose -Verbose "Building DEB package" |
| 1010 | + $debPackageName = "dsc_$productVersion-1_$debArch.deb" |
| 1011 | + |
| 1012 | + # Build the DEB |
| 1013 | + dpkg-deb --build $debBuildRoot 2>&1 > $debTarget/debbuild.log |
| 1014 | + |
| 1015 | + if ($LASTEXITCODE -ne 0) { |
| 1016 | + Write-Error (Get-Content $debTarget/debbuild.log -Raw) |
| 1017 | + throw "Failed to create DEB package" |
| 1018 | + } |
| 1019 | + |
| 1020 | + # Move the DEB to the bin directory with the correct name |
| 1021 | + $builtDeb = "$debBuildRoot.deb" |
| 1022 | + if (!(Test-Path $builtDeb)) { |
| 1023 | + throw "DEB package was not created" |
| 1024 | + } |
| 1025 | + |
| 1026 | + $finalDebPath = Join-Path $PSScriptRoot 'bin' $debPackageName |
| 1027 | + Move-Item $builtDeb $finalDebPath -Force |
| 1028 | + |
| 1029 | + Write-Host -ForegroundColor Green "`nDEB package is created at $finalDebPath" |
860 | 1030 | } |
861 | 1031 |
|
862 | 1032 | $env:RUST_BACKTRACE=1 |
0 commit comments