m4sterchain commented on code in PR #245:
URL: 
https://github.com/apache/teaclave-trustzone-sdk/pull/245#discussion_r2477152119


##########
cargo-optee/src/main.rs:
##########
@@ -0,0 +1,158 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use clap::{Parser, Subcommand};
+use std::env;
+use std::path::PathBuf;
+use std::process::abort;
+
+mod ca_builder;
+mod common;
+mod ta_builder;
+
+use common::Arch;
+
+#[derive(Debug, Parser)]
+#[clap(version = env!("CARGO_PKG_VERSION"))]
+#[clap(about = "Build tool for OP-TEE Rust projects")]
+pub(crate) struct Cli {
+    #[clap(subcommand)]
+    cmd: Command,
+}
+
+#[derive(Debug, Parser)]
+struct BuildTypeCommonOptions {
+    /// Path to the app directory (default: current directory)
+    #[arg(long = "path", default_value = ".")]
+    path: PathBuf,
+
+    /// Target architecture: aarch64 or arm (default: aarch64)
+    #[arg(long = "arch", default_value = "aarch64")]
+    arch: Arch,
+
+    /// Path to the UUID file (default: ../uuid.txt)
+    #[arg(long = "uuid_path", default_value = "../uuid.txt")]
+    uuid_path: PathBuf,
+
+    /// Build in debug mode (default is release)
+    #[arg(long = "debug")]
+    debug: bool,
+}
+
+#[derive(Debug, Subcommand)]
+enum BuildCommand {
+    /// Build a Trusted Application
+    TA {
+        /// Enable std feature for the TA
+        #[arg(long = "std")]
+        std: bool,
+
+        /// Path to the TA dev kit directory (mandatory)
+        #[arg(long = "ta_dev_kit_dir", required = true)]
+        ta_dev_kit_dir: PathBuf,
+
+        /// Path to the TA signing key (default: 
$(TA_DEV_KIT_DIR)/keys/default_ta.pem)
+        #[arg(long = "signing_key")]
+        signing_key: Option<PathBuf>,
+
+        #[command(flatten)]
+        common: BuildTypeCommonOptions,
+    },
+    /// Build a Client Application (Host)
+    CA {
+        /// Path to the OP-TEE client export directory (mandatory)
+        #[arg(long = "optee_client_export", required = true)]
+        optee_client_export: PathBuf,
+
+        #[command(flatten)]
+        common: BuildTypeCommonOptions,
+    },
+}
+
+#[derive(Debug, Subcommand)]
+enum Command {

Review Comment:
   Before we move further, could you clarify what kind of user experience you 
envision for TA developers using the cargo-optee toolchain?
   
   From my perspective, **the cargo-optee build command should provide a 
seamless interface aligned with the existing cargo build workflow**, either 
through transparent parameter passing or through complementary extensions. The 
key principle is to stay consistent with Cargo’s CLI conventions and user 
expectations.
   It’s perfectly fine for the internal implementation to have a different 
interface, but here I’m mainly referring to the **user-facing design**.
   
   Here I just expand one point for illustration.
   Q: “But what should we write in the common examples’ Cargo.toml? If we set 
no-std, how would we build it in std mode for CI? By modifying Cargo.toml each 
time? I don't have the answer.”
   
   My view: when designing the interface, we should ask — how do Rust 
developers normally address this problem (e.g., switching between no_std and 
std, or specifying architectures)? We should adopt the same mechanism.
   
   For std / no_std switching, Rust developers use Cargo features declared in 
Cargo.toml, together with `--no-default-features` or `--features xxx` or 
nothing for `cargo build`. This convention can also be applied for our 
customized tooling.
   
   The underlying build logic can follow Cargo’s native feature resolution 
model (via `cargo_metadata`), for example:
   ```
   cargo (optee) build
   cargo (optee) build --no-default-features
   cargo (optee) build --no-default-features --features no_std // or std
   ```
   The key concept here is transparent delegation to Cargo, cargo-optee does 
not need to reimplement or reinterpret feature logic, or use a reinvented 
`--std` parameter, but instead query and respect Cargo’s native feature 
resolution. This ensures consistent developer experience and predictable build 
behavior.
   
   A similar comparison and concept mapping approach to existing Cargo 
mechanisms can be applied to other aspects as well, such as toolchain 
conventions and project conventions, to achieve a more consistent and intuitive 
CLI experience.



-- 
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