add the base crate and repoint the moved modules at it (#16107)

* add the base crate and repoint the moved modules at it

`libs/base` (crate `base`) takes the parts of hbb_common that only this app
uses: `fs`, `platform`, `keyboard`, `message.proto`, and 145 of the 177
`config::keys` constants. hbb_common keeps what the server names, and the 32
keys it reads itself are re-exported from `base::config::keys` so call sites
still see the full set through one path.

Sources move verbatim. The only edits inside them are `crate::` prefixes that
now have to say `hbb_common::`; `keyboard.rs` and `platform/windows.rs` are
byte-identical. The crate stays on edition 2018, the edition the moved code was
written under. `log`, `lazy_static` and `anyhow` become direct dependencies so
the bare paths in that code resolve exactly as before, and its winapi features
are spelled out rather than left to feature unification.

Two call sites outside Rust and Cargo had to follow the move: the Android
protobuf source dir, which still pointed at hbb_common/protos for message.proto,
and the three AGENTS.md entries that named hbb_common for options, protos and
file transfer.

`scrap`'s `drm` feature now forwards to `base/wayland_probe`. Left pointing at
hbb_common it would still have compiled, silently dropping the Wayland
socket-probe fallback, so that forward is verified by a build with and without
the feature.

`config::keys` carries a test asserting its names stay disjoint from the ones
hbb_common kept: the glob re-export and the local constants share a namespace,
and Rust prefers the local item silently, so a name added to both sides would
otherwise let client and server disagree with no diagnostic.

Verified: macOS and Linux, debug and release, `--all-targets`; the 177 key
constants diffed name-for-name and value-for-value; the generated protobuf types
compared before and after; every `#[cfg]` gate on a moved import checked against
its original; and every file that was `rustfmt`-clean before this change still
is, compared against master file by file. Windows is checked by inspection only
-- it cannot be compiled here.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EZ49AbZJYfm8NTp5yDPMab

* one `use` per crate, and write the rule down

`fs.rs` came out of the move with two ungated `use hbb_common::` statements,
because the original single `use crate::{...}` had to give up `message_proto`
to the new crate and the rest was left in a second block. Fold it back into one.

A scan of the whole tree for the same shape finds nothing else: every other file
with more than one top-level `use base::` or `use hbb_common::` is split by a
`#[cfg]` that does not cover the whole block, or by `pub use` next to `use`.
Those are the cases that cannot merge, so AGENTS.md now states both the rule and
the exemption.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EZ49AbZJYfm8NTp5yDPMab

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
RustDeskandClaude Opus 5 authored and GitHub committed 2026-09-08 11:46:42 +08:00
1 parent e8eead5715
commit b50fde6910
79 files changed
+4966 -214

No files matched your search

+2 -3
View File
@@ -2,12 +2,11 @@
// Sometimes reboot is needed to refresh sudoers.
use crate::lang::translate;
use base::platform::linux::CMD_SH;
use gtk::{glib, prelude::*};
use hbb_common::{
anyhow::{bail, Error},
log,
platform::linux::CMD_SH,
ResultType,
log, ResultType,
};
use nix::{
libc::{fcntl, kill},
+3 -3
View File
@@ -1,6 +1,6 @@
use super::{gtk_sudo, CursorData, ResultType};
use desktop::Desktop;
pub use hbb_common::platform::linux::*;
pub use base::platform::linux::*;
#[cfg(feature = "drm")]
pub fn dispatch_wayland_display_probe() {
@@ -17,10 +17,10 @@ use hbb_common::{
config::Config,
libc::{c_char, c_int, c_long, c_uint, c_ulong, c_void},
log,
message_proto::{DisplayInfo, Resolution},
regex::{Captures, Regex},
users::{get_user_by_name, os::unix::UserExt},
};
use base::message_proto::{DisplayInfo, Resolution};
use libxdo_sys::{self, xdo_t, Window};
use std::{
cell::RefCell,
@@ -64,7 +64,7 @@ lazy_static::lazy_static! {
/// serve but the DRM path can. Unmemoised lookup on purpose: this may run mid-boot, and
/// a "no" cached that early would be wrong for the rest of the process.
pub static ref IS_X11: bool = {
let x11 = hbb_common::platform::linux::is_x11_or_headless();
let x11 = base::platform::linux::is_x11_or_headless();
#[cfg(feature = "drm")]
{
if x11 && !display_server_forced() && is_login_screen_wayland() {
+1 -1
View File
@@ -20,9 +20,9 @@ use core_graphics::{
use hbb_common::{
anyhow::anyhow,
bail, log,
message_proto::{DisplayInfo, Resolution},
sysinfo::{Pid, Process, ProcessRefreshKind, System},
};
use base::message_proto::{DisplayInfo, Resolution};
use include_dir::{include_dir, Dir};
use objc::rc::autoreleasepool;
use objc::{class, msg_send, sel, sel_impl};
+3 -1
View File
@@ -23,13 +23,15 @@ pub mod linux;
#[cfg(target_os = "linux")]
pub mod gtk_sudo;
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use base::message_proto::CursorData;
#[cfg(all(
not(all(target_os = "windows", not(target_pointer_width = "64"))),
not(any(target_os = "android", target_os = "ios"))
))]
use hbb_common::sysinfo::System;
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use hbb_common::{message_proto::CursorData, sysinfo::Pid, ResultType};
use hbb_common::{sysinfo::Pid, ResultType};
use std::sync::{Arc, Mutex};
#[cfg(not(any(target_os = "macos", target_os = "android", target_os = "ios")))]
pub const SERVICE_INTERVAL: u64 = 300;
+4 -5
View File
@@ -5,15 +5,14 @@ use crate::{
ipc,
privacy_mode::win_topmost_window::{self, WIN_TOPMOST_INJECTED_PROCESS_EXE},
};
use base::message_proto::{DisplayInfo, Resolution, WindowsSession};
use hbb_common::{
allow_err,
anyhow::anyhow,
bail,
config::{self, Config},
libc::{c_int, wchar_t},
log,
message_proto::{DisplayInfo, Resolution, WindowsSession},
sleep,
log, sleep,
sysinfo::{Pid, System},
timeout, tokio,
};
@@ -2482,7 +2481,7 @@ pub fn elevate_or_run_as_system(is_setup: bool, is_elevate: bool, is_run_as_syst
}
pub fn is_elevated(process_id: Option<DWORD>) -> ResultType<bool> {
use hbb_common::platform::windows::RAIIHandle;
use base::platform::windows::RAIIHandle;
unsafe {
let handle: HANDLE = match process_id {
Some(process_id) => OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, process_id),
@@ -4754,7 +4753,7 @@ mod tests {
// Test-only reusable Win32 HANDLE RAII helper.
// If a future non-test path needs the same pattern, move it out of this test module.
//
// This struct is similar to `hbb_common::platform::windows::RAIIHandle`,
// This struct is similar to `base::platform::windows::RAIIHandle`,
// but `RAIIHandle` depends on `WinApi` crate, while this `HandleGuard` only depends on `windows` crate.
struct HandleGuard(WinHANDLE);