Skip to content

Single edge crate - #8173

Merged
xzfc merged 5 commits into
devfrom
edge-single-crate
Feb 24, 2026
Merged

xzfc merged 5 commits into
devfrom
edge-single-crate

Conversation

@xzfc

@xzfc xzfc commented Feb 18, 2026 •

Copy link
Copy Markdown
Member

Depends on #8185.

This PR is a step towards publishing qdrant-edge at crates.io.

It adds script amalgamate.py (name coined by the SQLite Amalgamation) that combines 10 crates into a single qdrant-edge crate. This script fixes module paths using ast-grep and regexes. Also, it removes #[derive(Anonymize)] so we do not need to publish a separate proc-macro crate. Now, the only remaining non-crates.io dependency is https://github.com/qdrant/rust-stemmers.

Also, a GitHub workflow is added to check whether the generated crate is buildable.

Structure

Everything significant is placed in a new directory lib/edge/publish that contains:

  • examples Rust package (was in lib/edge/examples)
  • qdrant-edge Rust package (autogenerated, gitignored)
  • Rust workspace (so, it has its own Cargo.lock (gitignored))
  • amalgamate.py - script to generate qdrant-edge.

@xzfc
xzfc force-pushed the edge-single-crate branch 3 times, most recently from a0dd0e5 to 6b1e6d2 Compare February 20, 2026 12:06
@xzfc
xzfc changed the base branch from dev to wal-package-move February 20, 2026 13:09
@xzfc
xzfc force-pushed the edge-single-crate branch 3 times, most recently from ae1b74c to 78a7ce3 Compare February 20, 2026 16:59
@xzfc
xzfc force-pushed the edge-single-crate branch from 78a7ce3 to 3acad40 Compare February 20, 2026 17:41
@xzfc
xzfc marked this pull request as ready for review February 20, 2026 17:52
Base automatically changed from wal-package-move to dev February 20, 2026 18:02
xzfc added 5 commits February 20, 2026 18:03
Fix issues that break `qdrant-edge` build process:
- `use … as segment;` - this causes `ast-grep` rules to replace wrong
  paths. So, rename to avoid collisions.
- `#[macro_use]` and `extern crate` required be in the top-level
  `lib.rs`.
- `format!("…", crate::something::…)` - `ast-grep` can't fix paths
  inside macros. Fixed by moving `crate::something::…` out of the macro.
And fix them to use the generated `qdrant-edge` crate.
Removes empty modules. Checked by `cargo doc`.
@xzfc
xzfc force-pushed the edge-single-crate branch from 3acad40 to e1fb582 Compare February 20, 2026 18:04
@coderabbitai

coderabbitai Bot commented Feb 20, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR introduces an automated amalgamation pipeline for the Qdrant Edge library. It adds a GitHub Actions workflow that executes a Python script (amalgamate.py) to consolidate multiple Rust crates into a single workspace under lib/edge/publish. The amalgamation process merges dependencies, transforms code via AST grep rules to adjust module paths and remove problematic code patterns, and prepares the unified crate for distribution. The PR also restructures the edge module visibility by making several modules private while adding a public re-export of ShardInfo. All example code imports are updated to reference the new qdrant_edge namespace, and a Cargo wrapper script is added to standardize build output directories.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • generall
  • ffuugoo
  • Anush008
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Single edge crate' directly refers to the main objective of combining multiple crates into a single qdrant-edge crate for publication.
Description check ✅ Passed The description clearly explains the PR's purpose, dependencies, key changes (amalgamate.py script, removed Anonymize derives, GitHub workflow), and the new directory structure in lib/edge/publish.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch edge-single-crate

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (8)
lib/edge/publish/cargo (1)

21-21: os.execvpe is POSIX-only — acceptable for CI but worth documenting.

