Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cdn
key
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
# linux-packages
Cartesi Linux Packages Repository
# Cartesi Linux Packages

Cartesi Linux packages repository, containing packaging for:

- Debian 12 (Bookworm) - Host
- Ubuntu 24.04 LTS (Noble) - Guest
- Alpine Linux 3.21 - Host and Guest

Debian/Ubuntu packages are available in [debian](debian) subdirectory.
Alpine packages are available in [alpine](alpine) subdirectory.

You can find instructions on the sub directories.
13 changes: 13 additions & 0 deletions alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ARG BASE_IMAGE=alpine
FROM ${BASE_IMAGE}

# Install build essential
RUN apk update && \
apk upgrade && \
apk add alpine-sdk

# List local apk repository
RUN echo /root/packages/work >> /etc/apk/repositories && \
adduser -D builder

WORKDIR /work
118 changes: 118 additions & 0 deletions alpine/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# List of packages to compile for any architecture
PACKAGES_ANYARCH=\
cartesi-machine-linux-image \
cartesi-machine-rootfs-image \
cartesi-machine-emulator \
xgenext2fs

# List of packages to compile for riscv64
PACKAGES_RISCV64=\
cartesi-machine-guest-linux-headers \
cartesi-machine-guest-tools

# Target architecture to compile packages
TARGET_ARCH?=$(shell uname -m)

# Docker base image used for building packages
BASE_IMAGE=alpine:3.21
IMAGE=cartesi/apk-builder-$(TARGET_ARCH)

# Repository path to save built packages
REPO_PATH=$(abspath ../cdn)/apk
REPO_NAME=stable
KEY_NAME=cartesi-apk-key

# Package list to build
PACKAGES=$(PACKAGES_ANYARCH)
ifeq ($(TARGET_ARCH),riscv64)
PACKAGES+=$(PACKAGES_RISCV64)
endif

all: ## Generate a key (if needed) and build all packages
@$(MAKE) --no-print-directory image
@$(MAKE) --no-print-directory key
@$(MAKE) --no-print-directory packages-all

packages-all: ## Build packages for all architectures (x86_64/aarch64/riscv64)
@$(MAKE) --no-print-directory image TARGET_ARCH=x86_64
@$(MAKE) --no-print-directory packages TARGET_ARCH=x86_64
@$(MAKE) --no-print-directory image TARGET_ARCH=aarch64
@$(MAKE) --no-print-directory packages TARGET_ARCH=aarch64
@$(MAKE) --no-print-directory image TARGET_ARCH=riscv64
@$(MAKE) --no-print-directory packages TARGET_ARCH=riscv64

packages: $(patsubst %,%.apk,$(PACKAGES)) ## Build packages for given TARGET_ARCH

%.apk: ## Build a package for given TARGET_ARCH
@$(MAKE) --no-print-directory exec COMMAND="\
cd $* && \
export SOURCE_DATE_EPOCH=\\\`stat -c %Y APKBUILD\\\` && \
abuild -rF && \
chown -R $(shell id -u):$(shell id -g) /root/packages/work"

key: ## Generate package signature key
echo "NOTICE: Generating new key!"
@mkdir -p $(REPO_PATH)/keys key
docker run --platform=linux/$(TARGET_ARCH) \
--volume ./key:/root/.abuild \
--volume $(REPO_PATH):/apk \
--rm $(IMAGE) \
ash -c "\
abuild-keygen -n && \
mv /root/.abuild/*.rsa.pub /root/.abuild/$(KEY_NAME).rsa.pub && \
mv /root/.abuild/*.rsa /root/.abuild/$(KEY_NAME).rsa && \
cp /root/.abuild/$(KEY_NAME).rsa.pub /apk/keys/$(KEY_NAME).rsa.pub && \
chown -R $(shell id -u):$(shell id -g) /root/.abuild /apk/keys"

shell: ## Spawn an image shell for given TARGET_ARCH
@$(MAKE) --no-print-directory exec DOCKER_FLAGS="-it" COMMAND="ash"

exec: ## Execute a COMMAND inside an image for given TARGET_ARCH
docker run --platform=linux/$(TARGET_ARCH) \
--volume ./key:/key \
--volume $(REPO_PATH)/$(REPO_NAME):/root/packages/work \
--volume .:/work \
--workdir /work \
$(DOCKER_FLAGS) --rm $(IMAGE) \
ash -c "\
cp /key/*.rsa.pub /etc/apk/keys/ && \
cp -a /key /root/.abuild && \
chown -R root:root /root/.abuild && \
$(COMMAND)"

image: ## Build Docker image for building packages for given TARGET_ARCH
docker build --platform=linux/$(TARGET_ARCH) \
--build-arg=BASE_IMAGE=$(BASE_IMAGE) \
--tag=$(IMAGE) \
--progress=plain \
--file Dockerfile .

test: ## Test built packages for all architectures (x86_64/aarch64/riscv64)
@$(MAKE) --no-print-directory test-packages TARGET_ARCH=x86_64
@$(MAKE) --no-print-directory test-packages TARGET_ARCH=aarch64
@$(MAKE) --no-print-directory test-packages TARGET_ARCH=riscv64

