You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@teaclave.apache.org by "m4sterchain (via GitHub)" <gi...@apache.org> on 2025/07/08 04:09:15 UTC

[PR] build-env: introduce build config with management [incubator-teaclave-trustzone-sdk]

m4sterchain opened a new pull request, #206:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/206

   This PR introduces a flexible and maintainable build configuration system for the Teaclave TrustZone SDK development environment. The new system replaces the previous complex conditional logic with a clean, symlink-based configuration management approach.
   
   - Explicit configuration files organized by type and architecture
   - TA configurations: scripts/runtime/config/ta/{std,no-std}/{aarch64,arm32}
   - Host configurations: scripts/runtime/config/host/{aarch64,arm32}
   - Selection mechanism using symlinks to "active" configuration files
   - Each configuration file contains environment variables for build targets and toolchain settings
   - New switch_config script: A comprehensive tool to switch build configurations
   
     
   After the PR is merged, we need to rebuilt and update the docker image for the developers.


-- 
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: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] build-env: introduce build config with management [incubator-teaclave-trustzone-sdk]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #206:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/206#discussion_r2192208817


##########
scripts/runtime/environment:
##########
@@ -15,104 +17,78 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# This script is written into .bashrc to set up toolchains when enter the docker, like:
-# docker run -it \
-#   -e TA_ARCH=aarch64 \
-#   -e CA_ARCH=arm \
-#   -e STD=y \
-#   teaclave-dev bash
+# =============================================================================
+# config/environment (Main configuration - loads active configs)
+# =============================================================================
+
+# Get config script directory
+SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")/config"
 
-#export RUST_STD_DIR=${TEACLAVE_TOOLCHAIN_BASE}/rust
-#export RUST_TARGET_PATH=${TEACLAVE_TOOLCHAIN_BASE}/scripts/std
+echo "Loading OP-TEE environment configuration..."
 
-# validate environment variables
+# Validate required environment variables
 : "${TEACLAVE_TOOLCHAIN_BASE:?TEACLAVE_TOOLCHAIN_BASE must be set - directory where Teaclave toolchain is installed}"
 : "${OPTEE_DIR:?OPTEE_DIR must be set - directory where OPTEE will be built}"
 : "${OPTEE_OS_DIR:?OPTEE_OS_DIR must be set - directory where OPTEE OS will be built}"
 : "${OPTEE_CLIENT_DIR:?OPTEE_CLIENT_DIR must be set - directory where OPTEE Client will be built}"
 : "${IMG_DIRECTORY:?IMG_DIRECTORY must be set - directory where images will be stored}"
 : "${IMG_NAME:?IMG_NAME must be set - name of the image to download}"
 
-# Default ARCH_TA, ARCH_HOST, STD combination
-export ARCH_TA="${ARCH_TA:-aarch64}"
-export ARCH_HOST="${ARCH_HOST:-aarch64}"
-
-export CROSS_COMPILE32="${CROSS_COMPILE32:-arm-linux-gnueabihf-}"
-export CROSS_COMPILE64="${CROSS_COMPILE64:-aarch64-linux-gnu-}"
-
-if [ "$ARCH_TA" = "arm" ]
-then
-  # build TA as 32-bit
-  export TA_DEV_KIT_DIR="$OPTEE_OS_DIR/out/arm-plat-vexpress/export-ta_arm32"
-  if [ "$STD" ]
-  then
-    export TARGET_TA="arm-unknown-optee"
-    echo "set TARGET_TA=$TARGET_TA (std)"
-  else
-    export TARGET_TA="arm-unknown-linux-gnueabihf"
-    echo "set TARGET_TA=$TARGET_TA (no-std)"
-  fi
-  export CROSS_COMPILE_TA="$CROSS_COMPILE32"
-  echo "set CROSS_COMPILE_TA=$CROSS_COMPILE_TA"
-else
-  # build TA as 64-bit by default
-  export TA_DEV_KIT_DIR="$OPTEE_OS_DIR/out/arm-plat-vexpress/export-ta_arm64"
-  if [ "$STD" ]
-  then
-    export TARGET_TA="aarch64-unknown-optee"
-    echo "set TARGET_TA=$TARGET_TA (std)"
-  else
-    export TARGET_TA="aarch64-unknown-linux-gnu"
-    echo "set TARGET_TA=$TARGET_TA (no-std)"
-  fi
-  export CROSS_COMPILE_TA="$CROSS_COMPILE64"
-  echo "set CROSS_COMPILE_TA=$CROSS_COMPILE_TA"
+# Check if active configurations exist, set defaults if not
+if [ ! -f "$SCRIPT_DIR/ta/active" ]; then
+    echo "No active TA configuration found, setting default to no-std/aarch64"
+    (cd "$SCRIPT_DIR/ta" && ln -sf "no-std/aarch64" active)
 fi
 