os.execvpe semantics on Windows differ (does not replace the current process). Since this is a CI/developer utility targeting Linux/macOS, it is fine in practice. Consider adding a brief comment if Windows support is ever anticipated.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/edge/publish/cargo` at line 21, The call to os.execvpe in the cargo
script is POSIX-only and behaves differently on Windows (it doesn't replace the
current process), so add a brief comment immediately above the
os.execvpe("cargo", ["cargo"] + sys.argv[1:], env) call explaining that this
utility targets Linux/macOS and that execvpe semantics differ on Windows;
mention that if Windows support is needed in future we should either implement a
Windows-specific fallback (e.g., using subprocess) or guard the call behind an
OS check.
.github/workflows/edge-rust-package.yml (2)

42-44: Only cargo check is run — no tests or cargo build.

This validates type-checking but won't catch linker errors (e.g., missing C dependencies, duplicate symbols). If the intent is a build verification, consider upgrading to cargo build -p examples for stronger validation. Fine as-is if this is intentional to keep CI fast.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/edge-rust-package.yml around lines 42 - 44, The workflow
step named "Cargo check" only runs type-checking and won't catch build/linker
issues; update the step (the "Cargo check" step in the workflow for
working-directory lib/edge/publish) to run a full build instead—replace the run
command with "cargo build -p examples" (or "cargo build --all" if broader
coverage is desired) so CI verifies actual compilation and linking rather than
just type checking.

30-31: Consider pinning ast-grep version for reproducible CI.

npm install --global @ast-grep/cli`` installs the latest version, which could introduce breaking changes and non-reproducible builds. Consider pinning: npm install --global @ast-grep/cli`@`.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/edge-rust-package.yml around lines 30 - 31, The CI step
named "Install ast-grep" currently runs `npm install --global `@ast-grep/cli``
which installs the latest package; change this to a pinned version by updating
that command to `npm install --global `@ast-grep/cli`@<version>` (or reference a
workflow variable like AST_GREP_VERSION) so builds are reproducible and immune
to upstream breaking changes—update the step that contains the `npm install
--global `@ast-grep/cli`` invocation accordingly.
lib/edge/publish/amalgamate.py (4)

59-64: Unused manifest in loop.

The destructured manifest variable isn't used in this loop body. Use _ to signal intent.

Proposed fix
-    for pkg, (path, manifest) in packages.items():
+    for pkg, (path, _) in packages.items():
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/edge/publish/amalgamate.py` around lines 59 - 64, The loop over packages
destructures a second element named manifest that is never used; update the for
loop header to ignore it (e.g., change "for pkg, (path, manifest) in
packages.items():" to use an underscore like "for pkg, (path, _) in
packages.items():") so intent is clear and linter warnings are avoided; keep the
loop body using shutil.copytree and os.rename with pkg and path unchanged.

52-56: shutil.rmtree with ignore_errors=True silently swallows permission errors.

If the amalgamation directory can't be deleted due to permission issues (e.g., files locked by another process), the subsequent shutil.copytree calls will fail with a confusing error instead of surfacing the root cause. Consider removing ignore_errors=True and handling FileNotFoundError explicitly.

Proposed fix
-    shutil.rmtree(AMALGAMATION, ignore_errors=True)
+    if AMALGAMATION.exists():
+        shutil.rmtree(AMALGAMATION)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/edge/publish/amalgamate.py` around lines 52 - 56, The call
shutil.rmtree(AMALGAMATION, ignore_errors=True) is hiding permission/other
errors and leading to confusing failures later when copy operations run; update
main to remove ignore_errors=True, catch FileNotFoundError to treat missing
directory as fine, and otherwise let or re-raise permission/OS errors (or
log/raise a clear exception) so failures deleting AMALGAMATION are surfaced
before subsequent shutil.copytree calls; modify the code paths around
shutil.rmtree, AMALGAMATION, and any following shutil.copytree usage
accordingly.

239-260: all_file_dependencies only traverses dependencies, not build-dependencies or dev-dependencies for path-based transitive deps.

Line 253 only iterates manifest["dependencies"]. If any included crate has a path-based build- or dev-dependency that is also in PACKAGES_TO_INCLUDE, it won't be discovered here. This may be fine given the current crate graph, but could silently miss crates if the dependency structure changes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/edge/publish/amalgamate.py` around lines 239 - 260, all_file_dependencies
currently only inspects manifest["dependencies"], missing path-based transitive
deps declared under "build-dependencies" or "dev-dependencies"; update
all_file_dependencies to iterate the three dependency tables ("dependencies",
"build-dependencies", "dev-dependencies") (safely handling missing keys or
non-dict sections) and apply the same path-based resolution/seen/stack logic
used for manifest["dependencies"] so path deps from build or dev sections are
discovered and pushed onto the stack just like regular dependencies.

190-198: gather_dependencies skips optional deps and doesn't merge features — may cause build issues.

Line 191 silently skips optional dependencies. If any optional dep is actually needed at runtime (gated behind a default feature), it won't be included in the generated Cargo.toml. The comment on line 194 acknowledges the feature-merging gap. Both are acceptable for an initial version but could cause subtle build or runtime issues if the dependency graph evolves.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/edge/publish/amalgamate.py` around lines 190 - 198, The
gather_dependencies logic currently skips optional deps and overwrites workspace
entries without merging features; update gather_dependencies so it does NOT bail
out on spec.get("optional") — instead preserve the dependency entry (keeping
optional true) and include any feature requirements so optional-but-needed deps
get written to Cargo.toml; and when combining a workspace entry with
workspace_deps[name], merge feature-related fields rather than simple dict
overwrite: for the merge of workspace_deps[name] and spec (the block that sets
spec = { **workspace_deps[name], **... }), compute the union of "features" lists
(dedupe), reconcile "default-features" (prefer explicit spec value if present),
and copy other keys with spec taking precedence—this ensures features from both
sides are preserved when building the final spec.
lib/edge/publish/ast-grep-rules.yaml (1)

47-57: Minor: drop-anonymize-derive may leave empty #[derive()] when Anonymize is the sole derive.

If a struct has #[derive(Anonymize)] with no other derives, this rule removes Anonymize but leaves an empty #[derive()]. This compiles but is dead weight. Since the generated crate is gitignored and this is a build artifact, this is acceptable — just flagging for awareness.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/edge/publish/ast-grep-rules.yaml` around lines 47 - 57, The rule
drop-anonymize-derive currently removes the Anonymize token inside the
#[derive($$$)] but can leave an empty #[derive()]; update the rule (id:
drop-anonymize-derive, pattern: "Anonymize", inside: pattern: "#[derive($$$)]")
so that when the derive list becomes empty the whole attribute is removed:
change the fix to expand the removal to the attribute end (e.g., set expandEnd
to ')' or a regex matching the closing paren and optional surrounding
whitespace/commas) and keep template: "" so the entire #[derive(...)] (including
any leftover empty parens and dangling commas) is deleted instead of leaving
#[derive()].
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lib/edge/publish/amalgamate.py`:
- Around line 235-236: The loop in function/method that iterates "for seen,
(pattern, _) in zip(seen, replacements):" shadows the outer "seen" list and
should be fixed by renaming the loop variable (e.g., to "seen_flag" or "found")
so it doesn't collide with the outer name, updating the assert to reference the
new name (assert seen_flag, f"Pattern {pattern!r} not found"), and make the zip
call use strict=True (zip(seen, replacements, strict=True)) so mismatched
lengths raise immediately.

---

Nitpick comments:
In @.github/workflows/edge-rust-package.yml:
- Around line 42-44: The workflow step named "Cargo check" only runs
type-checking and won't catch build/linker issues; update the step (the "Cargo
check" step in the workflow for working-directory lib/edge/publish) to run a
full build instead—replace the run command with "cargo build -p examples" (or
"cargo build --all" if broader coverage is desired) so CI verifies actual
compilation and linking rather than just type checking.
- Around line 30-31: The CI step named "Install ast-grep" currently runs `npm
install --global `@ast-grep/cli`` which installs the latest package; change this
to a pinned version by updating that command to `npm install --global
`@ast-grep/cli`@<version>` (or reference a workflow variable like
AST_GREP_VERSION) so builds are reproducible and immune to upstream breaking
changes—update the step that contains the `npm install --global `@ast-grep/cli``
invocation accordingly.

In `@lib/edge/publish/amalgamate.py`:
- Around line 59-64: The loop over packages destructures a second element named
manifest that is never used; update the for loop header to ignore it (e.g.,
change "for pkg, (path, manifest) in packages.items():" to use an underscore
like "for pkg, (path, _) in packages.items():") so intent is clear and linter
warnings are avoided; keep the loop body using shutil.copytree and os.rename
with pkg and path unchanged.
- Around line 52-56: The call shutil.rmtree(AMALGAMATION, ignore_errors=True) is
hiding permission/other errors and leading to confusing failures later when copy
operations run; update main to remove ignore_errors=True, catch
FileNotFoundError to treat missing directory as fine, and otherwise let or
re-raise permission/OS errors (or log/raise a clear exception) so failures
deleting AMALGAMATION are surfaced before subsequent shutil.copytree calls;
modify the code paths around shutil.rmtree, AMALGAMATION, and any following
shutil.copytree usage accordingly.
- Around line 239-260: all_file_dependencies currently only inspects
manifest["dependencies"], missing path-based transitive deps declared under
"build-dependencies" or "dev-dependencies"; update all_file_dependencies to
iterate the three dependency tables ("dependencies", "build-dependencies",
"dev-dependencies") (safely handling missing keys or non-dict sections) and
apply the same path-based resolution/seen/stack logic used for
manifest["dependencies"] so path deps from build or dev sections are discovered
and pushed onto the stack just like regular dependencies.
- Around line 190-198: The gather_dependencies logic currently skips optional
deps and overwrites workspace entries without merging features; update
gather_dependencies so it does NOT bail out on spec.get("optional") — instead
preserve the dependency entry (keeping optional true) and include any feature
requirements so optional-but-needed deps get written to Cargo.toml; and when
combining a workspace entry with workspace_deps[name], merge feature-related
fields rather than simple dict overwrite: for the merge of workspace_deps[name]
and spec (the block that sets spec = { **workspace_deps[name], **... }), compute
the union of "features" lists (dedupe), reconcile "default-features" (prefer
explicit spec value if present), and copy other keys with spec taking
precedence—this ensures features from both sides are preserved when building the
final spec.

In `@lib/edge/publish/ast-grep-rules.yaml`:
- Around line 47-57: The rule drop-anonymize-derive currently removes the
Anonymize token inside the #[derive($$$)] but can leave an empty #[derive()];
update the rule (id: drop-anonymize-derive, pattern: "Anonymize", inside:
pattern: "#[derive($$$)]") so that when the derive list becomes empty the whole
attribute is removed: change the fix to expand the removal to the attribute end
(e.g., set expandEnd to ')' or a regex matching the closing paren and optional
surrounding whitespace/commas) and keep template: "" so the entire
#[derive(...)] (including any leftover empty parens and dangling commas) is
deleted instead of leaving #[derive()].

In `@lib/edge/publish/cargo`:
- Line 21: The call to os.execvpe in the cargo script is POSIX-only and behaves
differently on Windows (it doesn't replace the current process), so add a brief
comment immediately above the os.execvpe("cargo", ["cargo"] + sys.argv[1:], env)
call explaining that this utility targets Linux/macOS and that execvpe semantics
differ on Windows; mention that if Windows support is needed in future we should
either implement a Windows-specific fallback (e.g., using subprocess) or guard
the call behind an OS check.

Comment thread lib/edge/publish/amalgamate.py Resolved
@xzfc
xzfc merged commit 28d9c5b into dev Feb 24, 2026
16 checks passed
@xzfc
xzfc deleted the edge-single-crate branch February 24, 2026 16:44
@xzfc xzfc mentioned this pull request Mar 3, 2026
generall pushed a commit that referenced this pull request Mar 26, 2026
* Fixups of amalgamator

Fix issues that break `qdrant-edge` build process:
- `use … as segment;` - this causes `ast-grep` rules to replace wrong
  paths. So, rename to avoid collisions.
- `#[macro_use]` and `extern crate` required be in the top-level
  `lib.rs`.
- `format!("…", crate::something::…)` - `ast-grep` can't fix paths
  inside macros. Fixed by moving `crate::something::…` out of the macro.

* Add lib/edge/publish workspace and amalgamation script

* Move `lib/edge/examples` into `lib/edge/publish/` workspace

And fix them to use the generated `qdrant-edge` crate.

* Add github workflow

* Cleanup `qdrant-edge` public API

Removes empty modules. Checked by `cargo doc`.
KShivendu pushed a commit that referenced this pull request Mar 30, 2026
* Fixups of amalgamator

Fix issues that break `qdrant-edge` build process:
- `use … as segment;` - this causes `ast-grep` rules to replace wrong
  paths. So, rename to avoid collisions.
- `#[macro_use]` and `extern crate` required be in the top-level
  `lib.rs`.
- `format!("…", crate::something::…)` - `ast-grep` can't fix paths
  inside macros. Fixed by moving `crate::something::…` out of the macro.

* Add lib/edge/publish workspace and amalgamation script

* Move `lib/edge/examples` into `lib/edge/publish/` workspace

And fix them to use the generated `qdrant-edge` crate.

* Add github workflow

* Cleanup `qdrant-edge` public API

Removes empty modules. Checked by `cargo doc`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants