diff --git a/.gitignore b/.gitignore index f58abbf3..caa32699 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.ext2 +control machine-emulator-tools-*.tar.gz machine-emulator-tools-*.deb dep/ diff --git a/Dockerfile b/Dockerfile index c2911c3c..7fa98c74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,12 +14,10 @@ # limitations under the License. # -FROM --platform=linux/riscv64 riscv64/ubuntu:22.04 as sdk -ARG LINUX_SOURCES_VERSION=5.15.63-ctsi-2 -ARG LINUX_SOURCES_FILEPATH=dep/linux-sources-${LINUX_SOURCES_VERSION}.tar.gz -ARG RNDADDENTROPY_VERSION=3.0.0 -ARG RNDADDENTROPY_FILEPATH=dep/twuewand-$(RNDADDENTROPY_VERSION).tar.gz -ARG BUILD_BASE=/opt/cartesi/ +FROM --platform=linux/riscv64 riscv64/ubuntu:22.04 as tools-env +ARG LINUX_SOURCES_VERSION=6.5.9-ctsi-1 +ARG LINUX_SOURCES_URLPATH=https://github.com/cartesi/linux/archive/refs/tags/v${LINUX_SOURCES_VERSION}.tar.gz +ARG BUILD_BASE=/opt/cartesi # apt # ------------------------------------------------------------------------------ @@ -31,62 +29,65 @@ RUN DEBIAN_FRONTEND=noninteractive apt update && \ git \ protobuf-compiler \ rsync \ + wget \ rust-all=1.58.1+dfsg1~ubuntu1-0ubuntu2 \ && \ + mkdir -p ${BUILD_BASE} && \ rm -rf /var/lib/apt/lists/* # copy & extract kernel headers # TODO: Fix apt database entry for linux-headers (it is satisfied here) # ------------------------------------------------------------------------------ -COPY ${LINUX_SOURCES_FILEPATH} ${BUILD_BASE}${LINUX_SOURCES_FILEPATH} -RUN mkdir -p ${BUILD_BASE}linux-sources && \ - tar xf ${BUILD_BASE}${LINUX_SOURCES_FILEPATH} \ - --strip-components=1 -C ${BUILD_BASE}linux-sources && \ - make -C ${BUILD_BASE}linux-sources headers_install INSTALL_HDR_PATH=/usr && \ - rm ${BUILD_BASE}${LINUX_SOURCES_FILEPATH} +ENV LINUX_SOURCES_FILEPATH=/tmp/linux-${LINUX_SOURCES_VERSION}.tar.gz +RUN wget -O ${LINUX_SOURCES_FILEPATH} ${LINUX_SOURCES_URLPATH} && \ + echo "bfc4d196b90592a2a6bef83ead9e196da6ab6d5978b48ee5e8ccf02913355bc2 ${LINUX_SOURCES_FILEPATH}" | sha256sum --check && \ + tar xzf ${LINUX_SOURCES_FILEPATH} -C ${BUILD_BASE}/ && \ + make -C ${BUILD_BASE}/linux-${LINUX_SOURCES_VERSION} headers_install INSTALL_HDR_PATH=/usr && \ + rm -f {LINUX_SOURCES_FILEPATH} -# copy tools -COPY linux/ ${BUILD_BASE}tools/linux/ +FROM tools-env as builder +COPY linux/ ${BUILD_BASE}/tools/linux/ # build C/C++ tools # ------------------------------------------------------------------------------ -RUN make -C ${BUILD_BASE}tools/linux/xhalt/ CROSS_COMPILE="" xhalt.toolchain -RUN make -C ${BUILD_BASE}tools/linux/htif/ CROSS_COMPILE="" yield.toolchain -RUN make -C ${BUILD_BASE}tools/linux/rollup/ioctl-echo-loop/ CROSS_COMPILE="" ioctl-echo-loop.toolchain -RUN make -C ${BUILD_BASE}tools/linux/rollup/rollup/ CROSS_COMPILE="" rollup.toolchain +FROM builder as c-builder +RUN make -C ${BUILD_BASE}/tools/linux/xhalt/ CROSS_COMPILE="" xhalt.toolchain +RUN make -C ${BUILD_BASE}/tools/linux/htif/ CROSS_COMPILE="" yield.toolchain +RUN make -C ${BUILD_BASE}/tools/linux/rollup/ioctl-echo-loop/ CROSS_COMPILE="" ioctl-echo-loop.toolchain +RUN make -C ${BUILD_BASE}/tools/linux/rollup/rollup/ CROSS_COMPILE="" rollup.toolchain # build rust tools # ------------------------------------------------------------------------------ +FROM builder as rust-builder + # NOTE: cargo update RAM usage keeps going up without this RUN mkdir -p $HOME/.cargo && \ echo "[net]" >> $HOME/.cargo/config && \ echo "git-fetch-with-cli = true" >> $HOME/.cargo/config -RUN cd ${BUILD_BASE}tools/linux/rollup/http/echo-dapp && \ +RUN cd ${BUILD_BASE}/tools/linux/rollup/http/echo-dapp && \ cargo build --release -RUN cd ${BUILD_BASE}tools/linux/rollup/http/rollup-http-server && \ +RUN cd ${BUILD_BASE}/tools/linux/rollup/http/rollup-http-server && \ cargo build --release -# pack tools (tar.gz) -# ------------------------------------------------------------------------------ -ARG STAGING_BASE=/tmp/staging/ -ARG STAGING_BIN=${STAGING_BASE}opt/cartesi/bin/ -ARG MACHINE_EMULATOR_TOOLS_TAR_GZ=machine-emulator-tools.tar.gz - -COPY skel/ ${STAGING_BASE} -RUN mkdir -p ${STAGING_BIN} && \ - cp ${BUILD_BASE}tools/linux/xhalt/xhalt ${STAGING_BIN} && \ - cp ${BUILD_BASE}tools/linux/htif/yield ${STAGING_BIN} && \ - cp ${BUILD_BASE}tools/linux/rollup/ioctl-echo-loop/ioctl-echo-loop ${STAGING_BIN} && \ - cp ${BUILD_BASE}tools/linux/rollup/rollup/rollup ${STAGING_BIN} && \ - cp ${BUILD_BASE}tools/linux/rollup/http/echo-dapp/target/release/echo-dapp ${STAGING_BIN} && \ - cp ${BUILD_BASE}tools/linux/rollup/http/rollup-http-server/target/release/rollup-http-server ${STAGING_BIN} && \ - cp ${BUILD_BASE}tools/linux/utils/* ${STAGING_BIN} && \ - tar czf ${BUILD_BASE}${MACHINE_EMULATOR_TOOLS_TAR_GZ} -C ${STAGING_BASE} . - # pack tools (deb) # ------------------------------------------------------------------------------ +FROM c-builder as packer ARG MACHINE_EMULATOR_TOOLS_DEB=machine-emulator-tools.deb -COPY Makefile . -COPY tools tools -RUN make deb STAGING_BASE=${STAGING_BASE} DESTDIR=${BUILD_BASE}_install PREFIX=/ MACHINE_EMULATOR_TOOLS_DEB=${BUILD_BASE}${MACHINE_EMULATOR_TOOLS_DEB} +ARG STAGING_BASE=${BUILD_BASE}/_install +ARG STAGING_DEBIAN=${STAGING_BASE}/DEBIAN +ARG STAGING_BIN=${STAGING_BASE}/opt/cartesi/bin + +RUN mkdir -p ${STAGING_DEBIAN} ${STAGING_BIN} && \ + cp ${BUILD_BASE}/tools/linux/xhalt/xhalt ${STAGING_BIN} && \ + cp ${BUILD_BASE}/tools/linux/htif/yield ${STAGING_BIN} && \ + cp ${BUILD_BASE}/tools/linux/rollup/ioctl-echo-loop/ioctl-echo-loop ${STAGING_BIN} && \ + cp ${BUILD_BASE}/tools/linux/rollup/rollup/rollup ${STAGING_BIN} && \ + cp ${BUILD_BASE}/tools/linux/utils/* ${STAGING_BIN} + +COPY --from=rust-builder ${BUILD_BASE}/tools/linux/rollup/http/echo-dapp/target/release/echo-dapp ${STAGING_BIN} +COPY --from=rust-builder ${BUILD_BASE}/tools/linux/rollup/http/rollup-http-server/target/release/rollup-http-server ${STAGING_BIN} +COPY skel/ ${STAGING_BASE}/ +COPY control ${STAGING_DEBIAN}/control + +RUN dpkg-deb -Zxz --root-owner-group --build ${STAGING_BASE} ${BUILD_BASE}/${MACHINE_EMULATOR_TOOLS_DEB} diff --git a/Makefile b/Makefile index 7f2a74aa..96fd2064 100644 --- a/Makefile +++ b/Makefile @@ -15,78 +15,46 @@ # MAJOR := 0 -MINOR := 13 +MINOR := 14 PATCH := 0 LABEL := VERSION := $(MAJOR).$(MINOR).$(PATCH)$(LABEL) MACHINE_EMULATOR_TOOLS_VERSION ?= v$(VERSION) -MACHINE_EMULATOR_TOOLS_TAR_GZ := machine-emulator-tools-$(MACHINE_EMULATOR_TOOLS_VERSION).tar.gz MACHINE_EMULATOR_TOOLS_DEB := machine-emulator-tools-$(MACHINE_EMULATOR_TOOLS_VERSION).deb MACHINE_EMULATOR_TOOLS_IMAGE := cartesi/machine-emulator-tools:$(MACHINE_EMULATOR_TOOLS_VERSION) -LINUX_SOURCES_VERSION ?= 5.15.63-ctsi-2 -LINUX_SOURCES_FILEPATH := dep/linux-$(LINUX_SOURCES_VERSION).tar.gz +LINUX_SOURCES_VERSION ?= 6.5.9-ctsi-1 LINUX_SOURCES_URLPATH := https://github.com/cartesi/linux/archive/refs/tags/v$(LINUX_SOURCES_VERSION).tar.gz -RNDADDENTROPY_VERSION ?= 3.0.0 -RNDADDENTROPY_FILEPATH := dep/twuewand-$(RNDADDENTROPY_VERSION).tar.gz -RNDADDENTROPY_URLPATH := https://www.finnie.org/software/twuewand/twuewand-$(RNDADDENTROPY_VERSION).tar.gz +all: $(MACHINE_EMULATOR_TOOLS_DEB) -SHASUMFILES := $(LINUX_SOURCES_FILEPATH) $(RNDADDENTROPY_FILEPATH) - -all: build copy - -build: Dockerfile checksum +build: Dockerfile control docker buildx build --platform=linux/riscv64 --load \ - --build-arg MACHINE_EMULATOR_TOOLS_TAR_GZ=$(MACHINE_EMULATOR_TOOLS_TAR_GZ) \ --build-arg MACHINE_EMULATOR_TOOLS_DEB=$(MACHINE_EMULATOR_TOOLS_DEB) \ --build-arg LINUX_SOURCES_VERSION=$(LINUX_SOURCES_VERSION) \ - --build-arg LINUX_SOURCES_FILEPATH=$(LINUX_SOURCES_FILEPATH) \ - --build-arg RNDADDENTROPY_VERSION=$(RNDADDENTROPY_VERSION) \ - --build-arg RNDADDENTROPY_FILEPATH=$(RNDADDENTROPY_FILEPATH) \ + --build-arg LINUX_SOURCES_URLPATH=$(LINUX_SOURCES_URLPATH) \ -t $(MACHINE_EMULATOR_TOOLS_IMAGE) \ -f $< \ . copy: ID=`docker create --platform=linux/riscv64 $(MACHINE_EMULATOR_TOOLS_IMAGE)` && \ - docker cp $$ID:/opt/cartesi/$(MACHINE_EMULATOR_TOOLS_TAR_GZ) . && \ docker cp $$ID:/opt/cartesi/$(MACHINE_EMULATOR_TOOLS_DEB) . && \ docker rm $$ID -deb: - mkdir -p $(DESTDIR)/DEBIAN - cat tools/template/control.template | sed 's|ARG_VERSION|$(VERSION)|g' > $(DESTDIR)/DEBIAN/control - cp -R $(STAGING_BASE)* $(DESTDIR)$(PREFIX) - dpkg-deb -Zxz --root-owner-group --build $(DESTDIR) $(MACHINE_EMULATOR_TOOLS_DEB) - -$(LINUX_SOURCES_FILEPATH): - T=`mktemp` && \ - mkdir -p `dirname $@` && \ - wget $(LINUX_SOURCES_URLPATH) -O $$T && \ - mv $$T $@ || (rm $$T && false) +control: + sed 's|ARG_VERSION|$(VERSION)|g' control.template > control -$(RNDADDENTROPY_FILEPATH): - T=`mktemp` && \ - mkdir -p `dirname $@` && \ - wget $(RNDADDENTROPY_URLPATH) -O $$T && \ - mv $$T $@ || (rm $$T && false) +$(MACHINE_EMULATOR_TOOLS_DEB): build copy -shasumfile: $(SHASUMFILES) - shasum -a 256 $^ > $@ - -checksum: $(SHASUMFILES) - @shasum -ca 256 shasumfile +fs: $(MACHINE_EMULATOR_TOOLS_DEB) env: - @echo MACHINE_EMULATOR_TOOLS_TAR_GZ=$(MACHINE_EMULATOR_TOOLS_TAR_GZ) @echo MACHINE_EMULATOR_TOOLS_DEB=$(MACHINE_EMULATOR_TOOLS_DEB) @echo MACHINE_EMULATOR_TOOLS_VERSION=$(MACHINE_EMULATOR_TOOLS_VERSION) @echo LINUX_SOURCES_VERSION=$(LINUX_SOURCES_VERSION) - @echo LINUX_SOURCES_FILEPATH=$(LINUX_SOURCES_FILEPATH) - @echo RNDADDENTROPY_VERSION=$(RNDADDENTROPY_VERSION) - @echo RNDADDENTROPY_FILEPATH=$(RNDADDENTROPY_FILEPATH) + @echo LINUX_SOURCES_URLPATH=$(LINUX_SOURCES_URLPATH) setup: docker run --privileged --rm linuxkit/binfmt:bebbae0c1100ebf7bf2ad4dfb9dfd719cf0ef132 @@ -98,18 +66,12 @@ help: @echo 'available commands:' @echo ' setup - setup riscv64 buildx' @echo ' setup-required - check if riscv64 buildx setup is required' - @echo '+ tgz - create "$(MACHINE_EMULATOR_TOOLS_TAR_GZ)" (default)' @echo ' help - list makefile commands' - @echo ' checksum - verify downloaded files' - @echo ' shasumfile - recreate shasumfile of downloaded files' @echo ' env - print useful Makefile variables as a KEY=VALUE list' @echo ' clean - remove the generated artifacts' @echo ' distclean - clean and remove dependencies' clean: - rm -f $(MACHINE_EMULATOR_TOOLS_TAR_GZ) $(MACHINE_EMULATOR_TOOLS_DEB) - -distclean: clean - rm -rf dep + rm -f $(MACHINE_EMULATOR_TOOLS_DEB) control -.PHONY: checksum env setup help +.PHONY: build copy fs env setup setup-required help distclean diff --git a/tools/template/control.template b/control.template similarity index 100% rename from tools/template/control.template rename to control.template diff --git a/shasumfile b/shasumfile deleted file mode 100644 index 2f691555..00000000 --- a/shasumfile +++ /dev/null @@ -1,2 +0,0 @@ -e8d4d1882632eac7fd8e433b4eb4db014fd56e645fdad3b89be7d1ca4f20ca07 dep/linux-5.15.63-ctsi-2.tar.gz -cf69d000714d38da51b0eeb6cbc99bea8ccd9becf6d1cd30c64f7297d167afb6 dep/twuewand-3.0.0.tar.gz