Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS x64 build support (macOS Mojave 10.14+) #194

Merged
merged 9 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:

build-osx:
uses: ./.github/workflows/osx.yml
permissions:
actions: write

build-synology:
uses: ./.github/workflows/synology.yml
Expand Down
77 changes: 73 additions & 4 deletions .github/workflows/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,47 @@ on:
workflow_dispatch:

jobs:
build:
runs-on: [self-hosted, macos]
build-x64:
runs-on: [self-hosted, macos, x64]

steps:

- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Change version for non-release
if: github.ref_name != 'main'
run: |
VERSION=$(grep "set(VERSION" CMakeLists.txt | cut -d '"' -f 2)
NEW_VERSION="$VERSION-testing-$(date '+%Y%m%d')"
echo NEW_VERSION=$NEW_VERSION >> $GITHUB_ENV

- name: Build
run: |
bash osx/build-nzbget-x64.sh

- name: Rename build artifacts
if: github.ref_name != 'main' && github.ref_name != 'develop'
run: |
cd tmp
NEW_VERSION_FEATURE="$NEW_VERSION-${GITHUB_REF_NAME/\//-}"
for FILE in *.zip; do
[ -f $FILE ] || continue
NEW_FILE=${FILE/$NEW_VERSION/$NEW_VERSION_FEATURE}
mv $FILE $NEW_FILE
done

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: nzbget-osx-installers-x64
path: tmp/*.zip
retention-days: 5

build-universal:
runs-on: [self-hosted, macos, arm64]

steps:

Expand All @@ -25,7 +64,7 @@ jobs:

- name: Build
run: |
bash osx/build-nzbget.sh
bash osx/build-nzbget-universal.sh

- name: Rename build artifacts
if: github.ref_name != 'main' && github.ref_name != 'develop'
Expand All @@ -41,6 +80,36 @@ jobs:
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: nzbget-osx-installers
name: nzbget-osx-installers-universal
path: osx/build/Release/*.zip
retention-days: 5

combine-osx-artifacts:
runs-on: ubuntu-latest
needs: [build-x64, build-universal]
permissions:
actions: write
steps:

- name: Download build artifacts
uses: actions/download-artifact@v4

- name: Combine artifacts
run: |
mkdir -p nzbget-osx-installers
mv nzbget-osx-installers-x64/* nzbget-osx-installers
mv nzbget-osx-installers-universal/* nzbget-osx-installers

- name: Upload build artifacts with signatures
uses: actions/upload-artifact@v4
with:
name: nzbget-osx-installers
path: nzbget-osx-installers/*
retention-days: 5

- name: Delete unneded artifacts
uses: geekyeggo/delete-artifact@v4
with:
name: |
nzbget-osx-installers-x64
nzbget-osx-installers-universal
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ QNAP packages are available as native packages and buildroot packages. [QNAP rea

`Linux`: Linux kernel 2.6 and later, x86 (32 or 64 Bit), ARM 32-bit (armel armhf), ARM 64-bit (aarch64), MIPS (mipseb mipsel), PowerPC (ppc6xx ppc500), RISC-V 64-bit (riscv64)

`macOS`: macOS 10.13 High Sierra and later, Intel / Apple Silicon.
`macOS`: X64 binary: macOS Mojave 10.14+, Universal (Intel / Apple Silicon) binary: macOS Monterey 12+

## Building from sources

Expand Down
48 changes: 37 additions & 11 deletions osx/build-info.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
About
-----
"build-nzbget.sh" is a bash script which is used to build macOS universal (Intel/Apple Silicon) application.
# About
"build-nzbget-*.sh" is a bash scripts which is used to build macOS nzbget binaries
- [build-nzbget-universal.sh](#build-nzbget-universalsh) - universal (Intel/Apple Silicon) application (macOS Monterey 12+)
- [build-macos-x64.sh](#build-nzbget-x64sh) - x64 application (macOS Mojave 10.14+)

Prerequisites
-------------
## build-nzbget-universal.sh

### Prerequisites
- Homebrew package manager (https://brew.sh/) and several dependencies:

Install homebrew:
Expand All @@ -21,14 +22,39 @@ brew install git zlib libxml2 ncurses openssl@3 pkg-config boost
xcode-select --install
```

Building NZBGet
---------------
### Building NZBGet
From cloned repository run
```
bash osx/build-nzbget.sh
bash osx/build-nzbget-universal.sh
```

Output files
------------
### Output files
- osx/build/Release/NZBGet.app - application
- osx/build/Release/nzbget-$VERSION-bin-macos.zip - release archive
- osx/build/Release/nzbget-$VERSION-bin-macos-universal.zip - release archive

## build-nzbget-x64.sh

### Prerequisites
- vcpkg package manager (https://vcpkg.io/) and several dependencies:
```
cd $HOME
git clone https://github.com/microsoft/vcpkg
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg install boost-json boost-optional libxml2 zlib openssl
```
- Xcode build tools
```
xcode-select --install
```
- cmake 3.13+

### Building NZBGet
From cloned repository run
```
bash osx/build-nzbget-x64.sh
```

### Output files
- tmp/osx/build/Release/NZBGet.app - application
- tmp/nzbget-$VERSION-bin-macos-x64.zip - release archive
2 changes: 1 addition & 1 deletion osx/build-nzbget.sh → osx/build-nzbget-universal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Make_archive()
{
VERSION=`grep "AC_INIT(nzbget, " configure.ac`
VERSION=`expr "$VERSION" : '.*, \(.*\),.*)'`
(cd osx/build/Release/ && zip -r nzbget-$VERSION-bin-macos.zip NZBGet.app)
(cd osx/build/Release/ && zip -r nzbget-$VERSION-bin-macos-universal.zip NZBGet.app)
}

Make_OpenSSL_for_arm_and_x86
Expand Down
92 changes: 92 additions & 0 deletions osx/build-nzbget-x64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/sh

# strict error handling for debugging
set -o errexit

# config variables
# urls
URL_UNRAR=https://www.rarlab.com/rar/rarmacos-x64-624.tar.gz
URL_7Z=https://www.7-zip.org/a/7z2301-mac.tar.xz
# use vcpkg libs for build and link daemon - install it via ./vcpkg install boost-json boost-optional libxml2 zlib openssl
LIB_PATH=$HOME/vcpkg/installed/x64-osx/lib
INCLUDE_PATH=$HOME/vcpkg/installed/x64-osx/include
# make jobs
JOBS=$(sysctl -n hw.ncpu)

# create directories and cleanup
mkdir -p build
mkdir -p tmp
rm -rf build/*
rm -rf tmp/*

export LIBS="-liconv -lncurses $LIB_PATH/libboost_json.a $LIB_PATH/libxml2.a $LIB_PATH/libz.a $LIB_PATH/libssl.a $LIB_PATH/libcrypto.a $LIB_PATH/liblzma.a"
export INCLUDES="$INCLUDE_PATH/;$INCLUDE_PATH/libxml2/"
VERSION=$(grep "set(VERSION" CMakeLists.txt | cut -d '"' -f 2)

# copy macOS project to tmp
cp -r osx tmp/
DAEMON_PATH=osx/Resources/daemon/usr/local

# make static daemon binary
cd build
cmake .. -DENABLE_STATIC=ON -DCMAKE_INSTALL_PREFIX="$PWD/../tmp/$DAEMON_PATH"
# if running from CI/CD, add testing to builds from non-main branch
if [ -n "$GITHUB_REF_NAME" ]; then
if [ "$GITHUB_REF_NAME" != "main" ]; then
VERSION="$VERSION-testing-$(date '+%Y%m%d')"
sed -e "s|#define VERSION.*|#define VERSION \"$VERSION\"|g" -i '' config.h
fi
fi
cmake --build . -j $JOBS
strip nzbget
cmake --install .

# fetch tools and root certificates
cd ../tmp
mkdir -p $DAEMON_PATH/bin
rm -rf $DAEMON_PATH/etc

# 7zip
curl -o 7z.tar.xz $URL_7Z
mkdir -p 7z
tar xf 7z.tar.xz -C 7z
cp 7z/7zz $DAEMON_PATH/bin/7za

# unrar
curl -o unrar.tar.gz $URL_UNRAR
tar -xf unrar.tar.gz
cp rar/unrar $DAEMON_PATH/bin/unrar

# root certificates
curl -o $DAEMON_PATH/bin/cacert.pem https://curl.se/ca/cacert.pem

# adjust nzbget.conf
CONF_FILE=$DAEMON_PATH/share/nzbget/nzbget.conf
sed -i '' 's:^MainDir=.*:MainDir=~/Library/Application Support/NZBGet:' $CONF_FILE
sed -i '' 's:^DestDir=.*:DestDir=~/Downloads:' $CONF_FILE
sed -i '' 's:^InterDir=.*:InterDir=~/Downloads/Intermediate:' $CONF_FILE
sed -i '' 's:^WebDir=.*:# NOTE\: option WebDir cannot be changed because it is hardcoded in OSX version.:' $CONF_FILE
sed -i '' 's:^LockFile=.*:# NOTE\: option LockFile cannot be changed because it is hardcoded in OSX version.:' $CONF_FILE
sed -i '' 's:^LogFile=.*:LogFile=~/Library/Logs/NZBGet.log:' $CONF_FILE
sed -i '' '/# example configuration file (installed to/{N;s/.*/# example configuration file (installed to\n# \/usr\/local\/share\/nzbget\/nz bget.conf)./;}' $CONF_FILE
sed -i '' 's:^ConfigTemplate=.*:# NOTE\: option ConfigTemplate cannot be changed because it is hardcoded in OSX version.:' $CONF_FILE
sed -i '' 's:^DaemonUsername=.*:# NOTE\: option DaemonUsername cannot be changed because it is hardcoded in OSX version.:' $CONF_FILE
sed -i '' 's:^CertStore=.*:CertStore=${AppDir}/cacert.pem:' $CONF_FILE
sed -i '' 's:^CertCheck=.*:CertCheck=yes:' $CONF_FILE
sed -i '' 's:^AuthorizedIP=.*:AuthorizedIP=127.0.0.1:' $CONF_FILE
sed -i '' 's:^ArticleCache=.*:ArticleCache=700:' $CONF_FILE
sed -i '' 's:^DirectWrite=.*:DirectWrite=no:' $CONF_FILE
sed -i '' 's:^WriteBuffer=.*:WriteBuffer=1024:' $CONF_FILE
sed -i '' 's:^ParBuffer=.*:ParBuffer=500:' $CONF_FILE
sed -i '' 's:^DirectRename=.*:DirectRename=yes:' $CONF_FILE
sed -i '' 's:^DirectUnpack=.*:DirectUnpack=yes:' $CONF_FILE
sed -i '' 's:^UnrarCmd=.*:UnrarCmd=${AppDir}/unrar:' $CONF_FILE
sed -i '' 's:^SevenZipCmd=.*:SevenZipCmd=${AppDir}/7za:' $CONF_FILE

# build macos frontend
xcodebuild -project osx/NZBGet.xcodeproj -configuration "Release" -destination "platform=macOS" build

# create build archive
ARCHIVE_NAME=nzbget-$VERSION-bin-macos-x64.zip
(cd osx/build/Release/ && zip -r $ARCHIVE_NAME NZBGet.app)
mv osx/build/Release/$ARCHIVE_NAME .