Skip to content

Make proc-macro-crate optional for build systems without per-crate Ca… - #153

Open
rraometa wants to merge 1 commit into
ZettaScaleLabs:mainfrom
rraometa:optional-proc-macro-crate
Open

rraometa wants to merge 1 commit into
ZettaScaleLabs:mainfrom
rraometa:optional-proc-macro-crate

Conversation

@rraometa

Copy link
Copy Markdown

Problem

stabby-macros locates the stabby / stabby-abi crates with proc_macro_crate::crate_name(), which reads the calling crate's Cargo.toml. Build systems that compile crates without a per-crate manifest in place (Buck2, Bazel) have no such file, so every #[stabby] expansion panics:

Couldn't find `stabby` in your dependencies: Could not find `Cargo.toml` in manifest dir

This blocks using zenoh with shared memory (which depends on stabby) under those build systems.

Change

New proc-macro-crate feature, enabled by default in stabby and stabby-abi, so Cargo users see no change:

  • With the feature (default): unchanged behaviour; the existing code is only re-indented under #[cfg(feature = "proc-macro-crate")].
  • Without it: tl_mod() always emits stabby::abi, and stabby and stabby-abi each declare extern crate self as stabby; (plus pub(crate) mod abi { pub(crate) use super::*; } in stabby-abi) so that path resolves inside both crates and in dependents.
  • stabby-macros: proc-macro-crate becomes an optional dependency behind the feature; the proc_macro2::Ident import is gated with it to stay warning-free.

Crates depending on stabby or stabby-abi with default-features = false should add the proc-macro-crate feature to keep the old behaviour (worth a CHANGELOG note).

Testing

  • cargo test -p stabby -p stabby-abi -p stabby-macros: unit tests pass (8 + 18).
  • Feature off: cargo build -p stabby --no-default-features --features std and cargo build -p stabby-abi --no-default-features --features std build without warnings; cargo tree -i proc-macro-crate confirms the dependency is absent.
  • Pre-existing and unrelated, same on the default branch without this change: three tutorial doctests need the libloading feature, and cargo build -p library on its own does not enable an allocator.
  • We have built stabby without proc-macro-crate under Buck2 as a dependency of zenoh-shm (72.1.1 through a fork with this change, 72.1.16 with an equivalent patch), with SHM traffic on our robots.

…rgo manifests

Signed-off-by: rraometa <rrao@meta.com>
@rraometa

Copy link
Copy Markdown
Author

Hi! The "Check for required labels" job is failing because I don't have permission to add labels. Could a maintainer please add the bug enhancement? Thanks!

meta-codesync Bot pushed a commit to facebookexperimental/rust-shed that referenced this pull request Oct 28, 2026
Summary:
Upgrade zenoh from 1.7.1 to 1.10.1 for Rust, zenoh-c, zenoh-cpp and eclipse-zenoh (Python) together. They must move in lockstep: 1.10.1 bumps `SHM_VERSION` 1 -> 2, so 1.7.1 and 1.10.1 processes cannot share SHM buffers (the wire protocol is unchanged, 0x09).

This is D1 of a stack: pristine upstream 1.10.1 plus build plumbing. Behavior fixups that upstream does not yet carry are re-added on top in their own diffs, after being re-verified against this baseline.

**Rust (`third-party/rust`)**
- All zenoh crates 1.7.1 -> 1.10.1. New transitive crates: `lockfree`, `owned-alloc`, `lz4_flex` 0.10, `rlimit` 0.10; `stabby` 72.1.1 -> 72.1.16.
- Removed overlays:
  - `zenoh` `net/routing/dispatcher/queries.rs` (routing AB-BA deadlock T289921933, `pending_queries` use-after-free D124609602): fixed upstream, `route_send_response` now takes `tables` before `queries` and clones the query before releasing the lock.
  - `zenoh-shm` `lib.rs` / `shm_provider.rs`, `zenoh-codec` `zbuf.rs`, `zenoh-transport` `pipeline.rs` (in-flight SHM ref tracker D93568656 / D122891487, GC `total_freed`, `busy_count`, UDP stuck congestion D112961319): not in 1.10.1 upstream; re-added later in the stack only if the on-robot repros still fail on 1.10.1 (the SHM leak is expected to be covered by the unsafe allocation policy the zenoh team recommends).
