From cd65bce672c89b654dd01f96e147d5641705e777 Mon Sep 17 00:00:00 2001 From: Marcelo Politzer <251334+mpolitzer@users.noreply.github.com> Date: Wed, 29 May 2024 10:52:35 -0300 Subject: [PATCH 1/3] refactor: move README contents to a wiki --- sys-utils/libcmt/README.md | 205 ------------------------------------- 1 file changed, 205 deletions(-) diff --git a/sys-utils/libcmt/README.md b/sys-utils/libcmt/README.md index f8c5381..f5d86f2 100644 --- a/sys-utils/libcmt/README.md +++ b/sys-utils/libcmt/README.md @@ -128,208 +128,3 @@ cast calldata-decode "Notice(bytes)" 0x`xxd -p -c0 "$1"` | ( # sh decode-notice.sh $1 | jq '.bytes' | xxd -r ``` - -# binds - -This library is intented to be used with programming languages other than C. -They achieve this by different means. - -## Python - -Python has multiple Foreign Function Interface (FFI) options for interoperability with C. -This example uses CFFI and the `libcmt` mock. Which is assumed to be installed at `./libcmt-0.1.0`. - -This document uses the [main mode](https://cffi.readthedocs.io/en/latest/overview.html#main-mode-of-usage) of CFFI and works in two steps: `build`, then `use`. - -### Build - -The `build` step has the objective of creating a python module for libcmt. -To achieve this we'll use `libcmt/ffi.h` and the script below. -Paths may need adjustments. - -``` -import os -from cffi import FFI - -ffi = FFI() -with open(os.path.join(os.path.dirname(__file__), "../libcmt-0.1.0/usr/include/libcmt/ffi.h")) as f: - ffi.cdef(f.read()) -ffi.set_source("pycmt", -""" -#include "libcmt/rollup.h" -""", - include_dirs=["libcmt-0.1.0/usr/include"], - library_dirs=["libcmt-0.1.0/usr/lib"], - libraries=['cmt']) - -if __name__ == "__main__": - ffi.compile(verbose=True) -``` - -### Use - -With the module built, we can import it with python and use its functions. -This example uses the raw bindings and just serves to illustrate the process. -Better yet would be to wrap these functions into a more "pythonic" API. - -`LD_LIBRARY_PATH=libcmt-0.1.0/lib/ python` - -``` -#!/usr/bin/env python - -# run this file only after building pycmt! -import os -from pycmt.lib import ffi, lib - -r = ffi.new("cmt_rollup_t[1]") -assert(lib.cmt_rollup_init(r) == 0) - -address = ffi.new("uint8_t[20]", b"1000000000000") -value = ffi.new("uint8_t[32]", b"0000000000001") -data = b"hello world" -index = ffi.new("uint64_t *") -print(os.strerror(-lib.cmt_rollup_emit_voucher(r, - 20, address, - 32, value, - len(data), data, index))) - -ffi.gc(r, lib.cmt_rollup_fini) -``` - -Common errors such as the one below indicate that python couldn't find libcmt, -make sure `LD_LIBRARY_PATH` points to the correct directory, or better yet, link -against the static library. - -``` ->>> import pycmt -Traceback (most recent call last): - File "", line 1, in -ImportError: libcmt.so: cannot open shared object file: No such file or directory -``` - -## Go - -Go is able to include C headers directly with cgo. - -The application can be compiled with: `go build main.go`. -Assuming that the mock was installed at `./libcmt-0.1.0`. -For the actual risc-v binaries, use: -``` -CC=riscv64-linux-gnu-gcc-12 CGO_ENABLED=1 GOOS=linux GOARCH=riscv64 go build -``` - -In Debian, the cross compiler can be obtained with: -``` -apt-get install crossbuild-essential-riscv64 gcc-12-riscv64-linux-gnu g++-12-riscv64-linux-gnu -``` - -(Code below is for demonstration purposes and not intended for production) - -``` -package main - -/* -#cgo CFLAGS: -Ilibcmt-0.1.0/include/ -#cgo LDFLAGS: -Llibcmt-0.1.0/lib/ -lcmt - -#include "libcmt/rollup.h" -*/ -import "C" - -import ( - "math/big" - "fmt" - "unsafe" -) - -func main() { - var rollup C.cmt_rollup_t - err := C.cmt_rollup_init(&rollup) - if err != 0 { - fmt.Printf("initialization failed\n") - } - - bytes_s := []byte{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - } - wei := new(big.Int).SetBytes(bytes_s) - - finish := C.cmt_rollup_finish_t{ - accept_previous_request: true, - } - for { - var advance C.cmt_rollup_advance_t - err = C.cmt_rollup_finish(&rollup, &finish) - if err != 0 { return; } - - err = C.cmt_rollup_read_advance_state(&rollup, &advance); - if err != 0 { return; } - - bytes:= wei.Bytes() - size := len(bytes) - C.cmt_rollup_emit_voucher(&rollup, - C.CMT_ADDRESS_LENGTH, &advance.sender[0], - C.uint(size), unsafe.Pointer(&bytes[0]), - advance.length, advance.data, NULL) - C.cmt_rollup_emit_report(&rollup, advance.length, advance.data) - } -} -``` - -## Rust - -Rust interop with C requires bindings to be generated, we'll use bindgen to -accomplish this. - -Create the initial directory layout with `cargo`, then add the library to it: -``` -cargo init --bin cmt -# download the library and extract it into cmt/libcmt-0.1.0 -cd cmt -``` - -Generate the bindings, execute: -``` -# join all header files into one. -cat libcmt-0.1.0/include/libcmt/*.h > src/libcmt.h - -# generate the bindings -bindgen src/libcmt.h -o src/bindings.rs --allowlist-function '^cmt_.*' --allowlist-type '^cmt_.*' --no-doc-comments -- -I libcmt-0.1.0/include/libcmt -``` - -Include the bindings to the project, add the following to: `src/lib.rs` -``` -#![allow(non_upper_case_globals)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] - -include!("bindings.rs"); -``` - -Tell cargo to link with the C library, add the following to: `build.rs` -``` -fn main() { - println!("cargo:rustc-link-search=libcmt-0.1.0/lib"); - println!("cargo:rustc-link-lib=cmt"); -} -``` - -An example of the raw calls to C, add the following to: `src/main.rs` -``` -use std::mem; - -fn main() { - let mut rollup: cmt::cmt_rollup_t = unsafe { mem::zeroed() }; - let rc = unsafe { cmt::cmt_rollup_init(&mut rollup) }; - println!("got return value: {}!", rc); -} -``` - -Messages like the one below most likely mean that cargo didn't find the library -`libcmt.a` or `build.rs` is incomplete: -``` -undefined reference to `cmt_rollup_emit_voucher' -``` From ab9043186fd00fd5b6967edfb5df3d7b0b3f9a9a Mon Sep 17 00:00:00 2001 From: Marcelo Politzer <251334+mpolitzer@users.noreply.github.com> Date: Wed, 5 Jun 2024 10:34:44 -0300 Subject: [PATCH 2/3] feat!: Add run, dev and cross libcmt packages --- .github/workflows/main.yml | 14 ++-- Dockerfile | 24 +++++-- Makefile | 18 ++--- sys-utils/libcmt/Makefile | 69 ++++++++++++++----- sys-utils/libcmt/src/libcmt_mock.pc | 10 --- sys-utils/libcmt/tools/control.in | 8 +++ .../{src/libcmt.pc => tools/libcmt.pc.in} | 2 +- .../tools/template/cross-control.template | 8 --- 8 files changed, 98 insertions(+), 55 deletions(-) delete mode 100644 sys-utils/libcmt/src/libcmt_mock.pc create mode 100644 sys-utils/libcmt/tools/control.in rename sys-utils/libcmt/{src/libcmt.pc => tools/libcmt.pc.in} (90%) delete mode 100644 sys-utils/libcmt/tools/template/cross-control.template diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1df86d3..14d6ad8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: @@ -85,9 +85,9 @@ jobs: tags: ${{ env.TOOLS_IMAGE }}-libcmt push: false load: true - target: libcmt-debian-packager build-args: | - TOOLS_LIBCMT=${{ env.TOOLS_LIBCMT }} + VERSION=${{ env.VERSION }} + target: libcmt-debian-packager cache-from: type=gha,scope=regular,mode=max cache-to: type=gha,scope=regular @@ -101,14 +101,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') @@ -119,8 +119,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 diff --git a/Dockerfile b/Dockerfile index 0bf25de..8ef00c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -84,12 +84,26 @@ RUN make -C ${BUILD_BASE}/tools/sys-utils/ -j$(nproc) all # ------------------------------------------------------------------------------ FROM c-builder as libcmt-debian-packager ARG CMT_BASE=${BUILD_BASE}/tools/sys-utils/libcmt -ARG TOOLS_LIBCMT=libcmt.deb +ARG VERSION=0.0.0 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} \ + ARG_VERSION=${VERSION} \ + TARGET_PREFIX=/usr \ + TARGET_DESTDIR=${BUILD_BASE}/install/run \ + install-run libcmt-v${VERSION}.deb + +RUN make -C ${CMT_BASE} \ + ARG_VERSION=${VERSION} \ + TARGET_PREFIX=/usr \ + TARGET_DESTDIR=${BUILD_BASE}/install/dev \ + install libcmt-dev-v${VERSION}.deb + +RUN make -C ${CMT_BASE} \ + ARG_VERSION=${VERSION} \ + TARGET_PREFIX=/usr/riscv64-linux-gnu \ + TARGET_DESTDIR=${BUILD_BASE}/install/cross \ + install libcmt-dev-riscv64-cross-v${VERSION}.deb # build rust tools # ------------------------------------------------------------------------------ diff --git a/Makefile b/Makefile index 50645b0..6bbfd3e 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -63,25 +62,28 @@ $(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: + @mkdir $@ + +build-libcmt: @docker buildx build --load \ --target libcmt-debian-packager \ - --build-arg TOOLS_LIBCMT=$(TOOLS_LIBCMT) \ + --build-arg VERSION=$(VERSION) \ -t $(TOOLS_IMAGE)-libcmt \ -f Dockerfile \ . $(MAKE) copy-libcmt -copy-libcmt: +copy-libcmt: 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 VERSION=$(VERSION) @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) @@ -128,7 +130,7 @@ clean-image: @(docker rmi $(TOOLS_IMAGE) > /dev/null 2>&1 || true) clean: - @rm -f $(TOOLS_DEB) control rootfs* libcmt-* + @rm -f $(TOOLS_DEB) control rootfs* libcmt* @$(MAKE) -C sys-utils clean distclean: clean clean-image @@ -146,4 +148,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 build-libcmt env setup setup-required help distclean diff --git a/sys-utils/libcmt/Makefile b/sys-utils/libcmt/Makefile index b45a9c9..841fd0b 100644 --- a/sys-utils/libcmt/Makefile +++ b/sys-utils/libcmt/Makefile @@ -13,13 +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) @@ -65,7 +58,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 @@ -81,19 +74,62 @@ $(libcmt_SO): $(libcmt_OBJ) $(TARGET_CC) -shared -o $@ $^ libcmt: $(libcmt_LIB) $(libcmt_SO) -install: $(libcmt_LIB) $(libcmt_SO) build/ffi.h +install-run: $(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 + +install: $(libcmt_LIB) build/ffi.h + mkdir -p $(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|@SECTION@|$(ARG_SECTION)|' \ + -e 's|@PROVIDES@|$(ARG_PROVIDES)|' \ + -e 's|@DESCRIPTION@|$(ARG_DESCRIPTION)|' \ + $< > $@ + +# debian package variants +libcmt-v$(ARG_VERSION).deb: + $(MAKE) $(TARGET_DESTDIR)/DEBIAN/control \ + ARG_PACKAGE=libcmt \ + ARG_ARCHITECTURE=riscv64 \ + ARG_PROVIDES=libcmt \ + ARG_SECTION=libs \ + ARG_DESCRIPTION="Cartesi Machine Tools" + $(MAKE) debian-package DEB_FILENAME=build/deb/$@ + +libcmt-dev-v$(ARG_VERSION).deb: + $(MAKE) $(TARGET_DESTDIR)/DEBIAN/control \ + ARG_PACKAGE=libcmt-dev \ + ARG_ARCHITECTURE=riscv64 \ + 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-v$(ARG_VERSION).deb: + $(MAKE) $(TARGET_DESTDIR)/DEBIAN/control \ + ARG_PACKAGE=libcmt-riscv64-cross \ + ARG_ARCHITECTURE=all \ + 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 := \ @@ -259,4 +295,5 @@ distclean: clean OBJ := $(mock_OBJ) $(libcmt_OBJ) $(examples_OBJ) $(tools_OBJ) +.PHONY: install -include $(OBJ:%.o=%.d) diff --git a/sys-utils/libcmt/src/libcmt_mock.pc b/sys-utils/libcmt/src/libcmt_mock.pc deleted file mode 100644 index c1b4a7b..0000000 --- a/sys-utils/libcmt/src/libcmt_mock.pc +++ /dev/null @@ -1,10 +0,0 @@ -prefix=@ARG_PREFIX@ -exec_prefix=${prefix} -includedir=${prefix}/include -libdir=${exec_prefix}/lib - -Name: libcmt -Description: The Cartesi Machine Tools library -Version: 0.0.1 -Cflags: -I${includedir} -Libs: -L${libdir} -lcmt diff --git a/sys-utils/libcmt/tools/control.in b/sys-utils/libcmt/tools/control.in new file mode 100644 index 0000000..391dd65 --- /dev/null +++ b/sys-utils/libcmt/tools/control.in @@ -0,0 +1,8 @@ +Package: @PACKAGE@ +Version: @VERSION@ +Architecture: @ARCHITECTURE@ +Priority: optional +Section: @SECTION@ +Maintainer: Machine Reference Unit +Provides: @PROVIDES@ +Description: @DESCRIPTION@ diff --git a/sys-utils/libcmt/src/libcmt.pc b/sys-utils/libcmt/tools/libcmt.pc.in similarity index 90% rename from sys-utils/libcmt/src/libcmt.pc rename to sys-utils/libcmt/tools/libcmt.pc.in index c1b4a7b..a5fcbfb 100644 --- a/sys-utils/libcmt/src/libcmt.pc +++ b/sys-utils/libcmt/tools/libcmt.pc.in @@ -1,4 +1,4 @@ -prefix=@ARG_PREFIX@ +prefix=@PREFIX@ exec_prefix=${prefix} includedir=${prefix}/include libdir=${exec_prefix}/lib diff --git a/sys-utils/libcmt/tools/template/cross-control.template b/sys-utils/libcmt/tools/template/cross-control.template deleted file mode 100644 index 25193a4..0000000 --- a/sys-utils/libcmt/tools/template/cross-control.template +++ /dev/null @@ -1,8 +0,0 @@ -Package: libcmt-dev-riscv64-cross -Version: ARG_VERSION -Architecture: all -Priority: optional -Section: devel -Maintainer: Machine Reference Unit -Provides: libcmt-dev-riscv64-cross -Description: Libcmt Library and Headers From 4e27e552cb904b9956e2d0d44e27b2b12cfc0f1e Mon Sep 17 00:00:00 2001 From: Marcelo Politzer <251334+mpolitzer@users.noreply.github.com> Date: Fri, 21 Jun 2024 12:07:59 -0300 Subject: [PATCH 3/3] fix: Docker warnings from at lesat since 24.0.5 --- Dockerfile | 22 +++++++++++----------- fs/Dockerfile | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8ef00c0..5141e90 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ # limitations under the License. # -FROM ubuntu:22.04 as tools-env +FROM ubuntu:22.04 AS tools-env ARG IMAGE_KERNEL_VERSION=v0.20.0 ARG LINUX_VERSION=6.5.13-ctsi-1 ARG LINUX_HEADERS_URLPATH=https://github.com/cartesi/image-kernel/releases/download/${IMAGE_KERNEL_VERSION}/linux-libc-dev-riscv64-cross-${LINUX_VERSION}-${IMAGE_KERNEL_VERSION}.deb @@ -64,12 +64,12 @@ ENV RISCV_ABI="lp64d" ENV CFLAGS="-march=$RISCV_ARCH -mabi=$RISCV_ABI" ENV TOOLCHAIN_PREFIX="riscv64-linux-gnu-" -FROM tools-env as builder +FROM tools-env AS builder COPY --chown=developer:developer sys-utils/ ${BUILD_BASE}/tools/sys-utils/ # build C/C++ tools # ------------------------------------------------------------------------------ -FROM builder as c-builder +FROM builder AS c-builder ARG CMT_BASE=${BUILD_BASE}/tools/sys-utils/libcmt ARG BUILD_BASE=/opt/cartesi @@ -82,7 +82,7 @@ RUN make -C ${BUILD_BASE}/tools/sys-utils/ -j$(nproc) all # build libcmt debian package # ------------------------------------------------------------------------------ -FROM c-builder as libcmt-debian-packager +FROM c-builder AS libcmt-debian-packager ARG CMT_BASE=${BUILD_BASE}/tools/sys-utils/libcmt ARG VERSION=0.0.0 USER root @@ -107,7 +107,7 @@ RUN make -C ${CMT_BASE} \ # build rust tools # ------------------------------------------------------------------------------ -FROM c-builder as rust-env +FROM c-builder AS rust-env ENV PATH="/home/developer/.cargo/bin:${PATH}" ENV PKG_CONFIG_PATH_riscv64gc_unknown_linux_gnu="/usr/riscv64-linux-gnu/lib/pkgconfig" ENV PKG_CONFIG_riscv64gc_unknown_linux_gnu="/usr/bin/pkg-config" @@ -125,13 +125,13 @@ RUN cd && \ --target riscv64gc-unknown-linux-gnu && \ rm -rf rustup-1.27.0 1.27.0.tar.gz -FROM rust-env as rust-builder +FROM rust-env AS rust-builder COPY --chown=developer:developer rollup-http/rollup-init ${BUILD_BASE}/tools/rollup-http/rollup-init COPY --chown=developer:developer rollup-http/rollup-http-client ${BUILD_BASE}/tools/rollup-http/rollup-http-client COPY --chown=developer:developer rollup-http/.cargo ${BUILD_BASE}/tools/rollup-http/.cargo # build rollup-http-server dependencies -FROM rust-builder as http-server-dep-builder +FROM rust-builder AS http-server-dep-builder COPY --chown=developer:developer rollup-http/rollup-http-server/Cargo.toml rollup-http/rollup-http-server/Cargo.lock ${BUILD_BASE}/tools/rollup-http/rollup-http-server/ RUN cd ${BUILD_BASE}/tools/rollup-http/rollup-http-server && \ mkdir src/ && \ @@ -140,28 +140,28 @@ RUN cd ${BUILD_BASE}/tools/rollup-http/rollup-http-server && \ cargo build --target riscv64gc-unknown-linux-gnu --release # build rollup-http-server -FROM http-server-dep-builder as http-server-builder +FROM http-server-dep-builder AS http-server-builder COPY --chown=developer:developer rollup-http/rollup-http-server/build.rs ${BUILD_BASE}/tools/rollup-http/rollup-http-server/ COPY --chown=developer:developer rollup-http/rollup-http-server/src ${BUILD_BASE}/tools/rollup-http/rollup-http-server/src RUN cd ${BUILD_BASE}/tools/rollup-http/rollup-http-server && touch build.rs src/* && \ cargo build --target riscv64gc-unknown-linux-gnu --release # build echo-dapp dependencies -FROM rust-builder as echo-dapp-dep-builder +FROM rust-builder AS echo-dapp-dep-builder COPY --chown=developer:developer rollup-http/echo-dapp/Cargo.toml rollup-http/echo-dapp/Cargo.lock ${BUILD_BASE}/tools/rollup-http/echo-dapp/ RUN cd ${BUILD_BASE}/tools/rollup-http/echo-dapp && \ mkdir src/ && echo "fn main() {}" > src/main.rs && \ cargo build --target riscv64gc-unknown-linux-gnu --release # build echo-dapp -FROM echo-dapp-dep-builder as echo-dapp-builder +FROM echo-dapp-dep-builder AS echo-dapp-builder COPY --chown=developer:developer rollup-http/echo-dapp/src ${BUILD_BASE}/tools/rollup-http/echo-dapp/src RUN cd ${BUILD_BASE}/tools/rollup-http/echo-dapp && touch src/* && \ cargo build --target riscv64gc-unknown-linux-gnu --release # pack tools (deb) # ------------------------------------------------------------------------------ -FROM tools-env as packer +FROM tools-env AS packer ARG TOOLS_DEB=machine-emulator-tools.deb ARG STAGING_BASE=${BUILD_BASE}/_install ARG STAGING_DEBIAN=${STAGING_BASE}/DEBIAN diff --git a/fs/Dockerfile b/fs/Dockerfile index 27097d2..3d2d728 100644 --- a/fs/Dockerfile +++ b/fs/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM ubuntu:22.04 as cross-builder +FROM --platform=$BUILDPLATFORM ubuntu:22.04 AS cross-builder ENV BUILD_BASE=/tmp/build-extra # Install dependencies