Skip to content

Commit

Permalink
Merge #67
Browse files Browse the repository at this point in the history
67: fix crosscompilations and support macos with zfs 2.0.1 r=jmesmon a=jmesmon



Co-authored-by: Cody P Schafer <[email protected]>
  • Loading branch information
bors[bot] and codyps committed Aug 4, 2021
2 parents 5102416 + b2d69e8 commit 7da80fa
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 60 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
on:
push:
branches-ignore:
- '**.tmp'

name: mac
jobs:
mac:
runs-on: macos-10.15
strategy:
matrix:
rust:
- stable
- beta
- nightly
- 1.48.0
steps:
- uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true

- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v1

- name: Download openzfs-on-osx
run: curl -o zfs.pkg https://openzfsonosx.org/forum/download/file.php?id=309&sid=f486243ccdc8e8e13894f14ce0b28d93

- name: Install openzfs-on-osx
run: sudo installer -verbose -pkg zfs.pkg -target /

- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --all-targets --all


87 changes: 48 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion nvpair-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
fn var(s: &str) -> Result<String, std::env::VarError> {
println!("cargo:rerun-if-env-changed={}", s);
std::env::var(s)
}

fn main() {
let target_os = var("CARGO_CFG_TARGET_OS").expect("Could not get env var CARGO_CFG_TARGET_OS");

// when using "openzfs on macos", zfs libs are installed outside the default link path. Add it
// in
// TODO: Provide a way to disable
if target_os == "macos" {
println!("cargo:rustc-link-search=native=/usr/local/zfs/lib");
}

println!("cargo:rustc-link-lib=nvpair");
// FIXME: a bug exists in some versions of libnvpair causing it to depend on a symbol called
// `aok`, which is in `libzfs`.
println!("cargo:rustc-link-lib=zfs");
// nvpair uses functions from libspl on FreeBSD
if cfg!(target_os = "freebsd") {
if target_os == "freebsd" {
println!("cargo:rustc-link-lib=spl");
};
}
22 changes: 20 additions & 2 deletions nvpair-sys/generate-bindings
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
#!/bin/sh

os=$(uname -s)
case "$os" in
Darwin)
export PKG_CONFIG_PATH=/usr/local/zfs/lib/pkgconfig
sdkpath="$(xcrun --sdk macosx --show-sdk-path)"
CFLAGS=(-I "$sdkpath/usr/include/")
;;
*)
CFLAGS=()
;;
esac

d=$(dirname $0)
bindgen "$d/wrapper.h" \
-o "$d/src/bindings.rs" \
Expand All @@ -13,10 +26,15 @@ bindgen "$d/wrapper.h" \
--whitelist-type 'nvlist.*' \
--whitelist-type 'hrtime.*' \
--whitelist-type 'data_type_.*' \
--whitelist-type 'size_t' \
--constified-enum-module '.*' \
--blacklist-type 'va_list' \
--blacklist-type '_IO_FILE' \
--blacklist-type 'FILE' \
--no-recursive-whitelist \
-- `pkg-config libzfs_core --cflags`
--raw-line \
'
// workaround for https://github.com/rust-lang/rust-bindgen/issues/1651
#[allow(unknown_lints)]
#[allow(deref_nullptr)]
pub type size_t = ::std::os::raw::c_ulong;' \
-- `pkg-config libzfs_core --cflags` "${CFLAGS[@]}"
7 changes: 6 additions & 1 deletion nvpair-sys/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen 0.55.1 */
/* automatically generated by rust-bindgen 0.59.1 */


// workaround for https://github.com/rust-lang/rust-bindgen/issues/1651
#[allow(unknown_lints)]
#[allow(deref_nullptr)]
pub type size_t = ::std::os::raw::c_ulong;

pub mod boolean_t {
pub type Type = ::std::os::raw::c_uint;
pub const B_FALSE: Type = 0;
Expand Down
2 changes: 1 addition & 1 deletion zfs-core-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2018"

[build-dependencies]
pkg-config = "0.3"
#bindgen = "0.30"
build-env = "0.3"

[dependencies]
libc = "0.2"
Expand Down
Loading

0 comments on commit 7da80fa

Please sign in to comment.