Skip to content

Commit 4c574fa

Browse files
committed
feat!: Add run and dev and cross libcmt packages
1 parent cd65bce commit 4c574fa

File tree

8 files changed

+84
-54
lines changed

8 files changed

+84
-54
lines changed

.github/workflows/main.yml

+5-7
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
- name: Build rootfs
7777
run: make fs
7878

79-
- name: Build [${{ env.TOOLS_LIBCMT }}]
79+
- name: Build libcmt
8080
id: docker_build_libcmt
8181
uses: docker/build-push-action@v5
8282
with:
@@ -86,8 +86,6 @@ jobs:
8686
push: false
8787
load: true
8888
target: libcmt-debian-packager
89-
build-args: |
90-
TOOLS_LIBCMT=${{ env.TOOLS_LIBCMT }}
9189
cache-from: type=gha,scope=regular,mode=max
9290
cache-to: type=gha,scope=regular
9391

@@ -101,14 +99,14 @@ jobs:
10199
path: |
102100
${{ env.TOOLS_DEB }}
103101
${{ env.TOOLS_ROOTFS }}
104-
${{ env.TOOLS_LIBCMT }}
102+
libcmt/deb/*
105103
106104
- name: Checksum artifacts
107105
if: startsWith(github.ref, 'refs/tags/v')
108106
run: |
109107
sha512sum ${{ env.TOOLS_DEB }} > ${{ env.TOOLS_DEB }}.sha512
110108
sha512sum ${{ env.TOOLS_ROOTFS }} > ${{ env.TOOLS_ROOTFS }}.sha512
111-
sha512sum ${{ env.TOOLS_LIBCMT }} > ${{ env.TOOLS_LIBCMT }}.sha512
109+
for f in libcmt/deb/*; sha512sum $f > libcmt/$f.sha512; done
112110
113111
- uses: softprops/action-gh-release@v1
114112
if: startsWith(github.ref, 'refs/tags/v')
@@ -119,8 +117,8 @@ jobs:
119117
${{ env.TOOLS_DEB }}.sha512
120118
${{ env.TOOLS_ROOTFS }}
121119
${{ env.TOOLS_ROOTFS }}.sha512
122-
${{ env.TOOLS_LIBCMT }}
123-
${{ env.TOOLS_LIBCMT }}.sha512
120+
libcmt/deb/*
121+
libcmt/deb/*.sha512
124122
125123
test:
126124
runs-on: ubuntu-latest-8-cores

Dockerfile

+12-4
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,18 @@ FROM c-builder as libcmt-debian-packager
8686
ARG CMT_BASE=${BUILD_BASE}/tools/sys-utils/libcmt
8787
ARG TOOLS_LIBCMT=libcmt.deb
8888
USER root
89-
RUN make -C ${CMT_BASE} debian-package \
90-
TARGET_DESTDIR=${BUILD_BASE}/_install \
91-
TARGET_PREFIX=/usr/riscv64-linux-gnu \
92-
LIBCMT_DEB_FILENAME=${BUILD_BASE}/${TOOLS_LIBCMT}
89+
RUN make -C ${CMT_BASE} \
90+
TARGET_PREFIX=/usr \
91+
TARGET_DESTDIR=${BUILD_BASE}/install/run \
92+
install-run libcmt.deb && \
93+
make -C ${CMT_BASE} \
94+
TARGET_PREFIX=/usr \
95+
TARGET_DESTDIR=${BUILD_BASE}/install/dev \
96+
install libcmt-dev.deb && \
97+
make -C ${CMT_BASE} \
98+
TARGET_PREFIX=/usr/riscv64-linux-gnu \
99+
TARGET_DESTDIR=${BUILD_BASE}/install/cross \
100+
install libcmt-dev-riscv64-cross.deb
93101

94102
# build rust tools
95103
# ------------------------------------------------------------------------------

Makefile

+4-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ VERSION := $(MAJOR).$(MINOR).$(PATCH)$(LABEL)
2323
TOOLS_DEB := machine-emulator-tools-v$(VERSION).deb
2424
TOOLS_IMAGE := cartesi/machine-emulator-tools:$(VERSION)
2525
TOOLS_ROOTFS := rootfs-tools-v$(VERSION).ext2
26-
TOOLS_LIBCMT := libcmt-v$(VERSION)-dev.deb
2726

2827
IMAGE_KERNEL_VERSION ?= v0.20.0
2928
LINUX_VERSION ?= 6.5.13-ctsi-1
@@ -63,25 +62,24 @@ $(TOOLS_ROOTFS) fs: $(TOOLS_DEB)
6362
xgenext2fs -fzB 4096 -b 25600 -i 4096 -a rootfs.tar -L rootfs $(TOOLS_ROOTFS) && \
6463
rm -f rootfs.tar
6564

66-
$(TOOLS_LIBCMT) libcmt:
65+
libcmt:
6766
@docker buildx build --load \
6867
--target libcmt-debian-packager \
69-
--build-arg TOOLS_LIBCMT=$(TOOLS_LIBCMT) \
7068
-t $(TOOLS_IMAGE)-libcmt \
7169
-f Dockerfile \
7270
.
7371
$(MAKE) copy-libcmt
7472

7573
copy-libcmt:
74+
@mkdir libcmt
7675
@ID=`docker create $(TOOLS_IMAGE)-libcmt` && \
77-
docker cp $$ID:/opt/cartesi/$(TOOLS_LIBCMT) . && \
76+
docker cp $$ID:/opt/cartesi/tools/sys-utils/libcmt/build/deb/ libcmt && \
7877
docker rm $$ID
7978

8079
env:
8180
@echo TOOLS_DEB=$(TOOLS_DEB)
8281
@echo TOOLS_ROOTFS=$(TOOLS_ROOTFS)
8382
@echo TOOLS_IMAGE=$(TOOLS_IMAGE)
84-
@echo TOOLS_LIBCMT=$(TOOLS_LIBCMT)
8583
@echo IMAGE_KERNEL_VERSION=$(IMAGE_KERNEL_VERSION)
8684
@echo LINUX_VERSION=$(LINUX_VERSION)
8785
@echo LINUX_HEADERS_URLPATH=$(LINUX_HEADERS_URLPATH)
@@ -146,4 +144,4 @@ help:
146144
@echo ' env - print useful Makefile variables as a KEY=VALUE list'
147145
@echo ' clean - remove the generated artifacts'
148146

149-
.PHONY: build fs deb env setup setup-required help distclean
147+
.PHONY: build fs deb libcmt env setup setup-required help distclean

sys-utils/libcmt/Makefile

+54-18
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
17-
LIBCMT_VERSION ?=0.0.0
18-
19-
INSTALL_FILE= install -m0644
20-
INSTALL_EXEC= install -m0755
21-
22-
# paths
23-
PREFIX = /usr
24-
TARGET_PREFIX ?= $(PREFIX)
25-
2616
TOOLCHAIN_PREFIX ?= riscv64-linux-gnu-
2717
TARGET_CC := $(TOOLCHAIN_PREFIX)gcc
2818
TARGET_AR := $(TOOLCHAIN_PREFIX)ar
@@ -65,7 +55,7 @@ libcmt_SRC := \
6555
src/util.c \
6656
src/io.c
6757

68-
libcmt_OBJDIR := build/lib
58+
libcmt_OBJDIR := build/riscv64
6959
libcmt_OBJ := $(patsubst %.c,$(libcmt_OBJDIR)/%.o,$(libcmt_SRC))
7060
libcmt_LIB := $(libcmt_OBJDIR)/libcmt.a
7161
libcmt_SO := $(libcmt_OBJDIR)/libcmt.so
@@ -81,19 +71,64 @@ $(libcmt_SO): $(libcmt_OBJ)
8171
$(TARGET_CC) -shared -o $@ $^
8272

8373
libcmt: $(libcmt_LIB) $(libcmt_SO)
74+
install-run: $(libcmt_SO)
75+
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
76+
cp -f $(libcmt_SO) $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
77+
8478
install: $(libcmt_LIB) $(libcmt_SO) build/ffi.h
8579
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
86-
cp -f $(libcmt_LIB) $(libcmt_SO) $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
80+
cp -f $(libcmt_LIB) $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
8781
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/include/libcmt/
8882
cp -f include/libcmt/*.h $(TARGET_DESTDIR)$(TARGET_PREFIX)/include/libcmt/
8983
cp -f build/ffi.h $(TARGET_DESTDIR)$(TARGET_PREFIX)/include/libcmt/
9084
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib/pkgconfig
91-
sed -e 's|@ARG_PREFIX@|$(TARGET_PREFIX)|g' src/libcmt.pc > $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib/pkgconfig/libcmt.pc
92-
93-
debian-package: install
94-
mkdir -p $(TARGET_DESTDIR)/DEBIAN
95-
sed 's|ARG_VERSION|$(LIBCMT_VERSION)|g;' tools/template/cross-control.template > $(TARGET_DESTDIR)/DEBIAN/control
96-
dpkg-deb -Zxz --root-owner-group --build $(TARGET_DESTDIR) $(LIBCMT_DEB_FILENAME)
85+
sed -e 's|@PREFIX@|$(TARGET_PREFIX)|g' \
86+
tools/libcmt.pc.in > $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib/pkgconfig/libcmt.pc
87+
88+
# requires either install-run or install
89+
debian-package:
90+
mkdir -p $(dir $(DEB_FILENAME))
91+
dpkg-deb -Zxz --root-owner-group --build $(TARGET_DESTDIR) $(DEB_FILENAME)
92+
93+
$(TARGET_DESTDIR)/DEBIAN/control: tools/control.in
94+
mkdir -p $(@D)
95+
sed -e 's|@PACKAGE@|$(ARG_PACKAGE)|' \
96+
-e 's|@VERSION@|$(ARG_VERSION)|' \
97+
-e 's|@ARCHITECTURE@|$(ARG_ARCHITECTURE)|' \
98+
-e 's|@PROVIDES@|$(ARG_PROVIDES)|' \
99+
-e 's|@DESCRIPTION@|$(ARG_DESCRIPTION)|' \
100+
$< > $@
101+
102+
# debian package variants
103+
libcmt.deb:
104+
$(MAKE) $(TARGET_DESTDIR)/DEBIAN/control \
105+
ARG_PACKAGE=libcmt \
106+
ARG_VERSION=0.0.1 \
107+
ARG_ARCHITECTURE=riscv64 \
108+
ARG_PROVIDES=libcmt \
109+
ARG_SECTION=libs \
110+
ARG_DESCRIPTION="Libcmt runtime"
111+
$(MAKE) debian-package DEB_FILENAME=build/deb/$@
112+
113+
libcmt-dev.deb:
114+
$(MAKE) $(TARGET_DESTDIR)/DEBIAN/control \
115+
ARG_PACKAGE=libcmt-dev \
116+
ARG_VERSION=0.0.1 \
117+
ARG_ARCHITECTURE=any \
118+
ARG_PROVIDES=libcmt-dev \
119+
ARG_SECTION=devel \
120+
ARG_DESCRIPTION="Libcmt native libraries and header files"
121+
$(MAKE) debian-package DEB_FILENAME=build/deb/$@
122+
123+
libcmt-dev-riscv64-cross.deb:
124+
$(MAKE) $(TARGET_DESTDIR)/DEBIAN/control \
125+
ARG_PACKAGE=libcmt \
126+
ARG_VERSION=0.0.1 \
127+
ARG_ARCHITECTURE=riscv64 \
128+
ARG_PROVIDES=libcmt \
129+
ARG_SECTION=devel \
130+
ARG_DESCRIPTION="Libcmt cross libraries and header files"
131+
$(MAKE) debian-package DEB_FILENAME=build/deb/$@
97132

98133
#-------------------------------------------------------------------------------
99134
mock_SRC := \
@@ -259,4 +294,5 @@ distclean: clean
259294

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

297+
.PHONY: install
262298
-include $(OBJ:%.o=%.d)

sys-utils/libcmt/src/libcmt_mock.pc

-10
This file was deleted.

sys-utils/libcmt/tools/control.in

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Package: @PACKAGE@
2+
Version: @VERSION@
3+
Architecture: @ARCHITECTURE@
4+
Priority: optional
5+
Section: libs
6+
Maintainer: Machine Reference Unit <https://discord.com/channels/600597137524391947/1107965671976992878>
7+
Provides: @PROVIDES@
8+
Description: @DESCRIPTION@

sys-utils/libcmt/src/libcmt.pc renamed to sys-utils/libcmt/tools/libcmt.pc.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
prefix=@ARG_PREFIX@
1+
prefix=@PREFIX@
22
exec_prefix=${prefix}
33
includedir=${prefix}/include
44
libdir=${exec_prefix}/lib

sys-utils/libcmt/tools/template/cross-control.template

-8
This file was deleted.

0 commit comments

Comments
 (0)