Skip to content

Commit 89baca9

Browse files
committed
support building the rust bindings on Mac. Add feature to enable hardening, and do so for the fuzzer
1 parent 2ac6d81 commit 89baca9

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

rust_bindings/build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ fn main() {
1010

1111
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
1212

13+
let is_fuzzing = std::env::var("CARGO_CFG_FUZZING").is_ok();
14+
let is_debug_build = std::env::var_os("OPT_LEVEL").unwrap_or("".into()) == "0";
15+
1316
let mut src_dir = manifest_dir.join("cpp");
1417
if !src_dir.exists() {
1518
src_dir = manifest_dir
@@ -24,6 +27,8 @@ fn main() {
2427
.define("BUILD_CHIAVDFC", "ON")
2528
.env("BUILD_VDF_CLIENT", "N")
2629
.define("BUILD_PYTHON", "OFF")
30+
.define("HARDENING", if is_fuzzing || is_debug_build { "ON" } else { "OFF" })
31+
.very_verbose(true)
2732
.build();
2833

2934
println!("cargo:rustc-link-lib=static=chiavdfc");
@@ -48,6 +53,9 @@ fn main() {
4853
.to_str()
4954
.unwrap()
5055
);
56+
} else if cfg!(target_os = "macos") {
57+
println!("cargo:rustc-link-lib=static=gmp");
58+
println!("cargo:rustc-link-search=native=/opt/homebrew/lib");
5159
} else {
5260
println!("cargo:rustc-link-lib=gmp");
5361
}

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)