Skip to content

Commit 8b555fa

Browse files
committed
Add Cargo configuration and improve control identifier handling in FDB
1 parent 1fdaada commit 8b555fa

13 files changed

Lines changed: 116 additions & 113 deletions

File tree

.cargo/config.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[build]
2+
jobs = -1
3+
4+
[target.'cfg(all())']
5+
rustflags = [
6+
"-Wclippy::all",
7+
"-Wclippy::pedantic",
8+
"-Wclippy::nursery",
9+
"-Wclippy::unwrap_used",
10+
"-Aclippy::module_name_repetitions",
11+
"-Aclippy::missing_errors_doc",
12+
]
13+
14+
[net]
15+
git-fetch-with-cli = true

rust/crates/fdb-sys/build.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ fn emit_rpath_flags() {
530530

531531
/// Copy libraries to target directory for portable binaries.
532532
/// Returns the path to the libs directory where libraries were copied.
533-
/// This MUST be called BEFORE emit_link_directives so we link against the copied location.
533+
/// This MUST be called BEFORE `emit_link_directives` so we link against the copied location.
534534
#[cfg(feature = "vendored")]
535535
fn copy_resources_to_output(
536536
fdb_install_dir: &std::path::Path,
@@ -562,7 +562,9 @@ fn copy_resources_to_output(
562562
let file_name = path.file_name().and_then(|n| n.to_str()).unwrap_or("");
563563

564564
// Match .so, .dylib, and versioned .so.X files
565-
let is_shared_lib = file_name.ends_with(".dylib")
565+
let is_shared_lib = std::path::Path::new(file_name)
566+
.extension()
567+
.is_some_and(|ext| ext.eq_ignore_ascii_case("dylib"))
566568
|| file_name.contains(".so")
567569
|| path.extension().is_some_and(|ext| ext == "so");
568570

@@ -594,5 +596,5 @@ fn copy_resources_to_output(
594596
// Export resource directory name for runtime discovery
595597
println!("cargo:rustc-env=FDB_LIBS_DIR=fdb_libs");
596598

597-
libs_dest.to_path_buf()
599+
libs_dest.clone()
598600
}

rust/crates/fdb-sys/cpp/fdb_bridge.cpp

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -122,44 +122,6 @@ static fdb5::FDBToolRequest make_tool_request(const std::string& request_str) {
122122
return fdb5::FDBToolRequest{mars, all, std::vector<std::string>{}};
123123
}
124124

125-
/// Convert ControlIdentifier enum to string
126-
static std::string control_identifier_to_string(fdb5::ControlIdentifier id) {
127-
switch (id) {
128-
case fdb5::ControlIdentifier::List:
129-
return "list";
130-
case fdb5::ControlIdentifier::Retrieve:
131-
return "retrieve";
132-
case fdb5::ControlIdentifier::Archive:
133-
return "archive";
134-
case fdb5::ControlIdentifier::Wipe:
135-
return "wipe";
136-
case fdb5::ControlIdentifier::UniqueRoot:
137-
return "uniqueRoot";
138-
default:
139-
return "unknown";
140-
}
141-
}
142-
143-
/// Convert string to ControlIdentifier enum
144-
static fdb5::ControlIdentifier control_identifier_from_string(const std::string& s) {
145-
if (s == "list") {
146-
return fdb5::ControlIdentifier::List;
147-
}
148-
if (s == "retrieve") {
149-
return fdb5::ControlIdentifier::Retrieve;
150-
}
151-
if (s == "archive") {
152-
return fdb5::ControlIdentifier::Archive;
153-
}
154-
if (s == "wipe") {
155-
return fdb5::ControlIdentifier::Wipe;
156-
}
157-
if (s == "uniqueRoot") {
158-
return fdb5::ControlIdentifier::UniqueRoot;
159-
}
160-
return fdb5::ControlIdentifier::None;
161-
}
162-
163125
// ============================================================================
164126
// FdbHandle implementation
165127
// ============================================================================
@@ -200,10 +162,8 @@ FdbStatsData FdbHandle::stats() const {
200162
return data;
201163
}
202164

203-
bool FdbHandle::enabled(rust::Str identifier) const {
204-
std::string id_str{identifier};
205-
auto ctrl_id = control_identifier_from_string(id_str);
206-
return impl_.enabled(ctrl_id);
165+
bool FdbHandle::enabled(fdb5::ControlIdentifier identifier) const {
166+
return impl_.enabled(identifier);
207167
}
208168

209169
rust::String FdbHandle::id() const {
@@ -607,7 +567,7 @@ ControlElementData ControlIteratorHandle::next() {
607567
ControlElementData data;
608568
data.location = rust::String(current_.location.asString());
609569
for (const auto& id : current_.controlIdentifiers) {
610-
data.identifiers.push_back(rust::String(control_identifier_to_string(id)));
570+
data.identifiers.push_back(id);
611571
}
612572
return data;
613573
}
@@ -889,14 +849,13 @@ std::unique_ptr<StatsIteratorHandle> stats_iterator(FdbHandle& handle, rust::Str
889849
// ============================================================================
890850

891851
std::unique_ptr<ControlIteratorHandle> control(FdbHandle& handle, rust::Str request, fdb5::ControlAction action,
892-
const rust::Vec<rust::String>& identifiers) {
852+
rust::Slice<const fdb5::ControlIdentifier> identifiers) {
893853
std::string request_str{request};
894854
auto tool_request = make_tool_request(request_str);
895855

896-
// Parse control identifiers using |= operator
897856
fdb5::ControlIdentifiers ctrl_ids;
898-
for (const auto& id : identifiers) {
899-
ctrl_ids |= control_identifier_from_string(std::string(id));
857+
for (auto id : identifiers) {
858+
ctrl_ids |= id;
900859
}
901860

902861
auto it = handle.inner().control(tool_request, action, ctrl_ids);

rust/crates/fdb-sys/cpp/fdb_bridge.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class FdbHandle {
130130
FdbStatsData stats() const;
131131

132132
/// Check if a control identifier is enabled.
133-
bool enabled(rust::Str identifier) const;
133+
bool enabled(fdb5::ControlIdentifier identifier) const;
134134

135135
/// Get the FDB configuration ID.
136136
rust::String id() const;
@@ -535,7 +535,7 @@ std::unique_ptr<StatsIteratorHandle> stats_iterator(FdbHandle& handle, rust::Str
535535

536536
/// Control database features.
537537
std::unique_ptr<ControlIteratorHandle> control(FdbHandle& handle, rust::Str request, fdb5::ControlAction action,
538-
const rust::Vec<rust::String>& identifiers);
538+
rust::Slice<const fdb5::ControlIdentifier> identifiers);
539539

540540
// ============================================================================
541541
// Move functions

rust/crates/fdb-sys/src/lib.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ mod ffi {
164164
pub struct ControlElementData {
165165
/// Location
166166
pub location: String,
167-
/// Control identifiers
168-
pub identifiers: Vec<String>,
167+
/// Control identifiers (each variant is the same as `fdb5::ControlIdentifier`).
168+
pub identifiers: Vec<ControlIdentifier>,
169169
}
170170

171171
/// Result from move iteration.
@@ -186,7 +186,7 @@ mod ffi {
186186
pub config_path: String,
187187
}
188188

189-
// Bind to existing fdb5::ControlAction C++ enum.
189+
// Bind to existing fdb5::ControlAction / fdb5::ControlIdentifier C++ enums.
190190
// The shared enum + extern type pattern tells CXX to use the existing
191191
// C++ enum and generate static assertions to verify the values match.
192192
/// Control action for database features.
@@ -201,10 +201,25 @@ mod ffi {
201201
Enable = 2,
202202
}
203203

204+
/// Feature identifier for `control()` operations. Bitflag values match
205+
/// `fdb5::ControlIdentifier` exactly.
206+
#[namespace = "fdb5"]
207+
#[repr(u16)]
208+
#[derive(Debug)]
209+
pub enum ControlIdentifier {
210+
None = 0,
211+
List = 1,
212+
Retrieve = 2,
213+
Archive = 4,
214+
Wipe = 8,
215+
UniqueRoot = 16,
216+
}
217+
204218
#[namespace = "fdb5"]
205219
unsafe extern "C++" {
206220
include!("fdb5/api/helpers/ControlIterator.h");
207221
type ControlAction;
222+
type ControlIdentifier;
208223
}
209224

210225
// =========================================================================
@@ -231,7 +246,7 @@ mod ffi {
231246
fn stats(self: &FdbHandle) -> FdbStatsData;
232247

233248
/// Check if a control identifier is enabled.
234-
fn enabled(self: &FdbHandle, identifier: &str) -> bool;
249+
fn enabled(self: &FdbHandle, identifier: ControlIdentifier) -> bool;
235250

236251
/// Get the FDB configuration ID.
237252
fn id(self: &FdbHandle) -> String;
@@ -563,7 +578,7 @@ mod ffi {
563578
handle: Pin<&mut FdbHandle>,
564579
request: &str,
565580
action: ControlAction,
566-
identifiers: &Vec<String>,
581+
identifiers: &[ControlIdentifier],
567582
) -> Result<UniquePtr<ControlIteratorHandle>>;
568583

569584
// =====================================================================

rust/crates/fdb/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Build script for fdb crate.
22
//!
33
//! Emits RPATH linker flags so binaries can find dynamic libraries
4-
//! at runtime without setting LD_LIBRARY_PATH/DYLD_LIBRARY_PATH.
4+
//! at runtime without setting `LD_LIBRARY_PATH`/`DYLD_LIBRARY_PATH`.
55
66
fn main() {
77
println!("cargo:rerun-if-changed=build.rs");

rust/crates/fdb/examples/fdb_basic.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! Run with: `cargo run --example fdb_basic -p fdb`
44
5-
use fdb::Fdb;
5+
use fdb::{ControlIdentifier, Fdb};
66

77
fn main() -> Result<(), Box<dyn std::error::Error>> {
88
// Print version info (works without FDB config)
@@ -17,9 +17,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1717

1818
// Check capabilities
1919
println!("\nCapabilities:");
20-
println!(" retrieve enabled: {}", fdb.enabled("retrieve"));
21-
println!(" archive enabled: {}", fdb.enabled("archive"));
22-
println!(" list enabled: {}", fdb.enabled("list"));
20+
println!(
21+
" retrieve enabled: {}",
22+
fdb.enabled(ControlIdentifier::Retrieve)
23+
);
24+
println!(
25+
" archive enabled: {}",
26+
fdb.enabled(ControlIdentifier::Archive)
27+
);
28+
println!(" list enabled: {}", fdb.enabled(ControlIdentifier::List));
2329

2430
Ok(())
2531
}

rust/crates/fdb/src/datareader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl Seek for DataReader {
9797
if new < 0 {
9898
return Err(std::io::Error::other("seek to negative position"));
9999
}
100-
new as u64
100+
new.cast_unsigned()
101101
}
102102
SeekFrom::Current(offset) => {
103103
let current = i64::try_from(self.tell())
@@ -108,7 +108,7 @@ impl Seek for DataReader {
108108
if new < 0 {
109109
return Err(std::io::Error::other("seek to negative position"));
110110
}
111-
new as u64
111+
new.cast_unsigned()
112112
}
113113
};
114114

rust/crates/fdb/src/handle.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use std::collections::HashMap;
44
use std::sync::Once;
55

6-
use fdb_sys::ControlAction;
76
use fdb_sys::UniquePtr;
7+
use fdb_sys::{ControlAction, ControlIdentifier};
88
use parking_lot::Mutex;
99

1010
use crate::datareader::DataReader;
@@ -433,7 +433,8 @@ impl Fdb {
433433
///
434434
/// * `request` - The request specifying which databases to control
435435
/// * `action` - The action to perform
436-
/// * `identifiers` - The feature identifiers to control (e.g., "retrieve", "archive")
436+
/// * `identifiers` - The feature identifiers to control (e.g.
437+
/// `ControlIdentifier::Retrieve`, `ControlIdentifier::Archive`)
437438
///
438439
/// # Errors
439440
///
@@ -442,11 +443,11 @@ impl Fdb {
442443
&self,
443444
request: &Request,
444445
action: ControlAction,
445-
identifiers: &[String],
446+
identifiers: &[ControlIdentifier],
446447
) -> Result<ControlIterator> {
447-
let ids: Vec<String> = identifiers.to_vec();
448-
let it =
449-
self.with_handle(|h| fdb_sys::control(h, &request.to_request_string(), action, &ids))?;
448+
let it = self.with_handle(|h| {
449+
fdb_sys::control(h, &request.to_request_string(), action, identifiers)
450+
})?;
450451
Ok(ControlIterator::new(it))
451452
}
452453

@@ -469,9 +470,10 @@ impl Fdb {
469470
///
470471
/// # Arguments
471472
///
472-
/// * `identifier` - The identifier to check (e.g., "retrieve", "archive")
473+
/// * `identifier` - The identifier to check (e.g.
474+
/// `ControlIdentifier::Retrieve`, `ControlIdentifier::Archive`)
473475
#[must_use]
474-
pub fn enabled(&self, identifier: &str) -> bool {
476+
pub fn enabled(&self, identifier: ControlIdentifier) -> bool {
475477
self.with_handle_ref(|h| h.enabled(identifier))
476478
}
477479

rust/crates/fdb/src/iterator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,8 @@ unsafe impl Send for ControlIterator {}
608608
pub struct ControlElement {
609609
/// Location of the database.
610610
pub location: String,
611-
/// Control identifiers (e.g., "retrieve", "archive").
612-
pub identifiers: Vec<String>,
611+
/// Control identifiers enabled for this database.
612+
pub identifiers: Vec<fdb_sys::ControlIdentifier>,
613613
}
614614

615615
// =============================================================================

0 commit comments

Comments
 (0)