Skip to content

Commit

Permalink
feat!: Add run and dev libcmt packages
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed May 28, 2024
1 parent 5a82a6e commit 846e96b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
with:
path: ${{ env.TOOLS_ROOTFS }}

- name: Build [${{ env.TOOLS_LIBCMT }}]
- name: Build [${{ env.TOOLS_LIBCMT }}, ${{ env.TOOLS_LIBCMT_DEV }}]
id: docker_build_libcmt
uses: docker/build-push-action@v4
with:
Expand All @@ -98,23 +98,27 @@ jobs:
target: libcmt-debian-packager
build-args: |
TOOLS_LIBCMT=${{ env.TOOLS_LIBCMT }}
TOOLS_LIBCMT_DEV=${{ env.TOOLS_LIBCMT_DEV }}
cache-from: type=gha,scope=regular,mode=max
cache-to: type=gha,scope=regular

- name: Retrieve artifacts
run: make copy-libcmt

- name: Upload [${{ env.TOOLS_LIBCMT }}]
- name: Upload [${{ env.TOOLS_LIBCMT }}, ${{ env.TOOLS_LIBCMT_DEV }}]
uses: actions/upload-artifact@v3
with:
path: ${{ env.TOOLS_LIBCMT }}
path:
${{ env.TOOLS_LIBCMT }}
${{ env.TOOLS_LIBCMT_DEV }}

- name: Checksum artifacts
if: startsWith(github.ref, 'refs/tags/v')
run: |
sha512sum ${{ env.TOOLS_DEB }} > ${{ env.TOOLS_DEB }}.sha512
sha512sum ${{ env.TOOLS_ROOTFS }} > ${{ env.TOOLS_ROOTFS }}.sha512
sha512sum ${{ env.TOOLS_LIBCMT }} > ${{ env.TOOLS_LIBCMT }}.sha512
sha512sum ${{ env.TOOLS_LIBCMT_DEV }} > ${{ env.TOOLS_LIBCMT_DEV }}.sha512
- uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/v')
Expand All @@ -127,6 +131,8 @@ jobs:
${{ env.TOOLS_ROOTFS }}.sha512
${{ env.TOOLS_LIBCMT }}
${{ env.TOOLS_LIBCMT }}.sha512
${{ env.TOOLS_LIBCMT_DEV }}
${{ env.TOOLS_LIBCMT_DEV }}.sha512
test:
runs-on: ubuntu-latest-8-cores
Expand Down
13 changes: 9 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,24 @@ ARG BUILD_BASE=/opt/cartesi
USER developer
RUN make -C ${CMT_BASE} -j$(nproc) libcmt
USER root
RUN make -C ${BUILD_BASE}/tools/sys-utils/libcmt/ -j$(nproc) install TARGET_PREFIX=/usr/riscv64-linux-gnu
RUN make -C ${BUILD_BASE}/tools/sys-utils/libcmt/ -j$(nproc) install-dev TARGET_PREFIX=/usr/riscv64-linux-gnu
USER developer
RUN make -C ${BUILD_BASE}/tools/sys-utils/ -j$(nproc) all

# build libcmt debian package
# build libcmt and libcmt-dev debian packages
# ------------------------------------------------------------------------------
FROM c-builder as libcmt-debian-packager
ARG CMT_BASE=${BUILD_BASE}/tools/sys-utils/libcmt
ARG TOOLS_LIBCMT=libcmt.deb
ARG TOOLS_LIBCMT_DEV=libcmt-dev.deb
USER root
RUN make -C ${CMT_BASE} debian-package \
TARGET_DESTDIR=${BUILD_BASE}/_install \
RUN make -C ${CMT_BASE} install-dev debian-dev-package \
TARGET_DESTDIR=${BUILD_BASE}/_install-dev \
TARGET_PREFIX=/usr/riscv64-linux-gnu \
LIBCMT_DEB_FILENAME=${BUILD_BASE}/${TOOLS_LIBCMT_DEV}
RUN make -C ${CMT_BASE} install debian-package \
TARGET_DESTDIR=${BUILD_BASE}/_install-run \
TARGET_PREFIX=/usr/ \
LIBCMT_DEB_FILENAME=${BUILD_BASE}/${TOOLS_LIBCMT}

# build rust tools
Expand Down
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ PATCH := 0
LABEL :=
VERSION := $(MAJOR).$(MINOR).$(PATCH)$(LABEL)

