forked from 1b-agent/opencadstudio-upstream
chore: silence native and wasm build warnings
Gate target-specific code so neither build warns about the other's items: native-only helpers (view, window icon, file dialogs, file association, plugin host/guard/registry, self-update) are cfg'd to non-wasm; the wasm-only font fallback (script_of / cjk_lang / request) is cfg'd to wasm. Drop an unused mut, allow the few genuinely-conditional dead items (mesh_click_hit, GPU layout helpers, parity stubs), and gate the embedded PlotSettings-unrelated dead constants. Both targets now build clean (only the unavoidable nom/quick-xml future-incompat dependency notice remains). Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
2de5c7668f
commit
10e4c18ba7
20 files changed
+37
-2
No files matched your search
@@ -159,6 +159,7 @@ pub(super) struct DocumentTab {
|
||||
/// rest of the code can treat it as a normal tab when reading.
|
||||
pub(super) is_start: bool,
|
||||
/// Per-plugin document state (`plugin::BuiltinPlugin` manifest id → state).
|
||||
#[cfg_attr(target_arch = "wasm32", allow(dead_code))]
|
||||
pub(super) plugin_state: HashMap<&'static str, Box<dyn Any + Send + Sync>>,
|
||||
pub(super) suspended_cmd: Option<Box<dyn CadCommand>>,
|
||||
}
|
||||
|
||||
@@ -286,6 +286,7 @@ pub(super) fn title_case_word(value: &str) -> String {
|
||||
// ── Window icon ────────────────────────────────────────────────────────────
|
||||
|
||||
/// Builds a 32×32 RGBA icon: red background with OCS drawn in white pixels.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(super) fn build_window_icon() -> Vec<u8> {
|
||||
const W: usize = 32;
|
||||
const SZ: usize = W * W * 4;
|
||||
|
||||
@@ -11,6 +11,7 @@ mod history;
|
||||
mod layers;
|
||||
mod model_ops;
|
||||
mod mtext_editor;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod plugin_host;
|
||||
mod properties;
|
||||
mod settings;
|
||||
@@ -819,6 +820,7 @@ pub enum ModalKind {
|
||||
DimStyle,
|
||||
Unsaved,
|
||||
SaveDialog,
|
||||
#[cfg_attr(target_arch = "wasm32", allow(dead_code))]
|
||||
AssocPrompt,
|
||||
PointStyle,
|
||||
}
|
||||
@@ -2020,6 +2022,7 @@ impl OpenCADStudio {
|
||||
/// open. Secondary manager windows are unavailable on the web for now.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn boot_web() -> (Self, Task<Message>) {
|
||||
#[cfg_attr(target_arch = "wasm32", allow(unused_mut))]
|
||||
let mut s = Self::new();
|
||||
let focus = s.focus_cmd_input();
|
||||
(s, focus)
|
||||
|
||||
@@ -238,6 +238,7 @@ impl OpenCADStudio {
|
||||
|
||||
/// Snapshot of disabled plugin ids — lets the registry skip them while it
|
||||
/// holds a `&mut` borrow of the app via `HostSession`.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) fn disabled_plugin_ids(&self) -> rustc_hash::FxHashSet<String> {
|
||||
self.disabled_plugins.clone()
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ impl std::fmt::Display for RenderModeChoice {
|
||||
}
|
||||
|
||||
impl OpenCADStudio {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn view(&self, window_id: window::Id) -> Element<'_, Message> {
|
||||
// ── Floating panel windows ─────────────────────────────────────────
|
||||
// All dialogs are in-canvas modals now (Plan B); view_main stacks the
|
||||
@@ -3893,6 +3894,7 @@ pub(super) fn start_page_view<'a>() -> Element<'a, Message> {
|
||||
.spacing(12)
|
||||
.align_y(iced::Center);
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", allow(unused_mut))]
|
||||
let mut secondary_row = row![
|
||||
outline_btn(
|
||||
"Send Feedback",
|
||||
|
||||
@@ -37,6 +37,7 @@ const APP_ID: &str = "io.github.HakanSeven12.OpenCadStudio";
|
||||
/// Idempotent and best-effort; safe to call on every launch. Runs synchronously
|
||||
/// (registry / small file writes), so callers should invoke it off the UI
|
||||
/// thread.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn register_as_handler() -> Result<(), String> {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
|
||||
@@ -31,6 +31,7 @@ const PHASE_FINALIZING: u8 = 3;
|
||||
/// Show the file picker and return the chosen path plus its size in bytes.
|
||||
/// Returning size up-front lets the loading overlay display "47.3 MB" before
|
||||
/// the parser thread starts.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub async fn pick_open_path() -> Option<(PathBuf, u64)> {
|
||||
let handle = rfd::AsyncFileDialog::new()
|
||||
.set_title("Open CAD file")
|
||||
|
||||
@@ -79,6 +79,7 @@ pub fn plugins_dir() -> Option<PathBuf> {
|
||||
|
||||
/// Delete an installed package's folder. It stays loaded for the current
|
||||
/// session (the library is resident); the removal takes effect on next start.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn uninstall(id: &str) -> Result<(), String> {
|
||||
let dir = plugins_dir().ok_or("cannot locate the plugins folder")?.join(id);
|
||||
if dir.is_dir() {
|
||||
|
||||
@@ -4,4 +4,5 @@
|
||||
// The session adapter the registry wraps `app` in to dispatch to plugins. The
|
||||
// plugin-facing contract — `BuiltinPlugin` + `HostApi` — lives in
|
||||
// `ocs_plugin_api`; external cdylibs target it directly.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) use crate::app::plugin_host::HostSession;
|
||||
@@ -16,6 +16,7 @@ pub(crate) use registry::try_dispatch;
|
||||
/// the cdylib boundary — it does NOT contain genuine UB (a plugin that
|
||||
/// segfaults or violates memory safety via `unsafe` can still crash the host;
|
||||
/// only out-of-process isolation would). (#145)
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) fn guard<T>(what: &str, f: impl FnOnce() -> T) -> Option<T> {
|
||||
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)) {
|
||||
Ok(v) => Some(v),
|
||||
@@ -38,12 +39,14 @@ pub(crate) fn guard<T>(what: &str, f: impl FnOnce() -> T) -> Option<T> {
|
||||
|
||||
/// Process-wide queue of plugin-guard errors waiting to surface in the host's
|
||||
/// command-line history. Flushed by [`drain_errors`] from the app loop.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn errors() -> &'static std::sync::Mutex<Vec<String>> {
|
||||
static E: std::sync::OnceLock<std::sync::Mutex<Vec<String>>> = std::sync::OnceLock::new();
|
||||
E.get_or_init(|| std::sync::Mutex::new(Vec::new()))
|
||||
}
|
||||
|
||||
/// Take and return every queued plugin-guard error since the last drain.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) fn drain_errors() -> Vec<String> {
|
||||
std::mem::take(&mut *errors().lock().unwrap())
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ pub fn all_ribbon_modules() -> Vec<Box<dyn CadModule>> {
|
||||
pub fn ribbon_modules_enabled(
|
||||
disabled: &rustc_hash::FxHashSet<String>,
|
||||
) -> Vec<Box<dyn CadModule>> {
|
||||
#[cfg_attr(target_arch = "wasm32", allow(unused_mut))]
|
||||
let mut core = core_registry::all_modules();
|
||||
// Dynamically-loaded external plugins contribute tabs (their libraries stay
|
||||
// resident for the session, so these vtables remain valid).
|
||||
|
||||
@@ -385,6 +385,7 @@ pub(crate) fn collect_loop_polygon(
|
||||
|
||||
/// All loops of a face: the outer boundary first, then any inner hole loops.
|
||||
/// Each loop is returned as an ordered 3-D polygon (≥ 3 points).
|
||||
#[cfg(feature = "solid3d")]
|
||||
pub(crate) fn collect_face_loops(
|
||||
sat: &SatDocument,
|
||||
face: &SatFace,
|
||||
|
||||
@@ -19,6 +19,7 @@ use truck_polymesh::PolygonMesh;
|
||||
// Chord-height tolerance used for adaptive curve sampling (world units).
|
||||
const CURVE_TOL: f64 = 0.005;
|
||||
// Triangle mesh tolerance (world units).
|
||||
#[allow(dead_code)]
|
||||
pub const MESH_TOL: f64 = 0.01;
|
||||
|
||||
// ── Zoom-adaptive curve tolerance override ────────────────────────────────
|
||||
|
||||
@@ -2429,6 +2429,7 @@ impl Scene {
|
||||
|
||||
/// Pick a meshed 3D solid by clicking on its shaded body (face), not just
|
||||
/// its thin projected edges. Returns the front-most mesh under `cursor`.
|
||||
#[allow(dead_code)]
|
||||
pub fn mesh_click_hit(
|
||||
&self,
|
||||
cursor: iced::Point,
|
||||
|
||||
@@ -106,6 +106,7 @@ pub struct HatchBatchedVertex {
|
||||
}
|
||||
|
||||
impl HatchBatchedVertex {
|
||||
#[allow(dead_code)]
|
||||
pub fn layout<'a>() -> wgpu::VertexBufferLayout<'a> {
|
||||
wgpu::VertexBufferLayout {
|
||||
array_stride: std::mem::size_of::<HatchBatchedVertex>() as u64,
|
||||
@@ -450,6 +451,7 @@ impl HatchBatchedGpu {
|
||||
/// constructed once at startup. All four bindings are read-only
|
||||
/// storage and visible to both VS (AABB+visibility lookup) and FS
|
||||
/// (boundary / family / dash sampling).
|
||||
#[allow(dead_code)]
|
||||
pub fn bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout {
|
||||
let entry = |binding: u32| wgpu::BindGroupLayoutEntry {
|
||||
binding,
|
||||
|
||||
@@ -1001,7 +1001,7 @@ impl Pipeline {
|
||||
// O(highlighted), no per-wire string parse. Selection recolours blue,
|
||||
// hover orange. Drawn on top (depth-compare Always) over the base pass.
|
||||
let mut out: Vec<WireModel> = Vec::new();
|
||||
let mut push = |handle_val: u64, color: [f32; 4], wires: &[WireModel], out: &mut Vec<WireModel>| {
|
||||
let push = |handle_val: u64, color: [f32; 4], wires: &[WireModel], out: &mut Vec<WireModel>| {
|
||||
if let Some(idxs) = self.wire_handle_index.get(&handle_val) {
|
||||
let mut slots = idxs.clone();
|
||||
slots.sort_unstable();
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
use crate::scene::model::wire_model::WireModel;
|
||||
use iced::wgpu;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use crate::par::prelude::*;
|
||||
|
||||
/// Allocate a VERTEX buffer with `mapped_at_creation` and write `data` directly
|
||||
|
||||
@@ -205,6 +205,7 @@ fn shape_cache() -> &'static Mutex<ShapeCache> {
|
||||
|
||||
/// Pixel font size the layout runs at. Positions and outlines are normalized
|
||||
/// out of pixel space afterwards, so the exact value only affects rounding.
|
||||
#[allow(dead_code)]
|
||||
const SHAPE_FS: f32 = 1000.0;
|
||||
|
||||
/// Shared cosmic-text layout engine, loaded once with the system fonts. Held
|
||||
|
||||
@@ -57,6 +57,7 @@ impl Script {
|
||||
/// 2 = Korean. Set from the active document's code page.
|
||||
static CJK_LANG: AtomicU8 = AtomicU8::new(0);
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn cjk_lang() -> Script {
|
||||
match CJK_LANG.load(Ordering::Relaxed) {
|
||||
1 => Script::Japanese,
|
||||
@@ -83,6 +84,7 @@ pub fn set_cjk_lang_from_codepage(code_page: &str) -> bool {
|
||||
|
||||
/// The script font that covers `ch`, or `None` for control / uncovered code
|
||||
/// points. Ranges mirror the subset unicode ranges in `web/fonts/generate.sh`.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub fn script_of(ch: char) -> Option<Script> {
|
||||
Some(match ch as u32 {
|
||||
0x0000..=0x024F | 0x1E00..=0x1EFF | 0x2000..=0x206F => Script::Latin,
|
||||
@@ -184,6 +186,8 @@ mod imp {
|
||||
use super::Script;
|
||||
use std::sync::Arc;
|
||||
|
||||
// Kept for parity with the wasm impl; only the wasm path has a caller.
|
||||
#[allow(dead_code)]
|
||||
pub fn request(_script: Script) -> Option<Arc<Vec<u8>>> {
|
||||
None
|
||||
}
|
||||
@@ -196,4 +200,7 @@ mod imp {
|
||||
}
|
||||
}
|
||||
|
||||
pub use imp::{fetch, insert, request, take_pending};
|
||||
pub use imp::{fetch, insert, take_pending};
|
||||
// `request` only has a caller in the wasm font-fallback path.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub use imp::request;
|
||||
@@ -6,6 +6,7 @@
|
||||
// returns `Some(UpdateInfo)` when a newer release is available, or
|
||||
// `None` when up to date / on network failure / on parse error.
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
const RELEASES_API: &str =
|
||||
"https://api.github.com/repos/HakanSeven12/OpenCADStudio/releases/latest";
|
||||
pub const RELEASES_PAGE: &str =
|
||||
@@ -16,6 +17,7 @@ pub const RELEASES_PAGE: &str =
|
||||
/// after a tag is pushed, so suppressing notifications for the first 30
|
||||
/// minutes prevents users from clicking through to a release page whose
|
||||
/// asset list is still empty.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
const MIN_RELEASE_AGE_SECS: u64 = 30 * 60;
|
||||
|
||||
/// What `check_for_update` reports when a newer release exists.
|
||||
@@ -39,6 +41,7 @@ pub async fn check_for_update() -> Option<UpdateInfo> {
|
||||
/// On wasm there is no background thread or blocking HTTP client; the web build
|
||||
/// skips the self-update check (the page is always served fresh).
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[allow(dead_code)]
|
||||
pub async fn check_for_update() -> Option<UpdateInfo> {
|
||||
None
|
||||
}
|
||||
@@ -86,6 +89,7 @@ fn fetch_latest_if_outdated() -> Option<UpdateInfo> {
|
||||
/// Parse a GitHub timestamp like `2026-05-29T12:34:56Z` into UNIX seconds.
|
||||
/// Only handles the fixed `YYYY-MM-DDTHH:MM:SSZ` format the GitHub API
|
||||
/// emits; returns `None` for anything else.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn parse_iso8601_utc(s: &str) -> Option<u64> {
|
||||
let b = s.as_bytes();
|
||||
if b.len() != 20 || b[4] != b'-' || b[7] != b'-' || b[10] != b'T'
|
||||
@@ -132,6 +136,7 @@ fn parse_iso8601_utc(s: &str) -> Option<u64> {
|
||||
/// Avoids pulling in `serde_json` for two fields. Handles standard JSON
|
||||
/// string escapes (`\"`, `\\`, `\n`, `\r`, `\t`, `\/`) which are all the
|
||||
/// GitHub release body uses in practice.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn extract_string_field(body: &str, field: &str) -> Option<String> {
|
||||
let key = format!("\"{}\":\"", field);
|
||||
let start = body.find(&key)? + key.len();
|
||||
|
||||
Reference in new issue
Block a user