@@ -2,12 +2,17 @@ extern crate bindgen;
2
2
extern crate cbindgen;
3
3
4
4
use std:: env;
5
+ use std:: fs:: File ;
6
+ use std:: io:: Write ;
5
7
use std:: path:: PathBuf ;
8
+ use std:: process:: Command ;
6
9
7
10
const VERSION : & ' static str = env ! ( "CARGO_PKG_VERSION" ) ;
8
11
9
12
fn main ( ) {
10
13
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 ( "../../.." ) ;
11
16
12
17
let cfg = cbindgen:: Config :: from_root_or_default ( std:: path:: Path :: new ( & crate_dir) ) ;
13
18
@@ -22,7 +27,7 @@ fn main() {
22
27
// but rather just tell the rest of the system we can't proceed.
23
28
match c {
24
29
Ok ( res) => {
25
- res. write_to_file ( "libfilecoin_proofs.h" ) ;
30
+ res. write_to_file ( target_path . join ( "libfilecoin_proofs.h" ) ) ;
26
31
}
27
32
Err ( err) => {
28
33
eprintln ! ( "unable to generate bindings: {:?}" , err) ;
@@ -31,7 +36,7 @@ fn main() {
31
36
}
32
37
33
38
let b = bindgen:: builder ( )
34
- . header ( "libfilecoin_proofs.h" )
39
+ . header ( target_path . join ( "libfilecoin_proofs.h" ) . to_string_lossy ( ) )
35
40
// Here, we tell Rust to link libfilecoin_proofs so that auto-generated
36
41
// symbols are linked to symbols in the compiled dylib. For reasons
37
42
// unbeknown to me, the link attribute needs to precede an extern block.
@@ -40,8 +45,6 @@ fn main() {
40
45
41
46
match b {
42
47
Ok ( res) => {
43
- let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
44
-
45
48
res. write_to_file ( out_path. join ( "libfilecoin_proofs.rs" ) )
46
49
. expect ( "could not write file" ) ;
47
50
}
@@ -50,4 +53,38 @@ fn main() {
50
53
std:: process:: exit ( 1 ) ;
51
54
}
52
55
}
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: {:?}" ) ;
53
90
}
0 commit comments