Skip to content

Commit

Permalink
build: use rust stable for linting
Browse files Browse the repository at this point in the history
Nightly clippy is no longer required, so we can remove its
requirement and thus simplify the devel rather than require using both
stable and nightly compiler.
Nightly fmt is still required, but since the options we need are still not
stable, I think it's better to drop them for a more mainstream approach.
This should also reduce the target/debug size as there'll be only
builds from one compiler.

Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro committed Nov 21, 2024
1 parent 2578b43 commit 1821cfe
Show file tree
Hide file tree
Showing 33 changed files with 159 additions and 509 deletions.
15 changes: 0 additions & 15 deletions .rustfmt.toml

This file was deleted.

20 changes: 4 additions & 16 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ fn rust_fmt_nightly() -> Option<PathBuf> {
fn get_spdk_path() -> Result<PathBuf, Error> {
let spdk_path = match env::var_os("SPDK_ROOT_DIR") {
Some(s) => {
println!(
"SPDK_ROOT_DIR variable is set to {}",
s.to_str().unwrap()
);
println!("SPDK_ROOT_DIR variable is set to {}", s.to_str().unwrap());
PathBuf::from(s)
}
None => {
Expand Down Expand Up @@ -122,10 +119,7 @@ fn configure_spdk() -> Result<LibraryConfig, Error> {
spdk_path.join("include/spdk/module"),
spdk_path.join("module"),
)?;
spdk_lib.add_inc_alt(
spdk_path.join("include/spdk/lib"),
spdk_path.join("lib"),
)?;
spdk_lib.add_inc_alt(spdk_path.join("include/spdk/lib"), spdk_path.join("lib"))?;
spdk_lib.add_inc_alt(
spdk_path.join("include/spdk/lib/ftl"),
spdk_path.join("lib/ftl"),
Expand Down Expand Up @@ -240,11 +234,7 @@ where
src_files.push(p);
}
}
Err(e) => {
return Err(Error::Generic(format!(
"Bad SPDK helper source {s}: {e}"
)))
}
Err(e) => return Err(Error::Generic(format!("Bad SPDK helper source {s}: {e}"))),
}
}

Expand Down Expand Up @@ -355,9 +345,7 @@ fn main() {
.prepend_enum_name(false)
.size_t_is_usize(false)
.generate_inline_functions(true)
.parse_callbacks(Box::new(MacroCallback {
macros,
}));
.parse_callbacks(Box::new(MacroCallback { macros }));

// Use nightly rustfmt if it is possible.
let bindings = if let Some(rust_fmt) = rust_fmt_nightly() {
Expand Down
53 changes: 16 additions & 37 deletions build_helpers/library_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,19 @@ impl Display for Library {

impl Library {
/// Creates a new `Library` instance.
fn new<U: AsRef<OsStr>, V: AsRef<OsStr>>(
name: U,
parent_name: V,
cfg: &LibraryConfig,
) -> Self {
fn new<U: AsRef<OsStr>, V: AsRef<OsStr>>(name: U, parent_name: V, cfg: &LibraryConfig) -> Self {
let pkg_name = name.as_ref().to_str().unwrap();

let (lib_name, is_ar) =
if pkg_name.starts_with(":lib") && pkg_name.ends_with(".a") {
let s = pkg_name
.strip_prefix(":lib")
.unwrap()
.strip_suffix(".a")
.unwrap();
(OsString::from(&s), true)
} else {
(OsString::from(&pkg_name), false)
};
let (lib_name, is_ar) = if pkg_name.starts_with(":lib") && pkg_name.ends_with(".a") {
let s = pkg_name
.strip_prefix(":lib")
.unwrap()
.strip_suffix(".a")
.unwrap();
(OsString::from(&s), true)
} else {
(OsString::from(&pkg_name), false)
};

let is_system = cfg.marked_system.contains(&lib_name);

Expand All @@ -153,10 +148,7 @@ impl Library {
/// Prints Cargo link instructions.
fn cargo(&self) {
if self.is_system {
println!(
"cargo:rustc-link-lib={}",
self.lib_name.to_str().unwrap()
);
println!("cargo:rustc-link-lib={}", self.lib_name.to_str().unwrap());
} else {
// Use 'whole-archive' flag on non-system libs.
println!(
Expand Down Expand Up @@ -224,16 +216,10 @@ impl LibraryConfig {
/// Adds a new pkg_config search path. The path must exist on the file
/// system.
#[allow(dead_code)]
pub fn add_pkg_cfg_path<T: AsRef<Path>>(
&self,
new_path: T,
) -> Result<(), Error> {
pub fn add_pkg_cfg_path<T: AsRef<Path>>(&self, new_path: T) -> Result<(), Error> {
match fs::canonicalize(&new_path) {
Ok(cp) => {
println!(
"Added PKG_CONFIG_PATH_FOR_TARGET: {}",
cp.to_str().unwrap()
);
println!("Added PKG_CONFIG_PATH_FOR_TARGET: {}", cp.to_str().unwrap());
append_path_var(OsStr::new("PKG_CONFIG_PATH_FOR_TARGET"), &cp);
Ok(())
}
Expand Down Expand Up @@ -314,10 +300,7 @@ impl LibraryConfig {
}

/// Finds a library via pkg_config.
pub fn find_lib<T: AsRef<OsStr>>(
&mut self,
lib_name: T,
) -> Result<(), Error> {
pub fn find_lib<T: AsRef<OsStr>>(&mut self, lib_name: T) -> Result<(), Error> {
let lib_name = OsString::from(&lib_name);
let library = self.cfg.probe(lib_name.to_str().unwrap())?;

Expand Down Expand Up @@ -425,11 +408,7 @@ impl LibraryConfig {

/// Builds a shared (.so) library from all the libraries found previously.
#[allow(dead_code)]
pub fn build_shared_lib(
&self,
out_dir: &Path,
lib_name: &OsStr,
) -> Result<PathBuf, Error> {
pub fn build_shared_lib(&self, out_dir: &Path, lib_name: &OsStr) -> Result<PathBuf, Error> {
let mut tool = Tool::new()?;

tool.add_flag("shared");
Expand Down
5 changes: 1 addition & 4 deletions build_helpers/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ impl Tool {
}

/// Creates a shared library path from the given directory and library name.
pub fn make_shared_lib_path(
out_dir: &Path,
lib_name: &OsStr,
) -> Result<PathBuf, Error> {
pub fn make_shared_lib_path(out_dir: &Path, lib_name: &OsStr) -> Result<PathBuf, Error> {
let lib_path = &format!("lib{}.so", lib_name.to_str().unwrap());
let res = out_dir.to_path_buf().join(lib_path);
Ok(res)
Expand Down
10 changes: 2 additions & 8 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ use std::{
};

use spdk_rs::libspdk::{
size_t,
spdk_app_fini,
spdk_app_opts,
spdk_app_opts_init,
spdk_app_parse_args,
spdk_app_start,
spdk_app_stop,
SPDK_APP_PARSE_ARGS_SUCCESS,
size_t, spdk_app_fini, spdk_app_opts, spdk_app_opts_init, spdk_app_parse_args, spdk_app_start,
spdk_app_stop, SPDK_APP_PARSE_ARGS_SUCCESS,
};

extern "C" fn hello_world_parse_arg(_ch: c_int, _arg: *mut c_char) -> c_int {
Expand Down
2 changes: 1 addition & 1 deletion nix/shell/rust.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let

shellEnv = {
# Path to nightly Rust, needed for linter and style.
RUST_NIGHTLY_PATH = rustChannels.nightly;
# RUST_NIGHTLY_PATH = rustChannels.nightly;

# Path to debug output dir.
RUST_TARGET_DEBUG = "target/debug";
Expand Down
8 changes: 4 additions & 4 deletions scripts/rust-linter-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ fi
# rustfmt and clippy "2021-11-29".
# When upgrading Rust toolchain version, check 'cargo --version',
# 'cargo fmt --version', 'cargo clippy --version' and put them here.
RUST_TOOLCHAIN_VER="2024-10-30"
WANTED_CARGO_VER="cargo 1.84.0-nightly (* 2024-10-25)"
WANTED_RUSTFMT_VER="rustfmt 1.8.0-nightly (* 2024-10-29)"
WANTED_CLIPPY_VER="clippy 0.1.84 (* 2024-10-29)"
RUST_TOOLCHAIN_VER=${RUST_TOOLCHAIN_VER:-"1.82.0"}
WANTED_CARGO_VER=${WANTED_CARGO_VER:-"cargo 1.82.0 (* 2024-08-21)"}
WANTED_RUSTFMT_VER=${WANTED_RUSTFMT_VER:-"rustfmt 1.7.1-stable (* 2024-10-15)"}
WANTED_CLIPPY_VER=${WANTED_CLIPPY_VER:-"clippy 0.1.82 (* 2024-10-15)"}
CARGO="cargo"
CARGO_MODE="system"

Expand Down
63 changes: 13 additions & 50 deletions src/bdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,15 @@ use std::{
use nix::errno::Errno;

use crate::{
ffihelper::{
errno_result_from_i32,
AsStr,
ErrnoResult,
FfiResult,
IntoCString,
},
ffihelper::{errno_result_from_i32, AsStr, ErrnoResult, FfiResult, IntoCString},
libspdk::{
spdk_bdev,
spdk_bdev_alias_add,
spdk_bdev_alias_del,
spdk_bdev_fn_table,
spdk_bdev_get_aliases,
spdk_bdev_get_buf_align,
spdk_bdev_get_by_name,
spdk_bdev_has_write_cache,
spdk_bdev_io_type_supported,
spdk_bdev_module,
spdk_bdev_module_release_bdev,
spdk_bdev_register,
spdk_bdev_unregister,
SPDK_BDEV_CLAIM_EXCL_WRITE,
SPDK_BDEV_CLAIM_NONE,
spdk_bdev, spdk_bdev_alias_add, spdk_bdev_alias_del, spdk_bdev_fn_table,
spdk_bdev_get_aliases, spdk_bdev_get_buf_align, spdk_bdev_get_by_name,
spdk_bdev_has_write_cache, spdk_bdev_io_type_supported, spdk_bdev_module,
spdk_bdev_module_release_bdev, spdk_bdev_register, spdk_bdev_unregister,
SPDK_BDEV_CLAIM_EXCL_WRITE, SPDK_BDEV_CLAIM_NONE,
},
BdevIo,
BdevModule,
BdevOps,
IoChannel,
IoDevice,
IoType,
Thread,
Uuid,
BdevIo, BdevModule, BdevOps, IoChannel, IoDevice, IoType, Thread, Uuid,
};

/// Wrapper for SPDK `spdk_bdev` structure and the related API.
Expand Down Expand Up @@ -80,11 +57,7 @@ where
/// TODO
pub fn unregister_bdev(&mut self) {
unsafe {
spdk_bdev_unregister(
self.as_inner_ptr(),
None,
null_mut::<c_void>(),
);
spdk_bdev_unregister(self.as_inner_ptr(), None, null_mut::<c_void>());
}
}

Expand Down Expand Up @@ -193,21 +166,15 @@ where
/// If the alias is already present we return true
pub fn add_alias(&mut self, alias: &str) -> bool {
let alias = alias.into_cstring();
let ret =
unsafe { spdk_bdev_alias_add(self.as_inner_ptr(), alias.as_ptr()) }
.to_result(Errno::from_raw);
let ret = unsafe { spdk_bdev_alias_add(self.as_inner_ptr(), alias.as_ptr()) }
.to_result(Errno::from_raw);

matches!(ret, Err(Errno::EEXIST) | Ok(_))
}

/// Removes the given alias from the Bdev.
pub fn remove_alias(&mut self, alias: &str) {
unsafe {
spdk_bdev_alias_del(
self.as_inner_ptr(),
alias.into_cstring().as_ptr(),
)
};
unsafe { spdk_bdev_alias_del(self.as_inner_ptr(), alias.into_cstring().as_ptr()) };
}

/// Returns a list of Bdev aliases.
Expand Down Expand Up @@ -261,9 +228,7 @@ where

/// Returns true if this Bdev is claimed by some other component.
pub fn is_claimed(&self) -> bool {
unsafe {
self.as_inner_ref().internal.claim_type != SPDK_BDEV_CLAIM_NONE
}
unsafe { self.as_inner_ref().internal.claim_type != SPDK_BDEV_CLAIM_NONE }
}

/// Returns true if this Bdev is claimed by the given component.
Expand Down Expand Up @@ -296,9 +261,7 @@ where

/// Determines whenever the Bdev supports the requested I/O type.
pub fn io_type_supported(&self, io_type: IoType) -> bool {
unsafe {
spdk_bdev_io_type_supported(self.as_inner_ptr(), io_type.into())
}
unsafe { spdk_bdev_io_type_supported(self.as_inner_ptr(), io_type.into()) }
}

/// Returns a reference to a data object associated with this Bdev.
Expand Down
19 changes: 4 additions & 15 deletions src/bdev_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,12 @@ use futures::channel::{oneshot, oneshot::Canceled};

use crate::{
error::{SpdkError::BdevUnregisterFailed, SpdkResult},
ffihelper::{
cb_arg,
done_errno_cb,
errno_error,
errno_result_from_i32,
ErrnoResult,
},
ffihelper::{cb_arg, done_errno_cb, errno_error, errno_result_from_i32, ErrnoResult},
libspdk::{
bdev_reset_device_stat,
spdk_bdev,
spdk_bdev_get_device_stat,
spdk_bdev_io_stat,
spdk_bdev_unregister,
SPDK_BDEV_RESET_STAT_ALL,
bdev_reset_device_stat, spdk_bdev, spdk_bdev_get_device_stat, spdk_bdev_io_stat,
spdk_bdev_unregister, SPDK_BDEV_RESET_STAT_ALL,
},
Bdev,
BdevOps,
Bdev, BdevOps,
};

/// TODO
Expand Down
Loading

0 comments on commit 1821cfe

Please sign in to comment.