-# check if libraries exist
-if [ -d "$TA_DEV_KIT_DIR" ]
-then
-  echo "set TA_DEV_KIT_DIR=$TA_DEV_KIT_DIR"
-else
-  echo -e "Error: TA_DEV_KIT_DIR=$TA_DEV_KIT_DIR does not exist, please set the correct TA_DEV_KIT_DIR or run \"$ ./build_optee_libraries.sh optee/\" then try again\n"
-  unset OPTEE_DIR
+if [ ! -f "$SCRIPT_DIR/host/active" ]; then

Review Comment:
   Use `-L` instead of `-f` to check for the presence of the `active` symlink itself; that way broken links will also trigger recreation of the default config.



##########
scripts/runtime/environment:
##########
@@ -1,3 +1,5 @@
+#!/bin/bash

Review Comment:
   Add `set -euo pipefail` immediately after the shebang to ensure the script exits on unhandled errors, unset variables, and pipe failures.



##########
Dockerfile.dev:
##########
@@ -33,6 +33,7 @@ RUN . ./environment && ./build_optee_libraries.sh
 
 # Set up shell environment and link useful scripts
 COPY scripts/runtime/bin ${TEACLAVE_TOOLCHAIN_BASE}/bin
+COPY scripts/runtime/config ${TEACLAVE_TOOLCHAIN_BASE}/config

Review Comment:
   The new `switch_config` script isn't included in the image; consider adding a `COPY` for `scripts/runtime/switch_config` (or its location) into `${TEACLAVE_TOOLCHAIN_BASE}/bin` so it’s available inside the container.
   ```suggestion
   COPY scripts/runtime/config ${TEACLAVE_TOOLCHAIN_BASE}/config
   COPY scripts/runtime/switch_config ${TEACLAVE_TOOLCHAIN_BASE}/bin/switch_config
   ```



-- 
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: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] build-env: introduce build config with management [incubator-teaclave-trustzone-sdk]

Posted by "m4sterchain (via GitHub)" <gi...@apache.org>.
m4sterchain merged PR #206:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/206


-- 
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: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] build-env: introduce build config with management [incubator-teaclave-trustzone-sdk]

Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #206:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/206#discussion_r2191848713


##########
scripts/runtime/environment:
##########
@@ -15,104 +17,81 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# This script is written into .bashrc to set up toolchains when enter the docker, like:
-# docker run -it \
-#   -e TA_ARCH=aarch64 \
-#   -e CA_ARCH=arm \
-#   -e STD=y \
-#   teaclave-dev bash
+# =============================================================================
+# config/environment (Main configuration - loads active configs)
+# =============================================================================
+
+# Exit on any error
+set -euo pipefail

Review Comment:
   The `-e` causes docker container shell exit on any error. e.g. 
   ```
   ~/teaclave_sdk_src# switch_config
   Error: No option specified
   [The docker container stopped]
   ```
   And other errors such as "vim command not found" also causes container shell exit.
   Recommend remove the '-e'.



-- 
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: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] build-env: introduce build config with management [incubator-teaclave-trustzone-sdk]

Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on PR #206:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/206#issuecomment-3047592806

   Would we have some documentation on the usage of `switch_config` script?


