Skip to content

Commit 2dec213

Browse files
authored
Merge pull request #434 from filecoin-project/chores/generate-native-dependencies-432
generate native dependencies
2 parents 6d5c880 + 41a1b12 commit 2dec213

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

filecoin-proofs/.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
**/*.rs.bk
33
Cargo.lock
44
.criterion
5-
**/libproofs.h
6-
heaptrack*
5+
heaptrack*

filecoin-proofs/build.rs

Lines changed: 41 additions & 4 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

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

scripts/publish-release.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
RELEASE_BRANCH="master"
4-
RELEASE_NAME="$CIRCLE_PROJECT_REPONAME-$(uname)"
4+
RELEASE_NAME="$CIRCLE_PROJECT_REPONAME-`uname`"
55
RELEASE_PATH="$CIRCLE_ARTIFACTS/$RELEASE_NAME"
66
RELEASE_FILE="$RELEASE_PATH.tar.gz"
77
RELEASE_TAG="${CIRCLE_SHA1:0:16}"
@@ -23,11 +23,12 @@ echo "preparing release file"
2323
mkdir $RELEASE_PATH
2424
mkdir $RELEASE_PATH/bin
2525
mkdir $RELEASE_PATH/include
26-
mkdir $RELEASE_PATH/lib
26+
mkdir -p $RELEASE_PATH/lib/pkgconfig
2727

2828
cp target/release/paramcache $RELEASE_PATH/bin/
29-
cp filecoin-proofs/libfilecoin_proofs.h $RELEASE_PATH/include/
29+
cp target/release/libfilecoin_proofs.h $RELEASE_PATH/include/
3030
cp target/release/libfilecoin_proofs.a $RELEASE_PATH/lib/
31+
cp target/release/libfilecoin_proofs.pc $RELEASE_PATH/lib/pkgconfig
3132

3233
pushd $RELEASE_PATH
3334

0 commit comments

Comments
 (0)