Skip to content

Commit 9f6ced7

Browse files
dannycjonescberner
authored andcommitted
Replace features libfuse2,libfuse3 with a dedicated build cfg value
Signed-off-by: Daniel Carl Jones <[email protected]>
1 parent f69c838 commit 9f6ced7

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

build.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,51 @@
11
fn main() {
2+
// Register rustc cfg for switching between mount implementations.
3+
// When fuser MSRV is updated to v1.77 or above, we should switch from 'cargo:' to 'cargo::' syntax.
4+
println!("cargo:rustc-check-cfg=cfg(fuser_mount_impl, values(\"pure-rust\", \"libfuse2\", \"libfuse3\"))");
5+
26
#[cfg(all(not(feature = "libfuse"), not(target_os = "linux")))]
37
unimplemented!("Building without libfuse is only supported on Linux");
48

9+
#[cfg(not(feature = "libfuse"))]
10+
{
11+
println!("cargo:rustc-cfg=fuser_mount_impl=\"pure-rust\"");
12+
}
513
#[cfg(feature = "libfuse")]
614
{
7-
#[cfg(target_os = "macos")]
8-
{
15+
if cfg!(target_os = "macos") {
916
if pkg_config::Config::new()
1017
.atleast_version("2.6.0")
1118
.probe("fuse") // for macFUSE 4.x
1219
.map_err(|e| eprintln!("{}", e))
1320
.is_ok()
1421
{
15-
println!("cargo:rustc-cfg=feature=\"libfuse2\"");
22+
println!("cargo:rustc-cfg=fuser_mount_impl=\"libfuse2\"");
1623
println!("cargo:rustc-cfg=feature=\"macfuse-4-compat\"");
1724
} else {
1825
pkg_config::Config::new()
1926
.atleast_version("2.6.0")
2027
.probe("osxfuse") // for osxfuse 3.x
2128
.map_err(|e| eprintln!("{}", e))
2229
.unwrap();
23-
println!("cargo:rustc-cfg=feature=\"libfuse2\"");
30+
println!("cargo:rustc-cfg=fuser_mount_impl=\"libfuse2\"");
2431
}
25-
}
26-
#[cfg(not(target_os = "macos"))]
27-
{
32+
} else {
2833
// First try to link with libfuse3
2934
if pkg_config::Config::new()
3035
.atleast_version("3.0.0")
3136
.probe("fuse3")
3237
.map_err(|e| eprintln!("{e}"))
3338
.is_ok()
3439
{
35-
println!("cargo:rustc-cfg=feature=\"libfuse3\"");
40+
println!("cargo:rustc-cfg=fuser_mount_impl=\"libfuse3\"");
3641
} else {
3742
// Fallback to libfuse
3843
pkg_config::Config::new()
3944
.atleast_version("2.6.0")
4045
.probe("fuse")
4146
.map_err(|e| eprintln!("{e}"))
4247
.unwrap();
43-
println!("cargo:rustc-cfg=feature=\"libfuse2\"");
48+
println!("cargo:rustc-cfg=fuser_mount_impl=\"libfuse2\"");
4449
}
4550
}
4651
}

src/mnt/fuse2_sys.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct fuse_args {
1616
pub allocated: c_int,
1717
}
1818

19-
#[cfg(feature = "libfuse2")]
19+
#[cfg(fuser_mount_impl = "libfuse2")]
2020
extern "C" {
2121
// *_compat25 functions were introduced in FUSE 2.6 when function signatures changed.
2222
// Therefore, the minimum version requirement for *_compat25 functions is libfuse-2.6.0.

src/mnt/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
//!
33
//! Raw communication channel to the FUSE kernel driver.
44
5-
#[cfg(feature = "libfuse2")]
5+
#[cfg(fuser_mount_impl = "libfuse2")]
66
mod fuse2;
77
#[cfg(any(feature = "libfuse", test))]
88
mod fuse2_sys;
9-
#[cfg(feature = "libfuse3")]
9+
#[cfg(fuser_mount_impl = "libfuse3")]
1010
mod fuse3;
11-
#[cfg(feature = "libfuse3")]
11+
#[cfg(fuser_mount_impl = "libfuse3")]
1212
mod fuse3_sys;
1313

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

18-
#[cfg(any(feature = "libfuse", test))]
18+
#[cfg(any(test, feature = "libfuse"))]
1919
use fuse2_sys::fuse_args;
2020
#[cfg(any(test, not(feature = "libfuse")))]
2121
use std::fs::File;
22-
#[cfg(any(test, not(feature = "libfuse"), not(feature = "libfuse3")))]
22+
#[cfg(any(test, fuser_mount_impl = "pure-rust", fuser_mount_impl = "libfuse2"))]
2323
use std::io;
2424

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

50-
#[cfg(feature = "libfuse2")]
50+
#[cfg(fuser_mount_impl = "libfuse2")]
5151
pub use fuse2::Mount;
52-
#[cfg(feature = "libfuse3")]
52+
#[cfg(fuser_mount_impl = "libfuse3")]
5353
pub use fuse3::Mount;
54-
#[cfg(not(feature = "libfuse"))]
54+
#[cfg(fuser_mount_impl = "pure-rust")]
5555
pub use fuse_pure::Mount;
56-
#[cfg(not(feature = "libfuse3"))]
56+
#[cfg(not(fuser_mount_impl = "libfuse3"))]
5757
use std::ffi::CStr;
5858

59-
#[cfg(not(feature = "libfuse3"))]
59+
#[cfg(not(fuser_mount_impl = "libfuse3"))]
6060
#[inline]
6161
fn libc_umount(mnt: &CStr) -> io::Result<()> {
6262
#[cfg(any(
@@ -85,7 +85,7 @@ fn libc_umount(mnt: &CStr) -> io::Result<()> {
8585

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

0 commit comments

Comments
 (0)