Azure / Azure/azure-sdk-for-rust

[Core] azure_core_amqp does not build with only the `ffi` feature

Open
#4,978 0 comments 1 reaction 1 assignee Claimed by @j7nw4r View on GitHub
Azure.Core bug Client
Dominant language
Rust
Stars
884
Forks
365
Avg merge
2d 19h
Merged PRs (30d)
109

Description

## Summary

The crate `azure_core_amqp` does not compile when `ffi` is the only feature that is on. On `main` at b7e1b8671, the command `cargo check -p azure_core_amqp --no-default-features --features ffi` stops with three errors: one `E0433` (``cannot find `fe2o3` in `crate` ``) and two `E0405` (``cannot find trait `Serializable` in this scope`` and the same for `Deserializable`). The feature is declared as `ffi = []`, so it names no backend, but code behind it uses items that exist only when `fe2o3_amqp` is on.

## Motivation

Three separate defects make the feature unbuildable on its own.

1. `sdk/core/azure_core_amqp/src/value.rs:9` gates `use crate::fe2o3::error::Fe2o3SerializationError;` on `ffi` alone. The module `fe2o3` (`sdk/core/azure_core_amqp/src/lib.rs:9`) needs `fe2o3_amqp`. This gives the `E0433`.
2. `sdk/core/azure_core_amqp/src/value.rs:11` gates `use crate::{Deserializable, Serializable};` on `all(ffi, fe2o3_amqp)`, but the two traits (`src/lib.rs:91` and `src/lib.rs:101`) and the impls that need them (`src/value.rs:311` and `src/value.rs:347`) are gated on `ffi` alone. The import is therefore compiled out while its users stay in. This gives the two `E0405` errors.
3. `sdk/core/azure_core_amqp/src/messaging.rs:1404` gives `AmqpMessage::decode` a body only under `fe2o3_amqp`, and it has no `not(fe2o3_amqp)` arm. The function then returns `()` in place of `Result`, which is an `E0308`. The sibling method `AmqpMessage::serialize` (`src/messaging.rs:1294`) has the fallback arm. This third error appears only after the first two are fixed, because the name resolution errors stop the build before type checking.

No CI gate sees any of this. `eng/scripts/Analyze-Code.ps1` passes `--all-features` to `cargo check`, `cargo clippy`, and `cargo doc` (lines 56, 62, and 68), and `eng/scripts/Test-Packages.ps1` does the same for `cargo build` and `cargo test` (lines 28 and 111). Every one of those runs turns `fe2o3_amqp` on with `ffi`, which hides the fault.

The defects predate the WASM removal in #3781. That commit collapsed two stacked `cfg` attributes on `src/value.rs:11` into a single `all(...)` form and kept the same condition. The feature began as `cplusplus` in #1786 and took its present name in #3093. No crate in this repository enables `azure_core_amqp/ffi` today, so nothing in the workspace is blocked by the fault.

## Proposal

Correct each gate so that it matches the true availability of the item it guards. This keeps a backend-free `ffi` build, which is what the code appears to intend: the `Serializable` and `Deserializable` impls already carry `#[cfg(not(feature = "fe2o3_amqp"))]` arms that call `unimplemented!` (`src/value.rs:313-324`, `src/value.rs:329-343`, `src/value.rs:350-361`, and `src/messaging.rs:1284-1297`). Those arms are dead unless the feature can build without a backend.

The edits:

1. `src/value.rs:9`: change `#[cfg(feature = "ffi")]` to `#[cfg(all(feature = "ffi", feature = "fe2o3_amqp"))]`.
2. `src/value.rs:11`: change `#[cfg(all(feature = "ffi", feature = "fe2o3_amqp"))]` to `#[cfg(feature = "ffi")]`.
3. `src/messaging.rs:1404`: add a `#[cfg(not(feature = "fe2o3_amqp"))]` arm to `decode` that calls `unimplemented!`, in the shape that `serialize` already uses.
4. Add `#[allow(unused_variables)]` at `src/messaging.rs:1283` and `src/messaging.rs:1404`. The two stub bodies leave `message` and `data` unused, and the repository denies warnings.

A prototype of these edits builds `--no-default-features --features ffi` clean with no warnings, and leaves `--all-features --all-targets` clean. The change is 8 insertions and 2 deletions across 2 files.

The alternative is to declare `ffi = ["fe2o3_amqp"]` in `sdk/core/azure_core_amqp/Cargo.toml:42`. That is a one-line change and it also builds clean, but it forces the whole `fe2o3-amqp` dependency tree onto an FFI-only consumer and it makes the `unimplemented!` arms unreachable. Pick this alternative only if a backend-free `ffi` build is not a goal. The owner of the FFI story must make that call.

## Validation

- `cargo check -p azure_core_amqp --no-default-features --features ffi` must pass with no warnings.
- `cargo check -p azure_core_amqp --all-features --all-targets` must stay clean.
- `cargo hack check -p azure_core_amqp --each-feature --no-dev-deps` covers this combination. It fails on `main` today.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.