Skip to content

Commit

Permalink
feat: add debian source package files
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed Jul 22, 2024
1 parent 223ceef commit 40cf70a
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 41 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ jobs:
uarch-pristine-ram.c
uarch-pristine-hash.c
machine-c-version.h
cartesi-machine-v${{ env.MACHINE_EMULATOR_VERSION }}_amd64.deb
cartesi-machine-v${{ env.MACHINE_EMULATOR_VERSION }}_arm64.deb
cartesi-machine-dev-v${{ env.MACHINE_EMULATOR_VERSION }}_amd64.deb
cartesi-machine-dev-v${{ env.MACHINE_EMULATOR_VERSION }}_arm64.deb
cartesi-machine0-v${{ env.MACHINE_EMULATOR_VERSION }}_amd64.deb
cartesi-machine0-v${{ env.MACHINE_EMULATOR_VERSION }}_arm64.deb
test_amd64:
name: Test (linux/amd64)
Expand Down
69 changes: 39 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@ ARG RELEASE=no
ARG COVERAGE=no
ARG SANITIZE=no

RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \
build-essential vim wget git clang-tidy-16 clang-format-16 lcov \
libboost1.81-dev libssl-dev libslirp-dev \
ca-certificates pkg-config lua5.4 liblua5.4-dev \
luarocks xxd procps && \
update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-16 120 && \
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-16 120 && \
rm -rf /var/lib/apt/lists/*


RUN luarocks install --lua-version=5.4 luasocket && \
luarocks install --lua-version=5.4 luasec && \
luarocks install --lua-version=5.4 luaposix && \
luarocks install --lua-version=5.4 lpeg && \
luarocks install --lua-version=5.4 dkjson && \
luarocks install --lua-version=5.4 luacheck && \
cargo install [email protected] --features lua54
# Install dependencies
COPY debian debian
RUN <<EOF
set -e
apt update
apt build-dep . --no-install-recommends -y # Packages from Build-Depends on debian/control

apt install --no-install-recommends -y \
clang-format-16 \
clang-tidy-16
update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-16 120
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-16 120
cargo install [email protected] --features lua54

rm -rf /var/lib/apt/lists/*
EOF

# Environment has the riscv64-cartesi-linux-gnu-* toolchain
ENV DEV_ENV_HAS_TOOLCHAIN=yes
Expand All @@ -36,27 +34,38 @@ COPY third-party third-party
FROM --platform=$TARGETPLATFORM dep-builder as builder

COPY . .
RUN make -j$(nproc) git_commit=$GIT_COMMIT release=$RELEASE coverage=$COVERAGE sanitize=$SANITIZE
RUN dpkg-buildpackage # Make invoked by debian/rules

FROM --platform=$TARGETPLATFORM builder as debian-packager
ARG MACHINE_EMULATOR_VERSION=0.0.0

RUN make install-uarch debian-package DESTDIR=$PWD/_install

##RUN make install-uarch debian-package DESTDIR=$PWD/_install
#
FROM --platform=$TARGETPLATFORM debian:bookworm-20230725-slim
ARG MACHINE_EMULATOR_VERSION=0.0.0
ARG TARGETARCH

COPY --from=debian-packager \
/usr/src/emulator/cartesi-machine-v${MACHINE_EMULATOR_VERSION}_${TARGETARCH}.deb \
cartesi-machine.deb
COPY --from=debian-packager /usr/local/lib/lua /usr/local/lib/lua
COPY --from=debian-packager /usr/local/share/lua /usr/local/share/lua

RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y \
./cartesi-machine.deb \
&& rm -rf /var/lib/apt/lists/* \
&& rm cartesi-machine.deb
/usr/src/cartesi-machine0_${MACHINE_EMULATOR_VERSION}_${TARGETARCH}.deb \
.
COPY --from=debian-packager \
/usr/src/cartesi-machine-dev_${MACHINE_EMULATOR_VERSION}_${TARGETARCH}.deb \
.

RUN <<EOF
set -e
export DEBIAN_FRONTEND="noninteractive"

apt update
apt install --no-install-recommends -y \
./cartesi-machine0_${MACHINE_EMULATOR_VERSION}_${TARGETARCH}.deb \
./cartesi-machine-dev_${MACHINE_EMULATOR_VERSION}_${TARGETARCH}.deb

rm -rf \
./cartesi-machine0_${MACHINE_EMULATOR_VERSION}_${TARGETARCH}.deb \
./cartesi-machine-dev_${MACHINE_EMULATOR_VERSION}_${TARGETARCH}.deb \
/var/lib/apt/lists/*
EOF

RUN addgroup --system --gid 102 cartesi && \
adduser --system --uid 102 --ingroup cartesi --disabled-login --no-create-home --home /nonexistent --gecos "cartesi user" --shell /bin/false cartesi
Expand Down
12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ DEB_ARCH?= $(shell dpkg --print-architecture 2>/dev/null || echo amd64)
PREFIX= /usr
MACHINE_EMULATOR_VERSION= $(shell make -sC src version)
MACHINE_EMULATOR_SO_VERSION= $(shell make -sC src so-version)
DEB_FILENAME= cartesi-machine-v$(MACHINE_EMULATOR_VERSION)_$(DEB_ARCH).deb
DEB_FILENAME_DEV= cartesi-machine-dev-v$(MACHINE_EMULATOR_VERSION)_$(DEB_ARCH).deb
DEB_FILENAME0= cartesi-machine0-v$(MACHINE_EMULATOR_VERSION)_$(DEB_ARCH).deb
BIN_RUNTIME_PATH= $(PREFIX)/bin
LIB_RUNTIME_PATH= $(PREFIX)/lib
DOC_RUNTIME_PATH= $(PREFIX)/doc/cartesi-machine
Expand Down Expand Up @@ -272,7 +273,8 @@ copy-tests-debian-packages:

copy:
docker create --name uarch-ram-bin $(DOCKER_PLATFORM) $(DEBIAN_IMG)
docker cp uarch-ram-bin:/usr/src/emulator/$(DEB_FILENAME) .
docker cp uarch-ram-bin:/usr/src/emulator/../$(DEB_FILENAME0) .
docker cp uarch-ram-bin:/usr/src/emulator/../$(DEB_FILENAME_DEV) .
docker cp uarch-ram-bin:/usr/src/emulator/src/machine-c-version.h .
docker cp uarch-ram-bin:/usr/src/emulator/uarch/uarch-ram.bin .
docker cp uarch-ram-bin:/usr/src/emulator/uarch/uarch-pristine-ram.c .
Expand Down Expand Up @@ -352,12 +354,6 @@ install: install-headers install-static-libs install-shared-libs install-lua-lib
install-uarch: install $(UARCH_INSTALL_PATH)
$(INSTALL_FILE) uarch/$(UARCH_TO_SHARE) $(UARCH_INSTALL_PATH)

debian-package: install
mkdir -p $(DESTDIR)/DEBIAN $(DOC_INSTALL_PATH)
$(INSTALL_FILE) COPYING $(DOC_INSTALL_PATH)/copyright
sed 's|ARG_VERSION|$(MACHINE_EMULATOR_VERSION)|g;s|ARG_ARCH|$(DEB_ARCH)|g' tools/template/control.template > $(DESTDIR)/DEBIAN/control
dpkg-deb -Zxz --root-owner-group --build $(DESTDIR) $(DEB_FILENAME)

install-tests-data: | $(TESTS_DATA_INSTALL_PATH)
$(INSTALL_DIR) $(TESTS_DATA_TO_TESTS_DATA_PATH) $(TESTS_DATA_INSTALL_PATH)

Expand Down
2 changes: 2 additions & 0 deletions debian/cartesi-machine-dev.dirs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
usr/lib
usr/include
13 changes: 13 additions & 0 deletions debian/cartesi-machine-dev.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
usr/bin/cartesi-machine
usr/bin/cartesi-machine-stored-hash
usr/bin/jsonrpc-remote-cartesi-machine
usr/bin/merkle-tree-hash
usr/include/cartesi-machine/*
usr/lib/lib*.a
usr/share/cartesi-machine/*
usr/share/cartesi-machine/gdb/gdbinit
usr/share/lua/5.4/cartesi-machine-stored-hash.lua
usr/share/lua/5.4/cartesi-machine.lua
usr/share/lua/5.4/cartesi/gdbstub.lua
usr/share/lua/5.4/cartesi/proof.lua
usr/share/lua/5.4/cartesi/util.lua
1 change: 1 addition & 0 deletions debian/cartesi-machine0.dirs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/lib
3 changes: 3 additions & 0 deletions debian/cartesi-machine0.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
usr/lib/lib*.so
usr/lib/lua/5.4/cartesi.so
usr/lib/lua/5.4/cartesi/jsonrpc.so
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cartesi-machine (0.17.0) UNRELEASED; urgency=medium

* Initial release.

-- root <root@unknown> Fri, 28 Jun 2024 15:46:07 +0000
54 changes: 54 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Source: cartesi-machine
Section: libs
Priority: optional
Maintainer: root <root@unknown>
Rules-Requires-Root: no
Build-Depends:
build-essential,
ca-certificates,
clang-format-16,
clang-tidy-16,
debhelper,
debhelper-compat (= 13),
devscripts,
git,
lcov,
libboost1.81-dev,
liblua5.4-dev,
libslirp-dev,
libslirp-dev,
lua5.4,
luarocks,
pkg-config,
procps,
vim,
wget,
xxd,
Standards-Version: 4.6.2
Homepage: <insert the upstream URL, if relevant>
#Vcs-Browser: https://salsa.debian.org/debian/cartesi-machine
#Vcs-Git: https://salsa.debian.org/debian/cartesi-machine.git

Package: cartesi-machine-dev
Section: libdevel
Architecture: any
Multi-Arch: same
Depends:
libboost1.81-dev,
liblua5.4-dev,
libslirp-dev,
lua5.4,
cartesi-machine0 (= ${binary:Version}),
Description: The Cartesi Machine Emulator is the reference off-chain implementation of the Cartesi Machine Specification.
It's written in C/C++ with POSIX dependencies restricted to the terminal, process, and memory-mapping facilities.
It is distributed as a library and scriptable in the Lua programming language.

Package: cartesi-machine0
Architecture: any
Multi-Arch: same
Depends:
lua5.4,
libslirp0,
Description: The Cartesi Machine Emulator is the reference off-chain implementation of the Cartesi Machine Specification.
It's written in C/C++ with POSIX dependencies restricted to the terminal, process, and memory-mapping facilities.
It is distributed as a library and scriptable in the Lua programming language.
35 changes: 35 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Source: <url://example.com>
Upstream-Name: cartesi-machine
Upstream-Contact: <preferred name and address to reach the upstream project>

Files:
*
Copyright:
<years> <put author's name and email here>
<years> <likewise for another author>
License: <special license>
<Put the license of the package here indented by 1 space>
<This follows the format of Description: lines in control file>
.
<Including paragraphs>

# If you want to use GPL v2 or later for the /debian/* files use
# the following clauses, or change it to suit. Delete these two lines
Files:
debian/*
Copyright:
2024 root <root@unknown>
License: LGPL-3
.
Comment:
.

# Please also look if there are files or directories which have a
# different copyright/license attached and list them here.
# Please avoid picking licenses with terms that are more restrictive than the
# packaged work, as it may make Debian's contributions unacceptable upstream.
#
# If you need, there are some extra license texts available in two places:
# /usr/share/debhelper/dh_make/licenses/
# /usr/share/common-licenses/
8 changes: 8 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/make -f

%:
dh $@

override_dh_auto_test: # skip
override_dh_auto_build:
make -j$(nproc) uarch all
1 change: 1 addition & 0 deletions debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (native)
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ uarch-pristine-hash.o: $(UARCH_PRISTINE_HASH_C)

generate-uarch-pristine:
ifeq (,$(wildcard ../uarch/uarch-pristine-hash.c))
@if [ "$(DEV_ENV_HAS_TOOLCHAIN)" = "yes" ]; then \
@if [ "$(shell which riscv64-cartesi-linux-gnu-gcc)" -o "$(DEV_ENV_HAS_TOOLCHAIN)" = "yes" ]; then \
$(MAKE) -C .. uarch; \
else \
$(MAKE) -C .. uarch-with-linux-env; \
Expand Down

0 comments on commit 40cf70a

Please sign in to comment.