Skip to content

Commit

Permalink
Cross-compile solc
Browse files Browse the repository at this point in the history
  • Loading branch information
guidanoli committed May 21, 2024
1 parent 922934b commit 007c366
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 51 deletions.
2 changes: 1 addition & 1 deletion tests/bounties/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ all:

$(MAKE) -C busybox-bounty riscv64 VERSION=1.36.1

$(MAKE) -C solidity-bounty riscv64 VERSION=0.8.24
$(MAKE) -C solidity-bounty riscv64 VERSION=0.8.26

clean:
$(MAKE) -C lua-bounty clean
Expand Down
67 changes: 59 additions & 8 deletions tests/bounties/solidity-bounty/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,61 @@
FROM --platform=linux/riscv64 riscv64/ubuntu:22.04
FROM ubuntu:22.04 as base-builder
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y --no-install-recommends ca-certificates build-essential wget xz-utils
RUN apt-get install -y --no-install-recommends cmake libboost-all-dev libcln-dev libcvc4-dev
WORKDIR /root
COPY Makefile .
COPY --chmod=755 start.sh .
RUN apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
crossbuild-essential-riscv64 \
git \
make \
wget \
xz-utils

#
# Build Boost
#

FROM base-builder as boost-builder
WORKDIR /opt/build
RUN wget "https://boostorg.jfrog.io/artifactory/main/release/1.74.0/source/boost_1_74_0.tar.gz"
RUN tar xzf boost_1_74_0.tar.gz
WORKDIR /opt/build/boost_1_74_0
RUN mkdir -p /opt/boost
RUN ./bootstrap.sh --prefix=/opt/boost
RUN echo "using gcc : riscv64 : riscv64-linux-gnu-g++ ;" > "${HOME}/user-config.jam"
RUN ./b2 toolset=gcc-riscv64 headers
RUN ./b2 toolset=gcc-riscv64 link=static variant=release runtime-link=static \
--with-system --with-filesystem --with-test --with-program_options \
install -j `nproc`

#
# Build Solidity
#

FROM base-builder as solidity-builder
WORKDIR /opt/build
RUN apt-get install -y --no-install-recommends cmake
ARG VERSION
RUN make download VERSION=${VERSION}
RUN make VERSION=${VERSION}
RUN wget -O solidity-${VERSION}.tar.gz https://github.com/ethereum/solidity/releases/download/v${VERSION}/solidity_${VERSION}.tar.gz
RUN tar xzf solidity-${VERSION}.tar.gz
COPY --from=boost-builder /opt/boost /opt/boost
RUN cmake \
-S solidity_${VERSION} \
-B solidity_${VERSION}/build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_C_COMPILER=riscv64-linux-gnu-gcc \
-DCMAKE_CXX_COMPILER=riscv64-linux-gnu-g++ \
-DBoost_INCLUDE_DIR=/opt/boost \
-DBoost_USE_STATIC_RUNTIME=ON \
-DUSE_CVC4=OFF \
-DUSE_Z3=OFF \
-DTESTS=OFF

RUN make -C solidity_${VERSION}/build -j `nproc` solc

#
# Create the .tar.xz file
#

RUN mv solidity_${VERSION}/build/solc/solc .
COPY --chmod=755 start.sh .
RUN tar cfJ /root/solidity-${VERSION}-bounty_riscv64.tar.xz solc start.sh
41 changes: 2 additions & 39 deletions tests/bounties/solidity-bounty/Makefile
Original file line number Diff line number Diff line change
@@ -1,49 +1,12 @@
ARCH=$(shell uname -m)
VERSION=0.8.24
SOURCE_TAR=solidity-$(VERSION).tar.gz
SOURCE_DIR=solidity_$(VERSION)
BUILD_DIR=$(SOURCE_DIR)/build
BOUNTY_TAR=solidity-$(VERSION)-bounty_$(ARCH).tar.xz
VERSION=0.8.26
BOUNTY_RISCV64_TAR=solidity-$(VERSION)-bounty_riscv64.tar.xz

CMAKEFLAGS=-DTESTS=OFF -DUSE_Z3=OFF

all: $(BOUNTY_TAR)

riscv64: $(BOUNTY_RISCV64_TAR)

download: | $(SOURCE_DIR)

$(BOUNTY_TAR): solc start.sh
tar cfJ $@ $^

$(BUILD_DIR)/solc/solc: | $(SOURCE_DIR) $(BUILD_DIR)
$(MAKE) -C $(BUILD_DIR) solc

$(BUILD_DIR):
cmake -S $(SOURCE_DIR) -B $(BUILD_DIR) $(CMAKEFLAGS)

solc: $(BUILD_DIR)/solc/solc
cp $< $@

$(SOURCE_DIR): $(SOURCE_TAR)
tar xzf $<

$(SOURCE_TAR):
wget -O $(SOURCE_TAR) https://github.com/ethereum/solidity/releases/download/v$(VERSION)/solidity_$(VERSION).tar.gz

ifneq ($(ARCH), riscv64)
$(BOUNTY_RISCV64_TAR): Dockerfile start.sh
docker build --tag solidity-bounty-cp --file Dockerfile --progress plain --build-arg VERSION=$(VERSION) .
docker create --platform=linux/riscv64 --name solidity-bounty-cp solidity-bounty-cp
docker create --name solidity-bounty-cp solidity-bounty-cp
docker cp solidity-bounty-cp:/root/$@ $@
docker rm solidity-bounty-cp
touch $@
endif

clean:
rm -f solc $(SOURCE_DIR)-bounty_*.tar.xz
if [ -d "$(BUILD_DIR)" ]; then $(MAKE) -C $(BUILD_DIR) clean; fi

distclean: clean
rm -rf solidity*
4 changes: 2 additions & 2 deletions tests/bounties/solidity-bounty/info.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Solidity 0.8.24",
"name": "Solidity 0.8.26",
"description": "Solidity is a programming language for implementing smart contracts on various blockchain platforms, most notably, Ethereum.",
"imgLink": "https://upload.wikimedia.org/wikipedia/commons/9/98/Solidity_logo.svg"
"imgLink": "https://docs.soliditylang.org/en/v0.8.26/_static/img/logo-dark.svg"
}
2 changes: 1 addition & 1 deletion tests/bounties/solidity-bounty/start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
./solc --standard-json $1
./solc $1
status=$?
# Status is always 139 when program crashes with "Segmentation fault" (SIGSEGV)
if [ $status -eq 139 ]; then
Expand Down

0 comments on commit 007c366

Please sign in to comment.