Skip to content

[buildsystem] Improve solidity embeddability. #14860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,21 @@ option(SOLC_STATIC_STDLIBS "Link solc against static versions of libgcc and libs
option(STRICT_Z3_VERSION "Use the latest version of Z3" ON)
option(PEDANTIC "Enable extra warnings and pedantic build flags. Treat all warnings as errors." ON)
option(PROFILE_OPTIMIZER_STEPS "Output performance metrics for the optimiser steps." OFF)
option(USE_SYSTEM_LIBRARIES "Use system libraries" OFF)
option(ONLY_BUILD_SOLIDITY_LIBRARIES "Only build solidity libraries" OFF)
option(STRICT_JSONCPP_VERSION "Strictly check installed jsoncpp version" ON)

# Setup cccache.
include(EthCcache)

# Let's find our dependencies
include(EthDependencies)
include(fmtlib)
include(jsoncpp)
include(range-v3)
include_directories(SYSTEM ${JSONCPP_INCLUDE_DIR})
if (NOT USE_SYSTEM_LIBRARIES)
include(fmtlib)
include(jsoncpp)
include(range-v3)
include_directories(SYSTEM ${JSONCPP_INCLUDE_DIR})
endif()

find_package(Threads)

Expand All @@ -58,6 +63,10 @@ if (PROFILE_OPTIMIZER_STEPS)
add_definitions(-DPROFILE_OPTIMIZER_STEPS)
endif()

if (STRICT_JSONCPP_VERSION)
add_definitions(-DSTRICT_JSONCPP_VERSION_CHECK)
endif()

# Figure out what compiler and system are we using
include(EthCompilerSettings)

Expand Down Expand Up @@ -141,12 +150,16 @@ add_subdirectory(libyul)
add_subdirectory(libsolidity)
add_subdirectory(libsolc)
add_subdirectory(libstdlib)
add_subdirectory(tools)

if (NOT EMSCRIPTEN)
add_subdirectory(solc)
endif()
if (NOT ONLY_BUILD_SOLIDITY_LIBRARIES)
add_subdirectory(tools)

if (TESTS AND NOT EMSCRIPTEN)
add_subdirectory(test)
if (NOT EMSCRIPTEN)
add_subdirectory(solc)
endif()

if (TESTS AND NOT EMSCRIPTEN)
add_subdirectory(test)
endif()
endif()

2 changes: 2 additions & 0 deletions libsolutil/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
#include <map>
#include <memory>

#ifdef STRICT_JSONCPP_VERSION_CHECK
static_assert(
(JSONCPP_VERSION_MAJOR == 1) && (JSONCPP_VERSION_MINOR == 9) && (JSONCPP_VERSION_PATCH == 3),
"Unexpected jsoncpp version: " JSONCPP_VERSION_STRING ". Expecting 1.9.3."
);
#endif

namespace solidity::util
{
Expand Down
8 changes: 4 additions & 4 deletions libstdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# This will re-generate the headers if any file within src was modified.
set_directory_properties(PROPERTY CMAKE_CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/stdlib/src/)
set_directory_properties(PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/)

set(STDLIB stub)
set(GENERATED_STDLIB_HEADERS)
foreach(src IN LISTS STDLIB)
set(STDLIB_FILE ${PROJECT_SOURCE_DIR}/libstdlib/src/${src}.sol)
set(STDLIB_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/${src}.sol)
file(READ ${STDLIB_FILE} STDLIB_FILE_CONTENT HEX)
string(REGEX MATCHALL ".." STDLIB_FILE_CONTENT "${STDLIB_FILE_CONTENT}")
list(REMOVE_ITEM STDLIB_FILE_CONTENT "0d")
string(REGEX REPLACE ";" ",\n\t0x" STDLIB_FILE_CONTENT "${STDLIB_FILE_CONTENT}")
set(STDLIB_FILE_CONTENT "0x${STDLIB_FILE_CONTENT}")
set(STDLIB_FILE_NAME ${src})
configure_file("${PROJECT_SOURCE_DIR}/libstdlib/stdlib.src.h.in" ${PROJECT_BINARY_DIR}/include/libstdlib/${src}.h NEWLINE_STYLE LF @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/stdlib.src.h.in" ${PROJECT_BINARY_DIR}/include/libstdlib/${src}.h NEWLINE_STYLE LF @ONLY)
list(APPEND GENERATED_STDLIB_HEADERS ${PROJECT_BINARY_DIR}/include/libstdlib/${src}.h)
endforeach()

configure_file("${PROJECT_SOURCE_DIR}/libstdlib/stdlib.h.in" ${PROJECT_BINARY_DIR}/include/libstdlib/stdlib.h NEWLINE_STYLE LF @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/stdlib.h.in" ${PROJECT_BINARY_DIR}/include/libstdlib/stdlib.h NEWLINE_STYLE LF @ONLY)