TOOLS_DEB := machine-emulator-tools-v$(VERSION).deb
TOOLS_IMAGE := cartesi/machine-emulator-tools:$(VERSION)
TOOLS_ROOTFS := rootfs-tools-v$(VERSION).ext2
TOOLS_LIBCMT := libcmt-v$(VERSION)-dev.deb
TOOLS_DEB := machine-emulator-tools-v$(VERSION).deb
TOOLS_IMAGE := cartesi/machine-emulator-tools:$(VERSION)
TOOLS_ROOTFS := rootfs-tools-v$(VERSION).ext2
TOOLS_LIBCMT := libcmt-v$(VERSION).deb
TOOLS_LIBCMT_DEV := libcmt-v$(VERSION)-dev.deb

IMAGE_KERNEL_VERSION ?= v0.20.0
LINUX_VERSION ?= 6.5.13-ctsi-1
Expand Down Expand Up @@ -63,10 +64,11 @@ $(TOOLS_ROOTFS) fs: $(TOOLS_DEB)
xgenext2fs -fzB 4096 -b 25600 -i 4096 -a rootfs.tar -L rootfs $(TOOLS_ROOTFS) && \
rm -f rootfs.tar

$(TOOLS_LIBCMT) libcmt:
$(TOOLS_LIBCMT) $(TOOLS_LIBCMT_DEV) libcmt:
@docker buildx build --load \
--target libcmt-debian-packager \
--build-arg TOOLS_LIBCMT=$(TOOLS_LIBCMT) \
--build-arg TOOLS_LIBCMT_DEV=$(TOOLS_LIBCMT_DEV) \
-t $(TOOLS_IMAGE)-libcmt \
-f Dockerfile \
.
Expand All @@ -75,13 +77,15 @@ $(TOOLS_LIBCMT) libcmt:
copy-libcmt:
@ID=`docker create $(TOOLS_IMAGE)-libcmt` && \
docker cp $$ID:/opt/cartesi/$(TOOLS_LIBCMT) . && \
docker cp $$ID:/opt/cartesi/$(TOOLS_LIBCMT_DEV) . && \
docker rm $$ID

env:
@echo TOOLS_DEB=$(TOOLS_DEB)
@echo TOOLS_ROOTFS=$(TOOLS_ROOTFS)
@echo TOOLS_IMAGE=$(TOOLS_IMAGE)
@echo TOOLS_LIBCMT=$(TOOLS_LIBCMT)
@echo TOOLS_LIBCMT_DEV=$(TOOLS_LIBCMT_DEV)
@echo IMAGE_KERNEL_VERSION=$(IMAGE_KERNEL_VERSION)
@echo LINUX_VERSION=$(LINUX_VERSION)
@echo LINUX_HEADERS_URLPATH=$(LINUX_HEADERS_URLPATH)
Expand Down
14 changes: 11 additions & 3 deletions sys-utils/libcmt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,24 @@ $(libcmt_SO): $(libcmt_OBJ)
$(TARGET_CC) -shared -o $@ $^

libcmt: $(libcmt_LIB) $(libcmt_SO)
install: $(libcmt_LIB) $(libcmt_SO) build/ffi.h
install: $(libcmt_SO)
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
cp -f $(libcmt_LIB) $(libcmt_SO) $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
cp -f $(libcmt_SO) $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib

debian-package:
mkdir -p $(TARGET_DESTDIR)/DEBIAN
sed 's|ARG_VERSION|$(LIBCMT_VERSION)|g;' tools/template/control.template > $(TARGET_DESTDIR)/DEBIAN/control
dpkg-deb -Zxz --root-owner-group --build $(TARGET_DESTDIR) $(LIBCMT_DEB_FILENAME)

install-dev: install $(libcmt_LIB) $(libcmt_SO) build/ffi.h
cp -f $(libcmt_LIB) $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/include/libcmt/
cp -f include/libcmt/*.h $(TARGET_DESTDIR)$(TARGET_PREFIX)/include/libcmt/
cp -f build/ffi.h $(TARGET_DESTDIR)$(TARGET_PREFIX)/include/libcmt/
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib/pkgconfig
sed -e 's|@ARG_PREFIX@|$(TARGET_PREFIX)|g' src/libcmt.pc > $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib/pkgconfig/libcmt.pc

debian-package: install
debian-dev-package:
mkdir -p $(TARGET_DESTDIR)/DEBIAN
sed 's|ARG_VERSION|$(LIBCMT_VERSION)|g;' tools/template/cross-control.template > $(TARGET_DESTDIR)/DEBIAN/control
dpkg-deb -Zxz --root-owner-group --build $(TARGET_DESTDIR) $(LIBCMT_DEB_FILENAME)
Expand Down
8 changes: 8 additions & 0 deletions sys-utils/libcmt/tools/template/control.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Package: libcmt
Version: ARG_VERSION
Architecture: riscv64
Priority: optional
Section: devel
Maintainer: Machine Reference Unit <https://discord.com/channels/600597137524391947/1107965671976992878>
Provides: libcmt
Description: Libcmt Library and Headers

0 comments on commit 846e96b

Please sign in to comment.