ivila commented on code in PR #296:
URL: 
https://github.com/apache/teaclave-trustzone-sdk/pull/296#discussion_r3165519042


##########
examples/supp_plugin-rs/plugin/build.rs:
##########
@@ -15,32 +15,14 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use anyhow::{anyhow, Result};
-use std::env;
-use std::fs::File;
-use std::io::Write;
-use std::path::PathBuf;
-use uuid::Uuid;
-
-fn main() -> Result<()> {
-    let out = &PathBuf::from(env::var_os("OUT_DIR").ok_or_else(|| 
anyhow!("OUT_DIR not set"))?);
-    let mut buffer = File::create(out.join("plugin_static.rs"))?;
-    buffer.write_all(include_bytes!("plugin_static.rs"))?;
-
-    let plugin_uuid = Uuid::parse_str(proto::PLUGIN_UUID)?;
-    let (time_low, time_mid, time_hi_and_version, clock_seq_and_node) = 
plugin_uuid.as_fields();
-
-    writeln!(buffer)?;
-    write!(
-        buffer,
-        "const PLUGIN_UUID_STRUCT: optee_teec::raw::TEEC_UUID = 
optee_teec::raw::TEEC_UUID {{
-    timeLow: {:#x},
-    timeMid: {:#x},
-    timeHiAndVersion: {:#x},
-    clockSeqAndNode: {:#x?},
-}};",
-        time_low, time_mid, time_hi_and_version, clock_seq_and_node
-    )?;
+fn main() -> anyhow::Result<()> {
+    let config = optee_teec_plugin_bindgen::Config::new(
+        "syslog",
+        uuid::Uuid::parse_str(proto::PLUGIN_UUID)?,
+        "init",
+        "invoke",

Review Comment:
   Here's another idea I am considering: introducing a dedicated UUID 
conversion crate (for example, `optee-teec-build`) that converts a UUID string 
into `raw::TEEC_UUID` during build.rs.
   
   With this approach, `build.rs` would generate the UUID constant, and 
`lib.rs` would simply include the generated file and use the 
`declare_supp_plugin` macro to declare the plugin.
   
   ```rust
   // build.rs
   const OUTPUT_VAR_NAME: &str = "TA_PLUGIN_UUID";
   const OUTPUT_FILENAME: &str = "ta_plugin_uuid.rs";
   
   optee_teec_build::convert_uuid(
       uuid_str,
       OUTPUT_VAR_NAME,
       OUTPUT_FILENAME,
   )?;
   
   Ok(())
   ```
   
   ```rust
   // lib.rs
   include!(concat!(env!("OUT_DIR"), "/ta_plugin_uuid.rs"));
   
   declare_supp_plugin!(
       name: "syslog",
       uuid: TA_PLUGIN_UUID,
       init: plugin_init,
       invoke: plugin_invoke,
   );
   ```
   
   This approach keeps the UUID parsing and conversion logic in the build 
phase, while keeping the plugin declaration in lib.rs clean and declarative.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to