Skip to content

Commit

Permalink
Static lib and cc for wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Aug 13, 2024
1 parent e89180e commit 33a653e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ IF (BUILD_PROOF_OF_SPACE_STATICALLY)
target_link_libraries(ProofOfSpace PUBLIC -static -Wl,--whole-archive -lrt -lpthread -Wl,--no-whole-archive)
ENDIF()

option(BUILD_STATIC_CHIAPOS_LIBRARY "Build chiapos library statically" OFF)
IF (BUILD_STATIC_CHIAPOS_LIBRARY)
message("Statically build chiapos library")
add_library(chiapos_static STATIC src/chacha8.c src/verifier.hpp)
ENDIF()

FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
Expand Down
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ link-cplusplus = "1.0.9"
[build-dependencies]
bindgen = "0.69.4"
cmake = "0.1.50"
cc = "1.1.10"

[dev-dependencies]
34 changes: 22 additions & 12 deletions rust-bindings/build.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
use std::env;
use std::path::PathBuf;

use cc::Build;
use cmake::Config;

fn main() {
println!("cargo:rerun-if-changed=wrapper.h");
println!("cargo:rerun-if-changed=wrapper.cpp");
println!("cargo:rerun-if-changed=../CMakeLists.txt");

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

let dst = Config::new(manifest_dir.parent().unwrap())
.build_target("chiapos")
.define("BUILD_PROOF_OF_SPACE_STATICALLY", "ON")
.build_target("chiapos_static")
.define("BUILD_STATIC_CHIAPOS_LIBRARY", "ON")
.build();

let blake3_include_path = dst.join("build").join("_deps").join("blake3-src").join("c");

println!(
"cargo:rustc-link-search=native={}",
dst.join("build")
.join("lib")
.join("static")
.to_str()
.unwrap()
dst.join("build").to_str().unwrap()
);

println!("cargo:rustc-link-lib=static=chiapos");
println!("cargo:rustc-link-lib=static=chiapos_static");

Build::new()
.cpp(true)
.file(manifest_dir.join("wrapper.cpp"))
.include(
manifest_dir
.parent()
.unwrap()
.join("lib")
.join("include")
.to_str()
.unwrap(),
)
.include(blake3_include_path.to_str().unwrap())
.std("c++14")
.compile("wrapper");

let bindings = bindgen::Builder::default()
.header(manifest_dir.join("wrapper.h").to_str().unwrap())
.clang_arg("-x")
.clang_arg("c++")
.clang_arg(format!(
"-I{}",
manifest_dir.join("wrapper.cpp").to_str().unwrap()
))
.clang_arg(format!(
"-I{}",
manifest_dir
Expand Down

0 comments on commit 33a653e

Please sign in to comment.