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

pkg-config: add initial pkg-config files #8691

Merged
merged 2 commits into from
Feb 15, 2024

Conversation

billatarm
Copy link
Contributor

@billatarm billatarm commented Jan 9, 2024

Description

Add three package config files for mbedtls, mbedcrypto and mbedx509. Also update various project variables so the generated PC files have the required data needed without hardcoding it everywhere.

This will help distros package the project following existing conventsions between a normal and -devel package that includes the headers and .pc files for pkg-config aware consumers.

Fixes: #228

PR checklist

Please tick as appropriate and edit the reasons (e.g.: "backport: not needed because this is a new feature")

Copy link
Contributor

@Tachi107 Tachi107 left a comment

Choose a reason for hiding this comment

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

Hi, thanks for your patch! Distros will be really happy :)

I've left a few suggestions that I think should be addressed before merging this. I'm not a project maintainer, I'm just a guy that played too much with CMake that happens to maintain the mbedtls Debian package.

CMakeLists.txt Outdated Show resolved Hide resolved
pkgconfig/mbedcrypto.pc.in Outdated Show resolved Hide resolved
@billatarm
Copy link
Contributor Author

billatarm commented Jan 9, 2024

Hi, thanks for your patch! Distros will be really happy :)

I've left a few suggestions that I think should be addressed before merging this. I'm not a project maintainer, I'm just a guy that played too much with CMake that happens to maintain the mbedtls Debian package.

Perfect thanks, i've never touched CMake and I know enough about pkg-config to maintain my projects at tpm2-software and to injure others.

@gabor-mezei-arm gabor-mezei-arm added enhancement component-platform Portability layer and build scripts needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review labels Jan 10, 2024
@daverodgman
Copy link
Contributor

@billatarm is this still draft - or ready for review? thanks

@daverodgman daverodgman added the priority-high High priority - will be reviewed soon label Jan 15, 2024
@billatarm billatarm marked this pull request as ready for review January 16, 2024 18:06
@billatarm
Copy link
Contributor Author

@billatarm is this still draft - or ready for review? thanks

Yes thanks

pkgconfig/CMakeLists.txt Outdated Show resolved Hide resolved
@billatarm
Copy link
Contributor Author

@jtojnar could you comment if we could relicense this Cmake snippet under the dual Apache 2.0/GPL license scheme?

@jtojnar
Copy link

jtojnar commented Jan 23, 2024

Sure, feel free to relicense it. The intent is that anyone can use it in any software project.

billatarm added a commit to billatarm/rust-psa-crypto that referenced this pull request Jan 23, 2024
Support querying pkg-config for mbedtls directories.

When building against mbedtls, use the following search criteria to
locate the mbedtls dependency:
1. Env Variables
2. pkg-config
3. vendor directory

This will allow binary packages from distributions to work without
modification and not require a vendored mbedtls package. The problem
with vendored packages is upsates, and since mbedtls is a critical
cryptographic suite, it's important that the distributions can quickly
update a single mbedtls package that everyone links to.

Related to:
  - Mbed-TLS/mbedtls#8691

Signed-off-by: Bill Roberts <bill.roberts@arm.com>
billatarm added a commit to billatarm/rust-psa-crypto that referenced this pull request Jan 23, 2024
Support querying pkg-config for mbedtls directories.

When building against mbedtls, use the following search criteria to
locate the mbedtls dependency:
1. Env Variables
2. pkg-config
3. vendor directory

This will allow binary packages from distributions to work without
modification and not require a vendored mbedtls package. The problem
with vendored packages is upsates, and since mbedtls is a critical
cryptographic suite, it's important that the distributions can quickly
update a single mbedtls package that everyone links to.

Related to:
  - Mbed-TLS/mbedtls#8691

Signed-off-by: Bill Roberts <bill.roberts@arm.com>
billatarm added a commit to billatarm/rust-psa-crypto that referenced this pull request Jan 23, 2024
Support querying pkg-config for mbedtls directories.

When building against mbedtls, use the following search criteria to
locate the mbedtls dependency:
1. Env Variables
2. pkg-config
3. vendor directory

This will allow binary packages from distributions to work without
modification and not require a vendored mbedtls package. The problem
with vendored packages is upsates, and since mbedtls is a critical
cryptographic suite, it's important that the distributions can quickly
update a single mbedtls package that everyone links to.

Related to:
  - Mbed-TLS/mbedtls#8691

Signed-off-by: Bill Roberts <bill.roberts@arm.com>
@billatarm billatarm force-pushed the add-pc-files branch 3 times, most recently from b1a8e34 to a4da79f Compare January 23, 2024 21:40
billatarm added a commit to billatarm/rust-psa-crypto that referenced this pull request Jan 23, 2024
Support querying pkg-config for mbedtls directories.

When building against mbedtls, use the following search criteria to
locate the mbedtls dependency:
1. Env Variables
2. pkg-config
3. vendor directory

This will allow binary packages from distributions to work without
modification and not require a vendored mbedtls package. The problem
with vendored packages is upsates, and since mbedtls is a critical
cryptographic suite, it's important that the distributions can quickly
update a single mbedtls package that everyone links to.