-- 
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: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] build-env: introduce build config with management [incubator-teaclave-trustzone-sdk]

Posted by "m4sterchain (via GitHub)" <gi...@apache.org>.
m4sterchain commented on code in PR #206:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/206#discussion_r2192123661


##########
scripts/runtime/bin/switch_config:
##########
@@ -0,0 +1,132 @@
+#!/bin/bash
+
+# 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.
+
+# Switch active configurations
+
+SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")/../config"
+
+# Function to show usage
+show_usage() {
+    echo "Usage: $0 [OPTIONS]"
+    echo ""
+    echo "Options:"
+    echo "  --ta <config>     Switch TA configuration only"
+    echo "  --host <config>   Switch Host configuration only"
+    echo "  --status          Show current active configuration"
+    echo "  --list            List all available configurations"
+    echo "  --help            Show this help message"
+    echo ""
+    echo "Examples:"
+    echo "  $0 --ta std/aarch64           # Switch TA only"
+    echo "  $0 --host aarch64             # Switch Host only"
+    echo "  $0 --status                   # Show current status"
+    echo "  $0 --list                     # List available configs"
+}
+
+# Function to show current status
+show_status() {
+    echo "=== Current Active Configuration ==="
+    echo "TA:   $(readlink "$SCRIPT_DIR/ta/active" 2>/dev/null || echo "NOT SET")"
+    echo "Host: $(readlink "$SCRIPT_DIR/host/active" 2>/dev/null || echo "NOT SET")"
+}
+
+# Function to get available configs for a directory
+get_available_configs() {
+    local config_dir="$1"
+    find "$config_dir" -type f ! -name "active" | sed "s|$config_dir/||" | sort
+}
+
+# Function to list available configurations
+list_configs() {
+    echo "Available TA configurations:"
+    get_available_configs "$SCRIPT_DIR/ta"
+    echo ""
+    echo "Available Host configurations:"
+    get_available_configs "$SCRIPT_DIR/host"
+}
+
+# Function to check if config exists
+check_existence() {
+    local config_path="$1"
+    [ -n "$config_path" ] && [ -f "$SCRIPT_DIR/$config_path" ]
+}
+
+# Function to switch config
+switch_config() {
+    local config_type="$1"
+    local config_name="$2"
+    echo "Switching $config_type to: $config_name"
+    (cd "$SCRIPT_DIR/$config_type" && ln -sf "$config_name" active)

Review Comment:
   This is a nice-to-have feature that we can support in a follow-up commit.



##########
scripts/runtime/environment:
##########
@@ -15,104 +17,81 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# This script is written into .bashrc to set up toolchains when enter the docker, like:
-# docker run -it \
-#   -e TA_ARCH=aarch64 \
-#   -e CA_ARCH=arm \
-#   -e STD=y \
-#   teaclave-dev bash
+# =============================================================================
+# config/environment (Main configuration - loads active configs)
+# =============================================================================
+
+# Exit on any error
+set -euo pipefail

Review Comment:
   These lines will be removed.



-- 
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: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] build-env: introduce build config with management [incubator-teaclave-trustzone-sdk]

Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #206:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/206#discussion_r2191840380


