Skip to content

Commit 65d2b96

Browse files
authored
Merge pull request #289 from Chia-Network/fuzzer
build fuzzer with hardening
2 parents 2ac6d81 + 1995b40 commit 65d2b96

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

rust_bindings/build.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::env;
2+
use std::fs;
23
use std::path::PathBuf;
34

45
use 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
}

src/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CMAKE_MINIMUM_REQUIRED(VERSION 3.14 FATAL_ERROR)
22
option(BUILD_CHIAVDFC "Build the chiavdfc shared library" OFF)
33
option(BUILD_PYTHON "Build the python bindings for chiavdf" ON)
4+
option(HARDENING "Enable hardening" OFF)
45

56
set(CMAKE_CXX_STANDARD 17)
67
set(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:>"

0 commit comments

Comments
 (0)