Related to:
  - Mbed-TLS/mbedtls#8691

Signed-off-by: Bill Roberts <bill.roberts@arm.com>
@tom-daubney-arm tom-daubney-arm removed the needs-reviewer This PR needs someone to pick it up for review label Jan 24, 2024
billatarm added a commit to billatarm/rust-psa-crypto that referenced this pull request Jan 24, 2024
Support querying pkg-config for mbedtls directories.

When building against mbedtls, use the following search criteria to
locate the mbedtls dependency:
1. Env Variables
2. pkg-config
3. vendor directory

This will allow binary packages from distributions to work without
modification and not require a vendored mbedtls package. The problem
with vendored packages is upsates, and since mbedtls is a critical
cryptographic suite, it's important that the distributions can quickly
update a single mbedtls package that everyone links to.

Related to:
  - Mbed-TLS/mbedtls#8691

Signed-off-by: Bill Roberts <bill.roberts@arm.com>
billatarm added a commit to billatarm/rust-psa-crypto that referenced this pull request Jan 24, 2024
Support querying pkg-config for mbedtls directories.

When building against mbedtls, use the following search criteria to
locate the mbedtls dependency:
1. Env Variables
2. pkg-config
3. vendor directory

This will allow binary packages from distributions to work without
modification and not require a vendored mbedtls package. The problem
with vendored packages is upsates, and since mbedtls is a critical
cryptographic suite, it's important that the distributions can quickly
update a single mbedtls package that everyone links to.

Related to:
  - Mbed-TLS/mbedtls#8691

Signed-off-by: Bill Roberts <bill.roberts@arm.com>
billatarm added a commit to billatarm/rust-psa-crypto that referenced this pull request Jan 25, 2024
Support querying pkg-config for mbedtls directories.

When building against mbedtls, use the following search criteria to
locate the mbedtls dependency:
1. Env Variables
2. pkg-config
3. vendor directory

This will allow binary packages from distributions to work without
modification and not require a vendored mbedtls package. The problem
with vendored packages is upsates, and since mbedtls is a critical
cryptographic suite, it's important that the distributions can quickly
update a single mbedtls package that everyone links to.

Related to:
  - Mbed-TLS/mbedtls#8691

Signed-off-by: Bill Roberts <bill.roberts@arm.com>
tgonzalezorlandoarm pushed a commit to parallaxsecond/rust-psa-crypto that referenced this pull request Feb 2, 2024
Support querying pkg-config for mbedtls directories.

When building against mbedtls, use the following search criteria to
locate the mbedtls dependency:
1. Env Variables
2. pkg-config
3. vendor directory

This will allow binary packages from distributions to work without
modification and not require a vendored mbedtls package. The problem
with vendored packages is upsates, and since mbedtls is a critical
cryptographic suite, it's important that the distributions can quickly
update a single mbedtls package that everyone links to.

Related to:
  - Mbed-TLS/mbedtls#8691

Signed-off-by: Bill Roberts <bill.roberts@arm.com>
@tom-daubney-arm
Copy link
Contributor

@billatarm We have some CI failure on this PR. Would you be able to check them out please?

@billatarm
Copy link
Contributor Author

@billatarm We have some CI failure on this PR. Would you be able to check them out please?

The problem seems to be the useages of HOMEPAGE_URL and DESCRIPTION in the project declaration. Those need 3.12 and 3.9 respectively and those CI builds are on cmake version 3.5.1. Which is also at odds with your own readme requiring 3.10.2 here, but even correcting that would only fix one of the variable usages.

I'll just have to define the variables for now and use those.

Add three package config files for mbedtls, mbedcrypto and mbedx509.
Also update various project variables so the generated PC files have the
required data needed without hardcoding it everywhere.

This will help distros package the project following existing
conventsions between a normal and -devel package that includes the
headers and .pc files for pkg-config aware consumers.

Fixes: Mbed-TLS#228
Signed-off-by: Bill Roberts <bill.roberts@arm.com>
@billatarm
Copy link
Contributor Author

@billatarm We have some CI failure on this PR. Would you be able to check them out please?

The problem seems to be the useages of HOMEPAGE_URL and DESCRIPTION in the project declaration. Those need 3.12 and 3.9 respectively and those CI builds are on cmake version 3.5.1. Which is also at odds with your own readme requiring 3.10.2 here, but even correcting that would only fix one of the variable usages.

I'll just have to define the variables for now and use those.

Ahh it's documented as why the README and CIs are disparate:

mbedtls/CMakeLists.txt

Lines 19 to 21 in 32c28ce

# We specify a minimum requirement of 3.10.2, but for now use 3.5.1 here
# until our infrastructure catches up.
cmake_minimum_required(VERSION 3.5.1)

@tom-daubney-arm
Copy link
Contributor

@billatarm Apologies for the delay on this. I was on leave last week. Thanks for addressing the CI failures. I have kicked off a new CI run just now so we should know if it was successful in a few hours.

Fix syntax errors in Changelog (and tidy up punctuation)

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
@daverodgman
Copy link
Contributor

I tweaked the changelog to fix trivial syntax errors, as I think this is the only thing blocking CI - hope that's OK @billatarm

