Skip to content

Commit 2ea49c1

Browse files
authored
Merge pull request #345 from cosmic-utils/apk-local-build
2 parents 7448040 + 352e579 commit 2ea49c1

5 files changed

Lines changed: 126 additions & 4 deletions

File tree

.github/APKBUILD.prebuilt.template

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Packaging-only APKBUILD for pre-built binary (used by `just apk-build`)
2+
pkgname=camera
3+
pkgver=@@VERSION@@
4+
pkgrel=0
5+
pkgdesc="Camera application for the COSMIC Desktop Environment"
6+
url="https://github.com/cosmic-utils/camera"
7+
arch="all"
8+
license="GPL-3.0-only"
9+
depends="
10+
cosmic-icons
11+
gst-plugins-base
12+
gst-plugins-bad
13+
"
14+
15+
build() { :; }
16+
17+
package() {
18+
install -Dm0755 /prebuilt/camera "$pkgdir/usr/bin/camera"
19+
cd /src
20+
install -Dm0644 resources/io.github.cosmic_utils.camera.desktop "$pkgdir/usr/share/applications/io.github.cosmic_utils.camera.desktop"
21+
install -Dm0644 resources/io.github.cosmic_utils.camera.metainfo.xml "$pkgdir/usr/share/metainfo/io.github.cosmic_utils.camera.metainfo.xml"
22+
install -Dm0644 resources/icons/hicolor/scalable/apps/io.github.cosmic_utils.camera.svg "$pkgdir/usr/share/icons/hicolor/scalable/apps/io.github.cosmic_utils.camera.svg"
23+
for size in 16x16 24x24 32x32 48x48 64x64 128x128 256x256; do
24+
install -Dm0644 "resources/icons/hicolor/$size/apps/io.github.cosmic_utils.camera.png" "$pkgdir/usr/share/icons/hicolor/$size/apps/io.github.cosmic_utils.camera.png"
25+
done
26+
}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ build-dir
2020
repo
2121
flatpak-cargo-generator.py
2222
*.flatpak
23-
test-recordings/
23+
test-recordings/
24+
apk-out/

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ debug = 1
8181

8282
[profile.release-fast]
8383
inherits = "release"
84-
lto = "thin"
84+
lto = false
8585
codegen-units = 16
86+
debug = 0
87+
opt-level = 1
8688

8789
[dev-dependencies]
8890
naga = { version = "29.0.1", features = ["wgsl-in"] }

docker/Dockerfile.apk

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Alpine APK build environment
2+
FROM alpine:edge
3+
4+
RUN apk add --no-cache \
5+
alpine-sdk sudo git \
6+
cargo \
7+
clang-libclang \
8+
cmake \
9+
cosmic-icons \
10+
eudev-dev \
11+
glib-dev \
12+
gst-plugins-bad-dev \
13+
gst-plugins-base-dev \
14+
gstreamer-dev \
15+
just \
16+
libcamera-dev \
17+
libinput-dev \
18+
libseat-dev \
19+
libxkbcommon-dev \
20+
nasm \
21+
pkgconf \
22+
samurai \
23+
wayland-dev
24+
25+
RUN adduser -D builder && \
26+
addgroup builder abuild && \
27+
echo "builder ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
28+
sudo -Hu builder abuild-keygen -a -n && \
29+
cp /home/builder/.abuild/*.rsa.pub /etc/apk/keys/

justfile

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,5 +322,69 @@ flatpak-deps arch="":
322322
sudo flatpak install -y --noninteractive flathub com.system76.Cosmic.BaseApp//stable $ARCH_FLAG
323323
echo "Flatpak dependencies installed!"
324324

325-
# Full clean (cargo + vendor + flatpak)
326-
clean-all: clean clean-vendor flatpak-clean
325+
# ============================================================================
326+
# Alpine APK recipes
327+
# ============================================================================
328+
329+
# Build Alpine APK package (optionally specify arch, e.g. aarch64)
330+
# Cross-compiles first, then packages the pre-built binary in an Alpine container.
331+
apk-build arch="":
332+
#!/usr/bin/env bash
333+
set -euo pipefail
334+
arch="{{arch}}"
335+
if [ -z "$arch" ]; then
336+
arch=$(uname -m)
337+
fi
338+
339+
# Map arch to Rust target triple
340+
case "$arch" in
341+
aarch64) rust_target="aarch64-unknown-linux-musl" ;;
342+
x86_64) rust_target="x86_64-unknown-linux-musl" ;;
343+
*) echo "Unsupported arch: $arch"; exit 1 ;;
344+
esac
345+
346+
echo "Cross-compiling for $rust_target (release-fast)..."
347+
cross build --target "$rust_target" --profile release-fast
348+
349+
binary="target/$rust_target/release-fast/camera"
350+
[ -f "$binary" ] || { echo "Error: binary not found at $binary"; exit 1; }
351+
352+
echo "Packaging APK for $arch..."
353+
platform="linux/$arch"
354+
[ "$arch" = "x86_64" ] && platform="linux/amd64"
355+
image_tag="camera-apk-$arch"
356+
VERSION=$(grep "^version" Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
357+
358+
mkdir -p apk-out
359+
podman build --platform "$platform" -t "$image_tag" -f docker/Dockerfile.apk .
360+
361+
podman run --rm --platform "$platform" \
362+
-v "$(pwd)":/src:ro \
363+
-v "$(pwd)/apk-out":/out \
364+
-v "$(pwd)/$binary":/prebuilt/camera:ro \
365+
"$image_tag" sh -c '
366+
set -e
367+
VERSION="'"$VERSION"'"
368+
369+
mkdir -p /home/builder/apkbuild
370+
sed "s/@@VERSION@@/$VERSION/g" /src/.github/APKBUILD.prebuilt.template \
371+
> /home/builder/apkbuild/APKBUILD
372+
chown -R builder:builder /home/builder/apkbuild
373+
374+
cd /home/builder/apkbuild
375+
sudo -Hu builder abuild -r
376+
377+
mkdir -p /out
378+
find /home/builder/packages -name "camera-*.apk" ! -name "*-doc-*" ! -name "*-dev-*" -exec cp {} /out/ \;
379+
echo "APK built successfully:"
380+
ls -la /out/
381+
'
382+
echo "Output in apk-out/"
383+
ls -la apk-out/
384+
385+
# Clean APK build artifacts
386+
apk-clean:
387+
rm -rf apk-out
388+
389+
# Full clean (cargo + vendor + flatpak + apk)
390+
clean-all: clean clean-vendor flatpak-clean apk-clean

0 commit comments

Comments
 (0)