pdk_macros/
lib.rs

1// Copyright (c) 2025, Salesforce, Inc.,
2// All rights reserved.
3// For full license text, see the LICENSE.txt file
4
5//! PDK Macros
6//!
7//! This module provides the macros to declare the entry points of your code as a custom policy.
8
9mod entrypoint;
10
11use crate::entrypoint::{generate_entrypoint, generate_entrypoint_flex};
12use proc_macro2::TokenStream;
13
14#[proc_macro_attribute]
15/// Use this macro to annotate the configuration function for you custom policy.
16/// ```rust
17/// #[entrypoint]
18/// async fn configure(
19///     launcher: Launcher,
20///     Configuration(configuration): Configuration,
21/// ) -> anyhow::Result<()> {
22///     ...
23/// }
24/// ```
25pub fn entrypoint(
26    metadata: proc_macro::TokenStream,
27    input: proc_macro::TokenStream,
28) -> proc_macro::TokenStream {
29    let input = TokenStream::from(input);
30    let metadata = TokenStream::from(metadata);
31    let output = match generate_entrypoint(metadata, input) {
32        Ok(stream) => stream,
33        Err(error) => error.to_compile_error(),
34    };
35    proc_macro::TokenStream::from(output)
36}
37
38#[proc_macro_attribute]
39/// Macro to annotate the setup function for the flex abi entrypoint. Manual usage of this macro is
40/// discouraged. It should is automatically handled with the autogenerated code from the policy definition.
41pub fn entrypoint_flex(
42    metadata: proc_macro::TokenStream,
43    input: proc_macro::TokenStream,
44) -> proc_macro::TokenStream {
45    let input = TokenStream::from(input);
46    let metadata = TokenStream::from(metadata);
47    let output = match generate_entrypoint_flex(metadata, input) {
48        Ok(stream) => stream,
49        Err(error) => error.to_compile_error(),
50    };
51    proc_macro::TokenStream::from(output)
52}