Skip to content

Commit

Permalink
chore: make unnecessary to install libcmt to build tools
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Jan 14, 2025
1 parent 338ca84 commit 4602034
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 59 deletions.
33 changes: 9 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,55 +55,48 @@ rm -rf /var/lib/apt/lists/* ${LINUX_HEADERS_FILEPATH}
EOF

ENV TOOLCHAIN_PREFIX="riscv64-linux-gnu-"
ENV PKG_CONFIG_PATH="/usr/riscv64-linux-gnu/lib/pkgconfig"

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
ARG CMT_BASE=${BUILD_BASE}/tools/sys-utils/libcmt
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 PREFIX=/usr/riscv64-linux-gnu
USER developer
RUN make -C ${BUILD_BASE}/tools/sys-utils/ -j$(nproc) all
RUN make -C ${BUILD_BASE}/tools/sys-utils -j$(nproc) all
RUN make -C ${BUILD_BASE}/tools/sys-utils install \
DESTDIR=${BUILD_BASE}/tools/sys-utils_staging PREFIX=/usr

# build libcmt debian package
# ------------------------------------------------------------------------------
FROM c-builder AS libcmt-debian-packager
ARG CMT_BASE=${BUILD_BASE}/tools/sys-utils/libcmt
ARG VERSION=0.0.0
USER root

RUN make -C ${CMT_BASE} \
RUN make -C ${BUILD_BASE}/tools/sys-utils/libcmt \
ARG_VERSION=${VERSION} \
PREFIX=/usr \
DESTDIR=${BUILD_BASE}/install/run \
install-run libcmt-v${VERSION}.deb

RUN make -C ${CMT_BASE} \
RUN make -C ${BUILD_BASE}/tools/sys-utils/libcmt \
ARG_VERSION=${VERSION} \
PREFIX=/usr \
DESTDIR=${BUILD_BASE}/install/dev \
install-dev libcmt-dev-v${VERSION}.deb

RUN make -C ${CMT_BASE} \
RUN make -C ${BUILD_BASE}/tools/sys-utils/libcmt \
ARG_VERSION=${VERSION} \
PREFIX=/usr/riscv64-linux-gnu \
DESTDIR=${BUILD_BASE}/install/cross \
install libcmt-dev-riscv64-cross-v${VERSION}.deb
install-dev libcmt-dev-riscv64-cross-v${VERSION}.deb

# build rust tools
# ------------------------------------------------------------------------------
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"

USER developer

Expand Down Expand Up @@ -158,7 +151,6 @@ FROM tools-env AS packer
ARG TOOLS_DEB=machine-emulator-tools.deb
ARG STAGING_BASE=${BUILD_BASE}/_install
ARG STAGING_DEBIAN=${STAGING_BASE}/DEBIAN
ARG STAGING_SBIN=${STAGING_BASE}/usr/sbin
ARG STAGING_BIN=${STAGING_BASE}/usr/bin
ARG STAGING_SHARE=${STAGING_BASE}/usr/share/machine-emulator-tools

Expand All @@ -170,15 +162,8 @@ COPY package.json ${STAGING_SHARE}/package.json
COPY postinst ${STAGING_DEBIAN}/postinst
COPY copyright ${STAGING_BASE}/usr/share/doc/machine-emulator-tools/copyright

COPY --from=builder ${BUILD_BASE}/tools/sys-utils/cartesi-init/cartesi-init ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/xhalt/xhalt ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/yield/yield ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/hex/hex ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/rollup/rollup ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/ioctl-echo-loop/ioctl-echo-loop ${STAGING_BIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/yield/yield ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/misc/* ${STAGING_BIN}
COPY --from=rust-builder ${BUILD_BASE}/tools/rollup-http/rollup-init/rollup-init ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils_staging ${STAGING_BASE}
COPY --from=rust-builder ${BUILD_BASE}/tools/rollup-http/rollup-init/rollup-init ${STAGING_BIN}
COPY --from=http-server-builder ${BUILD_BASE}/tools/rollup-http/rollup-http-server/target/riscv64gc-unknown-linux-gnu/release/rollup-http-server ${STAGING_BIN}
COPY --from=echo-dapp-builder ${BUILD_BASE}/tools/rollup-http/echo-dapp/target/riscv64gc-unknown-linux-gnu/release/echo-dapp ${STAGING_BIN}

Expand Down
28 changes: 3 additions & 25 deletions rollup-http/rollup-http-server/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,11 @@ fn main() {
let lib_dir = if mock_build {
"../../sys-utils/libcmt/build/mock".into()
} else {
pkg_config::Config::new()
.statik(true)
.probe("libcmt")
.expect("Could not find library")
.link_paths
.iter()
.map(|path| path.to_string_lossy().into_owned())
.collect::<Vec<String>>()
.get(0)
.expect("Library path not found")
.clone()
"../../sys-utils/libcmt/build/riscv64".to_string()
};

let header_path = if mock_build {
"../../sys-utils/libcmt/include/libcmt/rollup.h".into()
} else {
pkg_config::get_variable("libcmt", "includedir").expect("Could not find include directory")
+ "/libcmt/rollup.h"
};

let include_path = if mock_build {
"-I../../sys-utils/libcmt/include/libcmt".into()
} else {
"-I".to_string()
+ &pkg_config::get_variable("libcmt", "includedir")
.expect("Could not find include directory")
};
let header_path = "../../sys-utils/libcmt/include/libcmt/rollup.h";
let include_path = "-I../../sys-utils/libcmt/include/libcmt";

// link the libcmt shared library
println!("cargo:rustc-link-search=native={}", lib_dir);
Expand Down
11 changes: 8 additions & 3 deletions sys-utils/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@
# limitations under the License.
#

UTILITIES := hex xhalt yield rollup ioctl-echo-loop
UTILITIES := libcmt hex xhalt yield rollup ioctl-echo-loop

all: $(UTILITIES)
all:
@$(MAKE) libcmt
@$(MAKE) $(UTILITIES)

$(UTILITIES):
@$(MAKE) -C $@

install:
@$(foreach utility,$(UTILITIES),$(MAKE) -C $(utility) install;)

clean:
@$(foreach utility,$(UTILITIES),$(MAKE) -C $(utility) clean;)

.PHONY: all $(UTILITIES)
.PHONY: all install clean $(UTILITIES)
5 changes: 5 additions & 0 deletions sys-utils/cartesi-init/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PREFIX = /usr/local

install:
mkdir -p $(DESTDIR)$(PREFIX)/sbin
install -Dm755 cartesi-init $(DESTDIR)$(PREFIX)/sbin/
5 changes: 5 additions & 0 deletions sys-utils/hex/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
#

PREFIX = /usr/local
CXX = $(TOOLCHAIN_PREFIX)g++
CXXFLAGS += -Wall -Wextra -pedantic -O2 -std=c++20

Expand All @@ -22,5 +23,9 @@ all: hex
hex: hex.cpp
$(CXX) $(CFLAGS) -o $@ $< $(LDFLAGS)

install: hex
mkdir -p $(DESTDIR)$(PREFIX)/bin
install -Dm755 hex $(DESTDIR)$(PREFIX)/bin/

clean:
@rm -f hex
9 changes: 7 additions & 2 deletions sys-utils/ioctl-echo-loop/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@
# limitations under the License.
#

PREFIX = /usr/local
CC = $(TOOLCHAIN_PREFIX)gcc
CFLAGS += -Wall -Wextra -pedantic -O2 `pkg-config --cflags libcmt`
LDFLAGS += `pkg-config --libs libcmt`
CFLAGS += -Wall -Wextra -pedantic -O2 -I../libcmt/include
LDFLAGS += -L../libcmt/build/riscv64 -l:libcmt.a

all: ioctl-echo-loop

ioctl-echo-loop: ioctl-echo-loop.c
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)

install: ioctl-echo-loop
mkdir -p $(DESTDIR)$(PREFIX)/bin
install -Dm755 ioctl-echo-loop $(DESTDIR)$(PREFIX)/bin/

clean:
@rm -f ioctl-echo-loop
2 changes: 1 addition & 1 deletion sys-utils/libcmt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CFLAGS += -Wvla -O2 -g -Wall -pedantic -Wextra -Iinclude \
-fno-strict-aliasing -fno-strict-overflow -fPIC
LIBCMT_CFLAGS += -ftrivial-auto-var-init=zero -Wstrict-aliasing=3

all: libcmt host
all: libcmt
host: mock tools
#-------------------------------------------------------------------------------
examples_SRC := \
Expand Down
6 changes: 6 additions & 0 deletions sys-utils/misc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PREFIX = /usr/local

install:
install -Dm755 flashdrive $(DESTDIR)$(PREFIX)/bin/
install -Dm755 readbe64 $(DESTDIR)$(PREFIX)/bin/
install -Dm755 writebe64 $(DESTDIR)$(PREFIX)/bin/
9 changes: 7 additions & 2 deletions sys-utils/rollup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@
# limitations under the License.
#

PREFIX = /usr/local
CXX = $(TOOLCHAIN_PREFIX)g++
CXXFLAGS += -Wall -Wextra -pedantic -O2 -std=c++20 `pkg-config --cflags libcmt`
LDFLAGS += `pkg-config --libs libcmt`
CXXFLAGS += -Wall -Wextra -pedantic -O2 -std=c++20 -I../libcmt/include
LDFLAGS += -L../libcmt/build/riscv64 -l:libcmt.a

all: rollup

rollup: rollup.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS)

install: rollup
mkdir -p $(DESTDIR)$(PREFIX)/bin
install -Dm755 rollup $(DESTDIR)$(PREFIX)/bin/

clean:
@rm -f rollup
5 changes: 5 additions & 0 deletions sys-utils/xhalt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
#

PREFIX = /usr/local
CC = $(TOOLCHAIN_PREFIX)gcc
CFLAGS += -Wall -Wextra -pedantic -O2

Expand All @@ -22,5 +23,9 @@ all: xhalt
xhalt: xhalt.c
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)

install: xhalt
mkdir -p $(DESTDIR)$(PREFIX)/bin
install -Dm755 xhalt $(DESTDIR)$(PREFIX)/bin/

clean:
@rm -f xhalt
9 changes: 7 additions & 2 deletions sys-utils/yield/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@
# limitations under the License.
#

PREFIX = /usr/local
CC = $(TOOLCHAIN_PREFIX)gcc
CFLAGS += -Wall -Wextra -pedantic -O2 `pkg-config --cflags libcmt`
LDFLAGS += `pkg-config --libs libcmt`
CFLAGS += -Wall -Wextra -pedantic -O2 -I../libcmt/include
LDFLAGS += -L../libcmt/build/riscv64 -l:libcmt.a

all: yield

yield: yield.c
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)

install: yield
mkdir -p $(DESTDIR)$(PREFIX)/bin
install -Dm755 yield $(DESTDIR)$(PREFIX)/bin/

clean:
@rm -f yield

0 comments on commit 4602034

Please sign in to comment.