Skip to content

Commit

Permalink
Add build cfg for FUSE mounting implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Carl Jones <[email protected]>
  • Loading branch information
dannycjones committed Nov 6, 2024
1 parent e7dfd3b commit 8d9e2ac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
23 changes: 12 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
fn main() {
// Register rustc cfg for switching between mount implementations
println!("cargo::rustc-check-cfg=cfg(fuser_mount_impl, values(\"pure-rust\", \"libfuse2\", \"libfuse3\"))");

#[cfg(all(not(feature = "libfuse"), not(target_os = "linux")))]
unimplemented!("Building without libfuse is only supported on Linux");

#[cfg(feature = "libfuse")]
{
#[cfg(target_os = "macos")]
{
if cfg!(feature = "libfuse") {
if cfg!(target_os = "macos") {
if pkg_config::Config::new()
.atleast_version("2.6.0")
.probe("fuse") // for macFUSE 4.x
.map_err(|e| eprintln!("{}", e))
.is_ok()
{
println!("cargo:rustc-cfg=feature=\"libfuse2\"");
println!("cargo:rustc-cfg=fuser_mount_impl=\"libfuse2\"");
println!("cargo:rustc-cfg=feature=\"macfuse-4-compat\"");
} else {
pkg_config::Config::new()
.atleast_version("2.6.0")
.probe("osxfuse") // for osxfuse 3.x
.map_err(|e| eprintln!("{}", e))
.unwrap();
println!("cargo:rustc-cfg=feature=\"libfuse2\"");
println!("cargo:rustc-cfg=fuser_mount_impl=\"libfuse2\"");
}
}
#[cfg(not(target_os = "macos"))]
{
} else {
// First try to link with libfuse3
if pkg_config::Config::new()
.atleast_version("3.0.0")
.probe("fuse3")
.map_err(|e| eprintln!("{e}"))
.is_ok()
{
println!("cargo:rustc-cfg=feature=\"libfuse3\"");
println!("cargo:rustc-cfg=fuser_mount_impl=\"libfuse3\"");
} else {
// Fallback to libfuse
pkg_config::Config::new()
.atleast_version("2.6.0")
.probe("fuse")
.map_err(|e| eprintln!("{e}"))
.unwrap();
println!("cargo:rustc-cfg=feature=\"libfuse2\"");
println!("cargo:rustc-cfg=fuser_mount_impl=\"libfuse2\"");
}
}
} else {
println!("cargo:rustc-cfg=fuser_mount_impl=\"pure-rust\"");
}
}
2 changes: 1 addition & 1 deletion src/mnt/fuse2_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct fuse_args {
pub allocated: c_int,
}

#[cfg(feature = "libfuse2")]
#[cfg(fuser_mount_impl = "libfuse2")]
extern "C" {
// *_compat25 functions were introduced in FUSE 2.6 when function signatures changed.
// Therefore, the minimum version requirement for *_compat25 functions is libfuse-2.6.0.
Expand Down
24 changes: 12 additions & 12 deletions src/mnt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
//!
//! Raw communication channel to the FUSE kernel driver.
#[cfg(feature = "libfuse2")]
#[cfg(fuser_mount_impl = "libfuse2")]
mod fuse2;
#[cfg(any(feature = "libfuse", test))]
mod fuse2_sys;
#[cfg(feature = "libfuse3")]
#[cfg(fuser_mount_impl = "libfuse3")]
mod fuse3;
#[cfg(feature = "libfuse3")]
#[cfg(fuser_mount_impl = "libfuse3")]
mod fuse3_sys;

#[cfg(not(feature = "libfuse"))]
#[cfg(fuser_mount_impl = "pure-rust")]
mod fuse_pure;
pub mod mount_options;

#[cfg(any(feature = "libfuse", test))]
#[cfg(any(test, feature = "libfuse"))]
use fuse2_sys::fuse_args;
#[cfg(any(test, not(feature = "libfuse")))]
use std::fs::File;
#[cfg(any(test, not(feature = "libfuse"), not(feature = "libfuse3")))]
#[cfg(any(test, fuser_mount_impl = "pure-rust", fuser_mount_impl = "libfuse2"))]
use std::io;

#[cfg(any(feature = "libfuse", test))]
Expand Down Expand Up @@ -47,16 +47,16 @@ fn with_fuse_args<T, F: FnOnce(&fuse_args) -> T>(options: &[MountOption], f: F)
})
}

#[cfg(feature = "libfuse2")]
#[cfg(fuser_mount_impl = "libfuse2")]
pub use fuse2::Mount;
#[cfg(feature = "libfuse3")]
#[cfg(fuser_mount_impl = "libfuse3")]
pub use fuse3::Mount;
#[cfg(not(feature = "libfuse"))]
#[cfg(fuser_mount_impl = "pure-rust")]
pub use fuse_pure::Mount;
#[cfg(not(feature = "libfuse3"))]
#[cfg(not(fuser_mount_impl = "libfuse3"))]
use std::ffi::CStr;

#[cfg(not(feature = "libfuse3"))]
#[cfg(not(fuser_mount_impl = "libfuse3"))]
#[inline]
fn libc_umount(mnt: &CStr) -> io::Result<()> {
#[cfg(any(
Expand Down Expand Up @@ -87,7 +87,7 @@ fn libc_umount(mnt: &CStr) -> io::Result<()> {

/// Warning: This will return true if the filesystem has been detached (lazy unmounted), but not
/// yet destroyed by the kernel.
#[cfg(any(test, not(feature = "libfuse")))]
#[cfg(any(test, fuser_mount_impl = "pure-rust"))]
fn is_mounted(fuse_device: &File) -> bool {
use libc::{poll, pollfd};
use std::os::unix::prelude::AsRawFd;
Expand Down

0 comments on commit 8d9e2ac

Please sign in to comment.