Skip to content
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
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git
.github
*.d
*.o
rtlmux
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI

on:
push:
branches:
- main
- master
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

- name: Install build dependencies
run: sudo apt-get update && sudo apt-get install --yes libevent-dev

- name: Build and test
run: make test

- uses: docker/setup-buildx-action@v4

- name: Build static Linux binary
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64
target: release
outputs: type=local,dest=dist

- name: Verify static Linux binary
run: |
file dist/rtlmux-linux-amd64
file dist/rtlmux-linux-amd64 | grep -q "statically linked"
130 changes: 130 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Release

on:
push:
branches:
- main
- master
tags:
- "v*"
workflow_dispatch:

permissions:
contents: read

jobs:
static-binaries:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
strategy:
matrix:
include:
- platform: linux/amd64
name: amd64
- platform: linux/arm64
name: arm64
- platform: linux/arm/v7
name: armv7
steps:
- uses: actions/checkout@v7

- uses: docker/setup-qemu-action@v4

- uses: docker/setup-buildx-action@v4

- name: Build static binary
uses: docker/build-push-action@v7
with:
context: .
platforms: ${{ matrix.platform }}
target: release
outputs: type=local,dest=dist

- name: Verify artifact
run: |
test -x "dist/rtlmux-linux-${{ matrix.name }}"
file "dist/rtlmux-linux-${{ matrix.name }}" | grep -q "statically linked"

- uses: actions/upload-artifact@v7
with:
name: rtlmux-linux-${{ matrix.name }}
path: dist/rtlmux-linux-${{ matrix.name }}
if-no-files-found: error

github-release:
if: startsWith(github.ref, 'refs/tags/v')
needs: static-binaries
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v8
with:
path: dist
merge-multiple: true

- name: Create checksums
run: |
cd dist
sha256sum rtlmux-linux-* > SHA256SUMS

- name: Publish GitHub release
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: gh release create "$GITHUB_REF_NAME" dist/* --verify-tag --generate-notes

docker:
runs-on: ubuntu-latest
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
steps:
- uses: actions/checkout@v7

- name: Check Docker Hub credentials
id: dockerhub
run: |
if [ -z "$DOCKERHUB_USERNAME" ] || [ -z "$DOCKERHUB_TOKEN" ]; then
echo "::notice::Docker Hub publishing skipped; configure DOCKERHUB_USERNAME and DOCKERHUB_TOKEN."
echo "enabled=false" >> "$GITHUB_OUTPUT"
elif [[ "$GITHUB_REF" == "refs/heads/main" || "$GITHUB_REF" == "refs/heads/master" || "$GITHUB_REF" == refs/tags/v* ]]; then
echo "enabled=true" >> "$GITHUB_OUTPUT"
else
echo "::notice::Docker Hub publishing skipped for $GITHUB_REF."
echo "enabled=false" >> "$GITHUB_OUTPUT"
fi

- if: steps.dockerhub.outputs.enabled == 'true'
uses: docker/setup-qemu-action@v4

- if: steps.dockerhub.outputs.enabled == 'true'
uses: docker/setup-buildx-action@v4

- if: steps.dockerhub.outputs.enabled == 'true'
uses: docker/login-action@v4
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}

- if: steps.dockerhub.outputs.enabled == 'true'
id: metadata
uses: docker/metadata-action@v6
with:
images: slepp/rtlmux
tags: |
type=raw,value=edge,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}

- name: Publish Docker image
if: steps.dockerhub.outputs.enabled == 'true'
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
target: runtime
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*.o
/*.d
/rtlmux
_codeql_detected_source_root
9 changes: 0 additions & 9 deletions .gitlab-ci.yml

This file was deleted.

31 changes: 24 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
FROM alpine
# syntax=docker/dockerfile:1

RUN apk --no-cache add libevent
FROM alpine:3.22 AS build

COPY Makefile *.c *.h options.ggo /app/
ARG TARGETARCH
ARG TARGETVARIANT

RUN apk --no-cache add bsd-compat-headers build-base libevent-dev libevent-static pkgconf

WORKDIR /app
COPY Makefile *.c *.h options.ggo ./
COPY tests tests

RUN make static \
&& strip rtlmux \
&& case "${TARGETARCH}/${TARGETVARIANT}" in \
amd64/) name=amd64 ;; \
arm64/) name=arm64 ;; \
arm/v7) name=armv7 ;; \
*) echo "Unsupported target: ${TARGETARCH}/${TARGETVARIANT}" >&2; exit 1 ;; \
esac \
&& mkdir /out \
&& cp rtlmux "/out/rtlmux-linux-${name}"

RUN apk --no-cache add --virtual build-dependencies build-base libevent-dev bsd-compat-headers \
&& make \
&& apk del build-dependencies
FROM scratch AS release
COPY --from=build /out/ /

CMD ["/app/rtlmux"]
FROM scratch AS runtime
COPY --from=build /app/rtlmux /rtlmux
ENTRYPOINT ["/rtlmux"]
70 changes: 41 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
CC=gcc
CFLAGS=-Wall -I/usr/local/include -O3
CC ?= cc
PKG_CONFIG ?= pkg-config
PYTHON ?= python3
GENGETOPT ?= gengetopt

PREFIX ?= /usr/local
DESTDIR ?=

CPPFLAGS += $(shell $(PKG_CONFIG) --cflags libevent_pthreads)
CFLAGS ?= -O2 -g
CFLAGS += -Wall -Wextra -Wformat=2 -pthread
LDFLAGS ?=
LDLIBS += -pthread $(shell $(PKG_CONFIG) --libs libevent_pthreads)

ifeq ($(STATIC),1)
LDFLAGS += -static
LDLIBS := -pthread $(shell $(PKG_CONFIG) --static --libs libevent_pthreads)
endif

LIBS=-pthread `pkg-config libevent --libs-only-L` -levent -levent_pthreads
SRC = slog.c rtlmux.c config.c cmdline.c main.c
OBJS = $(SRC:.c=.o)
DEPS = $(OBJS:.o=.d)

ifeq ($(shell uname -m),armv7l)
CFLAGS+=-O3 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -ffast-math -funsafe-math-optimizations
else
CFLAGS+=-O3
endif
.PHONY: all clean generate install static test

ifneq ($(shell uname),Darwin)
LIBS+=-lrt
endif
all: rtlmux

ifeq ($(shell uname),Darwin)
CFLAGS+=-glldb
else
CFLAGS+=-ggdb3
endif
rtlmux: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)

SRC=slog.c rtlmux.c config.c cmdline.c main.c
OBJS=slog.o rtlmux.o config.o cmdline.o main.o
%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c -o $@ $<

all: cmdline.c rtlmux
cmdline.o: CFLAGS += -Wno-unused-but-set-variable

clean:
rm -f rtlmux $(OBJS)
generate: options.ggo
$(GENGETOPT) -C -i $< -f cmdline.c

depend:
makedepend -- $(CFLAGS) -- $(SRC)
static:
$(MAKE) clean
$(MAKE) STATIC=1 all

cmdline.h: options.ggo
gengetopt -C -i $< -f cmdline.c
test: rtlmux
$(PYTHON) tests/integration.py ./rtlmux

cmdline.c: cmdline.h
install: rtlmux
install -d $(DESTDIR)$(PREFIX)/bin
install -m 0755 rtlmux $(DESTDIR)$(PREFIX)/bin/rtlmux

rtlmux: $(OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
clean:
rm -f rtlmux $(OBJS) $(DEPS)

# DO NOT DELETE
-include $(DEPS)
Loading