Skip to content

Commit

Permalink
Windows: add version info, cmake migrate, update unpackers (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
phnzb authored Mar 27, 2024
1 parent c8c5927 commit 1ed83da
Show file tree
Hide file tree
Showing 11 changed files with 450 additions and 19 deletions.
26 changes: 11 additions & 15 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,29 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Change version for non-release
if: github.ref_name != 'main'
run: |
$Version = ((((Select-String -Path nzbget.vcxproj -Pattern ";VERSION=")[0] -split(';'))[2] -split('='))[1]) -replace '"', ''
$Date=Get-Date -Format "yyyyMMdd"
$NewVersion = "$Version-testing-$Date"
(Get-Content nzbget.vcxproj) | ForEach-Object {$_ -replace "VERSION=`"$Version`"", "VERSION=`"$NewVersion`""} | Set-Content nzbget.vcxproj
(Get-Content windows\nzbget-setup.nsi) | ForEach-Object {$_ -replace "`"DisplayVersion`" `"$Version`"", "`"DisplayVersion`" `"$NewVersion`""} | Set-Content windows\nzbget-setup.nsi
"NEW_VERSION=$NewVersion" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Build
run: |
.\windows\build-nzbget-vs22.bat
$BuildParams="-BuildRelease -Build32 -Build64 -BuildSetup"
If (-not ($env:GITHUB_REF_NAME -eq "main")) {
$BuildParams="$BuildParams -BuildTesting"
}
If (($env:GITHUB_REF_NAME -eq "main") -or ($env:GITHUB_REF_NAME -eq "develop")) {
$BuildParams="$BuildParams -BuildDebug"
}
Invoke-Expression "windows\build-nzbget.ps1 $BuildParams"
- name: Rename build artifacts
if: github.ref_name != 'main' && github.ref_name != 'develop'
run: |
$Output="c:\nzbget\build\output"
$NewVersion=$env:NEW_VERSION
$Output="build"
$Suffix = $env:GITHUB_REF_NAME.Replace("/","-")
ForEach ($File In Get-ChildItem -Path $Output -Filter "*.exe") {
Rename-Item -Path "$Output\$($File.Name)" -NewName $File.Name.Replace($NewVersion, "$NewVersion-$Suffix")
Rename-Item -Path "$Output\$($File.Name)" -NewName $File.Name.Replace("-bin-windows-setup.exe", "-$Suffix-bin-windows-setup.exe")
}
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: nzbget-windows-installers
path: C:\nzbget\build\output\*.exe
path: build\*.exe
retention-days: 5
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CONFIGURATION_TYPES "Release" "Debug")

string(REGEX MATCH "^([0-9]+)\\.([0-9]+)" VERSION_MATCH ${VERSION})
set(VERSION_MAJOR ${CMAKE_MATCH_1})
set(VERSION_MINOR ${CMAKE_MATCH_2})

add_compile_definitions(HAVE_CONFIG_H=1)

if(NOT CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -73,6 +77,21 @@ if(WIN32)
include(cmake/windows.cmake)
if(NOT BUILD_ONLY_TESTS)
target_sources(${PACKAGE} PRIVATE ${CMAKE_SOURCE_DIR}/windows/resources/nzbget.rc)
configure_file(
${CMAKE_SOURCE_DIR}/windows/resources/version.rc.in
${CMAKE_BINARY_DIR}/version.rc
)
configure_file(
${CMAKE_SOURCE_DIR}/windows/version.nsi.in
${CMAKE_BINARY_DIR}/version.nsi
@ONLY
)
configure_file(
${CMAKE_SOURCE_DIR}/windows/version-uninstall.nsi.in
${CMAKE_BINARY_DIR}/version-uninstall.nsi
@ONLY
)
target_sources(${PACKAGE} PRIVATE ${CMAKE_BINARY_DIR}/version.rc)
endif()
else()
include(cmake/posix.cmake)
Expand Down
2 changes: 1 addition & 1 deletion cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#cmakedefine PACKAGE "@PACKAGE@"

/* Version number of package */
#cmakedefine VERSION "@VERSION@"
#cmakedefine VERSION "@VERSION@@VERSION_SUFFIX@"

/* Define to the address where bug reports for this package should be sent. */
#cmakedefine PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"
Expand Down
1 change: 0 additions & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ List of files to change version:
1. configure.ac - "AC_INIT" macro
2. CMakeLists.txt - "project" block
3. nzbget.vcxproj - "PreprocessorDefinitions" blocks - 4 matches
4. windows/nzbget-setup.nsi - WriteRegStr - "DisplayVersion"
98 changes: 98 additions & 0 deletions windows/build-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# About
"build-nzbget.ps1" is a PowerShell script which is used to build Windows nzbget binaries and installer

# Prerequisites

## Execution policy

To run PowerShell scripts check ExecutionPolicy on yours system. From PowerShell prompt run:
```
Get-ExecutionPolicy
```
It should be minimum at `RemoteSigned` level. `Unrestricted` works too. To set desired policy, run as an Administrator from PowerShell prompt:
```
Set-ExecutionPolicy RemoteSigned
```


## Build package

- [vcpkg](https://vcpkg.io) with all needeed libraries (32-bit/64-bit must be installer separately)
- more info in [Windows readme](../docs/WINDOWS.md)
- script assumes that vcpkg is installed in `c:\vcpkg`
- [CMake](https://cmake.org)
- sed
- 4.2.1 binary can be found [here](https://github.com/chapvic/sed/releases)
- script assumes that sed.exe is placed in `c:\nzbget\sed\sed.exe`

## Build installer

- [NSIS 3.09](https://nsis.sourceforge.io)
- script assumes that NSIS is installed in `c:\nzbget\nsis`
- [Advanced logging](https://nsis.sourceforge.io/Special_Builds)
- download and extract to installed NSIS directory
- [AccessControl Plugin](https://nsis.sourceforge.io/AccessControl_plug-in)
- download and place `AccessControl.dll` from `Plugins\i386-unicode` to NSIS's `Plugins\x86-unicode`
- [Simple Service Plugin](https://nsis.sourceforge.io/NSIS_Simple_Service_Plugin)
- download unicode version and place `SimpleSC.dll` to NSIS's `Plugins\x86-unicode`

## Unpackers
For building nzbget package you must have downloaded 7zip/unrar unpackers to `$ToolsRoot\image` (default to `c:\nzbget\image`). 32/64 bit unpackers should be placed in `$ToolsRoot\image\32` and `$ToolsRoot\image\64` folders respectively. This can be done by running `build-nzbget.ps1` with `-DownloadUnpackers` parameter:
```
.\windows\build-nzbget.ps1 -DownloadUnpackers
```
Full `$ToolsRoot` layout:
```
nzbget
├── image
│   ├── 32
│   │   ├── 7za.exe
│   │   └── unrar.exe
│   └── 64
│   ├── 7za.exe
│   └── unrar.exe
├── nsis
│   ├── NSIS home
└── sed
└── sed.exe
```

# Building NZBGet
Run from PowerShell in cloned repository:
```
.\windows\build-nzbget.ps1 [options]
```
`[options]` can be:
| Option | Description |
|--------------------|-
| -BuildDebug | build debug package
| -BuildRelease | build release package
| -Build32 | build 32-bit package
| -Build64 | build 64-bit package
| -BuildSetup | build NSIS installer package
| -BuildTesting | build testing package (add VersionSuffix=`-testing-$yyyyMMdd` to package version)
| -DownloadUnpackers | download unpackers (see above)


Default parameters (if script invoked without options):
```
.\windows\build-nzbget.ps1 -BuildRelease -Build32 -Build64 -BuildSetup
```

If at least one parameter is present, all the others must be explicitly specified.
For example (build release/debug 32/64 package, release/debug installer, and add testing VersionSuffix):
```
.\windows\build-nzbget.ps1 -BuildRelease -BuildDebug -Build32 -Build64 -BuildSetup -BuildTesting
```

# Output files

| File(s) | Description |
|----------------------------------------|-
| build\Release32\Release\nzbget.exe | 32-bit release nzbget binary
| build\Release64\Release\nzbget.exe | 64-bit release nzbget binary
| build\Debug32\Debug\nzbget.exe | 32-bit debug nzbget binary
| build\Debug64\Debug\nzbget.exe | 64-bit debug nzbget binary
| build\distrib\nzbget\ | latest built nzbget package
| build\nzbget-*-windows-setup.exe | nzbget release installer
| build\nzbget-*-windows-debug-setup.exe | nzbget debug installer
Loading

0 comments on commit 1ed83da

Please sign in to comment.