- Kept overlay: `Session::matching_subscribers()` (camera 1:1 subscriber check, T280311274), rewritten for the 1.10.1 routing tables and gated to `=1.10.1`.
- New overlay (1.10.1 regression, upstream: eclipse-zenoh/zenoh#2891): closing a session while a publisher or querier is still alive leaked the session, its runtime and its SHM auth segment. Their states keep a key expression whose `KeyExprWireDeclaration` holds a strong session reference; `close_inner()` cleared subscriber and queryable states but not these, and undeclaring after close returns early. `api/session.rs`: `close_inner()` also takes `publishers` and `queriers`.
- `stabby`: replace the `github.com/nitinsingh-meta/stabby` fork (pinned at 72.1.1, no longer matched by zenoh's `^72.1.8`) with reindeer overlays on 72.1.16 carrying the same change: build without `proc-macro-crate`, which panics under Buck. The `stabby-abi` bootstrap-nightly `build.rs` overlay moves its gate to `=72.1.16` (upstream `build.rs` is unchanged).

**zenoh-c / zenoh-cpp**
- Re-import at 1.10.1.
- `000-buck-friendly-buildrs.patch` regenerated as a clean vendor-only diff. New in 1.10.1: Buck mode skips `sync_opaque_types_lockfile()` (no `Cargo.lock` under Buck) and logs with `eprintln!` instead of the new `build_print` dependency.
- Drop `001-rand-compat.patch`: depend on `rand_09`, the version zenoh-c declares.

**eclipse-zenoh**
- Import 1.10.1 wheels, remove 1.7.1.
- Import test also checks `zenoh.shm` and `GarbageCollect(safe=False)`.

**First-party (`rl_robot`)**, minimal API adaptations:
- `connect.endpoints` is now `Vec<EndPoints>`: convert with `.into()` in pubsub `config.rs`, camcat, zctl and motor_control `wuji_comm`.
- `SampleFields` gained `timestamp_stack`: ignored in recording `subscribe.rs` and `zctl play` (same behavior as 1.7.1).
- `ReplyBuilder::priority()` / `congestion_control()` are deprecated no-ops in 1.10.1 (replies use the query's QoS): removed from state_machine `client.rs`.
- Python API changes are additive only; zenoh encoding IDs (hardcoded in zctl) are unchanged; no `rl_robot` zenoh config sets the routing keys 1.10.1 removed.

Upstream:
- session-close leak: eclipse-zenoh/zenoh#2891
- subscriber count on `MatchingStatus` (feature request): eclipse-zenoh/zenoh#2894
- stabby optional `proc-macro-crate`: ZettaScaleLabs/stabby#153

allow-large-files

#build_targets_regex[fbcode//rl_robot/.*]

Reviewed By: guoweis-work

Differential Revision: D127603619

fbshipit-source-id: bc362f20fbb6d06119928fd90608d2ee552f59e7
meta-codesync Bot pushed a commit to meta/sapling that referenced this pull request Oct 28, 2026
Summary:
Upgrade zenoh from 1.7.1 to 1.10.1 for Rust, zenoh-c, zenoh-cpp and eclipse-zenoh (Python) together. They must move in lockstep: 1.10.1 bumps `SHM_VERSION` 1 -> 2, so 1.7.1 and 1.10.1 processes cannot share SHM buffers (the wire protocol is unchanged, 0x09).

This is D1 of a stack: pristine upstream 1.10.1 plus build plumbing. Behavior fixups that upstream does not yet carry are re-added on top in their own diffs, after being re-verified against this baseline.

**Rust (`third-party/rust`)**
- All zenoh crates 1.7.1 -> 1.10.1. New transitive crates: `lockfree`, `owned-alloc`, `lz4_flex` 0.10, `rlimit` 0.10; `stabby` 72.1.1 -> 72.1.16.
- Removed overlays:
  - `zenoh` `net/routing/dispatcher/queries.rs` (routing AB-BA deadlock T289921933, `pending_queries` use-after-free D124609602): fixed upstream, `route_send_response` now takes `tables` before `queries` and clones the query before releasing the lock.
  - `zenoh-shm` `lib.rs` / `shm_provider.rs`, `zenoh-codec` `zbuf.rs`, `zenoh-transport` `pipeline.rs` (in-flight SHM ref tracker D93568656 / D122891487, GC `total_freed`, `busy_count`, UDP stuck congestion D112961319): not in 1.10.1 upstream; re-added later in the stack only if the on-robot repros still fail on 1.10.1 (the SHM leak is expected to be covered by the unsafe allocation policy the zenoh team recommends).
- Kept overlay: `Session::matching_subscribers()` (camera 1:1 subscriber check, T280311274), rewritten for the 1.10.1 routing tables and gated to `=1.10.1`.
- New overlay (1.10.1 regression, upstream: eclipse-zenoh/zenoh#2891): closing a session while a publisher or querier is still alive leaked the session, its runtime and its SHM auth segment. Their states keep a key expression whose `KeyExprWireDeclaration` holds a strong session reference; `close_inner()` cleared subscriber and queryable states but not these, and undeclaring after close returns early. `api/session.rs`: `close_inner()` also takes `publishers` and `queriers`.
- `stabby`: replace the `github.com/nitinsingh-meta/stabby` fork (pinned at 72.1.1, no longer matched by zenoh's `^72.1.8`) with reindeer overlays on 72.1.16 carrying the same change: build without `proc-macro-crate`, which panics under Buck. The `stabby-abi` bootstrap-nightly `build.rs` overlay moves its gate to `=72.1.16` (upstream `build.rs` is unchanged).

**zenoh-c / zenoh-cpp**
- Re-import at 1.10.1.
- `000-buck-friendly-buildrs.patch` regenerated as a clean vendor-only diff. New in 1.10.1: Buck mode skips `sync_opaque_types_lockfile()` (no `Cargo.lock` under Buck) and logs with `eprintln!` instead of the new `build_print` dependency.
- Drop `001-rand-compat.patch`: depend on `rand_09`, the version zenoh-c declares.

**eclipse-zenoh**
- Import 1.10.1 wheels, remove 1.7.1.
- Import test also checks `zenoh.shm` and `GarbageCollect(safe=False)`.

**First-party (`rl_robot`)**, minimal API adaptations:
- `connect.endpoints` is now `Vec<EndPoints>`: convert with `.into()` in pubsub `config.rs`, camcat, zctl and motor_control `wuji_comm`.
- `SampleFields` gained `timestamp_stack`: ignored in recording `subscribe.rs` and `zctl play` (same behavior as 1.7.1).
- `ReplyBuilder::priority()` / `congestion_control()` are deprecated no-ops in 1.10.1 (replies use the query's QoS): removed from state_machine `client.rs`.
- Python API changes are additive only; zenoh encoding IDs (hardcoded in zctl) are unchanged; no `rl_robot` zenoh config sets the routing keys 1.10.1 removed.

Upstream:
- session-close leak: eclipse-zenoh/zenoh#2891
- subscriber count on `MatchingStatus` (feature request): eclipse-zenoh/zenoh#2894
- stabby optional `proc-macro-crate`: ZettaScaleLabs/stabby#153

allow-large-files

#build_targets_regex[fbcode//rl_robot/.*]

Reviewed By: guoweis-work

Differential Revision: D127603619

fbshipit-source-id: bc362f20fbb6d06119928fd90608d2ee552f59e7
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.

1 participant