Skip to content

Commit 5f752a8

Browse files
committed
feat: add package scripts for Debian and Alpine
1 parent 4cfb444 commit 5f752a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3924
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cdn
2+
key

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
# linux-packages
2-
Cartesi Linux Packages Repository
1+
# Cartesi Linux Packages
2+
3+
Cartesi Linux packages repository, containing packaging for:
4+
5+
- Debian 12 (Bookworm) - Host
6+
- Ubuntu 24.04 LTS (Noble) - Guest
7+
- Alpine Linux 3.21 - Host and Guest
8+
9+
Debian/Ubuntu packages are available in [debian](debian) subdirectory.
10+
Alpine packages are available in [alpine](alpine) subdirectory.
11+
12+
You can find instructions on the sub directories.

alpine/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ARG BASE_IMAGE=alpine
2+
FROM ${BASE_IMAGE}
3+
4+
# Install build essential
5+
RUN apk update && \
6+
apk upgrade && \
7+
apk add alpine-sdk
8+
9+
# List local apk repository
10+
RUN echo /root/packages/work >> /etc/apk/repositories && \
11+
adduser -D builder
12+
13+
WORKDIR /work

alpine/Makefile

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# List of packages to compile for any architecture
2+
PACKAGES_ANYARCH=\
3+
cartesi-machine-linux-image \
4+
cartesi-machine-rootfs-image \
5+
cartesi-machine-emulator \
6+
xgenext2fs
7+
8+
# List of packages to compile for riscv64
9+
PACKAGES_RISCV64=\
10+
cartesi-machine-guest-linux-headers \
11+
cartesi-machine-guest-tools
12+
13+
# Target architecture to compile packages
14+
TARGET_ARCH?=$(shell uname -m)
15+
16+
# Docker base image used for building packages
17+
BASE_IMAGE=alpine:3.21
18+
IMAGE=cartesi/apk-builder-$(TARGET_ARCH)
19+
20+
# Repository path to save built packages
21+
REPO_PATH=$(abspath ../cdn)/apk
22+
REPO_NAME=stable
23+
KEY_NAME=cartesi-apk-key
24+
25+
# Package list to build
26+
PACKAGES=$(PACKAGES_ANYARCH)
27+
ifeq ($(TARGET_ARCH),riscv64)
28+
PACKAGES+=$(PACKAGES_RISCV64)
29+
endif
30+
31+
all: ## Generate a key (if needed) and build all packages
32+
@$(MAKE) --no-print-directory image
33+
@$(MAKE) --no-print-directory key
34+
@$(MAKE) --no-print-directory packages-all
35+
36+
packages-all: ## Build packages for all architectures (x86_64/aarch64/riscv64)
37+
@$(MAKE) --no-print-directory image TARGET_ARCH=x86_64
38+
@$(MAKE) --no-print-directory packages TARGET_ARCH=x86_64
39+
@$(MAKE) --no-print-directory image TARGET_ARCH=aarch64
40+
@$(MAKE) --no-print-directory packages TARGET_ARCH=aarch64
41+
@$(MAKE) --no-print-directory image TARGET_ARCH=riscv64
42+
@$(MAKE) --no-print-directory packages TARGET_ARCH=riscv64
43+
44+
packages: $(patsubst %,%.apk,$(PACKAGES)) ## Build packages for given TARGET_ARCH
45+
46+
%.apk: ## Build a package for given TARGET_ARCH
47+
@$(MAKE) --no-print-directory exec COMMAND="\
48+
cd $* && \
49+
export SOURCE_DATE_EPOCH=\\\`stat -c %Y APKBUILD\\\` && \
50+
abuild -rF && \
51+
chown -R $(shell id -u):$(shell id -g) /root/packages/work"
52+
53+
key: ## Generate package signature key
54+
echo "NOTICE: Generating new key!"
55+
@mkdir -p $(REPO_PATH)/keys key
56+
docker run --platform=linux/$(TARGET_ARCH) \
57+
--volume ./key:/root/.abuild \
58+
--volume $(REPO_PATH):/apk \
59+
--rm $(IMAGE) \
60+
ash -c "\
61+
abuild-keygen -n && \
62+
mv /root/.abuild/*.rsa.pub /root/.abuild/$(KEY_NAME).rsa.pub && \
63+
mv /root/.abuild/*.rsa /root/.abuild/$(KEY_NAME).rsa && \
64+
cp /root/.abuild/$(KEY_NAME).rsa.pub /apk/keys/$(KEY_NAME).rsa.pub && \
65+
chown -R $(shell id -u):$(shell id -g) /root/.abuild /apk/keys"
66+
67+
shell: ## Spawn an image shell for given TARGET_ARCH
68+
@$(MAKE) --no-print-directory exec DOCKER_FLAGS="-it" COMMAND="ash"
69+
70+
exec: ## Execute a COMMAND inside an image for given TARGET_ARCH
71+
docker run --platform=linux/$(TARGET_ARCH) \
72+
--volume ./key:/key \
73+
--volume $(REPO_PATH)/$(REPO_NAME):/root/packages/work \
74+
--volume .:/work \
75+
--workdir /work \
76+
$(DOCKER_FLAGS) --rm $(IMAGE) \
77+
ash -c "\
78+
cp /key/*.rsa.pub /etc/apk/keys/ && \
79+
cp -a /key /root/.abuild && \
80+
chown -R root:root /root/.abuild && \
81+
$(COMMAND)"
82+
83+
image: ## Build Docker image for building packages for given TARGET_ARCH
84+
docker build --platform=linux/$(TARGET_ARCH) \
85+
--build-arg=BASE_IMAGE=$(BASE_IMAGE) \
86+
--tag=$(IMAGE) \
87+
--progress=plain \
88+
--file Dockerfile .
89+
90+
test: ## Test built packages for all architectures (x86_64/aarch64/riscv64)
91+
@$(MAKE) --no-print-directory test-packages TARGET_ARCH=x86_64
92+
@$(MAKE) --no-print-directory test-packages TARGET_ARCH=aarch64
93+
@$(MAKE) --no-print-directory test-packages TARGET_ARCH=riscv64
94+
95+
ifeq ($(TARGET_ARCH),riscv64)
96+
test-packages:
97+
@$(MAKE) --no-print-directory exec COMMAND="\
98+
apk add $(PACKAGES) && \
99+
rollup --help && \
100+
cartesi-machine"
101+
else
102+
test-packages: ## Test built packages for given TARGET_ARCH
103+
@$(MAKE) --no-print-directory exec COMMAND="\
104+
apk add $(PACKAGES) && \
105+
cartesi-machine"
106+
endif
107+
108+
distclean: ## Remove everything from APK repository directory
109+
rm -rf $(REPO_PATH)/$(REPO_NAME)
110+
111+
help: ## Show this help
112+
@sed \
113+
-e '/^[a-zA-Z0-9_\-]*:.*##/!d' \
114+
-e 's/:.*##\s*/:/' \
115+
-e 's/^\(.\+\):\(.*\)/$(shell tput setaf 6)\1$(shell tput sgr0):\2/' \
116+
$(MAKEFILE_LIST) | column -c2 -t -s :
117+
118+
.PHONY: all packages-all packages shell exec image test test-packages distclean help

alpine/README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Cartesi Alpine packages
2+
3+
This repository contains scripts and `.apk` packages for Cartesi Machine and other Cartesi related software.
4+
5+
All packages binaries are available in the [cdn](https://github.com/edubart/linux-packages/tree/cdn) branch in the `apk` directory,
6+
while the scripts to generate them are available in the main branch.
7+
8+
9+
## Quick start
10+
11+
Packages provided by this repository can be installed on **Alpine 3.21** for *amd64/arm64/riscv64 architectures using an APK package manager.
12+
Here is a quick example on how to use it:
13+
14+
```sh
15+
# Install key to verify signature of repository packages
16+
wget -qO /etc/apk/keys/cartesi-apk-key.rsa.pub https://edubart.github.io/linux-packages/apk/keys/cartesi-apk-key.rsa.pub
17+
18+
# Add repository
19+
echo "https://edubart.github.io/linux-packages/apk/stable" >> /etc/apk/repositories
20+
21+
# Update list of available packages
22+
apk update
23+
24+
# Install cartesi-machine
25+
apk add cartesi-machine
26+
27+
# Test cartesi-machine
28+
cartesi-machine
29+
```
30+
31+
## Guest using Dockerfile
32+
33+
In case you are building a riscv64 guest rootfs with a Dockerfile, it could be installed more simpler, this way:
34+
35+
```Dockerfile
36+
FROM --platform=linux/riscv64 alpine:latest
37+
38+
# Install guest tools
39+
ADD --chmod=644 https://edubart.github.io/linux-packages/apk/keys/cartesi-apk-key.rsa.pub /etc/apk/keys/cartesi-apk-key.rsa.pub
40+
RUN echo "https://edubart.github.io/linux-packages/apk/stable" >> /etc/apk/repositories
41+
RUN apk update && apk add cartesi-machine-guest-tools
42+
43+
# Remove unneeded packages to shrink image
44+
RUN apk del --purge apk-tools alpine-release alpine-keys ca-certificates-bundle libc-utils && rm -rf /var/cache/apk /etc/apk
45+
```
46+
47+
## Developing
48+
49+
If you would like to contribute to a package addition or update, clone first:
50+
51+
```sh
52+
git clone [email protected]:edubart/linux-packages.git
53+
cd linux-packages/alpine
54+
```
55+
56+
You can check for all possible developing make targets with `make help`.
57+
Make sure you have Docker is installed in your system to run any of them.
58+
59+
### Building packages
60+
61+
You can build all packages with:
62+
63+
```sh
64+
make all
65+
```
66+
67+
In the first time this will generate the Docker image, a new key for signing packages, and build all packages
68+
69+
This may take a while (hours) when building packages from scratch.
70+
When finished the packages will be available in the `../cdn/apk` directory.
71+
72+
### Building a single package
73+
74+
First make sure you have signature key set up and the builder image for the architecture you want to build:
75+
76+
```sh
77+
make key
78+
make image TARGET_ARCH=riscv64
79+
```
80+
81+
Now add or patch the related package build script,
82+
you can then build it for a specific architecture with:
83+
84+
```sh
85+
make cartesi-machine-emulator.apk TARGET_ARCH=riscv64
86+
```
87+
88+
In this case it will build the `cartesi-machine-emulator` package for `riscv64`.
89+
90+
### Testing
91+
92+
You can test installing all built packages with:
93+
94+
```sh
95+
make test
96+
```
97+
98+
This will install all packages for all architectures, and run some very basic tests to check if it's working.
99+
100+
### Debugging
101+
102+
Sometimes to develop a new package build script, it's useful to have a shell to test things:
103+
104+
```sh
105+
make shell TARGET_ARCH=riscv64
106+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Maintainer: Eduardo Bart <[email protected]>
2+
pkgname=cartesi-machine-emulator
3+
pkgver=0.19.0
4+
pkgrel=1
5+
_pkgver=$pkgver-test1
6+
pkgdesc="Cartesi Machine emulator for RISC-V Linux systems"
7+
url="https://github.com/cartesi/machine-emulator"
8+
arch="all"
9+
license="LGPL-3.0"
10+
depends="libslirp lua5.4"
11+
makedepends="build-base boost-dev libslirp-dev lua5.4-dev"
12+
options="!check"
13+
source="machine-emulator-$_pkgver.tar.gz::https://github.com/cartesi/machine-emulator/archive/refs/tags/v$_pkgver.tar.gz
14+
add-generated-files.diff::https://github.com/cartesi/machine-emulator/releases/download/v$_pkgver/add-generated-files.diff"
15+
sha256sums="93121d1c7edf5ebc8d5b8b042d3b18a4cf2454c702ec2cfe8c92086d7529e16d machine-emulator-$_pkgver.tar.gz
16+
162d62ec8b66801f1ad421774050ea1d6c5cc4c7dcc8f5615956853d6baed87f add-generated-files.diff"
17+
subpackages="$pkgname-dev:package_dev cartesi-machine:package_meta"
18+
19+
_builddir="$srcdir/machine-emulator-$_pkgver"
20+
21+
prepare() {
22+
cd "$_builddir"
23+
patch -Np1 < ../add-generated-files.diff
24+
}
25+
26+
build() {
27+
cd "$_builddir"
28+
export LDFLAGS="-static-libgcc -static-libstdc++"
29+
make
30+
}
31+
32+
package() {
33+
cd "$_builddir"
34+
make install-shared-libs install-lua-libs install-bins install-lua-bins install-shared-files \
35+
PREFIX=/usr DESTDIR="$pkgdir"
36+
}
37+
38+
package_dev() {
39+
pkgdesc="Cartesi Machine emulator development files"
40+
depends="libslirp-dev"
41+
42+
cd "$_builddir"
43+
make install-headers install-static-libs \
44+
PREFIX=/usr DESTDIR="$subpkgdir"
45+
}
46+
47+
package_meta() {
48+
pkgdesc="Cartesi Machine (meta-package)"
49+
depends="cartesi-machine-emulator cartesi-machine-rootfs-image cartesi-machine-linux-image"
50+
51+
mkdir -p "$subpkgdir"
52+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Maintainer: Eduardo Bart <[email protected]>
2+
pkgname=cartesi-machine-guest-linux-headers
3+
pkgver=0.20.0
4+
pkgrel=1
5+
_linuxver=6.5.13-ctsi-1
6+
pkgdesc="Cartesi Machine guest Linux kernel headers"
7+
url="https://github.com/cartesi/machine-linux-image"
8+
arch="riscv64"
9+
license="GPL-2.0"
10+
options="!check"
11+
source="linux-headers.tar.xz::https://github.com/cartesi/machine-linux-image/releases/download/v$pkgver/linux-headers-$_linuxver-v$pkgver.tar.xz"
12+
sha256sums="4a4714bfa8c0028cb443db2036fad4f8da07065c1cb4ac8e0921a259fddd731b linux-headers.tar.xz"
13+
14+
package() {
15+
mkdir -p "$pkgdir/usr"
16+
cp -r "$srcdir/include" "$pkgdir/usr/include"
17+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Maintainer: Eduardo Bart <[email protected]>
2+
pkgname=cartesi-machine-guest-tools
3+
pkgver=0.17.0
4+
_pkgver=$pkgver-test1
5+
pkgrel=1
6+
pkgdesc="Cartesi Machine guest tools"
7+
url="https://github.com/cartesi/machine-guest-tools"
8+
arch="riscv64"
9+
license="Apache-2.0"
10+
depends="busybox"
11+
makedepends="build-base cartesi-machine-guest-linux-headers cargo clang-libclang"
12+
options="!check"
13+
source="machine-guest-tools-$_pkgver.tar.gz::https://github.com/cartesi/machine-guest-tools/archive/refs/tags/v$_pkgver.tar.gz"
14+
sha256sums="d6035c08e1555a9947fa002c512152a839f1dd2eeff68c20cf036817faefd55d machine-guest-tools-$_pkgver.tar.gz"
15+
subpackages="cartesi-machine-guest-libcmt:package_libcmt cartesi-machine-guest-libcmt-dev:package_libcmt_dev"
16+
install="$pkgname.pre-install"
17+
_builddir="$srcdir/machine-guest-tools-$_pkgver"
18+
19+
prepare() {
20+
cd "$_builddir"
21+
}
22+
23+
build() {
24+
cd "$_builddir"
25+
make
26+
}
27+
28+
package() {
29+
cd "$_builddir"
30+
make -C sys-utils install PREFIX=/usr DESTDIR="$pkgdir"
31+
make -C rollup-http install PREFIX=/usr DESTDIR="$pkgdir"
32+
make install-share PREFIX=/usr DESTDIR="$pkgdir"
33+
}
34+
35+
package_libcmt() {
36+
pkgdesc="Cartesi Machine guest libcmt"
37+
38+
cd "$_builddir"
39+
make -C sys-utils/libcmt install-run PREFIX=/usr DESTDIR="$subpkgdir"
40+
}
41+
42+
package_libcmt_dev() {
43+
pkgdesc="Cartesi Machine guest libcmt development files"
44+
45+
cd "$_builddir"
46+
make -C sys-utils/libcmt install-dev PREFIX=/usr DESTDIR="$subpkgdir"
47+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
adduser -D dapp dapp 2>/dev/null
3+
exit 0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Maintainer: Eduardo Bart <[email protected]>
2+
pkgname=cartesi-machine-linux-image
3+
pkgver=0.20.0
4+
pkgrel=1
5+
_linuxver=6.5.13-ctsi-1
6+
pkgdesc="Cartesi Machine guest Linux kernel image"
7+
url="https://github.com/cartesi/machine-linux-image"
8+
arch="noarch"
9+
license="GPL-2.0"
10+
options="!check"
11+
source="linux.bin::https://github.com/cartesi/machine-linux-image/releases/download/v$pkgver/linux-$_linuxver-v$pkgver.bin"
12+
sha256sums="65dd100ff6204346ac2f50f772721358b5c1451450ceb39a154542ee27b4c947 linux.bin"
13+
14+
package() {
15+
cd "$srcdir"
16+
install -Dm644 linux.bin "$pkgdir"/usr/share/cartesi-machine/images/linux.bin
17+
}

0 commit comments

Comments
 (0)