Skip to main content

consortium_tee_macros_impl/
lib.rs

1// Copyright 2026 Ethan Wu
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// SPDX-License-Identifier: Apache-2.0
16
17//! Macro implementations behind `consortium-tee-macros`.
18//!
19//! The logic for `consortium-tee`'s three macros lives here as ordinary
20//! `proc_macro2::TokenStream` functions, outside the `proc-macro = true` facade, so
21//! expansions can be asserted with unit tests and `insta` snapshots rather than only
22//! through `trybuild`. That matters more here than for the other macro families: these
23//! macros generate *both sides* of a privilege boundary, and the generated code is not
24//! something a reader can easily hold in their head.
25//!
26//! | Module          | Generates                                                        |
27//! | --------------- | ---------------------------------------------------------------- |
28//! | `tee_param`   | `impl<C: CodecFor<Self>> TeeParam<C>` for a user type.            |
29//! | `tee_command` | `call_<name>` (CA) and `<name>_dispatched` (TA) for one function.  |
30//! | `tee_service` | The `Command` enum and `invoke_command` dispatch for a TA.         |
31//!
32//! The load-bearing design decision, shared by all three: **the codec is a type
33//! parameter, never baked into an expansion.** `tee_param` emits an impl generic over `C`
34//! and `tee_command` substitutes the `codec = …` argument at the call site. A message type
35//! is therefore reusable across commands with different codecs, and shareable with the IPC
36//! layer without inheriting its codec.
37//!
38//! Reusable `syn` predicates — `is_primitive`, `is_slice_ref`, `is_tee_param_path`,
39//! `collect_field_types`, and friends — live in `consortium-macros-helpers`, because
40//! `tee_command`'s parameter classification and `tee_param`'s field validation need the
41//! same AST questions answered. What stays here is TEE-specific policy: which Rust type
42//! maps to which parameter slot, and in which direction.
43//!
44//! This is an implementation detail of `consortium-tee`. Do not depend on it directly; its
45//! API is not stable.
46
47mod tee_command;
48mod tee_param;
49mod tee_service;
50
51pub use tee_command::tee_command;
52pub use tee_param::derive_tee_param;
53pub use tee_service::tee_service;