Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit cf5f07b

Browse files
committed
Generalize build system and update for ZoL master
The LIBCLANG_PATH environment variable was unused, the 'boolean' enum is anonymous and typedef'd to 'boolean_t', the ZoL-specific 'thread_init' and 'thread_fini' have disappeared, gcc is now queried for system include paths, and the include paths of the libzfs pkg-config are now used. Signed-off-by: David Sheets <sheets@alum.mit.edu>
1 parent 30f5771 commit cf5f07b

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

libzfs-sys/build.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ extern crate bindgen;
66
extern crate pkg_config;
77

88
use std::env;
9+
use std::io::{BufRead, BufReader};
10+
use std::path::PathBuf;
11+
use std::process::{Command, Stdio};
912

1013
fn main() {
1114
let out_file = env::current_dir().unwrap().join("src").join("bindings.rs");
1215

13-
env::set_var("LIBCLANG_PATH", "/opt/llvm-5.0.0/lib64/");
14-
15-
pkg_config::Config::new().probe("libzfs").unwrap();
16+
let libzfs = pkg_config::Config::new().probe("libzfs").unwrap();
1617
println!("cargo:rustc-link-lib=zpool");
1718

1819
let bindings = bindgen::Builder::default()
1920
.header("wrapper.h")
20-
.constified_enum_module("boolean")
21+
.constified_enum_module("boolean_t")
2122
.whitelist_var("vdev_stat_t")
2223
.whitelist_type("vdev_stat_t")
2324
.whitelist_var("ZPOOL_MAXPROPLEN")
@@ -61,8 +62,6 @@ fn main() {
6162
.blacklist_type("nvlist")
6263
.whitelist_function("libzfs_init")
6364
.whitelist_function("libzfs_fini")
64-
.whitelist_function("thread_init")
65-
.whitelist_function("thread_fini")
6665
.whitelist_function("zpool_import")
6766
.whitelist_function("zpool_export")
6867
.whitelist_function("zpool_find_import")
@@ -91,10 +90,17 @@ fn main() {
9190
.whitelist_function("zfs_expand_proplist")
9291
.whitelist_function("zfs_prop_to_name")
9392
.whitelist_function("zfs_validate_name")
94-
.whitelist_function("zprop_free_list")
95-
.clang_arg("-I/usr/lib/gcc/x86_64-redhat-linux/4.8.2/include/")
96-
.clang_arg("-I/usr/src/zfs-0.7.9/lib/libspl/include/")
97-
.clang_arg("-I/usr/src/zfs-0.7.9/include/")
93+
.whitelist_function("zprop_free_list");
94+
95+
let bindings = list_gcc_include_paths()
96+
.chain(libzfs.include_paths)
97+
.fold(bindings, |bindings, include_path| {
98+
let flag = format!("-I{}", include_path.to_string_lossy());
99+
bindings.clang_arg(flag)
100+
})
101+
// include directory for zfsonlinux/zfs master branch
102+
.clang_arg("-I/usr/src/zfs-0.7.0/include/")
103+
98104
.generate()
99105
.expect("Unable to generate bindings");
100106

@@ -103,3 +109,18 @@ fn main() {
103109
.write_to_file(out_file)
104110
.expect("Couldn't write bindings!");
105111
}
112+
113+
fn list_gcc_include_paths() -> impl Iterator<Item = PathBuf> {
114+
let script_path = "./list_gcc_include_paths.sh";
115+
let child = Command::new(script_path)
116+
.stdout(Stdio::piped())
117+
.spawn()
118+
.expect(&format!("Unable to spawn {}", script_path));
119+
120+
match child.stdout {
121+
Some(stdout) =>
122+
BufReader::new(stdout).lines()
123+
.map(|line| PathBuf::from(line.unwrap())),
124+
None => panic!("Couldn't read from {}", script_path),
125+
}
126+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
gcc -Wp,-v -x c - -fsyntax-only < /dev/null 2>&1 | grep '^ ' | sed -e 's/^ //'

libzfs/src/libzfs.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ impl Libzfs {
6060
pub fn find_importable_pools(&mut self) -> nvpair::NvList {
6161
let _l = LOCK.lock().unwrap();
6262
unsafe {
63-
sys::thread_init();
6463
let x = sys::zpool_find_import(self.raw, 0, ptr::null_mut());
65-
sys::thread_fini();
6664

6765
nvpair::NvList::from_ptr(x)
6866
}

libzfs/src/zfs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ impl Zfs {
4747
sys::zfs_expand_proplist(
4848
self.raw,
4949
&mut prop_list_ptr,
50-
sys::boolean::B_TRUE,
51-
sys::boolean::B_TRUE,
50+
sys::boolean_t::B_TRUE,
51+
sys::boolean_t::B_TRUE,
5252
)
5353
};
5454

@@ -62,7 +62,7 @@ impl Zfs {
6262
let pl = self.prop_list()?;
6363

6464
let xs = pl.filter_map(|x: ZpropItem| match x.prop() {
65-
sys::zfs_prop_t_ZFS_PROP_BAD => self.user_props()
65+
sys::zfs_prop_t_ZPROP_INVAL => self.user_props()
6666
.lookup_nv_list(x.user_prop())
6767
.and_then(|nv| nv.lookup_string(sys::zprop_value()))
6868
.map(|v| ZProp {
@@ -82,7 +82,7 @@ impl Zfs {
8282
ptr::null_mut(),
8383
ptr::null_mut(),
8484
0,
85-
sys::boolean::B_TRUE,
85+
sys::boolean_t::B_TRUE,
8686
)
8787
};
8888

libzfs/src/zpool.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl Zpool {
5656
raw,
5757
sys::ZPOOL_MAXPROPLEN as usize,
5858
ptr::null_mut(),
59-
sys::boolean::B_FALSE,
59+
sys::boolean_t::B_FALSE,
6060
);
6161

6262
let out = CString::from_raw(raw);
@@ -141,15 +141,15 @@ impl Zpool {
141141
}
142142
}
143143
pub fn disable_datasets(&self) -> Result<()> {
144-
let code = unsafe { sys::zpool_disable_datasets(self.raw, sys::boolean::B_FALSE) };
144+
let code = unsafe { sys::zpool_disable_datasets(self.raw, sys::boolean_t::B_FALSE) };
145145

146146
match code {
147147
0 => Ok(()),
148148
e => Err(LibZfsError::Io(Error::from_raw_os_error(e))),
149149
}
150150
}
151151
pub fn export(&self) -> Result<()> {
152-
let code = unsafe { sys::zpool_export(self.raw, sys::boolean::B_FALSE, ptr::null_mut()) };
152+
let code = unsafe { sys::zpool_export(self.raw, sys::boolean_t::B_FALSE, ptr::null_mut()) };
153153

154154
match code {
155155
0 => Ok(()),

0 commit comments

Comments
 (0)