ifeq ($(TARGET_ARCH),riscv64)
test-packages:
@$(MAKE) --no-print-directory exec COMMAND="\
apk add $(PACKAGES) && \
rollup --help && \
cartesi-machine"
else
test-packages: ## Test built packages for given TARGET_ARCH
@$(MAKE) --no-print-directory exec COMMAND="\
apk add $(PACKAGES) && \
cartesi-machine"
endif

distclean: ## Remove everything from APK repository directory
rm -rf $(REPO_PATH)/$(REPO_NAME)

help: ## Show this help
@sed \
-e '/^[a-zA-Z0-9_\-]*:.*##/!d' \
-e 's/:.*##\s*/:/' \
-e 's/^\(.\+\):\(.*\)/$(shell tput setaf 6)\1$(shell tput sgr0):\2/' \
$(MAKEFILE_LIST) | column -c2 -t -s :

.PHONY: all packages-all packages shell exec image test test-packages distclean help
102 changes: 102 additions & 0 deletions alpine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Cartesi Alpine Packages

This repository contains build scripts for packaging Cartesi related software for Alpine.

## Quick start

Packages in this repository are compatible with **Alpine 3.21** on *amd64*, *arm64*, and *riscv64* architectures using the APK package manager.
Example usage:

```sh
# Install key to verify signature of repository packages
wget -qO /etc/apk/keys/cartesi-apk-key.rsa.pub https://edubart.github.io/linux-packages/apk/keys/cartesi-apk-key.rsa.pub

# Add repository
echo "https://edubart.github.io/linux-packages/apk/stable" >> /etc/apk/repositories

# Update list of available packages
apk update

# Install cartesi-machine
apk add cartesi-machine

# Test cartesi-machine
cartesi-machine
```

## Guest using Dockerfile

In case you are building a riscv64 guest rootfs with a Dockerfile, it could be installed more simpler, this way:

```Dockerfile
FROM --platform=linux/riscv64 alpine:latest

# Install guest tools
ADD --chmod=644 https://edubart.github.io/linux-packages/apk/keys/cartesi-apk-key.rsa.pub /etc/apk/keys/cartesi-apk-key.rsa.pub
RUN echo "https://edubart.github.io/linux-packages/apk/stable" >> /etc/apk/repositories
RUN apk update && apk add cartesi-machine-guest-tools

# Remove unneeded packages to shrink image
RUN apk del --purge apk-tools alpine-release alpine-keys ca-certificates-bundle libc-utils && rm -rf /var/cache/apk /etc/apk
```

## Developing

If you would like to contribute to a package addition or update, clone first:

```sh
git clone git@github.com:edubart/linux-packages.git
cd linux-packages/alpine
```

You can check for all possible developing make targets with `make help`.
Make sure you have Docker is installed in your system to run any of them.

### Building packages

You can build all packages with:

```sh
make all
```

In the first time this will generate the Docker image, a new key for signing packages, and build all packages

This may take a while (hours) when building packages from scratch.
When finished the packages will be available in the `../cdn/apk` directory.

### Building a single package

First make sure you have signature key set up and the builder image for the architecture you want to build:

```sh
make key
make image TARGET_ARCH=riscv64
```

Now add or patch the related package build script,
you can then build it for a specific architecture with:

```sh
make cartesi-machine-emulator.apk TARGET_ARCH=riscv64
```

In this case it will build the `cartesi-machine-emulator` package for `riscv64`.

### Testing

You can test installing all built packages with:

```sh
make test
```

This will install all packages for all architectures, and run some very basic tests to check if it's working.

### Debugging

Sometimes to develop a new package build script, it's useful to have a shell to test things:

```sh
make shell TARGET_ARCH=riscv64
```
52 changes: 52 additions & 0 deletions alpine/cartesi-machine-emulator/APKBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Maintainer: Eduardo Bart <edub4rt@gmail.com>
pkgname=cartesi-machine-emulator
pkgver=0.19.0
pkgrel=1
_pkgver=$pkgver-test1
pkgdesc="Cartesi Machine emulator for RISC-V Linux systems"
url="https://github.com/cartesi/machine-emulator"
arch="all"
license="LGPL-3.0"
depends="libslirp lua5.4"
makedepends="build-base boost-dev libslirp-dev lua5.4-dev"
options="!check"
source="machine-emulator-$_pkgver.tar.gz::https://github.com/cartesi/machine-emulator/archive/refs/tags/v$_pkgver.tar.gz
add-generated-files.diff::https://github.com/cartesi/machine-emulator/releases/download/v$_pkgver/add-generated-files.diff"
sha256sums="93121d1c7edf5ebc8d5b8b042d3b18a4cf2454c702ec2cfe8c92086d7529e16d machine-emulator-$_pkgver.tar.gz
162d62ec8b66801f1ad421774050ea1d6c5cc4c7dcc8f5615956853d6baed87f add-generated-files.diff"
subpackages="$pkgname-dev:package_dev cartesi-machine:package_meta"

