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

Commit f8ba55d

Browse files
committed
Update build system to support ZFS in FreeBSD 11.2
ZoL `master` (2e5dc449c1a65e0b0bf730fd69c9b5804bd57ee8) and FreeBSD 11.2 have compatible libzfs APIs but FreeBSD lacks pkg-config and has different ZFS source include directories. Fixes #63. Signed-off-by: David Sheets <sheets@alum.mit.edu>
1 parent cf5f07b commit f8ba55d

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

libzfs-sys/build.rs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ use std::process::{Command, Stdio};
1313
fn main() {
1414
let out_file = env::current_dir().unwrap().join("src").join("bindings.rs");
1515

16-
let libzfs = pkg_config::Config::new().probe("libzfs").unwrap();
17-
println!("cargo:rustc-link-lib=zpool");
18-
1916
let bindings = bindgen::Builder::default()
2017
.header("wrapper.h")
2118
.constified_enum_module("boolean_t")
@@ -92,17 +89,35 @@ fn main() {
9289
.whitelist_function("zfs_validate_name")
9390
.whitelist_function("zprop_free_list");
9491

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/")
92+
let bindings = if cfg!(target_os = "freebsd") {
93+
println!("cargo:rustc-link-lib=zfs");
94+
// a subset of include paths in cddl/sbin/zfs/Makefile
95+
bindings
96+
.clang_arg("-I/usr/src/cddl/compat/opensolaris/include")
97+
.clang_arg("-I/usr/src/cddl/compat/opensolaris/lib/libumem")
98+
.clang_arg("-I/usr/src/cddl/contrib/opensolaris/head")
99+
.clang_arg("-I/usr/src/cddl/contrib/opensolaris/lib/libuutil/common")
100+
.clang_arg("-I/usr/src/cddl/contrib/opensolaris/lib/libzfs/common")
101+
.clang_arg("-I/usr/src/cddl/contrib/opensolaris/lib/libzpool/common")
102+
.clang_arg("-I/usr/src/sys/cddl/compat/opensolaris")
103+
.clang_arg("-I/usr/src/sys/cddl/contrib/opensolaris/uts/common")
104+
.clang_arg("-I/usr/src/sys/cddl/contrib/opensolaris/uts/common/fs/zfs")
105+
.clang_arg("-I/usr/src/sys/cddl/contrib/opensolaris/common/zfs")
106+
} else {
107+
let libzfs = pkg_config::Config::new().probe("libzfs").unwrap();
108+
list_gcc_include_paths()
109+
.chain(libzfs.include_paths)
110+
.fold(bindings, |bindings, include_path| {
111+
let flag = format!("-I{}", include_path.to_string_lossy());
112+
bindings.clang_arg(flag)
113+
})
114+
// include directory for zfsonlinux/zfs master branch
115+
.clang_arg("-I/usr/src/zfs-0.7.0/include/")
116+
};
103117

104-
.generate()
105-
.expect("Unable to generate bindings");
118+
let bindings = bindings.generate().expect("Unable to generate bindings");
119+
120+
println!("cargo:rustc-link-lib=zpool");
106121

107122
// Write bindings to src.
108123
bindings

libzfs-sys/wrapper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44

55
#define _LARGEFILE64_SOURCE
66

7+
#define NEED_SOLARIS_BOOLEAN
8+
79
#include <libzfs_impl.h>

0 commit comments

Comments
 (0)