Skip to content

Commit

Permalink
bazel: add a build target for RPM package
Browse files Browse the repository at this point in the history
  • Loading branch information
jesec committed May 27, 2022
1 parent 73db469 commit a660861
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 7 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/publish-rolling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- name: Tag rolling release
run: |
sed s/-jc+master/-jc+`date +%s`-`git rev-parse --short HEAD`/ BUILD.bazel > BUILD.versioned
cat BUILD.bazel | sed s/-jc+master/-jc+`date +%s`-`git rev-parse --short HEAD`/ | sed s/jc+master/jc+`date +%s`.`git rev-parse --short HEAD`/ > BUILD.versioned
cat BUILD.versioned
mv BUILD.versioned BUILD.bazel
Expand Down Expand Up @@ -69,6 +69,11 @@ jobs:
name: rtorrent-deb-${{ matrix.arch }}
path: root/rtorrent/dist/rtorrent-deb.deb

- uses: actions/upload-artifact@v2
with:
name: rtorrent-rpm-${{ matrix.arch }}
path: root/rtorrent/dist/rtorrent-rpm.rpm

docker-manifest:
needs: docker
runs-on: ubuntu-20.04
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Tag release
run: |
release=`echo ${{ steps.get_version.outputs.VERSION }} | cut -d'-' -f2`
sed s/-jc+master/-jc-$release/ BUILD.bazel > BUILD.versioned
cat BUILD.bazel | sed s/-jc+master/-jc-$release/ | sed s/jc+master/jc.$release/ > BUILD.versioned
cat BUILD.versioned
mv BUILD.versioned BUILD.bazel
Expand Down Expand Up @@ -74,6 +74,11 @@ jobs:
name: rtorrent-deb-${{ matrix.arch }}
path: root/rtorrent/dist/rtorrent-deb.deb

- uses: actions/upload-artifact@v2
with:
name: rtorrent-rpm-${{ matrix.arch }}
path: root/rtorrent/dist/rtorrent-rpm.rpm

docker-manifest:
needs: docker
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -122,6 +127,8 @@ jobs:
cp artifacts/rtorrent-linux-arm64/rtorrent rtorrent-linux-arm64
cp artifacts/rtorrent-deb-amd64/rtorrent-deb.deb rtorrent-linux-amd64.deb
cp artifacts/rtorrent-deb-arm64/rtorrent-deb.deb rtorrent-linux-arm64.deb
cp artifacts/rtorrent-rpm-amd64/rtorrent-rpm.rpm rtorrent-linux-amd64.rpm
cp artifacts/rtorrent-rpm-arm64/rtorrent-rpm.rpm rtorrent-linux-arm64.rpm
- name: Create Release
uses: softprops/action-gh-release@v1
Expand All @@ -132,7 +139,9 @@ jobs:
files: |
rtorrent-linux-amd64
rtorrent-linux-amd64.deb
rtorrent-linux-amd64.rpm
rtorrent-linux-arm64
rtorrent-linux-arm64.deb
rtorrent-linux-arm64.rpm
rtorrent.rc
[email protected]
14 changes: 12 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
load("@rules_pkg//:pkg.bzl", "pkg_deb", "pkg_tar")
load("@rules_pkg//:rpm.bzl", "pkg_rpm")

config_setting(
name = "opt",
Expand Down Expand Up @@ -151,7 +152,7 @@ pkg_tar(
)

pkg_tar(
name = "rtorrent-deb-data",
name = "rtorrent-pkg-data",
extension = "tar.gz",
deps = [
":rtorrent-bin",
Expand All @@ -167,10 +168,19 @@ pkg_deb(
"/etc/rtorrent/rtorrent.rc",
"/etc/systemd/system/[email protected]",
],
data = ":rtorrent-deb-data",
data = ":rtorrent-pkg-data",
description = "a stable and high-performance BitTorrent client",
homepage = "https://github.com/jesec/rtorrent",
maintainer = "Jesse Chan <[email protected]>",
package = "rtorrent",
version = "0.9.8-jc+master",
)

pkg_rpm(
name = "rtorrent-rpm",
architecture = "all",
data = [":rtorrent-pkg-data"],
release = "jc+master",
spec_file = "doc/rtorrent.spec",
version = "0.9.8",
)
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,32 @@ RUN apk --no-cache add \
git \
linux-headers \
python2 \
python3
python3 \
rpm

RUN rpm --initdb

# Checkout rTorrent sources from current directory
COPY . ./

# # Checkout rTorrent sources from Github repository
# RUN git clone https://github.com/jesec/rtorrent .

# Set architecture for .deb package
# Set architecture for packages
RUN if [[ `uname -m` == "aarch64" ]]; \
then sed -i 's/architecture = \"all\"/architecture = \"arm64\"/' BUILD.bazel; \
elif [[ `uname -m` == "x86_64" ]]; \
then sed -i 's/architecture = \"all\"/architecture = \"amd64\"/' BUILD.bazel; \
fi

# Build rTorrent packages
RUN bazel build rtorrent-deb --features=fully_static_link --verbose_failures
RUN bazel build rtorrent-deb rtorrent-rpm --features=fully_static_link --verbose_failures

# Copy outputs
RUN mkdir dist
RUN cp -L bazel-bin/rtorrent dist/
RUN cp -L bazel-bin/rtorrent-deb.deb dist/
RUN cp -L bazel-bin/rtorrent-rpm.rpm dist/

# Now get the clean image
FROM ${ALPINE_IMAGE} as build-sysroot
Expand Down
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")

rules_pkg_dependencies()

load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild")

find_system_rpmbuild(name = "rules_pkg_rpmbuild")

http_archive(
name = "cares",
build_file = "@rtorrent//:third_party/cares.BUILD",
Expand Down
28 changes: 28 additions & 0 deletions doc/rtorrent.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Name: rtorrent
License: GPLv2+ with exceptions
Version: 0.9.8
Release: jc+master
Summary: a stable and high-performance BitTorrent client
URL: https://github.com/jesec/rtorrent

%description
a stable and high-performance BitTorrent client

%build
tar xf bazel-out/*/bin/rtorrent-pkg-data.tar.gz

%install
rm -rf %{buildroot}

mkdir -p %{buildroot}%{_bindir}/
install -m 755 ./usr/bin/rtorrent %{buildroot}%{_bindir}/rtorrent

cp -rf ./etc %{buildroot}/

%clean
rm -rf %{buildroot}

%files
%attr(0755, root, root) %{_bindir}/rtorrent
%attr(0644, root, root) /etc/systemd/system/[email protected]
%attr(0644, root, root) /etc/rtorrent/rtorrent.rc

0 comments on commit a660861

Please sign in to comment.