Mbed-TLS / mbedtls

An open source, portable, easy to use, readable and flexible TLS library, and reference implementation of the PSA Cryptography API. Releases are on a varying cadence, typically around 3 - 6 months between releases.
https://www.trustedfirmware.org/projects/mbed-tls/
Other
5.57k stars 2.61k forks source link

Default CMake build fails with error "No module named ‘jsonschema'" #8109

Closed snej closed 1 year ago

snej commented 1 year ago

Summary

Just cloned the repo and am trying to build; as the README says, "Mbed TLS should build out of the box”. Nope; the usual CMake build fails very quickly for lack of what appear to be a Python module.

From some other related issues I gather that the Python stuff is just for testing. If that’s true, maybe the default build should not be building the tests? I don’t need to run tests, I just want to use the library.

System information

Mbed TLS version (number or commit id): Commit 41d689f, default branch from Github Operating system and version: macOS 13.4.1 Configuration (if not default, please attach mbedtls_config.h): Compiler and options (if you used a pre-built binary, please indicate how you obtained it): Apple Clang from Xcode 15; CMake 3.27.0 Additional environment information:

Expected behavior

I can run mkdir build && cd build && cmake --build . to build out-of-the-box.

Actual behavior

$ mkdir build && cd build && cmake --build .
[  0%] Generating psa_crypto_driver_wrappers.c
[  0%] Generating suites/test_suite_ecp.generated.data
[  0%] Generating psa_constant_names_generated.c
[  0%] Generating suites/test_suite_psa_crypto_generate_key.generated.data, suites/test_suite_psa_crypto_low_hash.generated.data, suites/test_suite_psa_crypto_not_supported.generated.data, suites/test_suite_psa_crypto_op_fail.generated.data, suites/test_suite_psa_crypto_storage_format.current.data, suites/test_suite_psa_crypto_storage_format.v0.data
[  0%] Generating suites/test_suite_bignum.generated.data, suites/test_suite_bignum_core.generated.data, suites/test_suite_bignum_mod.generated.data, suites/test_suite_bignum_mod_raw.generated.data
[  0%] Generating query_config.c
[  0%] Built target mbedtls_test_helpers
[  0%] Built target generate_query_config_c
[  3%] Built target mbedtls_test
Traceback (most recent call last):
  File "/Users/snej/Projects/coro/vendor/mbedtls/library/../scripts/generate_driver_wrappers.py", line 29, in <module>
    import jsonschema
ModuleNotFoundError: No module named 'jsonschema'

Steps to reproduce

  1. git clone --recursive https://github.com/Mbed-TLS/mbedtls.git mbedtls
  2. cd mbedtls
  3. mkdir build && cd build && cmake --build .
snej commented 1 year ago

Tried using CMake option -DENABLE_TESTING=OFF but I still hit the same error, albeit in a different way:

...
[  7%] Generating version_features.c
[  8%] Generating error.c
[  8%] Generating psa_crypto_driver_wrappers.c
Traceback (most recent call last):
  File "/Users/snej/Projects/coro/vendor/mbedtls/library/../scripts/generate_driver_wrappers.py", line 29, in <module>
    import jsonschema
ModuleNotFoundError: No module named 'jsonschema'
tom-cosgrove-arm commented 1 year ago

Did you follow the instructions in README.md?

The following tools are required:

* ...
* Python 3.8 and some Python packages, for some library source files, sample programs and test data. To install the necessary packages, run:
python3 -m pip install --user -r scripts/basic.requirements.txt
```
Depending on your Python installation, you may need to invoke `python` instead of `python3`. To install the packages system-wide, omit the `--user` option.


`jsonschema` is used to generate the PSA driver wrappers, part of the generated library source files
gilles-peskine-arm commented 1 year ago

To build the library from a release, you only need a C toolchain and make. To build the library from git, you also need Python, jsonschema and jinja2.

gilles-peskine-arm commented 1 year ago

By the way, we can make jsonschema optional with not much effort, but the dependency on jinja2 is another matter: we'd have to rewrite the driver wrapper code. Removing the dependency on python is not realistic.