Skip to content

Commit 29ac282

Browse files
author
Sidney Keese
committed
generate .pc file in build.rs
1 parent 236e2fa commit 29ac282

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

filecoin-proofs/build.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ extern crate bindgen;
22
extern crate cbindgen;
33

44
use std::env;
5+
use std::fs::File;
6+
use std::io::Write;
57
use std::path::PathBuf;
8+
use std::process::Command;
69

710
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
811

912
fn 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

@@ -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
}

scripts/publish-release.sh

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,10 @@ mkdir $RELEASE_PATH/bin
2525
mkdir $RELEASE_PATH/include
2626
mkdir -p $RELEASE_PATH/lib/pkgconfig
2727

28-
# pkg-config .pc file generation
29-
case `uname` in
30-
"Darwin")
31-
RELEASE_LIBS="-framework Security -lSystem -lresolv -lc -lm"
32-
;;
33-
"Linux")
34-
RELEASE_LIBS="-lutil -lutil -ldl -lrt -lpthread -lgcc_s -lc -lm -lrt -lpthread -lutil -lutil"
35-
;;
36-
*)
37-
echo "unknown system libraries for architecture"
38-
;;
39-
esac
40-
41-
echo "libdir=\${prefix}/lib
42-
includedir=\${prefix}/include
43-
44-
Name: libfilecoin_proofs
45-
Version: $RELEASE_TAG
46-
Description: rust-proofs library
47-
Libs: -L\${libdir} -lfilecoin_proofs $RELEASE_LIBS
48-
Cflags: -I\${includedir}" > $RELEASE_PATH/lib/pkgconfig/libfilecoin_proofs.pc
49-
5028
cp target/release/paramcache $RELEASE_PATH/bin/
5129
cp filecoin-proofs/libfilecoin_proofs.h $RELEASE_PATH/include/
5230
cp target/release/libfilecoin_proofs.a $RELEASE_PATH/lib/
31+
cp target/release/libfilecoin_proofs.pc $RELEASE_PATH/lib/pkgconfig
5332

5433
pushd $RELEASE_PATH
5534

0 commit comments

Comments
 (0)