forked from NilFoundation/zkLLVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
215 lines (172 loc) · 8.53 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#---------------------------------------------------------------------------#
# Copyright (c) 2018-2022 Mikhail Komarov <nemo@nil.foundation>
# Copyright (c) 2020-2022 Nikita Kaskov <nbering@nil.foundation>
#
# Distributed under the Boost Software License, Version 1.0
# See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt
#---------------------------------------------------------------------------#
cmake_minimum_required(VERSION 3.2)
cmake_policy(SET CMP0042 NEW)
cmake_policy(SET CMP0028 NEW)
cmake_policy(SET CMP0057 NEW)
cmake_policy(SET CMP0063 NEW)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake"
"${CMAKE_CURRENT_LIST_DIR}/cmake/packages"
"${CMAKE_CURRENT_LIST_DIR}/cmake/modules/share/modules/cmake")
include(CMConfig)
include(CMSetupVersion)
cm_workspace(zkllvm)
macro(cm_find_package NAME)
if(NOT "${NAME}" MATCHES "^${CMAKE_WORKSPACE_NAME}_.*$" AND NOT "${NAME}" STREQUAL CM)
find_package(${ARGV})
else()
set(${ARGV0}_FOUND ON CACHE BOOL "")
endif()
endmacro()
cm_setup_version(VERSION 0.3.0 PREFIX ${CMAKE_WORKSPACE_NAME})
option(BUILD_SHARED_LIBS "Build shared library" TRUE)
option(BUILD_WITH_CCACHE "Build with ccache usage" TRUE)
option(BUILD_WITH_BOOST_STATIC_LIBS "Build using Boost static libraries" TRUE)
option(BUILD_TESTS "Build unit tests" FALSE)
option(BUILD_DOCS "Build with configuring Doxygen documentation compiler" TRUE)
option(CIRCUIT_ASSEMBLY_OUTPUT "Emit circuit IR as assembly file" FALSE)
set(BUILD_WITH_TARGET_ARCHITECTURE "" CACHE STRING "Target build architecture")
set(DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_LIST_DIR}/docs" CACHE STRING "Specify doxygen output directory")
set(ZKLLVM_DEV_ENVIRONMENT TRUE)
include(TargetArchitecture)
include(CircuitCompile)
if(BUILD_WITH_BOOST_STATIC_LIBS)
set(Boost_USE_STATIC_LIBS TRUE)
else()
set(Boost_USE_STATIC_LIBS FALSE)
endif()
if(UNIX AND BUILD_WITH_CCACHE)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
endif()
if(BUILD_WITH_TARGET_ARCHITECTURE)
set(CMAKE_TARGET_ARCHITECTURE ${BUILD_WITH_TARGET_ARCHITECTURE})
else()
target_architecture(CMAKE_TARGET_ARCHITECTURE)
endif()
if(BUILD_TESTS)
cm_find_package(Boost COMPONENTS REQUIRED unit_test_framework)
endif()
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/libs/crypto3")
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/libs/blueprint")
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/libs/assigner")
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/libs/transpiler")
set(LLVM_ENABLE_PROJECTS "clang" CACHE STRING "Additional llvm projects")
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/libs/circifier/llvm")
add_subdirectory(examples)
if(BUILD_TESTS)
add_subdirectory(tests)
endif()
add_subdirectory(libs/stdlib)
install(FILES cmake/CircuitCompile.cmake DESTINATION share/zkllvm)
find_program(GIT_EXE git)
if(NOT ZKLLVM_VERSION)
execute_process(COMMAND ${GIT_EXE} describe --tags HEAD
OUTPUT_VARIABLE DESCRIBE_OUTBUT
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
if(NOT ("${DESCRIBE_OUTBUT}" STREQUAL "${ZKLLVM_VERSION}"))
set(ZKLLVM_VERSION "${DESCRIBE_OUTBUT}")
endif()
if(NOT ZKLLVM_VERSION)
message(FATAL_ERROR
"Unable to retrive version from git or ${VERSION_FILE} file.")
endif()
endif()
# Remove preceding 'v' from tag
string(REGEX REPLACE "^v" "" ZKLLVM_VERSION ${ZKLLVM_VERSION})
# Split numbers
string(REPLACE "-" "." ZKLLVM_VERSION_LIST ${ZKLLVM_VERSION})
string(REPLACE "." ";" ZKLLVM_VERSION_LIST ${ZKLLVM_VERSION_LIST})
list(LENGTH ZKLLVM_VERSION_LIST VERSION_LIST_LENGHT)
list(GET ZKLLVM_VERSION_LIST 0 ZKLLVM_VERSION_MAJOR)
list(GET ZKLLVM_VERSION_LIST 1 ZKLLVM_VERSION_MINOR)
list(GET ZKLLVM_VERSION_LIST 2 ZKLLVM_VERSION_PATCH)
if(VERSION_LIST_LENGHT GREATER 3)
list(GET ZKLLVM_VERSION_LIST 3 ZKLLVM_VERSION_INCREMENT)
endif()
set(CPACK_GENERATOR DEB)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "=nil; Foundation")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "zkllvm-stdlib, libstdc++-9-dev")
set(CPACK_PACKAGE_VERSION "${ZKLLVM_VERSION_MAJOR}.${ZKLLVM_VERSION_MINOR}.${ZKLLVM_VERSION_PATCH}")
if(ZKLLVM_VERSION_INCREMENT)
string(APPEND CPACK_PACKAGE_VERSION "-${ZKLLVM_VERSION_INCREMENT}")
endif()
include(CPack)
add_subdirectories("${CMAKE_CURRENT_LIST_DIR}/bin")
install(TARGETS assigner RUNTIME DESTINATION bin)
install(TARGETS transpiler RUNTIME DESTINATION bin)
# Package for stdlib
add_custom_target(stdlib_package
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/libs/stdlib/packaging/make_deb.sh ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS zkllvm-libc)
find_package(Python3 REQUIRED COMPONENTS Interpreter)
message(STATUS "Configuring rslang")
execute_process(COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/detect-platform.py
RESULT_VARIABLE DETECT_PLATFORM_RESULT
OUTPUT_VARIABLE RUSTC_HOST_TRIPLE
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT ${DETECT_PLATFORM_RESULT} EQUAL 0)
message(FATAL_ERROR "Failed to detect host platform")
endif()
option(RSLANG_BUILD_EXTENDED "Build Rust tools (see build.extended)" FALSE)
option(RSLANG_BUILD_TOOLS "Rust tools to build (see build.tools)" "")
set(RSLANG_BUILD_STAGE "1" CACHE STRING "Stage to build (see --stage)")
list(APPEND RSLANG_BUILD_ARGS --set llvm.download-ci-llvm=false)
list(APPEND RSLANG_BUILD_ARGS --release-channel=nightly)
list(APPEND RSLANG_BUILD_ARGS "--release-description=zkLLVM ${ZKLLVM_VERSION_MAJOR}.${ZKLLVM_VERSION_MINOR}.${ZKLLVM_VERSION_PATCH}")
list(APPEND RSLANG_BUILD_ARGS --target=${RUSTC_HOST_TRIPLE},assigner-unknown-unknown)
list(APPEND RSLANG_BUILD_ARGS --set target.${RUSTC_HOST_TRIPLE}.llvm-config=${CMAKE_CURRENT_BINARY_DIR}/libs/circifier/llvm/bin/llvm-config)
list(APPEND RSLANG_BUILD_ARGS --set target.${RUSTC_HOST_TRIPLE}.llvm-filecheck=${CMAKE_CURRENT_BINARY_DIR}/libs/circifier/llvm/bin/FileCheck)
list(APPEND RSLANG_BUILD_ARGS --set target.${RUSTC_HOST_TRIPLE}.llvm-has-rust-patches=false)
list(APPEND RSLANG_BUILD_ARGS --set target.assigner-unknown-unknown.llvm-config=${CMAKE_CURRENT_BINARY_DIR}/libs/circifier/llvm/bin/llvm-config)
list(APPEND RSLANG_BUILD_ARGS --set target.assigner-unknown-unknown.llvm-filecheck=${CMAKE_CURRENT_BINARY_DIR}/libs/circifier/llvm/bin/FileCheck)
list(APPEND RSLANG_BUILD_ARGS --set target.assigner-unknown-unknown.llvm-has-rust-patches=false)
list(APPEND RSLANG_BUILD_ARGS --set target.assigner-unknown-unknown.linker=llvm-link)
if(${BUILD_SHARED_LIBS})
list(APPEND RSLANG_BUILD_ARGS --enable-llvm-link-shared)
endif()
list(APPEND RSLANG_BUILD_ARGS --set build.build-dir=${CMAKE_CURRENT_BINARY_DIR}/libs/rslang/build)
list(APPEND RSLANG_BUILD_ARGS --set build.cargo=${CMAKE_CURRENT_BINARY_DIR}/libs/rslang/target/release/cargo)
list(APPEND RSLANG_BUILD_ARGS --disable-docs)
if(${RSLANG_BUILD_EXTENDED})
list(APPEND RSLANG_BUILD_ARGS --enable-extended)
if(RSLANG_BUILD_TOOLS)
list(APPEND RSLANG_BUILD_ARGS --tools=${RSLANG_BUILD_TOOLS})
endif()
endif()
if(CMAKE_BUILD_TYPE MATCHES Debug)
list(APPEND RSLANG_BUILD_ARGS --enable-debug)
endif()
list(APPEND RSLANG_BUILD_ARGS --dist-compression-formats=gz)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libs/rslang)
execute_process(COMMAND ${CMAKE_CURRENT_LIST_DIR}/libs/rslang/configure ${RSLANG_BUILD_ARGS}
COMMAND_ERROR_IS_FATAL ANY
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libs/rslang)
add_custom_target(cargo
COMMAND cargo build --release --target-dir ${CMAKE_CURRENT_BINARY_DIR}/libs/rslang/target --package cargo
COMMENT "Building cargo"
USES_TERMINAL
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/libs/rslang)
add_custom_target(rslang
COMMAND ./x build --config ${CMAKE_CURRENT_BINARY_DIR}/libs/rslang/config.toml --stage ${RSLANG_BUILD_STAGE}
DEPENDS llvm-libraries llvm-config llvm-link FileCheck cargo
COMMENT "Building rslang"
USES_TERMINAL
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/libs/rslang)
add_custom_target(rslang_dist
COMMAND ./x dist --config ${CMAKE_CURRENT_BINARY_DIR}/libs/rslang/config.toml
DEPENDS rslang
COMMENT "Building rslang distribution package"
USES_TERMINAL
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/libs/rslang)