Skip to content

Commit

Permalink
feat!: Add run and dev and cross libcmt packages
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed Jun 5, 2024
1 parent cd65bce commit 1e04808
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 54 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
- name: Build rootfs
run: make fs

- name: Build [${{ env.TOOLS_LIBCMT }}]
- name: Build libcmt
id: docker_build_libcmt
uses: docker/build-push-action@v5
with:
Expand All @@ -86,8 +86,6 @@ jobs:
push: false
load: true
target: libcmt-debian-packager
build-args: |
TOOLS_LIBCMT=${{ env.TOOLS_LIBCMT }}
cache-from: type=gha,scope=regular,mode=max
cache-to: type=gha,scope=regular

Expand All @@ -101,14 +99,14 @@ jobs:
path: |
${{ env.TOOLS_DEB }}
${{ env.TOOLS_ROOTFS }}
${{ env.TOOLS_LIBCMT }}
libcmt/deb/*
- 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
for f in libcmt/deb/*; sha512sum $f > libcmt/$f.sha512; done
- uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/v')
Expand All @@ -119,8 +117,8 @@ jobs:
${{ env.TOOLS_DEB }}.sha512
${{ env.TOOLS_ROOTFS }}
${{ env.TOOLS_ROOTFS }}.sha512
${{ env.TOOLS_LIBCMT }}
${{ env.TOOLS_LIBCMT }}.sha512
libcmt/deb/*
libcmt/deb/*.sha512
test:
runs-on: ubuntu-latest-8-cores
Expand Down
16 changes: 12 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,18 @@ FROM c-builder as libcmt-debian-packager
ARG CMT_BASE=${BUILD_BASE}/tools/sys-utils/libcmt
ARG TOOLS_LIBCMT=libcmt.deb
USER root
RUN make -C ${CMT_BASE} debian-package \
TARGET_DESTDIR=${BUILD_BASE}/_install \
TARGET_PREFIX=/usr/riscv64-linux-gnu \
LIBCMT_DEB_FILENAME=${BUILD_BASE}/${TOOLS_LIBCMT}
RUN make -C ${CMT_BASE} \
TARGET_PREFIX=/usr \
TARGET_DESTDIR=${BUILD_BASE}/install/run \
install-run libcmt.deb && \
make -C ${CMT_BASE} \
TARGET_PREFIX=/usr \
TARGET_DESTDIR=${BUILD_BASE}/install/dev \
install libcmt-dev.deb && \
make -C ${CMT_BASE} \
TARGET_PREFIX=/usr/riscv64-linux-gnu \
TARGET_DESTDIR=${BUILD_BASE}/install/cross \
install libcmt-dev-riscv64-cross.deb

# build rust tools
# ------------------------------------------------------------------------------
Expand Down
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ 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

IMAGE_KERNEL_VERSION ?= v0.20.0
LINUX_VERSION ?= 6.5.13-ctsi-1
Expand Down Expand Up @@ -63,25 +62,24 @@ $(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:
libcmt:
@docker buildx build --load \
--target libcmt-debian-packager \
--build-arg TOOLS_LIBCMT=$(TOOLS_LIBCMT) \
-t $(TOOLS_IMAGE)-libcmt \
-f Dockerfile \
.
$(MAKE) copy-libcmt

copy-libcmt:
@mkdir libcmt
@ID=`docker create $(TOOLS_IMAGE)-libcmt` && \
docker cp $$ID:/opt/cartesi/$(TOOLS_LIBCMT) . && \
docker cp $$ID:/opt/cartesi/tools/sys-utils/libcmt/build/deb/ libcmt && \
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 IMAGE_KERNEL_VERSION=$(IMAGE_KERNEL_VERSION)
@echo LINUX_VERSION=$(LINUX_VERSION)
@echo LINUX_HEADERS_URLPATH=$(LINUX_HEADERS_URLPATH)
Expand Down Expand Up @@ -146,4 +144,4 @@ help:
@echo ' env - print useful Makefile variables as a KEY=VALUE list'
@echo ' clean - remove the generated artifacts'

.PHONY: build fs deb env setup setup-required help distclean
.PHONY: build fs deb libcmt env setup setup-required help distclean
72 changes: 54 additions & 18 deletions sys-utils/libcmt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

LIBCMT_VERSION ?=0.0.0

INSTALL_FILE= install -m0644
INSTALL_EXEC= install -m0755

# paths
PREFIX = /usr
TARGET_PREFIX ?= $(PREFIX)

TOOLCHAIN_PREFIX ?= riscv64-linux-gnu-
TARGET_CC := $(TOOLCHAIN_PREFIX)gcc
TARGET_AR := $(TOOLCHAIN_PREFIX)ar
Expand Down Expand Up @@ -65,7 +55,7 @@ libcmt_SRC := \
src/util.c \
src/io.c

libcmt_OBJDIR := build/lib
libcmt_OBJDIR := build/riscv64
libcmt_OBJ := $(patsubst %.c,$(libcmt_OBJDIR)/%.o,$(libcmt_SRC))
libcmt_LIB := $(libcmt_OBJDIR)/libcmt.a
libcmt_SO := $(libcmt_OBJDIR)/libcmt.so
Expand All @@ -81,19 +71,64 @@ $(libcmt_SO): $(libcmt_OBJ)
$(TARGET_CC) -shared -o $@ $^

libcmt: $(libcmt_LIB) $(libcmt_SO)
install-run: $(libcmt_SO)
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
cp -f $(libcmt_SO) $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib

install: $(libcmt_LIB) $(libcmt_SO) build/ffi.h
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
cp -f $(libcmt_LIB) $(libcmt_SO) $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
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
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)
sed -e 's|@PREFIX@|$(TARGET_PREFIX)|g' \
tools/libcmt.pc.in > $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib/pkgconfig/libcmt.pc

# requires either install-run or install
debian-package:
mkdir -p $(dir $(DEB_FILENAME))
dpkg-deb -Zxz --root-owner-group --build $(TARGET_DESTDIR) $(DEB_FILENAME)

$(TARGET_DESTDIR)/DEBIAN/control: tools/control.in
mkdir -p $(@D)
sed -e 's|@PACKAGE@|$(ARG_PACKAGE)|' \
-e 's|@VERSION@|$(ARG_VERSION)|' \
-e 's|@ARCHITECTURE@|$(ARG_ARCHITECTURE)|' \
-e 's|@PROVIDES@|$(ARG_PROVIDES)|' \
-e 's|@DESCRIPTION@|$(ARG_DESCRIPTION)|' \
$< > $@

# debian package variants
libcmt.deb:
$(MAKE) $(TARGET_DESTDIR)/DEBIAN/control \
ARG_PACKAGE=libcmt \
ARG_VERSION=0.0.1 \
ARG_ARCHITECTURE=riscv64 \
ARG_PROVIDES=libcmt \
ARG_SECTION=libs \
ARG_DESCRIPTION="Cartesi Machine Tools"
$(MAKE) debian-package DEB_FILENAME=build/deb/$@

libcmt-dev.deb:
$(MAKE) $(TARGET_DESTDIR)/DEBIAN/control \
ARG_PACKAGE=libcmt-dev \
ARG_VERSION=0.0.1 \
ARG_ARCHITECTURE=any \
ARG_PROVIDES=libcmt-dev \
ARG_SECTION=devel \
ARG_DESCRIPTION="Cartesi Machine Tools - (development files)"
$(MAKE) debian-package DEB_FILENAME=build/deb/$@

libcmt-dev-riscv64-cross.deb:
$(MAKE) $(TARGET_DESTDIR)/DEBIAN/control \
ARG_PACKAGE=libcmt \
ARG_VERSION=0.0.1 \
ARG_ARCHITECTURE=riscv64 \
ARG_PROVIDES=libcmt-dev-riscv64-cross \
ARG_SECTION=devel \
ARG_DESCRIPTION="Cartesi Machine Tools - (development files) (riscv64)"
$(MAKE) debian-package DEB_FILENAME=build/deb/$@

#-------------------------------------------------------------------------------
mock_SRC := \
Expand Down Expand Up @@ -259,4 +294,5 @@ distclean: clean

OBJ := $(mock_OBJ) $(libcmt_OBJ) $(examples_OBJ) $(tools_OBJ)

.PHONY: install
-include $(OBJ:%.o=%.d)
10 changes: 0 additions & 10 deletions sys-utils/libcmt/src/libcmt_mock.pc

This file was deleted.

8 changes: 8 additions & 0 deletions sys-utils/libcmt/tools/control.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Package: @PACKAGE@
Version: @VERSION@
Architecture: @ARCHITECTURE@
Priority: optional
Section: libs
Maintainer: Machine Reference Unit <https://discord.com/channels/600597137524391947/1107965671976992878>
Provides: @PROVIDES@
Description: @DESCRIPTION@
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prefix=@ARG_PREFIX@
prefix=@PREFIX@
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Expand Down
8 changes: 0 additions & 8 deletions sys-utils/libcmt/tools/template/cross-control.template

This file was deleted.

0 comments on commit 1e04808

Please sign in to comment.