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:
RustDesk
2026-09-08 11:46:42 +08:00
committed by GitHub
parent e8eead5715
commit b50fde6910
79 changed files with 4966 additions and 214 deletions

View File

@@ -20,7 +20,7 @@ wayland = ["gstreamer", "gstreamer-app", "gstreamer-video", "dbus", "tracing", "
# Depends on `wayland`: the three drm modules live inside the `#[cfg(feature = "wayland")]` arm of
# common/mod.rs, so `scrap/drm` on its own would compile nothing. The root crate happens to always
# enable `scrap/wayland`, which is what hid this.
drm = ["wayland", "hbb_common/wayland_probe"]
drm = ["wayland", "base/wayland_probe"]
mediacodec = ["ndk"]
linux-pkg-config = ["dep:pkg-config"]
hwcodec = ["dep:hwcodec"]
@@ -31,6 +31,7 @@ cfg-if = "1.0"
num_cpus = "1.15"
lazy_static = "1.4"
hbb_common = { path = "../hbb_common" }
base = { path = "../base" }
webm = { git = "https://github.com/rustdesk-org/rust-webm" }
serde = {version="1.0", features=["derive"]}

View File

@@ -9,7 +9,8 @@ use jni::{
JavaVM,
};
use hbb_common::{message_proto::MultiClipboards, protobuf::Message};
use base::message_proto::MultiClipboards;
use hbb_common::protobuf::Message;
use jni::errors::{Error as JniError, Result as JniResult};
use lazy_static::lazy_static;
use serde::Deserialize;

View File

@@ -13,10 +13,9 @@ use crate::{EncodeInput, EncodeYuvFormat, Pixfmt};
use hbb_common::{
anyhow::{anyhow, Context},
bytes::Bytes,
log,
message_proto::{Chroma, EncodedVideoFrame, EncodedVideoFrames, VideoFrame},
ResultType,
log, ResultType,
};
use base::message_proto::{Chroma, EncodedVideoFrame, EncodedVideoFrames, VideoFrame};
use std::{ptr, slice};
generate_call_macro!(call_aom, false);

View File

@@ -11,7 +11,7 @@ use nokhwa::{
Camera,
};
use hbb_common::message_proto::{DisplayInfo, Resolution};
use base::message_proto::{DisplayInfo, Resolution};
#[cfg(feature = "vram")]
use crate::AdapterDevice;

View File

@@ -18,6 +18,10 @@ use crate::{
CodecFormat, EncodeInput, EncodeYuvFormat, ImageRgb, ImageTexture,
};
use base::message_proto::{
supported_decoding::PreferCodec, video_frame, Chroma, CodecAbility, EncodedVideoFrames,
SupportedDecoding, SupportedEncoding, VideoFrame,
};
#[cfg(any(
feature = "hwcodec",
feature = "mediacodec",
@@ -30,10 +34,6 @@ use hbb_common::{
bail,
config::{Config, PeerConfig},
lazy_static, log,
message_proto::{
supported_decoding::PreferCodec, video_frame, Chroma, CodecAbility, EncodedVideoFrames,
SupportedDecoding, SupportedEncoding, VideoFrame,
},
sysinfo::System,
ResultType,
};
@@ -269,7 +269,7 @@ impl Encoder {
let preference = most_frequent.enum_value_or(PreferCodec::Auto);
// auto: h265 > h264 > av1/vp9/vp8
let av1_test = Config::get_option(hbb_common::config::keys::OPTION_AV1_TEST) != "N";
let av1_test = Config::get_option(base::config::keys::OPTION_AV1_TEST) != "N";
let mut auto_codec = if av1_useable && av1_test {
CodecFormat::AV1
} else {
@@ -849,7 +849,7 @@ impl Decoder {
#[cfg(any(feature = "hwcodec", feature = "mediacodec"))]
pub fn enable_hwcodec_option() -> bool {
use hbb_common::config::keys::OPTION_ENABLE_HWCODEC;
use base::config::keys::OPTION_ENABLE_HWCODEC;
if !cfg!(target_os = "ios") {
return option2bool(
@@ -861,7 +861,7 @@ pub fn enable_hwcodec_option() -> bool {
}
#[cfg(feature = "vram")]
pub fn enable_vram_option(encode: bool) -> bool {
use hbb_common::config::keys::OPTION_ENABLE_HWCODEC;
use base::config::keys::OPTION_ENABLE_HWCODEC;
if cfg!(windows) {
let enable = option2bool(
@@ -880,13 +880,13 @@ pub fn enable_vram_option(encode: bool) -> bool {
#[cfg(windows)]
pub fn enable_directx_capture() -> bool {
use hbb_common::config::keys::OPTION_ENABLE_DIRECTX_CAPTURE as OPTION;
use base::config::keys::OPTION_ENABLE_DIRECTX_CAPTURE as OPTION;
option2bool(OPTION, &Config::get_option(OPTION))
}
#[cfg(windows)]
pub fn allow_d3d_render() -> bool {
use hbb_common::config::keys::OPTION_ALLOW_D3D_RENDER as OPTION;
use base::config::keys::OPTION_ALLOW_D3D_RENDER as OPTION;
option2bool(OPTION, &hbb_common::config::LocalConfig::get_option(OPTION))
}
@@ -980,7 +980,7 @@ pub fn codec_thread_num(limit: usize) -> usize {
#[cfg(windows)]
{
res = 0;
let percent = hbb_common::platform::windows::cpu_uage_one_minute();
let percent = base::platform::windows::cpu_uage_one_minute();
info = format!("cpu usage: {:?}", percent);
if let Some(pecent) = percent {
if pecent < 100.0 {
@@ -1038,7 +1038,7 @@ fn disable_av1() -> bool {
#[cfg(not(target_os = "ios"))]
pub fn test_av1() {
use hbb_common::config::keys::OPTION_AV1_TEST;
use base::config::keys::OPTION_AV1_TEST;
use hbb_common::rand::Rng;
use std::{sync::Once, time::Duration};

View File

@@ -3,11 +3,11 @@ use crate::{
convert::*,
CodecFormat, EncodeInput, ImageFormat, ImageRgb, Pixfmt, HW_STRIDE_ALIGN,
};
use base::message_proto::{EncodedVideoFrame, EncodedVideoFrames, VideoFrame};
use hbb_common::{
anyhow::{anyhow, bail, Context},
bytes::Bytes,
log,
message_proto::{EncodedVideoFrame, EncodedVideoFrames, VideoFrame},
serde_derive::{Deserialize, Serialize},
serde_json, ResultType,
};

View File

@@ -1,9 +1,6 @@
pub use self::vpxcodec::*;
use hbb_common::{
bail, log,
message_proto::{video_frame, Chroma, VideoFrame},
ResultType,
};
use base::message_proto::{video_frame, Chroma, VideoFrame};
use hbb_common::{bail, log, ResultType};
use std::{ffi::c_void, slice};
cfg_if! {
@@ -268,7 +265,7 @@ pub struct EncodeYuvFormat {
#[cfg(x11)]
#[inline]
pub fn is_x11() -> bool {
hbb_common::platform::linux::is_x11_or_headless()
base::platform::linux::is_x11_or_headless()
}
#[cfg(x11)]

View File

@@ -1,11 +1,8 @@
use crate::CodecFormat;
use base::message_proto::{message, video_frame, EncodedVideoFrame, Message};
#[cfg(feature = "hwcodec")]
use hbb_common::anyhow::anyhow;
use hbb_common::{
bail, chrono, log,
message_proto::{message, video_frame, EncodedVideoFrame, Message},
ResultType,
};
use hbb_common::{bail, chrono, log, ResultType};
#[cfg(feature = "hwcodec")]
use hwcodec::mux::{MuxContext, Muxer};
use std::{

View File

@@ -5,8 +5,8 @@
use hbb_common::anyhow::{anyhow, Context};
use hbb_common::log;
use hbb_common::message_proto::{Chroma, EncodedVideoFrame, EncodedVideoFrames, VideoFrame};
use hbb_common::ResultType;
use base::message_proto::{Chroma, EncodedVideoFrame, EncodedVideoFrames, VideoFrame};
use crate::codec::{base_bitrate, codec_thread_num, EncoderApi};
use crate::{EncodeInput, EncodeYuvFormat, GoogleImage, Pixfmt, STRIDE_ALIGN};

View File

@@ -9,12 +9,11 @@ use crate::{
hwcodec::HwCodecConfig,
AdapterDevice, CodecFormat, EncodeInput, EncodeYuvFormat, Pixfmt,
};
use base::message_proto::{EncodedVideoFrame, EncodedVideoFrames, VideoFrame};
use hbb_common::{
anyhow::{anyhow, bail, Context},
bytes::Bytes,
log,
message_proto::{EncodedVideoFrame, EncodedVideoFrames, VideoFrame},
ResultType,
log, ResultType,
};
use hwcodec::{
common::{DataFormat, Driver, MAX_GOP},
@@ -98,7 +97,7 @@ impl EncoderApi for VRamEncoder {
&mut self,
frame: EncodeInput,
ms: i64,
) -> ResultType<hbb_common::message_proto::VideoFrame> {
) -> ResultType<base::message_proto::VideoFrame> {
let (texture, rotation) = frame.texture()?;
if rotation != 0 {
// to-do: support rotation

View File

@@ -8,7 +8,7 @@ use std::{
};
use tracing::warn;
use hbb_common::platform::linux::{get_wayland_displays, WaylandDisplayInfo};
use base::platform::linux::{get_wayland_displays, WaylandDisplayInfo};
lazy_static! {
static ref DISPLAYS: Mutex<Option<Arc<Displays>>> = Mutex::new(None);
@@ -105,7 +105,7 @@ fn try_xrandr_primary() -> Option<String> {
}
fn try_kscreen_primary() -> Option<String> {
if !hbb_common::platform::linux::is_kde_session() {
if !base::platform::linux::is_kde_session() {
return None;
}

View File

@@ -23,7 +23,8 @@ use gstreamer_app::AppSink;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use hbb_common::{bail, config, platform::linux::CMD_SH, serde_json, tokio, ResultType};
use base::platform::linux::CMD_SH;
use hbb_common::{bail, config, serde_json, tokio, ResultType};
use super::capturable::PixelProvider;
use super::capturable::{Capturable, Recorder};