From a3d7fd6bad1a4b8796bf61ffab913f138eb0cd92 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Thu, 13 Aug 2026 02:16:10 +0900 Subject: [PATCH] bobbin-types: depend on `crates/lexicons` crate Signed-off-by: Seongmin Lee --- Cargo.lock | 7 +- bobbin/containerfiles/bobbin.Containerfile | 1 + bobbin/crates/types/Cargo.toml | 20 ++---- bobbin/crates/types/build.rs | 75 ---------------------- bobbin/crates/types/src/lib.rs | 18 +----- crates/lexicons/Cargo.toml | 4 +- crates/lexicons/build.rs | 2 - 7 files changed, 13 insertions(+), 114 deletions(-) delete mode 100644 bobbin/crates/types/build.rs diff --git a/Cargo.lock b/Cargo.lock index 3a7f5fe9..c6efab97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -977,18 +977,13 @@ dependencies = [ name = "bobbin-types" version = "0.0.1" dependencies = [ - "anyhow", "bytes", - "chrono", "cid", "jacquard-common", - "jacquard-derive", - "jacquard-lexicon", - "miette", + "lexicons", "serde", "serde_json", "thiserror 2.0.18", - "walkdir", ] [[package]] diff --git a/bobbin/containerfiles/bobbin.Containerfile b/bobbin/containerfiles/bobbin.Containerfile index 139e0904..72887295 100644 --- a/bobbin/containerfiles/bobbin.Containerfile +++ b/bobbin/containerfiles/bobbin.Containerfile @@ -15,6 +15,7 @@ ARG BOBBIN_PROFILE=release WORKDIR /src COPY Cargo.toml Cargo.lock rust-toolchain.toml ./ COPY lexicons ./lexicons +COPY crates/lexicons ./crates/lexicons COPY crates/trusted-proxies ./crates/trusted-proxies COPY bobbin ./bobbin # keep image lighter by not copying in shittle, knot2 diff --git a/bobbin/crates/types/Cargo.toml b/bobbin/crates/types/Cargo.toml index d8e0345b..a58d5d5b 100644 --- a/bobbin/crates/types/Cargo.toml +++ b/bobbin/crates/types/Cargo.toml @@ -7,25 +7,17 @@ rust-version.workspace = true [dependencies] bytes = { workspace = true } -chrono = { workspace = true } cid = { workspace = true } jacquard-common = { workspace = true } -jacquard-derive = { workspace = true } -jacquard-lexicon = { workspace = true } -miette = { workspace = true } +lexicons = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } -[build-dependencies] -anyhow = { workspace = true } -jacquard-lexicon = { workspace = true, features = ["codegen"] } -walkdir = { workspace = true } - [features] default = ["sh_tangled", "org_tangled"] -com_atproto = [] -com_bad_example = [] -sh_tangled = ["com_atproto"] -org_tangled = ["com_atproto"] -streaming = ["jacquard-common/websocket"] +com_atproto = ["lexicons/com_atproto"] +com_bad_example = ["lexicons/com_bad_example"] +sh_tangled = ["lexicons/sh_tangled"] +org_tangled = ["lexicons/org_tangled"] +streaming = ["lexicons/streaming"] diff --git a/bobbin/crates/types/build.rs b/bobbin/crates/types/build.rs deleted file mode 100644 index 02928bfb..00000000 --- a/bobbin/crates/types/build.rs +++ /dev/null @@ -1,75 +0,0 @@ -use std::path::{Path, PathBuf}; - -use anyhow::{Context, Result}; -use jacquard_lexicon::codegen::{CodeGenerator, CodegenMode}; -use jacquard_lexicon::corpus::LexiconCorpus; -use walkdir::WalkDir; - -const DEFAULT_LEXICONS_SUBDIR: &str = "lexicons"; -const STAGED_SUBDIR: &str = "lexicons-staged"; -const GENERATED_SUBDIR: &str = "src/_lex"; -const TEMP_SEGMENT: &str = "temp"; - -fn main() -> Result<()> { - let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR")?); - let workspace_root = manifest_dir - .parent() - .and_then(Path::parent) - .and_then(Path::parent) - .context("resolve workspace root from manifest dir")? - .to_path_buf(); - - let lexicons_dir = std::env::var("BOBBIN_LEXICONS_DIR") - .map(PathBuf::from) - .unwrap_or_else(|_| workspace_root.join(DEFAULT_LEXICONS_SUBDIR)); - - println!("cargo:rerun-if-env-changed=BOBBIN_LEXICONS_DIR"); - println!("cargo:rerun-if-changed={}", lexicons_dir.display()); - println!("cargo:rerun-if-changed=build.rs"); - - let out_dir = PathBuf::from(std::env::var("OUT_DIR")?); - - let staged = out_dir.join(STAGED_SUBDIR); - if staged.exists() { - std::fs::remove_dir_all(&staged).context("clean staged lexicons")?; - } - stage_lexicons(&lexicons_dir, &staged)?; - - let corpus = LexiconCorpus::load_from_dir(&staged) - .map_err(|e| anyhow::anyhow!("load lexicon corpus: {e:?}"))?; - - let generated = manifest_dir.join(GENERATED_SUBDIR); - if generated.exists() { - std::fs::remove_dir_all(&generated).context("clean generated dir")?; - } - std::fs::create_dir_all(&generated).context("create generated dir")?; - - let codegen = CodeGenerator::with_mode(&corpus, "crate", CodegenMode::Pretty); - codegen - .write_to_disk(&generated) - .map_err(|e| anyhow::anyhow!("write generated code: {e:?}"))?; - - Ok(()) -} - -fn stage_lexicons(src: &Path, dst: &Path) -> Result<()> { - WalkDir::new(src) - .into_iter() - .filter_map(std::result::Result::ok) - .filter(|e| e.file_type().is_file()) - .filter(|e| { - e.path() - .extension() - .is_some_and(|ext| ext.eq_ignore_ascii_case("json")) - }) - .filter(|e| !e.path().components().any(|c| c.as_os_str() == TEMP_SEGMENT)) - .try_for_each(|entry| -> Result<()> { - let rel = entry.path().strip_prefix(src).context("strip src prefix")?; - let target = dst.join(rel); - if let Some(parent) = target.parent() { - std::fs::create_dir_all(parent).context("create staged parent")?; - } - std::fs::copy(entry.path(), &target).context("copy lexicon file")?; - Ok(()) - }) -} diff --git a/bobbin/crates/types/src/lib.rs b/bobbin/crates/types/src/lib.rs index 3a61600e..11b564b2 100644 --- a/bobbin/crates/types/src/lib.rs +++ b/bobbin/crates/types/src/lib.rs @@ -1,21 +1,7 @@ extern crate alloc; -#[path = "_lex/lib.rs"] -#[allow(non_snake_case, unused_imports)] -#[allow( - clippy::absurd_extreme_comparisons, - clippy::collapsible_if, - clippy::manual_strip, - clippy::needless_update, - clippy::new_ret_no_self, - clippy::new_without_default, - clippy::should_implement_trait, - clippy::type_complexity -)] -#[rustfmt::skip] -mod _lex; - -pub use _lex::*; +// TODO(boltless): remove this later. or at least change to `pub use lexicons;` +pub use lexicons::*; pub mod edges; pub mod ids; diff --git a/crates/lexicons/Cargo.toml b/crates/lexicons/Cargo.toml index de20100d..d3cf39c3 100644 --- a/crates/lexicons/Cargo.toml +++ b/crates/lexicons/Cargo.toml @@ -23,8 +23,10 @@ jacquard-lexicon = { workspace = true, features = ["codegen"] } walkdir = { workspace = true } [features] -default = ["sh_tangled"] +default = ["sh_tangled", "org_tangled"] com_atproto = [] com_bad_example = [] sh_tangled = ["com_atproto"] +# org.tangled.temp.search.searchCode#fileResult.repo refs sh.tangled.repo.defs#repoViewBasic +org_tangled = ["sh_tangled"] streaming = ["jacquard-common/websocket"] diff --git a/crates/lexicons/build.rs b/crates/lexicons/build.rs index 8d139aed..24b9ae51 100644 --- a/crates/lexicons/build.rs +++ b/crates/lexicons/build.rs @@ -8,7 +8,6 @@ use walkdir::WalkDir; const DEFAULT_LEXICONS_SUBDIR: &str = "lexicons"; const STAGED_SUBDIR: &str = "lexicons-staged"; const GENERATED_SUBDIR: &str = "src/_lex"; -const TEMP_SEGMENT: &str = "temp"; fn main() -> Result<()> { let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR")?); @@ -61,7 +60,6 @@ fn stage_lexicons(src: &Path, dst: &Path) -> Result<()> { .extension() .is_some_and(|ext| ext.eq_ignore_ascii_case("json")) }) - .filter(|e| !e.path().components().any(|c| c.as_os_str() == TEMP_SEGMENT)) .try_for_each(|entry| -> Result<()> { let rel = entry.path().strip_prefix(src).context("strip src prefix")?; let target = dst.join(rel); -- 2.51.2