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 29, 2024
1 parent 14a2b86 commit 0ab23c3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
17 changes: 14 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,32 @@ 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
- name: Retrieve [${{ env.TOOLS_LIBCMT }}, ${{ env.TOOLS_LIBCMT_DEV }}]
run: make copy-libcmt

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

- name: Upload [${{ env.TOOLS_LIBCMT_DEV }}]
uses: actions/upload-artifact@v3
with:
path:
${{ 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 +136,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 src/*.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

0 comments on commit 0ab23c3

Please sign in to comment.