Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add out of source build functions for TF-PSA-Crypto #77

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Harry-Ramsey
Copy link
Contributor

@Harry-Ramsey Harry-Ramsey commented Nov 18, 2024

This commit adds helper functions to build TF-PSA-Crypto out of source using CMake.

This commit is used for: Mbed-TLS/mbedtls#9767

@Harry-Ramsey Harry-Ramsey self-assigned this Nov 20, 2024
@Harry-Ramsey Harry-Ramsey force-pushed the tf-psa-crypto-out-of-source-development branch from db35a71 to 6db9018 Compare November 21, 2024 14:06
@Harry-Ramsey Harry-Ramsey force-pushed the tf-psa-crypto-out-of-source-development branch 6 times, most recently from efa612e to 8902bd5 Compare December 5, 2024 12:54
Comment on lines 947 to 951
in_tf_psa_crypto_repo
running_tf_psa_crypto_test="$?"
if [ "$running_tf_psa_crypto_test" -eq 0 ]; then
pre_create_tf_psa_crypto_out_of_source_directory
fi
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We run the script with set -e active. This means that if any command exit with a nonzero status, the script exits. Note that this has a lot of limitations and pitfalls, but those limitations aren't a concern here. Also, we run parts of the script with an EXIT trap which catches some here, but that too is not relevant at this particular point in the script.

When all.sh is running in the mbedtls repository, the command in_tf_psa_crypto_repo exits with the status 1. This causes the whole script to exit with 1.

Here the fix is to put the command directly in an if statement. Untested:

Suggested change
in_tf_psa_crypto_repo
running_tf_psa_crypto_test="$?"
if [ "$running_tf_psa_crypto_test" -eq 0 ]; then
pre_create_tf_psa_crypto_out_of_source_directory
fi
if in_tf_psa_crypto_repo; then
running_tf_psa_crypto_test=1
pre_create_tf_psa_crypto_out_of_source_directory
fi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for saving me that debugging headache, that makes a lot more sense to me now.

@Harry-Ramsey Harry-Ramsey force-pushed the tf-psa-crypto-out-of-source-development branch 7 times, most recently from 26a98cb to 8879d15 Compare December 6, 2024 16:00
@Harry-Ramsey
Copy link
Contributor Author

I've ran a few various test cases for MbedTLS 3.6 and cannot seem to understand why this error is occurring. I have tried one with all the changes commented out and no changes to the test cases there appeared.

@Harry-Ramsey Harry-Ramsey force-pushed the tf-psa-crypto-out-of-source-development branch 3 times, most recently from a8ce45b to d09782c Compare December 12, 2024 17:23
@Harry-Ramsey Harry-Ramsey force-pushed the tf-psa-crypto-out-of-source-development branch from d09782c to 1797ef2 Compare December 17, 2024 10:22
@Harry-Ramsey Harry-Ramsey force-pushed the tf-psa-crypto-out-of-source-development branch 3 times, most recently from 1797ef2 to 6638abf Compare December 20, 2024 09:54
Copy link
Contributor

@ronald-cron-arm ronald-cron-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that can be removed now that all-core.sh does not cd automatically to the directory for the out of tree build, otherwise this looks good to me.

I think the component test_tf_psa_crypto_cmake_out_of_source of the CI against mbedtls:development fails because the component tries (as in version 9e4ac374e2 of TF-PSA-Crypto) to create the out of tree build directory while it already exists.
An update of the TF-PSA-Crypto submodule in mbedtls:development will probably be necessary.

The CI against mbedtls:mbedtls-3.6 fails completely but that does not seem to be related to the content of this PR. Error line 232 in framework/scripts/mbedtls_framework/config_common.py but I do not understand the root cause.

Comment on lines 992 to 996
# Reset working directory to TF_PSA_Crypto as it is build out of source..
if [ $running_tf_psa_crypto_test -eq 1 ]; then
cd "$TF_PSA_CRYPTO_ROOT_DIR"
fi

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not needed anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be kept as components which build out of source or change directory can be reset to source directory without additional code required in those tests. Components which don't change directory will be unaffected by this line as they should already be in the source directory.

Copy link
Contributor

@ronald-cron-arm ronald-cron-arm Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check with @mpg but I think components are run in a sub-shell thus if they change directory it does not matter to the calling shell and thus to all-core.sh.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't read this PR and haven't investigated whether this particular cd call is still needed. But I can confirm that components do run in a subshell, so if a component calls cd (or sets environment variables, and a few other things), this has no impact on subsequent components.

@@ -165,13 +165,19 @@ pre_initialize_variables () {
PSA_CORE_PATH='tf-psa-crypto/core'
BUILTIN_SRC_PATH='tf-psa-crypto/drivers/builtin/src'
CONFIG_TEST_DRIVER_H='tf-psa-crypto/tests/configs/crypto_config_test_driver.h'
MBEDTLS_ROOT_DIR="$PWD"
TF_PSA_CRYPTO_ROOT_DIR="$PWD/tf-psa-crypto"
MBEDTLS_FRAMEWORK_ROOT_DIR="$PWD/framework"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: we already have a variable FRAMEWORK defined in the top-level file (all.sh), why do we need that one in addition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that I added this before it was finalised where FRAMEWORK was going to be set as a temporary workaround. I can remove that now.

This commit adds helper functions to build TF-PSA-Crypto out of source
using CMake.

Signed-off-by: Harry Ramsey <[email protected]>
This commit adds MBEDTLS_ROOT_DIR as a variable to the bash script. This
will be used in later commits when migrating to an independent
TF-PSA-Crypto testing suite.

Signed-off-by: Harry Ramsey <[email protected]>
This commit fixes out of source directory builds, where
in_tf_psa_crypto_repo would fail due to project_name.txt not existing.

Signed-off-by: Harry Ramsey <[email protected]>
This commit adds a variable for locating Mbed TLS framework which is
used to run multiple test scripts between Mbed TLS and TF-PSA-Crypto.

Signed-off-by: Harry Ramsey <[email protected]>
This commit reverts changing the directory to the out of source
directory, enabling tests which require source code to run. Tests that
require building TF-PSA-Crypto will have to change directory to
OUT_OF_SOURCE_DIR.

Signed-off-by: Harry Ramsey <[email protected]>
This commit removes unnecessary directory changes as the commands for
components run in subshells which do not affect the main scripts
directory.

Signed-off-by: Harry Ramsey <[email protected]>
This commit replaces the relative Mbed TLS out of source build path with
a more generic named absolute out of source build path for both Mbed TLS
and TF-PSA-Crypto.

Signed-off-by: Harry Ramsey <[email protected]>
This commit removes a duplicate variable MBEDTLS_FRAMEWORK_ROOT_DIR as
it is now previously defined as FRAMEWORK.

Signed-off-by: Harry Ramsey <[email protected]>
@Harry-Ramsey Harry-Ramsey force-pushed the tf-psa-crypto-out-of-source-development branch from 2ff9ae9 to f3044f8 Compare December 24, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants