Skip to content

Commit 1821cfe

Browse files
build: use rust stable for linting
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 <tiagolobocastro@gmail.com>
1 parent 2578b43 commit 1821cfe

33 files changed

+159
-509
lines changed

.rustfmt.toml

-15
This file was deleted.

build.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ fn rust_fmt_nightly() -> Option<PathBuf> {
7676
fn get_spdk_path() -> Result<PathBuf, Error> {
7777
let spdk_path = match env::var_os("SPDK_ROOT_DIR") {
7878
Some(s) => {
79-
println!(
80-
"SPDK_ROOT_DIR variable is set to {}",
81-
s.to_str().unwrap()
82-
);
79+
println!("SPDK_ROOT_DIR variable is set to {}", s.to_str().unwrap());
8380
PathBuf::from(s)
8481
}
8582
None => {
@@ -122,10 +119,7 @@ fn configure_spdk() -> Result<LibraryConfig, Error> {
122119
spdk_path.join("include/spdk/module"),
123120
spdk_path.join("module"),
124121
)?;
125-
spdk_lib.add_inc_alt(
126-
spdk_path.join("include/spdk/lib"),
127-
spdk_path.join("lib"),
128-
)?;
122+
spdk_lib.add_inc_alt(spdk_path.join("include/spdk/lib"), spdk_path.join("lib"))?;
129123
spdk_lib.add_inc_alt(
130124
spdk_path.join("include/spdk/lib/ftl"),
131125
spdk_path.join("lib/ftl"),
@@ -240,11 +234,7 @@ where
240234
src_files.push(p);
241235
}
242236
}
243-
Err(e) => {
244-
return Err(Error::Generic(format!(
245-
"Bad SPDK helper source {s}: {e}"
246-
)))
247-
}
237+
Err(e) => return Err(Error::Generic(format!("Bad SPDK helper source {s}: {e}"))),
248238
}
249239
}
250240

@@ -355,9 +345,7 @@ fn main() {
355345
.prepend_enum_name(false)
356346
.size_t_is_usize(false)
357347
.generate_inline_functions(true)
358-
.parse_callbacks(Box::new(MacroCallback {
359-
macros,
360-
}));
348+
.parse_callbacks(Box::new(MacroCallback { macros }));
361349

362350
// Use nightly rustfmt if it is possible.
363351
let bindings = if let Some(rust_fmt) = rust_fmt_nightly() {

build_helpers/library_config.rs

+16-37
Original file line numberDiff line numberDiff line change
@@ -120,24 +120,19 @@ impl Display for Library {
120120

121121
impl Library {
122122
/// Creates a new `Library` instance.
123-
fn new<U: AsRef<OsStr>, V: AsRef<OsStr>>(
124-
name: U,
125-
parent_name: V,
126-
cfg: &LibraryConfig,
127-
) -> Self {
123+
fn new<U: AsRef<OsStr>, V: AsRef<OsStr>>(name: U, parent_name: V, cfg: &LibraryConfig) -> Self {
128124
let pkg_name = name.as_ref().to_str().unwrap();
129125

130-
let (lib_name, is_ar) =
131-
if pkg_name.starts_with(":lib") && pkg_name.ends_with(".a") {
132-
let s = pkg_name
133-
.strip_prefix(":lib")
134-
.unwrap()
135-
.strip_suffix(".a")
136-
.unwrap();
137-
(OsString::from(&s), true)
138-
} else {
139-
(OsString::from(&pkg_name), false)
140-
};
126+
let (lib_name, is_ar) = if pkg_name.starts_with(":lib") && pkg_name.ends_with(".a") {
127+
let s = pkg_name
128+
.strip_prefix(":lib")
129+
.unwrap()
130+
.strip_suffix(".a")
131+
.unwrap();
132+
(OsString::from(&s), true)
133+
} else {
134+
(OsString::from(&pkg_name), false)
135+
};
141136

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

@@ -153,10 +148,7 @@ impl Library {
153148
/// Prints Cargo link instructions.
154149
fn cargo(&self) {
155150
if self.is_system {
156-
println!(
157-
"cargo:rustc-link-lib={}",
158-
self.lib_name.to_str().unwrap()
159-
);
151+
println!("cargo:rustc-link-lib={}", self.lib_name.to_str().unwrap());
160152
} else {
161153
// Use 'whole-archive' flag on non-system libs.
162154
println!(
@@ -224,16 +216,10 @@ impl LibraryConfig {
224216
/// Adds a new pkg_config search path. The path must exist on the file
225217
/// system.
226218
#[allow(dead_code)]
227-
pub fn add_pkg_cfg_path<T: AsRef<Path>>(
228-
&self,
229-
new_path: T,
230-
) -> Result<(), Error> {
219+
pub fn add_pkg_cfg_path<T: AsRef<Path>>(&self, new_path: T) -> Result<(), Error> {
231220
match fs::canonicalize(&new_path) {
232221
Ok(cp) => {
233-
println!(
234-
"Added PKG_CONFIG_PATH_FOR_TARGET: {}",
235-
cp.to_str().unwrap()
236-
);
222+
println!("Added PKG_CONFIG_PATH_FOR_TARGET: {}", cp.to_str().unwrap());
237223
append_path_var(OsStr::new("PKG_CONFIG_PATH_FOR_TARGET"), &cp);
238224
Ok(())
239225
}
@@ -314,10 +300,7 @@ impl LibraryConfig {
314300
}
315301

316302
/// Finds a library via pkg_config.
317-
pub fn find_lib<T: AsRef<OsStr>>(
318-
&mut self,
319-
lib_name: T,
320-
) -> Result<(), Error> {
303+
pub fn find_lib<T: AsRef<OsStr>>(&mut self, lib_name: T) -> Result<(), Error> {
321304
let lib_name = OsString::from(&lib_name);
322305
let library = self.cfg.probe(lib_name.to_str().unwrap())?;
323306

@@ -425,11 +408,7 @@ impl LibraryConfig {
425408

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

435414
tool.add_flag("shared");

build_helpers/tool.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ impl Tool {
4141
}
4242

4343
/// Creates a shared library path from the given directory and library name.
44-
pub fn make_shared_lib_path(
45-
out_dir: &Path,
46-
lib_name: &OsStr,
47-
) -> Result<PathBuf, Error> {
44+
pub fn make_shared_lib_path(out_dir: &Path, lib_name: &OsStr) -> Result<PathBuf, Error> {
4845
let lib_path = &format!("lib{}.so", lib_name.to_str().unwrap());
4946
let res = out_dir.to_path_buf().join(lib_path);
5047
Ok(res)

examples/hello_world.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@ use std::{
55
};
66

77
use spdk_rs::libspdk::{
8-
size_t,
9-
spdk_app_fini,
10-
spdk_app_opts,
11-
spdk_app_opts_init,
12-
spdk_app_parse_args,
13-
spdk_app_start,
14-
spdk_app_stop,
15-
SPDK_APP_PARSE_ARGS_SUCCESS,
8+
size_t, spdk_app_fini, spdk_app_opts, spdk_app_opts_init, spdk_app_parse_args, spdk_app_start,
9+
spdk_app_stop, SPDK_APP_PARSE_ARGS_SUCCESS,
1610
};
1711

1812
extern "C" fn hello_world_parse_arg(_ch: c_int, _arg: *mut c_char) -> c_int {

nix/shell/rust.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let
1919

2020
shellEnv = {
2121
# Path to nightly Rust, needed for linter and style.
22-
RUST_NIGHTLY_PATH = rustChannels.nightly;
22+
# RUST_NIGHTLY_PATH = rustChannels.nightly;
2323

2424
# Path to debug output dir.
2525
RUST_TARGET_DEBUG = "target/debug";

scripts/rust-linter-env.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ fi
4646
# rustfmt and clippy "2021-11-29".
4747
# When upgrading Rust toolchain version, check 'cargo --version',
4848
# 'cargo fmt --version', 'cargo clippy --version' and put them here.
49-
RUST_TOOLCHAIN_VER="2024-10-30"
50-
WANTED_CARGO_VER="cargo 1.84.0-nightly (* 2024-10-25)"
51-
WANTED_RUSTFMT_VER="rustfmt 1.8.0-nightly (* 2024-10-29)"
52-
WANTED_CLIPPY_VER="clippy 0.1.84 (* 2024-10-29)"
49+
RUST_TOOLCHAIN_VER=${RUST_TOOLCHAIN_VER:-"1.82.0"}
50+
WANTED_CARGO_VER=${WANTED_CARGO_VER:-"cargo 1.82.0 (* 2024-08-21)"}
51+
WANTED_RUSTFMT_VER=${WANTED_RUSTFMT_VER:-"rustfmt 1.7.1-stable (* 2024-10-15)"}
52+
WANTED_CLIPPY_VER=${WANTED_CLIPPY_VER:-"clippy 0.1.82 (* 2024-10-15)"}
5353
CARGO="cargo"
5454
CARGO_MODE="system"
5555

src/bdev.rs

+13-50
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,15 @@ use std::{
1111
use nix::errno::Errno;
1212

1313
use crate::{
14-
ffihelper::{
15-
errno_result_from_i32,
16-
AsStr,
17-
ErrnoResult,
18-
FfiResult,
19-
IntoCString,
20-
},
14+
ffihelper::{errno_result_from_i32, AsStr, ErrnoResult, FfiResult, IntoCString},
2115
libspdk::{
22-
spdk_bdev,
23-
spdk_bdev_alias_add,
24-
spdk_bdev_alias_del,
25-
spdk_bdev_fn_table,
26-
spdk_bdev_get_aliases,
27-
spdk_bdev_get_buf_align,
28-
spdk_bdev_get_by_name,
29-
spdk_bdev_has_write_cache,
30-
spdk_bdev_io_type_supported,
31-
spdk_bdev_module,
32-
spdk_bdev_module_release_bdev,
33-
spdk_bdev_register,
34-
spdk_bdev_unregister,
35-
SPDK_BDEV_CLAIM_EXCL_WRITE,
36-
SPDK_BDEV_CLAIM_NONE,
16+
spdk_bdev, spdk_bdev_alias_add, spdk_bdev_alias_del, spdk_bdev_fn_table,
17+
spdk_bdev_get_aliases, spdk_bdev_get_buf_align, spdk_bdev_get_by_name,
18+
spdk_bdev_has_write_cache, spdk_bdev_io_type_supported, spdk_bdev_module,
19+
spdk_bdev_module_release_bdev, spdk_bdev_register, spdk_bdev_unregister,
20+
SPDK_BDEV_CLAIM_EXCL_WRITE, SPDK_BDEV_CLAIM_NONE,
3721
},
38-
BdevIo,
39-
BdevModule,
40-
BdevOps,
41-
IoChannel,
42-
IoDevice,
43-
IoType,
44-
Thread,
45-
Uuid,
22+
BdevIo, BdevModule, BdevOps, IoChannel, IoDevice, IoType, Thread, Uuid,
4623
};
4724

4825
/// Wrapper for SPDK `spdk_bdev` structure and the related API.
@@ -80,11 +57,7 @@ where
8057
/// TODO
8158
pub fn unregister_bdev(&mut self) {
8259
unsafe {
83-
spdk_bdev_unregister(
84-
self.as_inner_ptr(),
85-
None,
86-
null_mut::<c_void>(),
87-
);
60+
spdk_bdev_unregister(self.as_inner_ptr(), None, null_mut::<c_void>());
8861
}
8962
}
9063

@@ -193,21 +166,15 @@ where
193166
/// If the alias is already present we return true
194167
pub fn add_alias(&mut self, alias: &str) -> bool {
195168
let alias = alias.into_cstring();
196-
let ret =
197-
unsafe { spdk_bdev_alias_add(self.as_inner_ptr(), alias.as_ptr()) }
198-
.to_result(Errno::from_raw);
169+
let ret = unsafe { spdk_bdev_alias_add(self.as_inner_ptr(), alias.as_ptr()) }
170+
.to_result(Errno::from_raw);
199171

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

203175
/// Removes the given alias from the Bdev.
204176
pub fn remove_alias(&mut self, alias: &str) {
205-
unsafe {
206-
spdk_bdev_alias_del(
207-
self.as_inner_ptr(),
208-
alias.into_cstring().as_ptr(),
209-
)
210-
};
177+
unsafe { spdk_bdev_alias_del(self.as_inner_ptr(), alias.into_cstring().as_ptr()) };
211178
}
212179

213180
/// Returns a list of Bdev aliases.
@@ -261,9 +228,7 @@ where
261228

262229
/// Returns true if this Bdev is claimed by some other component.
263230
pub fn is_claimed(&self) -> bool {
264-
unsafe {
265-
self.as_inner_ref().internal.claim_type != SPDK_BDEV_CLAIM_NONE
266-
}
231+
unsafe { self.as_inner_ref().internal.claim_type != SPDK_BDEV_CLAIM_NONE }
267232
}
268233

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

297262
/// Determines whenever the Bdev supports the requested I/O type.
298263
pub fn io_type_supported(&self, io_type: IoType) -> bool {
299-
unsafe {
300-
spdk_bdev_io_type_supported(self.as_inner_ptr(), io_type.into())
301-
}
264+
unsafe { spdk_bdev_io_type_supported(self.as_inner_ptr(), io_type.into()) }
302265
}
303266

304267
/// Returns a reference to a data object associated with this Bdev.

src/bdev_async.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,12 @@ use futures::channel::{oneshot, oneshot::Canceled};
55

66
use crate::{
77
error::{SpdkError::BdevUnregisterFailed, SpdkResult},
8-
ffihelper::{
9-
cb_arg,
10-
done_errno_cb,
11-
errno_error,
12-
errno_result_from_i32,
13-
ErrnoResult,
14-
},
8+
ffihelper::{cb_arg, done_errno_cb, errno_error, errno_result_from_i32, ErrnoResult},
159
libspdk::{
16-
bdev_reset_device_stat,
17-
spdk_bdev,
18-
spdk_bdev_get_device_stat,
19-
spdk_bdev_io_stat,
20-
spdk_bdev_unregister,
21-
SPDK_BDEV_RESET_STAT_ALL,
10+
bdev_reset_device_stat, spdk_bdev, spdk_bdev_get_device_stat, spdk_bdev_io_stat,
11+
spdk_bdev_unregister, SPDK_BDEV_RESET_STAT_ALL,
2212
},
23-
Bdev,
24-
BdevOps,
13+
Bdev, BdevOps,
2514
};
2615

2716
/// TODO

0 commit comments

Comments
 (0)