Skip to content

Commit edf3aec

Browse files
authored
Build and test riscv32 (#700)
This uses a pre-built RISC-V toolchain to build and test evmone. This compiles evmone and dependencies to `rv32imafdc` with `ilp32d` ABI. I.e. this target has hardware support for floating point. Our preference would be to compile for `rv32imac` with `ilp32` ABI. However, there are some obstacles to get there: 1. The pre-built toolchain is built for `ilp32d`. We would need to build the toolchain ourselves. 2. We can hack it by setting `-march=rv32imac -mabi=ilp32d`. The compiler is not very happy about using architecture with incompatible ABI but it will proceed anyway. Unfortunately, the dependencies have some floating-point code so we also need to provide soft-float library. I was not able to make it build so far.
2 parents e1ac92c + 541efbb commit edf3aec

3 files changed

Lines changed: 40 additions & 2 deletions

File tree

circle.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ commands:
8686
command: |
8787
curl -L https://github.com/Kitware/CMake/releases/download/v<<parameters.version>>/cmake-<<parameters.version>>-linux-x86_64.tar.gz | sudo tar -xz --strip=1
8888
89+
install_riscv_toolchain:
90+
steps:
91+
- run:
92+
name: "Install RISC-V Toolchain"
93+
working_directory: /usr/local
94+
command: |
95+
curl -L https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2023.07.07/riscv32-glibc-ubuntu-22.04-llvm-nightly-2023.07.07-nightly.tar.gz | sudo tar -xz
96+
8997
checkout_submodules:
9098
steps:
9199
- run:
@@ -659,6 +667,16 @@ jobs:
659667
working_directory: ~/build
660668
command: (! qemu-x86_64-static bin/evmone-unittests 2>&1) | grep "CPU does not support"
661669

670+
riscv32:
671+
executor: linux-gcc-latest
672+
environment:
673+
BUILD_TYPE: Release
674+
CMAKE_OPTIONS: -DCMAKE_TOOLCHAIN_FILE=~/project/cmake/toolchains/riscv32.cmake
675+
steps:
676+
- install_riscv_toolchain
677+
- build
678+
- test
679+
662680

663681

664682
workflows:
@@ -705,4 +723,5 @@ workflows:
705723
# - xcode-min
706724
- gcc-32bit
707725
- x86-64-v1
726+
- riscv32
708727
- fuzzing

cmake/toolchains/riscv32.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# evmone: Ethereum Virtual Machine
2+
# Copyright 2023 Pawel Bylica.
3+
# Licensed under the Apache License, Version 2.0. See the LICENSE file.
4+
5+
set(RISCV /usr/local/riscv)
6+
7+
set(CMAKE_SYSTEM_PROCESSOR riscv32)
8+
set(CMAKE_SYSTEM_NAME Linux)
9+
set(CMAKE_C_COMPILER ${RISCV}/bin/clang)
10+
set(CMAKE_CXX_COMPILER ${RISCV}/bin/clang++)
11+
12+
set(CMAKE_CXX_FLAGS_INIT -stdlib=libc++)
13+
14+
set(CMAKE_FIND_ROOT_PATH ${RISCV}/sysroot)
15+
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
16+
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
17+
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
18+
19+
set(CMAKE_CROSSCOMPILING_EMULATOR qemu-riscv32-static;-L;${CMAKE_FIND_ROOT_PATH})

test/integration/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set(PREFIX ${PROJECT_NAME}/integration)
77
get_target_property(EVMONE_LIB_TYPE evmone TYPE)
88
if(EVMONE_LIB_TYPE STREQUAL SHARED_LIBRARY)
99

10-
add_test(NAME ${PREFIX}/histogram COMMAND $<TARGET_FILE:evmc::tool> --vm $<TARGET_FILE:evmone>,histogram run 6000808080800101010200)
10+
add_test(NAME ${PREFIX}/histogram COMMAND evmc::tool --vm $<TARGET_FILE:evmone>,histogram run 6000808080800101010200)
1111
set_tests_properties(
1212
${PREFIX}/histogram PROPERTIES PASS_REGULAR_EXPRESSION
1313
"--- # HISTOGRAM depth=0
@@ -19,7 +19,7 @@ PUSH1,1
1919
DUP1,4
2020
")
2121

22-
add_test(NAME ${PREFIX}/trace COMMAND $<TARGET_FILE:evmc::tool> --vm $<TARGET_FILE:evmone>,trace run 60006002800103)
22+
add_test(NAME ${PREFIX}/trace COMMAND evmc::tool --vm $<TARGET_FILE:evmone>,trace run 60006002800103)
2323
set_tests_properties(
2424
${PREFIX}/trace PROPERTIES PASS_REGULAR_EXPRESSION
2525
"\"pc\":0,\"op\":96,\"gas\":\"0xf4240\",\"gasCost\":\"0x3\",\"memSize\":0,\"stack\":\\[\\],\"depth\":1,\"refund\":0,\"opName\":\"PUSH1\"}

0 commit comments

Comments
 (0)