Complete the move of driver wrappers to the dispatch/ directory - #809
Complete the move of driver wrappers to the dispatch/ directory#809asmellby wants to merge 16 commits into
Conversation
gilles-peskine-arm
left a comment
There was a problem hiding this comment.
I think this is moving in the direction we want, thanks. But I've asked Ronald to review as well, as he's the architect of the directory structure and build scripts. We're currently focusing on some security fixes for our next release, so it might be a while before he can review.
I'm not sure what users are supposed to be able to do. Whatever it is, it needs to be documented and tested.
I reviewed 56449b8
| set(TF_PSA_CRYPTO_FRAMEWORK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/framework) | ||
|
|
||
| if(NOT DEFINED TF_PSA_CRYPTO_DISPATCH_DIR) | ||
| set(TF_PSA_CRYPTO_DISPATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dispatch) |
There was a problem hiding this comment.
From prior experience, I think CMakeLists.txt in Mbed TLS will need to know about the new location to populate TF_PSA_CRYPTO_PRIVATE_INCLUDE_DIRS. It isn't properly extracting the information from TF-PSA-Crypto.
Allow supplying a custom dispatch directory using the TF_PSA_CRYPTO_DISPATCH_DIR variable. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Use the dispatch directory for all driver wrapper files. When file generation is enabled, generate into a dispatch/ build directory. Move the generation logic into the dispatch CMakeLists.txt. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
The dispatch/include/ directory is added as a public include directory to contain dispatch and driver-specific include files. It is currently empty. In the installed CMake package, the new directory is collapsed into the existing structure to maintain backward compatibility. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
The crypto driver context headers are tightly coupled with the dispatch implementation. Move them to the dispatch include directory. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
56449b8 to
e22eb7b
Compare
Let the generated files directly be part of the dispatch target instead of using an intermediate custom target. Directly link drivers with the dispatch target, using the correct flavor for static and shared libraries. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Set the dispatch build directory explicitly to support out-of-tree dispatch directories. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Add a testcase for the use of TF_PSA_CRYPTO_DISPATCH_DIR to set a custom dispatch directory. The custom dispatch in the testcase is created by copying and generating the vanilla dispatch implementation into the test program directory. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Add a testcase for the use of TF_PSA_CRYPTO_DISPATCH_DIR to set a custom dispatch directory when building and installing a CMake package for TF-PSA-Crypto. The custom dispatch in the testcase is created by copying and generating the vanilla dispatch implementation into the test program directory. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Document the new include path and TF_PSA_CRYPTO_DISPATCH_DIR. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Simplify check for the new dispatch location and add new location to check_names.py Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
gilles-peskine-arm
left a comment
There was a problem hiding this comment.
Looks good to me, except I'd like one point clarified in the documentation. I don't know much about CMake, so my review of CMake code is superficial.
Our CI appears to be stuck today (ticket filed), so results might not be available until Monday.
|
Note that the CI isn't happy. There's at least a missing include directory in CMake builds. |
Remove exclusion of driver wrappers from check_names.py Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Make it explicit that this option should be an absolute path. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
The dispatch include dir was missing from the doxyfile and from the config check test. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Some test cases (tf_psa_crypto_test_memsan_constant_flow_psa) rely on reusing a generated version of the driver wrapper from a previous CMake invocation. If the driver wrapper doesn't exist in the source directory but does exist in the build directory, use the file from the build directory. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
The test driver include paths are included in core and drivers. Also include them in other object libraries. This is needed to support the move of driver wrappers from core to dispatch. Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
|
I manually kicked the CI because it didn't automatically start after the last push |
|
@asmellby Sorry for the delay. I've started looking at this PR. It seems to me that it addresses two separate things:
I would prefer to handle (1) first and (2) in a follow-up PR. Would you be able to split the changes accordingly? |
I could do that, but that will require a rebase, which the contribution guidelines tell me not to do without approval from reviewers. So I'll need some guidance: To what degree should I clean up the commits when I rebase? Am I allowed to merge fixup commits into the initial commits to create a more reviewable changeset, or should I keep them separate to preserve the (now no longer entirely real) history? |
|
I would prefer to keep (1) and (2) in the same pull request, because (2) checks that (1) has been done right. But if (1) and (2) are separate, please provide histories that help me review incrementally:
(Where rebases get really bad is if there's both a change of base and a change of commit structure.) |
|
By the way, for reviewing, the merge conflict on the framework submodule is not a concern. However, I haven't made this review a priority due to the CI failure. Note, I will be offline from tomorrow to 19 July. |
CI passes for the TF-PSA-Crypto tests as far as I can tell. The CI failure is on the Mbed TLS tests, which needs the corresponding change in Mbed-TLS/mbedtls#10780 to pass. How can I tell the TF-PSA-Crypto CI to use that Mbed TLS PR? |
You cannot. We will need to merge the Mbed TLS PR first. |
@gilles-peskine-arm I am not sure what do you mean by that. Could you elaborate? |
|
If we've moved too few files or too many files, the test with an alternative dispatch directory has a good change of telling us. Without this test, nothing will tell us. |
The tests with an alternative dispatch directory mostly reproduce the content of the More generally, I may have missed some discussion, but I am not sure what we are trying to achieve with the |
Ah, yes, they wouldn't really help with that, my bad.
Ah, my bad, I've mentioned it before but I hadn't put it in writing. I've filed #833. |
| ) | ||
| if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/psa_crypto_driver_wrappers_no_static.c" AND NOT | ||
| EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/psa_crypto_driver_wrappers_no_static.c") | ||
| # Some test cases (tf_psa_crypto_test_memsan_constant_flow_psa) rely on |
There was a problem hiding this comment.
Not “test cases” (this would be a stanza in tests/suites/*.data, but “test components”.
But it's weird to justify a feature by a test component. I don't quite understand why this is needed.
There was a problem hiding this comment.
Agree that it's weird. Added a comment below about why it's needed, but that it could be made less explicit by relying on implicit CMake search paths for relative paths, which was what the core did before. That would avoid explicitly calling out the test component -- the build system behavior would be exactly the same, though.
| if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/psa_crypto_driver_wrappers_no_static.c" AND NOT | ||
| EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/psa_crypto_driver_wrappers_no_static.c") |
There was a problem hiding this comment.
This should be an elseif.
| if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/psa_crypto_driver_wrappers_no_static.c" AND NOT | ||
| EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/psa_crypto_driver_wrappers_no_static.c") |
There was a problem hiding this comment.
I don't understand why this condition is needed now. Is it fixing a preexisting bug?
We run our CI with GEN_FILES=ON. It's supposed to work with GEN_FILES=OFF, but that's not something we test.
There was a problem hiding this comment.
The test component tf_psa_crypto_test_memsan_constant_flow_psa runs CMake twice -- first with GEN_FILES=ON to generate the driver wrapper. Then, it runs again with GEN_FILES=OFF and CMAKE_BUILD_TYPE=MemSan, relying on the previous invocation's copy of the generated driver wrapper to still exist and be picked up by the build system.
Introduced in 93a8114
This creates a weird scenario where the build system on that second pass needs to be able to pick up the file from the generation directory, despite GEN_FILES=OFF. The previous implementation in core handled this by using a relative path, which makes CMake check both the source and build directory: https://github.com/Mbed-TLS/TF-PSA-Crypto/blob/development/core/CMakeLists.txt#L3-L14
I can simplify this to match the way it was done in core before, they should be equivalent if my reading of https://cmake.org/cmake/help/v3.31/prop_tgt/SOURCES.html is correct -- what I did is just more explicit about the intention.
There was a problem hiding this comment.
#135 (comment) contains some discussion of why it's done this way for that test component.
There was a problem hiding this comment.
Thanks for the explanation.
I'm ok with this code if you improve the comments explaining why, mainly that it's about GEN_FILES=ON followed by GEN_FILES=OFF. I don't understand why we did that in 93a8114, as opposed to e.g. framework/scripts/make_generated_files.py or just directly running the build without touching GEN_FILES.
But I'm a CMake novice. Please wait for someone who is more experienced with CMake (Ronald) to give their opinion.
Description
The TF-PSA-Crypto 1.1 release introduced a
dispatchdirectory with the following description:This PR completes the move of generated driver wrapper files and API headers to the dispatch directory.
Resolves #833
PR checklist
Please remove the segment/s on either side of the | symbol as appropriate, and add any relevant link/s to the end of the line.
If the provided content is part of the present PR remove the # symbol.