##########
scripts/runtime/bin/switch_config:
##########
@@ -0,0 +1,132 @@
+#!/bin/bash
+
+# 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.
+
+# Switch active configurations
+
+SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")/../config"
+
+# Function to show usage
+show_usage() {
+    echo "Usage: $0 [OPTIONS]"
+    echo ""
+    echo "Options:"
+    echo "  --ta <config>     Switch TA configuration only"
+    echo "  --host <config>   Switch Host configuration only"
+    echo "  --status          Show current active configuration"
+    echo "  --list            List all available configurations"
+    echo "  --help            Show this help message"
+    echo ""
+    echo "Examples:"
+    echo "  $0 --ta std/aarch64           # Switch TA only"
+    echo "  $0 --host aarch64             # Switch Host only"
+    echo "  $0 --status                   # Show current status"
+    echo "  $0 --list                     # List available configs"
+}
+
+# Function to show current status
+show_status() {
+    echo "=== Current Active Configuration ==="
+    echo "TA:   $(readlink "$SCRIPT_DIR/ta/active" 2>/dev/null || echo "NOT SET")"
+    echo "Host: $(readlink "$SCRIPT_DIR/host/active" 2>/dev/null || echo "NOT SET")"
+}
+
+# Function to get available configs for a directory
+get_available_configs() {
+    local config_dir="$1"
+    find "$config_dir" -type f ! -name "active" | sed "s|$config_dir/||" | sort
+}
+
+# Function to list available configurations
+list_configs() {
+    echo "Available TA configurations:"
+    get_available_configs "$SCRIPT_DIR/ta"
+    echo ""
+    echo "Available Host configurations:"
+    get_available_configs "$SCRIPT_DIR/host"
+}
+
+# Function to check if config exists
+check_existence() {
+    local config_path="$1"
+    [ -n "$config_path" ] && [ -f "$SCRIPT_DIR/$config_path" ]
+}
+
+# Function to switch config
+switch_config() {
+    local config_type="$1"
+    local config_name="$2"
+    echo "Switching $config_type to: $config_name"
+    (cd "$SCRIPT_DIR/$config_type" && ln -sf "$config_name" active)

Review Comment:
   After I run the `switch_config`, the env (such as TARGET_TA,...) is not updated. They're updated after I manually run "source /opt/teaclave/environment".
   For the perspective of user, I'd prefer everything is set after "switch_config".



##########
scripts/runtime/environment:
##########
@@ -15,104 +17,81 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# This script is written into .bashrc to set up toolchains when enter the docker, like:
-# docker run -it \
-#   -e TA_ARCH=aarch64 \
-#   -e CA_ARCH=arm \
-#   -e STD=y \
-#   teaclave-dev bash
+# =============================================================================
+# config/environment (Main configuration - loads active configs)
+# =============================================================================
+
+# Exit on any error
+set -euo pipefail

Review Comment:
   The `-e` causes docker container shell exit on any error. e.g. 
   ```
   ~/teaclave_sdk_src# switch_config
   Error: No option specified
   [The docker container stopped]
   ```
   And other errors such as "vim command not found".
   Recommend remove the '-e'.



-- 
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: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] build-env: introduce build config with management [incubator-teaclave-trustzone-sdk]

Posted by "m4sterchain (via GitHub)" <gi...@apache.org>.
m4sterchain commented on PR #206:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/206#issuecomment-3047646252

   > Would we have some documentation on the usage of `switch_config` script?
   
   Not yet, but the script includes a helpful -h flag that outlines its usage. Once the standard build environment is supported, its usage will be documented—for example, demonstrating how to build std examples and switch back to non-std builds.


-- 
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: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] build-env: introduce build config with management [incubator-teaclave-trustzone-sdk]

Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on PR #206:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/206#issuecomment-3050906950

   LGTM.
   `Tested-by: Yuan Zhuang <yu...@apache.org>`
   Please add the above tag into the commit messages below your signed-off tag. This aligns with OP-TEE's guidelines:
   https://optee.readthedocs.io/en/latest/general/contribute.html#commit-messages


-- 
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: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] build-env: introduce build config with management [incubator-teaclave-trustzone-sdk]

Posted by "m4sterchain (via GitHub)" <gi...@apache.org>.
m4sterchain commented on PR #206:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/206#issuecomment-3051408697

   > LGTM. `Tested-by: Yuan Zhuang <yu...@apache.org>` Before merge, please add the above tag into the commit messages below your signed-off tag. This aligns with OP-TEE's guidelines: https://optee.readthedocs.io/en/latest/general/contribute.html#commit-messages
   
   Thanks for mentioning the OP-TEE guideline. Teaclave follows the Apache Software Foundation (ASF) model, which doesn't require DCO or extra tags in commit messages. We’re happy to merge PRs with DCO trailers, and equally happy to accept them without. I will add a note in the contributing section in a follow-up PR to clarify this policy.


-- 
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: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org