Skip to content

Commit 91bf0c8

Browse files
committed
Add build action
1 parent b2cc3fe commit 91bf0c8

14 files changed

+278
-2
lines changed

.github/workflows/build.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Build release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
cprintf_version:
7+
description: "Optional: cprintf version to use as tag_name (leave blank to use the latest remote version)"
8+
required: false
9+
release_name:
10+
description: "Optional: Custom release name (cprintf v* release)"
11+
required: false
12+
push:
13+
branches: [ "main" ]
14+
paths:
15+
- 'src/**'
16+
- 'build/**'
17+
- 'configure'
18+
- 'Makefile'
19+
pull_request:
20+
21+
jobs:
22+
check_update:
23+
name: Check update
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Check latest version
27+
id: check_version
28+
run: |
29+
remote_version=$(curl -L https://api.github.com/repos/Moe-hacker/cprintf/releases/latest | jq -r .tag_name)
30+
remote_name=$(curl -L https://api.github.com/repos/Moe-hacker/cprintf/releases/latest | jq -r .name)
31+
echo "remote_version=$remote_version" | tee -a $GITHUB_OUTPUT
32+
echo "remote_name=$remote_name" | tee -a $GITHUB_OUTPUT
33+
outputs:
34+
remote_version: ${{ steps.check_version.outputs.remote_version }}
35+
remote_name: ${{ steps.check_version.outputs.remote_name }}
36+
37+
build:
38+
name: Build
39+
needs: check_update
40+
runs-on: ubuntu-latest
41+
permissions:
42+
contents: write
43+
steps:
44+
- name: Set env
45+
run: |
46+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
47+
if [ -n "${{ github.event.inputs.cprintf_version }}" ]; then
48+
echo "version=${{ github.event.inputs.cprintf_version }}" | tee -a $GITHUB_ENV
49+
else
50+
echo "version=${{ needs.check_update.outputs.remote_version }}" | tee -a $GITHUB_ENV
51+
fi
52+
53+
if [ -n "${{ github.event.inputs.release_name }}" ]; then
54+
echo "release_name=${{ github.event.inputs.release_name }}" | tee -a $GITHUB_ENV
55+
elif [ -n "${{ github.event.inputs.cprintf_version }}" ]; then
56+
echo "release_name=${{ github.event.inputs.cprintf_version }}" | tee -a $GITHUB_ENV
57+
else
58+
echo "release_name=${{ needs.check_update.outputs.remote_name }}" | tee -a $GITHUB_ENV
59+
fi
60+
else
61+
echo "version=${{ needs.check_update.outputs.remote_version }}" | tee -a $GITHUB_ENV
62+
echo "release_name=${{ needs.check_update.outputs.remote_name }}" | tee -a $GITHUB_ENV
63+
fi
64+
echo "build_time=$(TZ=Asia/Shanghai date '+%Y%m%d%H%M')" | tee -a $GITHUB_ENV
65+
66+
- uses: actions/checkout@v4
67+
- name: Build-Release
68+
run: |
69+
cd build
70+
sudo bash build-all.sh
71+
72+
- name: Release
73+
uses: softprops/action-gh-release@v2
74+
with:
75+
tag_name: ${{ env.version }}
76+
name: ${{ env.release_name }}
77+
body: |
78+
This is cprintf binary release.
79+
NOTE:
80+
*-noupx means the binary is not upx compressed.
81+
cprintf use musl as libc to build by default (in alpine container), for smaller binary size and better security.
82+
But since I didn't found way to get stable musl container image for loongarch64, the binary for loongarch64 is built with glibc in debian.
83+
Build time: ${{ env.build_time }}
84+
prerelease: false
85+
files: |
86+
${{ github.workspace }}/x86_64.tar
87+
${{ github.workspace }}/i386.tar
88+
${{ github.workspace }}/s390x.tar
89+
${{ github.workspace }}/ppc64le.tar
90+
${{ github.workspace }}/loongarch64.tar
91+
${{ github.workspace }}/armv7.tar
92+
${{ github.workspace }}/armhf.tar
93+
${{ github.workspace }}/aarch64.tar
94+
${{ github.workspace }}/riscv64.tar
95+
${{ github.workspace }}/x86_64-noupx.tar
96+
${{ github.workspace }}/i386-noupx.tar
97+
${{ github.workspace }}/s390x-noupx.tar
98+
${{ github.workspace }}/ppc64le-noupx.tar
99+
${{ github.workspace }}/armv7-noupx.tar
100+
${{ github.workspace }}/armhf-noupx.tar
101+
${{ github.workspace }}/aarch64-noupx.tar
102+
${{ github.workspace }}/riscv64-noupx.tar
103+

build/build-all.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bash setup.sh
2+
bash build-amd64.sh
3+
bash build-loong64.sh
4+
bash build-riscv64.sh
5+
bash build-arm64.sh
6+
bash build-armhf.sh
7+
bash build-armv7.sh
8+
bash build-x86.sh
9+
bash build-ppc64le.sh
10+
bash build-s390x.sh

build/build-amd64.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
git clone https://github.com/moe-hacker/rootfstool
2+
rootfstool/rootfstool d -d alpine -v edge
3+
mkdir alpine
4+
sudo tar -xvf rootfs.tar.xz -C alpine
5+
sudo cp build.sh alpine/build.sh
6+
sudo chmod +x alpine/build.sh
7+
sudo ./ruri/ruri ./alpine /bin/sh /build.sh
8+
echo $(pwd)/x86_64.tar
9+
mv alpine/*-noupx.tar ./x86_64-noupx.tar
10+
mv alpine/*.tar ./x86_64.tar
11+
cp *.tar ../

build/build-arm64.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
BASE_URL="https://dl-cdn.alpinelinux.org/alpine/edge/releases/aarch64"
2+
ROOTFS_URL=$(curl -s -L "$BASE_URL/latest-releases.yaml" | grep "alpine-minirootfs" | grep "aarch64.tar.gz" | head -n 1 | awk '{print $2}')
3+
FULL_URL="$BASE_URL/$ROOTFS_URL"
4+
wget "$FULL_URL"
5+
mkdir aarch64
6+
tar -xvf "$ROOTFS_URL" -C aarch64
7+
sudo apt install -y qemu-user-static
8+
sudo cp build.sh aarch64/build.sh
9+
sudo chmod +x aarch64/build.sh
10+
sudo ./ruri/ruri -a aarch64 -q /usr/bin/qemu-aarch64-static ./aarch64 /bin/sh /build.sh
11+
mv aarch64/*-noupx.tar ../aarch64-noupx.tar
12+
cp aarch64/*.tar ../aarch64.tar

build/build-armhf.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
BASE_URL="https://dl-cdn.alpinelinux.org/alpine/edge/releases/armhf"
2+
ROOTFS_URL=$(curl -s -L "$BASE_URL/latest-releases.yaml" | grep "alpine-minirootfs" | grep "armhf.tar.gz" | head -n 1 | awk '{print $2}')
3+
FULL_URL="$BASE_URL/$ROOTFS_URL"
4+
wget "$FULL_URL"
5+
mkdir armhf
6+
tar -xvf "$ROOTFS_URL" -C armhf
7+
sudo apt install -y qemu-user-static
8+
sudo cp build.sh armhf/build.sh
9+
sudo chmod +x armhf/build.sh
10+
sudo ./ruri/ruri -a armhf -q /usr/bin/qemu-arm-static ./armhf /bin/sh /build.sh
11+
mv armhf/*-noupx.tar ../armhf-noupx.tar
12+
cp armhf/*.tar ../armhf.tar

build/build-armv7.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
BASE_URL="https://dl-cdn.alpinelinux.org/alpine/edge/releases/armv7"
2+
ROOTFS_URL=$(curl -s -L "$BASE_URL/latest-releases.yaml" | grep "alpine-minirootfs" | grep "armv7.tar.gz" | head -n 1 | awk '{print $2}')
3+
FULL_URL="$BASE_URL/$ROOTFS_URL"
4+
wget "$FULL_URL"
5+
mkdir armv7
6+
tar -xvf "$ROOTFS_URL" -C armv7
7+
sudo apt install -y qemu-user-static
8+
sudo cp build.sh armv7/build.sh
9+
sudo chmod +x armv7/build.sh
10+
sudo ./ruri/ruri -a armv7 -q /usr/bin/qemu-arm-static ./armv7 /bin/sh /build.sh
11+
mv armv7/*-noupx.tar ../armv7-noupx.tar
12+
cp armv7/*.tar ../armv7.tar

build/build-loong64.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
sudo debootstrap --foreign --arch=loong64 --variant=buildd --include=debian-ports-archive-keyring --verbose --components=main --resolve-deps --extra-suites=unreleased unstable ./debian http://ftp.ports.debian.org/debian-ports
2+
sudo cp /usr/bin/qemu-loongarch64-static debian/usr/bin/
3+
cat <<EOF >>./debian/build.sh
4+
rm /etc/resolv.conf
5+
echo nameserver 1.1.1.1 > /etc/resolv.conf
6+
apt update
7+
apt install -y wget make clang git libseccomp-dev libcap-dev libc-dev binutils
8+
apt install -y upx
9+
git clone https://github.com/moe-hacker/cprintf
10+
cd cprintf
11+
./configure -s
12+
make
13+
strip cprintf
14+
tar -cvf ../loong64.tar ./cprintf ./LICENSE
15+
EOF
16+
sudo chmod +x ./debian/build.sh
17+
./ruri/ruri -p -a loong64 -q /usr/bin/qemu-loongarch64-static ./debian /debootstrap/debootstrap --second-stage
18+
sudo ./ruri/ruri -p -a loong64 -q /usr/bin/qemu-loongarch64-static ./debian /bin/sh /build.sh
19+
cp ./debian/loong64.tar ../loongarch64.tar

build/build-ppc64le.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
BASE_URL="https://dl-cdn.alpinelinux.org/alpine/edge/releases/ppc64le"
2+
ROOTFS_URL=$(curl -s -L "$BASE_URL/latest-releases.yaml" | grep "alpine-minirootfs" | grep "ppc64le.tar.gz" | head -n 1 | awk '{print $2}')
3+
FULL_URL="$BASE_URL/$ROOTFS_URL"
4+
wget "$FULL_URL"
5+
mkdir ppc64le
6+
tar -xvf "$ROOTFS_URL" -C ppc64le
7+
sudo apt install -y qemu-user-static
8+
sudo cp build.sh ppc64le/build.sh
9+
sudo chmod +x ppc64le/build.sh
10+
sudo ./ruri/ruri -a ppc64le -q /usr/bin/qemu-ppc64le-static ./ppc64le /bin/sh /build.sh
11+
mv ppc64le/*-noupx.tar ../ppc64le-noupx.tar
12+
cp ppc64le/*.tar ../ppc64le.tar

build/build-riscv64.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
BASE_URL="https://dl-cdn.alpinelinux.org/alpine/edge/releases/riscv64"
2+
ROOTFS_URL=$(curl -s -L "$BASE_URL/latest-releases.yaml" | grep "alpine-minirootfs" | grep "riscv64.tar.gz" | head -n 1 | awk '{print $2}')
3+
FULL_URL="$BASE_URL/$ROOTFS_URL"
4+
wget "$FULL_URL"
5+
mkdir riscv64
6+
tar -xvf "$ROOTFS_URL" -C riscv64
7+
sudo apt install -y qemu-user-static
8+
sudo cp build.sh riscv64/build.sh
9+
sudo chmod +x riscv64/build.sh
10+
sudo ./ruri/ruri -a riscv64 -q /usr/bin/qemu-riscv64-static ./riscv64 /bin/sh /build.sh
11+
mv riscv64/*-noupx.tar ../riscv64-noupx.tar
12+
cp riscv64/*.tar ../riscv64.tar

build/build-s390x.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
BASE_URL="https://dl-cdn.alpinelinux.org/alpine/edge/releases/s390x"
2+
ROOTFS_URL=$(curl -s -L "$BASE_URL/latest-releases.yaml" | grep "alpine-minirootfs" | grep "s390x.tar.gz" | head -n 1 | awk '{print $2}')
3+
FULL_URL="$BASE_URL/$ROOTFS_URL"
4+
wget "$FULL_URL"
5+
mkdir s390x
6+
tar -xvf "$ROOTFS_URL" -C s390x
7+
sudo apt install -y qemu-user-static
8+
sudo cp build.sh s390x/build.sh
9+
sudo chmod +x s390x/build.sh
10+
sudo ./ruri/ruri -a s390x -q /usr/bin/qemu-s390x-static ./s390x /bin/sh /build.sh
11+
mv s390x/*-noupx.tar ../s390x-noupx.tar
12+
cp s390x/*.tar ../s390x.tar

build/build-x86.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
BASE_URL="https://dl-cdn.alpinelinux.org/alpine/edge/releases/x86"
2+
ROOTFS_URL=$(curl -s -L "$BASE_URL/latest-releases.yaml" | grep "alpine-minirootfs" | grep "x86.tar.gz" | head -n 1 | awk '{print $2}')
3+
FULL_URL="$BASE_URL/$ROOTFS_URL"
4+
wget "$FULL_URL"
5+
mkdir x86
6+
tar -xvf "$ROOTFS_URL" -C x86
7+
sudo cp build.sh x86/build.sh
8+
sudo chmod +x x86/build.sh
9+
sudo ./ruri/ruri ./x86 /bin/sh /build.sh
10+
mv x86/*-noupx.tar ../i386-noupx.tar
11+
cp x86/*.tar ../i386.tar

build/build.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
rm /etc/resolv.conf
2+
echo nameserver 1.1.1.1 >/etc/resolv.conf
3+
echo https://dl-cdn.alpinelinux.org/alpine/edge/testing >>/etc/apk/repositories
4+
apk add wget make clang git libseccomp-dev libseccomp-static libcap-static libcap-dev xz-dev libintl libbsd-static libsemanage-dev libselinux-utils libselinux-static xz-libs zlib zlib-static libselinux-dev linux-headers libssl3 libbsd libbsd-dev gettext-libs gettext-static gettext-dev gettext python3 build-base openssl-misc openssl-libs-static openssl zlib-dev xz-dev openssl-dev automake libtool bison flex gettext autoconf gettext sqlite sqlite-dev pcre-dev wget texinfo docbook-xsl libxslt docbook2x musl-dev gettext gettext-asprintf gettext-dbg gettext-dev gettext-doc gettext-envsubst gettext-lang gettext-libs gettext-static
5+
apk add upx
6+
apk add lld
7+
mkdir output
8+
mkdir output2
9+
git clone https://github.com/moe-hacker/cprintf
10+
cd cprintf
11+
./configure -s
12+
make
13+
strip cprintf
14+
cp cprintf ../output2/cprintf
15+
cp LICENSE ../output2/LICENSE
16+
upx cprintf
17+
cp cprintf ../output/cprintf
18+
cp LICENSE ../output/LICENSE
19+
cd ..
20+
cd output
21+
tar -cvf ../$(uname -m).tar .
22+
cd ..
23+
cd output2
24+
tar -cvf ../$(uname -m)-noupx.tar .
25+
exit 0

build/setup.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apt update
2+
apt install -y sudo
3+
sudo apt install -y git wget
4+
yes | sudo apt install --no-install-recommends -y curl xz-utils \
5+
make \
6+
clang \
7+
libseccomp-dev \
8+
libcap-dev \
9+
libc6-dev \
10+
binutils
11+
# Build ruri
12+
git clone https://github.com/moe-hacker/ruri
13+
cd ruri
14+
cc -Wl,--gc-sections -static src/*.c src/easteregg/*.c -o ruri -lcap -lseccomp -lpthread
15+
cd ..
16+
sudo apt install qemu-user-static pkg-config libglib2.0-dev qemu-system-misc python3-tomli binfmt-support debootstrap ninja-build
17+
# Build qemu-loongarch64
18+
git clone https://github.com/qemu/qemu.git
19+
cd qemu
20+
./configure --static --disable-system --target-list=loongarch64-linux-user
21+
make -j$(nproc)
22+
sudo cp build/loongarch64-linux-user/qemu-loongarch64 /usr/bin/qemu-loongarch64-static
23+
sudo cp build/qemu-loongarch64 /usr/bin/qemu-loongarch64-static
24+
sudo cp qemu-loongarch64 /usr/bin/qemu-loongarch64-static
25+
cd ..

configure

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#
33
# SPDX-License-Identifier: MIT
44
#
5-
# This file is part of ruri, with ABSOLUTELY NO WARRANTY.
5+
# This file is part of cprintf, with ABSOLUTELY NO WARRANTY.
66
#
77
# MIT License
88
#
9-
# Copyright (c) 2022-2024 Moe-hacker
9+
# Copyright (c) 2025 Moe-hacker
1010
#
1111
# Permission is hereby granted, free of charge, to any person obtaining a copy
1212
# of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)