File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use std:: env;
2+ use std:: fs;
23use std:: path:: PathBuf ;
34
45use cmake:: Config ;
@@ -10,6 +11,9 @@ fn main() {
1011
1112 let manifest_dir = PathBuf :: from ( env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ) ;
1213
14+ let is_fuzzing = std:: env:: var ( "CARGO_CFG_FUZZING" ) . is_ok ( ) ;
15+ let is_debug_build = std:: env:: var_os ( "OPT_LEVEL" ) . unwrap_or ( "" . into ( ) ) == "0" ;
16+
1317 let mut src_dir = manifest_dir. join ( "cpp" ) ;
1418 if !src_dir. exists ( ) {
1519 src_dir = manifest_dir
@@ -24,6 +28,14 @@ fn main() {
2428 . define ( "BUILD_CHIAVDFC" , "ON" )
2529 . env ( "BUILD_VDF_CLIENT" , "N" )
2630 . define ( "BUILD_PYTHON" , "OFF" )
31+ . define (
32+ "HARDENING" ,
33+ if is_fuzzing || is_debug_build {
34+ "ON"
35+ } else {
36+ "OFF"
37+ } ,
38+ )
2739 . build ( ) ;
2840
2941 println ! ( "cargo:rustc-link-lib=static=chiavdfc" ) ;
@@ -48,6 +60,14 @@ fn main() {
4860 . to_str( )
4961 . unwrap( )
5062 ) ;
63+ } else if cfg ! ( target_os = "macos" ) {
64+ println ! ( "cargo:rustc-link-lib=static=gmp" ) ;
65+ let homebrew_path = if fs:: metadata ( "/opt/homebrew" ) . is_ok ( ) {
66+ "/opt/homebrew/lib"
67+ } else {
68+ "/usr/local/lib"
69+ } ;
70+ println ! ( "cargo:rustc-link-search=native={homebrew_path}" ) ;
5171 } else {
5272 println ! ( "cargo:rustc-link-lib=gmp" ) ;
5373 }
Original file line number Diff line number Diff line change 11CMAKE_MINIMUM_REQUIRED (VERSION 3.14 FATAL_ERROR )
22option (BUILD_CHIAVDFC "Build the chiavdfc shared library" OFF )
33option (BUILD_PYTHON "Build the python bindings for chiavdf" ON )
4+ option (HARDENING "Enable hardening" OFF )
45
56set (CMAKE_CXX_STANDARD 17)
67set (CMAKE_CXX_STANDARD_REQUIRED ON )
@@ -108,6 +109,11 @@ if(BUILD_CHIAVDFC)
108109 target_link_libraries (chiavdfc_shared ${GMP_LIBRARIES} ${GMPXX_LIBRARIES} )
109110 target_link_libraries (chiavdfc_static ${GMP_LIBRARIES} ${GMPXX_LIBRARIES} )
110111
112+ if (HARDENING)
113+ target_compile_definitions (chiavdfc_shared PRIVATE "_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG" )
114+ target_compile_definitions (chiavdfc_static PRIVATE "_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG" )
115+ endif ()
116+
111117 set_target_properties (chiavdfc_shared PROPERTIES
112118 OUTPUT_NAME chiavdfc
113119 LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /lib/shared$<0:>"
You can’t perform that action at this time.
0 commit comments