@williamcroberts
Copy link

I tweaked the changelog to fix trivial syntax errors, as I think this is the only thing blocking CI - hope that's OK @billatarm

Thanks, appreciate it, yeah - *, I wonder why my editor added that, usually retext is pretty good.

Copy link
Contributor

@tom-daubney-arm tom-daubney-arm left a comment

Choose a reason for hiding this comment

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

I think this all looks sensible. I have been playing around with it and it seems to work as I would expect, and the CMake stuff all looks sensible. Thanks @billatarm. LGTM.

Copy link
Contributor

@yanesca yanesca left a comment

Choose a reason for hiding this comment

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

LGTM

@yanesca yanesca added this pull request to the merge queue Feb 15, 2024
Merged via the queue into Mbed-TLS:development with commit 0315123 Feb 15, 2024
4 checks passed
@Biswa96
Copy link
Contributor

Biswa96 commented Feb 20, 2024

The version field is empty in all pkgconfig files. Is that expected?

@billatarm
Copy link
Contributor Author

The version field is empty in all pkgconfig files. Is that expected?

No and I can reproduce, let me see whats up

@billatarm
Copy link
Contributor Author

The version field is empty in all pkgconfig files. Is that expected?

No and I can reproduce, let me see whats up

Ok, so in the final version of the patch when I removed the HOMEPAGE_URL and DESCRIPTION, and let that go back to original form, it broke, I dunno why, and github doesn't show my the version delats AFAIK. But this patch fixes it:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5585c78fa..3d6f14f4b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,10 +33,17 @@ cmake_policy(SET CMP0011 NEW)
 # is deprecated and will be removed in future versions.
 cmake_policy(SET CMP0012 NEW)
 
+
 if(TEST_CPP)
-    project("Mbed TLS" LANGUAGES C CXX)
+    project("Mbed TLS"
+           LANGUAGES C CXX
+           VERSION 3.5.2
+    )
 else()
-    project("Mbed TLS" LANGUAGES C)
+    project("Mbed TLS"
+           LANGUAGES C
+           VERSION 3.5.2
+    )
 endif()
 
 include(GNUInstallDirs)

I'll submit a PR

@billatarm
Copy link
Contributor Author

Follow up patch to fix empty version field: #8850

@@ -0,0 +1,4 @@
Features
Copy link
Contributor

Choose a reason for hiding this comment

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

We're announcing a new feature, but this isn't tested. Are you planning a follow-up with a test (either expanding an existing cmake-related component or a new component in tests/scripts/all.sh)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're announcing a new feature, but this isn't tested. Are you planning a follow-up with a test (either expanding an existing cmake-related component or a new component in tests/scripts/all.sh)?

Yeah the goal is to add this to automated tests doing a make install and then running pkg-config, I have to look at how the test suite is constructed to see where the best place is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See PR for tests: #8988

Description: @PKGCONFIG_PROJECT_DESCRIPTION@
URL: @PKGCONFIG_PROJECT_HOMEPAGE_URL@
Version: @PROJECT_VERSION@
Requires.private: mbedcrypto mbedx509
Copy link
Contributor

Choose a reason for hiding this comment

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

Late feedback: shouldn't this be Requires instead of Requires.private? The CMake code, for instance, has a PUBLIC dependency on mbedx509.

add_library(${mbedx509_target} SHARED ${src_x509})
set_target_properties(${mbedx509_target} PROPERTIES VERSION 3.6.0 SOVERSION 7)
target_link_libraries(${mbedx509_target} PUBLIC ${libs} ${mbedcrypto_target})
add_library(${mbedtls_target} SHARED ${src_tls})
set_target_properties(${mbedtls_target} PROPERTIES VERSION 3.6.0 SOVERSION 21)
target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target})

Copy link
Contributor

Choose a reason for hiding this comment

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

That depends on the following question. If a program links with mbedtls only dynamically, does it need to link with mbedcrypto and mbedx509 directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Requires.private is correct here. Those libraries are linked to the shared object not the requestor.

I think this explains it better than me:

Copy link
Contributor

@Tachi107 Tachi107 Apr 2, 2024

Choose a reason for hiding this comment

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

That depends on the following question. If a program links with mbedtls only dynamically, does it need to link with mbedcrypto and mbedx509 directly?

I was under the impression that this was the case, but no, Requires.private seems appropriate. mbedtls/ssl.h includes mbedtls/x509_crt.h, which is part of mbedx509, so the user ends up needing the appropriate compiler flags for mbedx509 too, but unless it uses x509 functions it does not need its linking flags. Due to multiple reasons, pkg-config's Requires.private propagates the Cflags when doing shared builds, but not the Libs, so this is exactly what we need.

In short: the pkg-config files are ok, but mebdtls' PUBLIC dependency on mbedx509 in CMake is probably wrong (or at least not precise enough).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-platform Portability layer and build scripts enhancement needs-review Every commit must be reviewed by at least two team members, priority-high High priority - will be reviewed soon
Projects
Status: Mbed TLS 3.6 release
Development

Successfully merging this pull request may close these issues.

Please provide a pkgconfig .pc file
10 participants