_builddir="$srcdir/machine-emulator-$_pkgver"

prepare() {
cd "$_builddir"
patch -Np1 < ../add-generated-files.diff
}

build() {
cd "$_builddir"
export LDFLAGS="-static-libgcc -static-libstdc++"
make
}

package() {
cd "$_builddir"
make install-shared-libs install-lua-libs install-bins install-lua-bins install-shared-files \
PREFIX=/usr DESTDIR="$pkgdir"
}

package_dev() {
pkgdesc="Cartesi Machine emulator development files"
depends="libslirp-dev"

cd "$_builddir"
make install-headers install-static-libs \
PREFIX=/usr DESTDIR="$subpkgdir"
}

package_meta() {
pkgdesc="Cartesi Machine (meta-package)"
depends="cartesi-machine-emulator cartesi-machine-rootfs-image cartesi-machine-linux-image"

mkdir -p "$subpkgdir"
}
17 changes: 17 additions & 0 deletions alpine/cartesi-machine-guest-linux-headers/APKBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Maintainer: Eduardo Bart <edub4rt@gmail.com>
pkgname=cartesi-machine-guest-linux-headers
pkgver=0.20.0
pkgrel=1
_linuxver=6.5.13-ctsi-1
pkgdesc="Cartesi Machine guest Linux kernel headers"
url="https://github.com/cartesi/machine-linux-image"
arch="riscv64"
license="GPL-2.0"
options="!check"
source="linux-headers.tar.xz::https://github.com/cartesi/machine-linux-image/releases/download/v$pkgver/linux-headers-$_linuxver-v$pkgver.tar.xz"
sha256sums="4a4714bfa8c0028cb443db2036fad4f8da07065c1cb4ac8e0921a259fddd731b linux-headers.tar.xz"

package() {
mkdir -p "$pkgdir/usr"
cp -r "$srcdir/include" "$pkgdir/usr/include"
}
47 changes: 47 additions & 0 deletions alpine/cartesi-machine-guest-tools/APKBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Maintainer: Eduardo Bart <edub4rt@gmail.com>
pkgname=cartesi-machine-guest-tools
pkgver=0.17.0
_pkgver=$pkgver-test2
pkgrel=1
pkgdesc="Cartesi Machine guest tools"
url="https://github.com/cartesi/machine-guest-tools"
arch="riscv64"
license="Apache-2.0"
depends="busybox"
makedepends="build-base cartesi-machine-guest-linux-headers cargo clang-libclang"
options="!check"
source="machine-guest-tools-$_pkgver.tar.gz::https://github.com/cartesi/machine-guest-tools/archive/refs/tags/v$_pkgver.tar.gz"
sha256sums="82e600f1610a03d0660af849a54b0ff7db6f88172203f77a54f3bfd5241f3b8b machine-guest-tools-$_pkgver.tar.gz"
subpackages="cartesi-machine-guest-libcmt:package_libcmt cartesi-machine-guest-libcmt-dev:package_libcmt_dev"
install="$pkgname.pre-install"
_builddir="$srcdir/machine-guest-tools-$_pkgver"

prepare() {
cd "$_builddir"
}

build() {
cd "$_builddir"
make
}

package() {
cd "$_builddir"
make -C sys-utils install PREFIX=/usr DESTDIR="$pkgdir"
make -C rollup-http install PREFIX=/usr DESTDIR="$pkgdir"
make install-share PREFIX=/usr DESTDIR="$pkgdir"
}

package_libcmt() {
pkgdesc="Cartesi Machine guest libcmt"

cd "$_builddir"
make -C sys-utils/libcmt install-run PREFIX=/usr DESTDIR="$subpkgdir"
}

package_libcmt_dev() {
pkgdesc="Cartesi Machine guest libcmt development files"

cd "$_builddir"
make -C sys-utils/libcmt install-dev PREFIX=/usr DESTDIR="$subpkgdir"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
adduser -D dapp dapp 2>/dev/null
exit 0
17 changes: 17 additions & 0 deletions alpine/cartesi-machine-linux-image/APKBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Maintainer: Eduardo Bart <edub4rt@gmail.com>
pkgname=cartesi-machine-linux-image
pkgver=0.20.0
pkgrel=1
_linuxver=6.5.13-ctsi-1
pkgdesc="Cartesi Machine guest Linux kernel image"
url="https://github.com/cartesi/machine-linux-image"
arch="noarch"
license="GPL-2.0"
options="!check"
source="linux.bin::https://github.com/cartesi/machine-linux-image/releases/download/v$pkgver/linux-$_linuxver-v$pkgver.bin"
sha256sums="65dd100ff6204346ac2f50f772721358b5c1451450ceb39a154542ee27b4c947 linux.bin"

package() {
cd "$srcdir"
install -Dm644 linux.bin "$pkgdir"/usr/share/cartesi-machine/images/linux.bin
}
Loading