Add std feature gate and no_std clip - #205
Conversation
What's new: - tokio-related features are now optional; - Update `lib.rs` to gate `std` at module level for `consumer.rs`, `handle.rs`, and `producer.rs` as most units are depend on `std` dependencies at the moment. Will gate at finer level in the futures; - Add build with no default feature in Makefile
There was a problem hiding this comment.
Thanks for this! The direction is right and the std path is preserved (25 doctests, both integration test files and examples/sync-api-demo all still pass unchanged).
One thing needs fixing before merge: the crate compiles without default features only because the host happens to have std. On a bare-metal target it doesn't build. Details in the inline comment on aimdb-sync/Cargo.toml:14.
I've left inline suggestions for everything that lands on a line this PR touches. Just hit "Add suggestion to batch" on each, then "Commit suggestions" to land all 16 as a single commit.
Five things can't be inline suggestions, because GitHub only allows them on lines already in the diff. They're below. I've run the whole set locally and it's green.
All line numbers in items 2 and 5 are as of after you commit the 16 suggestions, since the batch shifts them — the Makefile suggestion alone adds 10 lines. Each one also names its anchor text or enclosing item, so you can find it either way.
1. Gate the two test files
Neither file is in the diff, so no suggestion is possible. Both exercise attach() / SyncProducer / SyncConsumer, which don't exist without std, so cargo clippy -p aimdb-sync --no-default-features --all-targets currently fails with 23 errors.
aimdb-sync/tests/integration_test.rs — after the //! header:
// The whole file exercises `attach()` / `SyncProducer` / `SyncConsumer`, none of
// which exist without `std`.
#![cfg(feature = "std")]aimdb-sync/tests/settable_integration.rs — replace the existing #![cfg(feature = "data-contracts")]:
// `data-contracts` does not imply `std`, but the sync bridge used here does.
#![cfg(all(feature = "std", feature = "data-contracts"))]2. Three Makefile lanes outside the diff
Convention here is a clippy arm per feature combination, a matching test arm and a thumbv7em-none-eabihf check for embedded-capable crates.
After line 254 (cargo clippy --package aimdb-sync --all-targets -- -D warnings):
@printf "$(YELLOW) → Clippy on sync wrapper (no_std)$(NC)\n"
cargo clippy --package aimdb-sync --no-default-features --all-targets -- -D warningsAfter line 171 (cargo test --package aimdb-sync):
# --lib only: the crate-level doc examples document the std API (AimDbHandle /
# SyncProducer / SyncConsumer), which does not exist without `std`, so they
# cannot compile in this configuration. docs.rs builds the crate with
# all-features (aimdb-sync/Cargo.toml `[package.metadata.docs.rs]`).
@printf "$(YELLOW) → Testing sync wrapper (no_std)$(NC)\n"
cargo test --package aimdb-sync --no-default-features --libAt the end of the test-embedded: target (after line 406, the aimdb-tcp-connector check):
@printf "$(YELLOW) → Checking aimdb-sync (no_std) on thumbv7em-none-eabihf target$(NC)\n"
cargo check --package aimdb-sync --target thumbv7em-none-eabihf --target-dir $(EMBEDDED_CHECK_TARGET_DIR) --no-default-features3. Why --lib on the no_std test arm
Worth reading before "fixing" it back. Without --lib, that arm fails 7/7 on the crate-level doctests. The examples reference AimDbHandle, SyncProducer and SyncConsumer in their bodies, so no #[cfg] on a use line can rescue them — under --no-default-features those types genuinely don't exist. That's also why both the inline suggestions and item 5 below remove the doctest cfgs rather than correct them. Published docs are unaffected: docs.rs builds with all-features.
4. Why the embedded check goes in test-embedded, not build:
Every other thumbv7em-none-eabihf check in this repo lives in test-embedded and uses --target-dir $(EMBEDDED_CHECK_TARGET_DIR) — that separate target dir exists so an interrupted embedded build can't corrupt .rmeta for the host build.
Worth knowing what this catches that a host build can't: with aimdb-core pulled at default features, cargo build -p aimdb-sync --no-default-features passes, because the host has std. Cross-compiled, it fails on anyhow. That's exactly why CI is green here despite the no_std path being broken. A host-target build is the one check that cannot detect this class of bug.
5. Eleven more of these, from #204
#204 left these behind and they're on lines this PR doesn't touch. But this PR already edits all four files and you're revising it anyway, so it's cheaper to sweep them here than to land a second PR that collides with these hunks.
| File | Line | Item |
|---|---|---|
lib.rs |
57 | crate-level Quick Start |
consumer.rs |
91 | get |
consumer.rs |
131 | get_with_timeout |
consumer.rs |
172 | try_get |
consumer.rs |
220 | get_latest |
consumer.rs |
273 | get_latest_with_timeout |
handle.rs |
53 | attach |
producer.rs |
127 | set |
producer.rs |
164 | set_with_timeout |
producer.rs |
202 | try_set |
producer.rs |
247 | set_value |
All eleven are the same line, /// # #[cfg(feature = "std")]. Ten sit directly above the hidden # fn main() -> SyncResult<()> {. The eleventh (producer.rs:247) sits above # use aimdb_sync::SyncResult; — the type the un-guarded main on the next line returns.
Worth being precise about why they're inert, because the obvious explanation is wrong: rustdoc does propagate --cfg feature="…" into the doctest crate, so the guard really evaluates. Both branches are still useless. With std on — the only configuration where these examples compile at all — it's true and does nothing. With std off, #[cfg]-ing out fn main() doesn't skip the example, it deletes the entry point:
$ cargo test -p aimdb-sync --no-default-features --doc
---- aimdb-sync/src/lib.rs - (line 46) stdout ----
error[E0432]: unresolved import `aimdb_sync::AimDbBuilderSyncExt`
error[E0601]: `main` function not found in crate `rust_out`
--> aimdb-sync/src/lib.rs:86:2
|
42 | }
| ^ consider adding a `main` function to `aimdb-sync/src/lib.rs`
test result: FAILED. 0 passed; 7 failed
Those 7 fail with or without the guards, for the reason in item 3 — the guard only adds a second, more confusing error on top. After this PR it's moot regardless: with mod consumer/handle/producer gated at lib.rs:255-259, rustdoc stops collecting those examples under --no-default-features entirely, so the inner guards are unreachable by construction.
Please delete all eleven. Published docs are unaffected — docs.rs builds with all-features.
While you're in producer.rs, lines 246 and 275-276 are dead the same way — the impl is already #[cfg(feature = "data-contracts")], so both the guard and its not(...) fallback main are unreachable. Take or leave.
Verification
I applied the 16 suggestions plus the five items above to a local checkout of this branch and ran:
cargo clippy -p aimdb-sync --all-targets -- -D warnings— cleancargo clippy -p aimdb-sync --no-default-features --all-targets -- -D warnings— cleancargo test -p aimdb-sync— 39 passed, 0 failed (doctests 25/25)cargo test -p aimdb-sync --features data-contracts --doc— 26/26cargo test -p aimdb-sync --no-default-features --lib— passcargo check -p aimdb-sync --target thumbv7em-none-eabihf --no-default-features— passcargo tree -p aimdb-sync --no-default-features -e features,no-dev | grep -i tokio— no outputmake check— exit 0 (fmt, clippy, all feature combos, embedded, WASM, deny, readme, codegen-drift, check-no-sim)
sync-api-demo output was compared against this PR's parent (136a98e): identical line-for-line, with only thread interleaving differing — which varies run-to-run on the baseline too.
One aside, not for this PR: the demo prints AimDbHandle dropped without calling detach() even though it calls detach() at examples/sync-api-demo/src/main.rs:166. That reproduces on 136a98e, so it predates your changes — but #200 re-audits the AimDbHandle lifecycle and the unsafe impl Send/Sync, so it's worth catching there.
Co-authored-by: sounds.like.lx <147444674+lxsaah@users.noreply.github.com>
Co-authored-by: sounds.like.lx <147444674+lxsaah@users.noreply.github.com>
Co-authored-by: sounds.like.lx <147444674+lxsaah@users.noreply.github.com>
Co-authored-by: sounds.like.lx <147444674+lxsaah@users.noreply.github.com>
Co-authored-by: sounds.like.lx <147444674+lxsaah@users.noreply.github.com>
Co-authored-by: sounds.like.lx <147444674+lxsaah@users.noreply.github.com>
Co-authored-by: sounds.like.lx <147444674+lxsaah@users.noreply.github.com>
Co-authored-by: sounds.like.lx <147444674+lxsaah@users.noreply.github.com>
Co-authored-by: sounds.like.lx <147444674+lxsaah@users.noreply.github.com>
Co-authored-by: sounds.like.lx <147444674+lxsaah@users.noreply.github.com>
|
Ops my mistake I forgot the add to batch part. I was caught up understanding suggestions, will be more careful next time. I'll update the suggestions that not in diff. |
What's new: - Gate 'lib.rs` internal doctest with conditional `no_run` and `ignore` so `cargo test -p aimdb-sync --no-default-features --doc` does not fail - Several small reverted `std` guard as modules is now std-gated at `lib.rs`
Follow-on to the review of aimdb-dev#205, applied directly to avoid another round-trip. - consumer.rs: drop the last 4 inert `#[cfg(feature = "std")]` guards in doc examples. `mod consumer` is already std-gated at lib.rs:257, so they can never evaluate false. The one on `get_with_timeout` was also missing the `# ` hide prefix and rendered into the published docs. - consumer.rs: backtick `Arc<Mutex>` in a doc comment — it was the last `cargo doc` warning (unclosed HTML tag), pre-existing from before aimdb-dev#204. - Makefile: add the no_std clippy arm and the thumbv7em-none-eabihf check, matching the per-crate convention. The cross-compile lane is the only one that catches std arriving through a dependency's default features; a host `--no-default-features` build passes regardless because the host has std, which is why CI was green while the no_std path was broken. - Makefile: drop `--lib` from the no_std test arm. The conditional ```ignore fence added in 71102d8 means the full command now passes, so the arm covers unit tests, integration tests and doctests. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`aimdb-sync/data-contracts` had no coverage in any make target, so tests/settable_integration.rs and the `set_value` doctest never compiled in CI. No consumer enables the feature either, so nothing reached it transitively. Adds a test arm and a clippy arm, matching the per-feature-combination convention aimdb-client uses. The test arm picks up 4 integration tests and a 26th doctest that were previously invisible. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`bindings` (lib.rs:39) is the only consumer of CancelToken/CancelHandle and is itself `#[cfg(feature = "wasm-runtime")]`, so the host test lanes (`--no-default-features`) compiled these items with no reachable caller and emitted 6 dead_code warnings. Gating them on the same feature as their consumer keeps the two in step. `Cell` was used only by CancelInner, so it moves behind the same gate to avoid trading dead_code for unused_imports; `RefCell` stays unconditional. Not dead code — the wasm32 path is unchanged and still compiles clean with -D warnings. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
lxsaah
left a comment
There was a problem hiding this comment.
Thanks for clearing this issue @solus161. The cfg_attr fence-switching is a better fix than the --lib workaround I'd asked for and the thumbv7em cross-compile now builds clean.
I pushed three commits to save a round-trip: 37bbbbb finishes the consumer.rs doctest-cfg sweep and adds the missing no_std clippy + thumbv7em Makefile lanes, 1c769e0 adds data-contracts arms that surfaced 4 integration tests and a doctest CI had never run and c0ff11b gates the WASM cancel machinery on wasm-runtime to clear 6 pre-existing dead_code warnings.
Description
What's new:
lib.rsto gatestdat module level forconsumer.rs,handle.rs, andproducer.rsas most units are depend onstddependencies at the moment. Will gate at finer level in the futures;allocversion ofArc,coreversion ofDebug,Duration;Related Issue
Checklist
make check).