@@ -2,12 +2,17 @@ extern crate bindgen;
22extern crate cbindgen;
33
44use std:: env;
5+ use std:: fs:: File ;
6+ use std:: io:: Write ;
57use std:: path:: PathBuf ;
8+ use std:: process:: Command ;
69
710const VERSION : & ' static str = env ! ( "CARGO_PKG_VERSION" ) ;
811
912fn main ( ) {
1013 let crate_dir = std:: env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ;
14+ let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
15+ let target_path = out_path. join ( "../../.." ) ;
1116
1217 let cfg = cbindgen:: Config :: from_root_or_default ( std:: path:: Path :: new ( & crate_dir) ) ;
1318
@@ -22,7 +27,7 @@ fn main() {
2227 // but rather just tell the rest of the system we can't proceed.
2328 match c {
2429 Ok ( res) => {
25- res. write_to_file ( "libfilecoin_proofs.h" ) ;
30+ res. write_to_file ( target_path . join ( "libfilecoin_proofs.h" ) ) ;
2631 }
2732 Err ( err) => {
2833 eprintln ! ( "unable to generate bindings: {:?}" , err) ;
@@ -31,7 +36,7 @@ fn main() {
3136 }
3237
3338 let b = bindgen:: builder ( )
34- . header ( "libfilecoin_proofs.h" )
39+ . header ( target_path . join ( "libfilecoin_proofs.h" ) . to_string_lossy ( ) )
3540 // Here, we tell Rust to link libfilecoin_proofs so that auto-generated
3641 // symbols are linked to symbols in the compiled dylib. For reasons
3742 // unbeknown to me, the link attribute needs to precede an extern block.
@@ -40,8 +45,6 @@ fn main() {
4045
4146 match b {
4247 Ok ( res) => {
43- let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
44-
4548 res. write_to_file ( out_path. join ( "libfilecoin_proofs.rs" ) )
4649 . expect ( "could not write file" ) ;
4750 }
@@ -50,4 +53,38 @@ fn main() {
5053 std:: process:: exit ( 1 ) ;
5154 }
5255 }
56+
57+ let git_output = Command :: new ( "git" )
58+ . args ( & [ "rev-parse" , "HEAD" ] )
59+ . output ( )
60+ . unwrap ( ) ;
61+ let git_hash = String :: from_utf8 ( git_output. stdout ) . unwrap ( ) ;
62+
63+ let libs = if cfg ! ( target_os = "linux" ) {
64+ "-lutil -lutil -ldl -lrt -lpthread -lgcc_s -lc -lm -lrt -lpthread -lutil -lutil"
65+ } else if cfg ! ( target_os = "macos" ) {
66+ "-framework Security -lSystem -lresolv -lc -lm"
67+ } else {
68+ ""
69+ } ;
70+
71+ let mut pc_file = File :: create ( target_path. join ( "libfilecoin_proofs.pc" ) )
72+ . expect ( "unable to generate .pc file: {:?}" ) ;
73+
74+ write ! (
75+ pc_file,
76+ "prefix=/usr/local
77+ libdir=${{prefix}}/lib
78+ includedir=${{prefix}}/include
79+
80+ Name: libfilecoin_proofs
81+ Version: {version}
82+ Description: rust-proofs library
83+ Libs: -L${{libdir}} -lfilecoin_proofs {libs}
84+ Cflags: -I${{includedir}}
85+ " ,
86+ version = git_hash. trim( ) ,
87+ libs = libs
88+ )
89+ . expect ( "unable to write to .pc file: {:?}" ) ;
5390}
0 commit comments