From: Thomas Bertschinger <tahbertschinger@gmail.com>
To: kent.overstreet@linux.dev, linux-bcachefs@vger.kernel.org,
bfoster@redhat.com
Cc: Thomas Bertschinger <tahbertschinger@gmail.com>
Subject: [PATCH TOOLS 2/2] remove library from bcachefs-tools Rust package
Date: Sun, 14 Jan 2024 22:24:51 -0700 [thread overview]
Message-ID: <20240115052451.145611-3-tahbertschinger@gmail.com> (raw)
In-Reply-To: <20240115052451.145611-1-tahbertschinger@gmail.com>
When bcachefs was a C program that had some functions implemented in
Rust, it was necessary to make a static library containing the Rust
functions for the C program to link.
Now that bcachefs is a Rust program, that library is no longer needed.
Instead, the Rust executable links in libbachefs.a.
This patch updates the crate structure to reflect that. The command
functions are moved into their own module.
There could be a need to create a "libbachefs-tools" library in the
future that exposes an API for bcachefs functionality to other
userspace programs. That will be a different, external API as opposed to
the previous library functions which were an internal API for the
bcachefs tool itself.
Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
---
rust-src/Cargo.toml | 3 ---
rust-src/src/bcachefs.rs | 21 +++++++++++++++----
.../src/{ => commands}/cmd_completions.rs | 0
rust-src/src/{ => commands}/cmd_list.rs | 0
rust-src/src/{ => commands}/cmd_mount.rs | 0
rust-src/src/{ => commands}/logger.rs | 0
rust-src/src/{lib.rs => commands/mod.rs} | 10 ---------
7 files changed, 17 insertions(+), 17 deletions(-)
rename rust-src/src/{ => commands}/cmd_completions.rs (100%)
rename rust-src/src/{ => commands}/cmd_list.rs (100%)
rename rust-src/src/{ => commands}/cmd_mount.rs (100%)
rename rust-src/src/{ => commands}/logger.rs (100%)
rename rust-src/src/{lib.rs => commands/mod.rs} (72%)
diff --git a/rust-src/Cargo.toml b/rust-src/Cargo.toml
index 1e96f85..f50523b 100644
--- a/rust-src/Cargo.toml
+++ b/rust-src/Cargo.toml
@@ -9,9 +9,6 @@ rust-version = "1.65"
name = "bcachefs"
path = "src/bcachefs.rs"
-[lib]
-name = "bcachefs"
-
[dependencies]
atty = "0.2.14"
log = { version = "0.4", features = ["std"] }
diff --git a/rust-src/src/bcachefs.rs b/rust-src/src/bcachefs.rs
index ed5fd1d..0a76a92 100644
--- a/rust-src/src/bcachefs.rs
+++ b/rust-src/src/bcachefs.rs
@@ -1,11 +1,24 @@
+mod commands;
+mod key;
+
use std::ffi::CString;
-use bcachefs::cmd_completions::cmd_completions;
-use bcachefs::cmd_list::cmd_list;
-use bcachefs::cmd_mount::cmd_mount;
-use bcachefs::logger::SimpleLogger;
+use commands::cmd_completions::cmd_completions;
+use commands::cmd_list::cmd_list;
+use commands::cmd_mount::cmd_mount;
+use commands::logger::SimpleLogger;
use bch_bindgen::c;
+#[derive(Debug)]
+pub struct ErrnoError(pub errno::Errno);
+impl std::fmt::Display for ErrnoError {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
+ self.0.fmt(f)
+ }
+}
+
+impl std::error::Error for ErrnoError {}
+
fn handle_c_command(args: Vec<String>, symlink_cmd: Option<&str>) -> i32 {
let mut argv: Vec<_> = args.clone();
diff --git a/rust-src/src/cmd_completions.rs b/rust-src/src/commands/cmd_completions.rs
similarity index 100%
rename from rust-src/src/cmd_completions.rs
rename to rust-src/src/commands/cmd_completions.rs
diff --git a/rust-src/src/cmd_list.rs b/rust-src/src/commands/cmd_list.rs
similarity index 100%
rename from rust-src/src/cmd_list.rs
rename to rust-src/src/commands/cmd_list.rs
diff --git a/rust-src/src/cmd_mount.rs b/rust-src/src/commands/cmd_mount.rs
similarity index 100%
rename from rust-src/src/cmd_mount.rs
rename to rust-src/src/commands/cmd_mount.rs
diff --git a/rust-src/src/logger.rs b/rust-src/src/commands/logger.rs
similarity index 100%
rename from rust-src/src/logger.rs
rename to rust-src/src/commands/logger.rs
diff --git a/rust-src/src/lib.rs b/rust-src/src/commands/mod.rs
similarity index 72%
rename from rust-src/src/lib.rs
rename to rust-src/src/commands/mod.rs
index f8b508d..e05a084 100644
--- a/rust-src/src/lib.rs
+++ b/rust-src/src/commands/mod.rs
@@ -1,6 +1,5 @@
use clap::Subcommand;
-pub mod key;
pub mod logger;
pub mod cmd_mount;
pub mod cmd_list;
@@ -30,12 +29,3 @@ macro_rules! c_str {
}
};
}
-
-#[derive(Debug)]
-struct ErrnoError(errno::Errno);
-impl std::fmt::Display for ErrnoError {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
- self.0.fmt(f)
- }
-}
-impl std::error::Error for ErrnoError {}
--
2.43.0
next prev parent reply other threads:[~2024-01-15 5:26 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-15 5:24 [PATCH TOOLS 0/2] convert main() from C to Rust Thomas Bertschinger
2024-01-15 5:24 ` [PATCH TOOLS 1/2] " Thomas Bertschinger
2024-01-15 5:24 ` Thomas Bertschinger [this message]
2024-01-15 17:32 ` [PATCH TOOLS 0/2] " Kent Overstreet
2024-01-15 17:55 ` Thomas Bertschinger
2024-01-15 18:45 ` Kent Overstreet
2024-01-15 19:10 ` Thomas Bertschinger
2024-01-15 19:22 ` Kent Overstreet
2024-01-19 19:05 ` Trevor Gross
2024-01-19 21:37 ` Kent Overstreet
2024-01-21 16:11 ` packed, aligned structs in bcachefs (was: Re: [PATCH TOOLS 0/2] convert main() from C to Rust) Thomas Bertschinger
2024-01-21 18:19 ` Kent Overstreet
2024-01-21 19:32 ` Thomas Bertschinger
2024-01-22 2:47 ` Thomas Bertschinger
2024-01-15 17:48 ` [PATCH TOOLS 0/2] convert main() from C to Rust Kent Overstreet
2024-01-15 17:57 ` Thomas Bertschinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240115052451.145611-3-tahbertschinger@gmail.com \
--to=tahbertschinger@gmail.com \
--cc=bfoster@redhat.com \
--cc=kent.overstreet@linux.dev \
--cc=linux-bcachefs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox