Repository: ada-url/ada
Pull request #940: adding pkg support
Author: login: lemire
Created: 2025-04-23T21:09:47Z | Merged: 2025-04-24T22:21:37Z

fixes https://github.com/ada-url/ada/issues/939


Diff:
diff --git a/.github/workflows/pkg.yml b/.github/workflows/pkg.yml
new file mode 100644
index 000000000..77bf6f2ca
--- /dev/null
+++ b/.github/workflows/pkg.yml
@@ -0,0 +1,29 @@
+name: Debian pkg-config
+
+on: [push, pull_request]
+
+permissions:
+  contents: read
+
+jobs:
+  pkg-config:
+    runs-on: ubuntu-latest
+    container:
+      image: debian:12
+
+    steps:
+    - uses: actions/checkout@v3
+
+    - name: Install dependencies
+      run: |
+        apt -y update
+        apt -y --no-install-recommends install g++ cmake make pkg-config
+
+    - name: Build and install
+      run: |
+        cmake -B build
+        cmake --build build
+        cmake --install build
+
+    - name: Test pkg-config
+      run: pkg-config --cflags --libs ada
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c32c86925..8a3674b66 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -163,6 +163,18 @@ install(
   COMPONENT example_development
 )
 
+
+# pkg-config
+include(cmake/JoinPaths.cmake)
+join_paths(PKGCONFIG_INCLUDEDIR "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
+join_paths(PKGCONFIG_LIBDIR "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
+
+configure_file("ada.pc.in" "ada.pc" @ONLY)
+install(
+  FILES "${CMAKE_CURRENT_BINARY_DIR}/ada.pc"
+  DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
+)
+
 if(is_top_project)
   set(CPACK_PACKAGE_VENDOR "Ada Authors")
   set(CPACK_PACKAGE_CONTACT "yagiz@nizipli.com")
diff --git a/ada.pc.in b/ada.pc.in
new file mode 100644
index 000000000..7312a0107
--- /dev/null
+++ b/ada.pc.in
@@ -0,0 +1,11 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+includedir=@PKGCONFIG_INCLUDEDIR@
+libdir=@PKGCONFIG_LIBDIR@
+
+Name: @PROJECT_NAME@
+Description: @PROJECT_DESCRIPTION@
+URL: @PROJECT_HOMEPAGE_URL@
+Version: @PROJECT_VERSION@
+Cflags: -I${includedir} @PKGCONFIG_CFLAGS@
+Libs: -L${libdir} -l@PROJECT_NAME@
+@PKGCONFIG_LIBS_PRIVATE@
diff --git a/cmake/JoinPaths.cmake b/cmake/JoinPaths.cmake
new file mode 100644
index 000000000..4f0740a6c
--- /dev/null
+++ b/cmake/JoinPaths.cmake
@@ -0,0 +1,13 @@
+function(join_paths joined_path first_path_segment)
+  set(temp_path "${first_path_segment}")
+  foreach(current_segment IN LISTS ARGN)
+    if(NOT ("${current_segment}" STREQUAL ""))
+      if(IS_ABSOLUTE "${current_segment}")
+        set(temp_path "${current_segment}")
+      else()
+        set(temp_path "${temp_path}/${current_segment}")
+      endif()
+    endif()
+  endforeach()
+  set(${joined_path} "${temp_path}" PARENT_SCOPE)
+endfunction()


Reviews:
user: login: copilot-pull-request-reviewer[bot]
body: ## Pull Request Overview

This PR adds support for pkg-config by introducing a new GitHub Actions workflow for building, installing, and testing Debian packages.  
- Introduces a new workflow (.github/workflows/pkg.yml) that runs on push and pull_request events.
- Configures the job to run inside a Debian container and executes build, install, and pkg-config test steps.

<details>
<summary>Files not reviewed (2)</summary>

* **CMakeLists.txt**: Language not supported
* **cmake/JoinPaths.cmake**: Language not supported
</details>



state: COMMENTED
author_association: NONE
submitted_at: 2025-04-23T21:10:19Z
user: login: anonrig
state: APPROVED
author_association: MEMBER
submitted_at: 2025-04-23T21:14:49Z
user: login: aduh95
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-23T22:43:55Z
user: login: anonrig
state: APPROVED
author_association: MEMBER
submitted_at: 2025-04-23T23:10:48Z
user: login: aduh95
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-23T23:19:23Z

Review comments:
diff_hunk: @@ -0,0 +1,33 @@
+name: Debian pkg-config
+
+on: [push, pull_request]
+
+defaults:
+  run:
+    shell: sh
+
+permissions:
+  contents: read
+
+jobs:
+  pkg-config:
+    runs-on: ubuntu-latest
+    container:
+      image: debian:testing
path: .github/workflows/pkg.yml
user: login: Copilot
body: Using 'debian:testing' may lead to instability in builds due to potential changes in the testing branch. Consider using a stable or versioned image to ensure consistent behavior.
```suggestion
      image: debian:11
```
created_at: 2025-04-23T21:10:18Z
author_association: NONE
diff_hunk: @@ -0,0 +1,33 @@
+name: Debian pkg-config
+
+on: [push, pull_request]
+
+defaults:
+  run:
+    shell: sh
+
+permissions:
+  contents: read
+
+jobs:
+  pkg-config:
+    runs-on: ubuntu-latest
+    container:
+      image: debian:testing
+
+    steps:
+    - uses: actions/checkout@v3
+
+    - name: Install dependencies
+      run: |
+        apt -y update
+        apt -y --no-install-recommends install g++ cmake make pkg-config
+
+    - name: Build and install
+      run: |
+        cmake -B build
+        cmake --build build
+        cmake --install build
+
+    - name: Test pkg-config
+      run: pkg-config --cflags --libs ada-url
path: .github/workflows/pkg.yml
user: login: anonrig
body: Not that it matters but newline at the end is missing.
created_at: 2025-04-23T21:13:18Z
author_association: MEMBER
diff_hunk: @@ -163,6 +163,18 @@ install(
   COMPONENT example_development
 )
 
+
+# pkg-config
+include(cmake/JoinPaths.cmake)
+join_paths(PKGCONFIG_INCLUDEDIR "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
+join_paths(PKGCONFIG_LIBDIR "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
+
+configure_file("ada-url.pc.in" ""ada-url.pc" @ONLY)
+install(
+    FILES "${CMAKE_CURRENT_BINARY_DIR}/"ada-url.pc"
+    DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
path: CMakeLists.txt
user: login: anonrig
body: ```suggestion
  FILES "${CMAKE_CURRENT_BINARY_DIR}/"ada-url.pc"
  DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
```
created_at: 2025-04-23T21:13:30Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,13 @@
+function(join_paths joined_path first_path_segment)
+    set(temp_path "${first_path_segment}")
+    foreach(current_segment IN LISTS ARGN)
+        if(NOT ("${current_segment}" STREQUAL ""))
+            if(IS_ABSOLUTE "${current_segment}")
+                set(temp_path "${current_segment}")
+            else()
+                set(temp_path "${temp_path}/${current_segment}")
+            endif()
+        endif()
+    endforeach()
+    set(${joined_path} "${temp_path}" PARENT_SCOPE)
+endfunction()
path: cmake/JoinPaths.cmake
user: login: anonrig
body: Can we make the indentation 2?

nit: newline at the end.
created_at: 2025-04-23T21:13:45Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,33 @@
+name: Debian pkg-config
+
+on: [push, pull_request]
+
+defaults:
+  run:
+    shell: sh
+
+permissions:
+  contents: read
+
+jobs:
+  pkg-config:
+    runs-on: ubuntu-latest
+    container:
+      image: debian:testing
+
+    steps:
+    - uses: actions/checkout@v3
+
+    - name: Install dependencies
+      run: |
+        apt -y update
+        apt -y --no-install-recommends install g++ cmake make pkg-config
path: .github/workflows/pkg.yml
user: login: anonrig
body: ```suggestion
        apt -y --no-install-recommends install g++ cmake make pkg-config ninja
```
created_at: 2025-04-23T21:14:05Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,33 @@
+name: Debian pkg-config
+
+on: [push, pull_request]
+
+defaults:
+  run:
+    shell: sh
+
+permissions:
+  contents: read
+
+jobs:
+  pkg-config:
+    runs-on: ubuntu-latest
+    container:
+      image: debian:testing
+
+    steps:
+    - uses: actions/checkout@v3
+
+    - name: Install dependencies
+      run: |
+        apt -y update
+        apt -y --no-install-recommends install g++ cmake make pkg-config
+
+    - name: Build and install
+      run: |
+        cmake -B build
path: .github/workflows/pkg.yml
user: login: anonrig
body: If I remember it correctly:

```suggestion
        cmake -B build -G Ninja
```
created_at: 2025-04-23T21:14:20Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,33 @@
+name: Debian pkg-config
+
+on: [push, pull_request]
+
+defaults:
+  run:
+    shell: sh
path: .github/workflows/pkg.yml
user: login: anonrig
body: This might not be needed at all.
created_at: 2025-04-23T21:14:47Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,29 @@
+name: Debian pkg-config
+
+on: [push, pull_request]
+
+permissions:
+  contents: read
+
+jobs:
+  pkg-config:
+    runs-on: ubuntu-latest
+    container:
+      image: debian:12
+
+    steps:
+    - uses: actions/checkout@v3
+
+    - name: Install dependencies
+      run: |
+        apt -y update
+        apt -y --no-install-recommends install g++ cmake make pkg-config
+
+    - name: Build and install
+      run: |
+        cmake -B build
+        cmake --build build
+        cmake --install build
+
+    - name: Test pkg-config
+      run: pkg-config --cflags --libs ada
path: .github/workflows/pkg.yml
user: login: aduh95
body: nit
```suggestion
      run: pkg-config --cflags --libs ada

```
created_at: 2025-04-23T22:43:27Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,29 @@
+name: Debian pkg-config
+
+on: [push, pull_request]
+
+permissions:
+  contents: read
+
+jobs:
+  pkg-config:
+    runs-on: ubuntu-latest
+    container:
+      image: debian:12
+
+    steps:
+    - uses: actions/checkout@v3
path: .github/workflows/pkg.yml
user: login: aduh95
body: FWIW v4 is available
created_at: 2025-04-23T23:19:23Z
author_association: CONTRIBUTOR

PR comments:
user: login: lemire
created_at: 2025-04-23T21:30:23Z
body: @aduh95 @anonrig 

I named the pkg `ada-url` but this can be changed to `ada`. I am mildly concerned that `ada` could be too generic in this context.
author_association: MEMBER
user: login: aduh95
created_at: 2025-04-23T22:37:40Z
body: > I named the pkg `ada-url` but this can be changed to `ada`. I am mildly concerned that ada could be too generic in this context.

Shouldn't we name it to `ada` and give instructions on how to change the name if it conflicts? For my use-case, it's not going to conflict and it's slightly annoying to have to patch the name
author_association: CONTRIBUTOR
user: login: lemire
created_at: 2025-04-23T22:43:15Z
body: I switched the name to 'ada'.
author_association: MEMBER