Skip to content

Commit f84d508

Browse files
add perl xs bindings with cpan packaging support (#28)
1 parent 8520a2f commit f84d508

File tree

34 files changed

+5295
-2
lines changed

34 files changed

+5295
-2
lines changed

.github/workflows/ci.yml

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,64 @@ jobs:
115115
run: |
116116
docker run --rm liblpm-go:ci
117117
118+
# Perl bindings test
119+
test-perl-bindings:
120+
name: Test Perl Bindings
121+
runs-on: ubuntu-latest
122+
123+
steps:
124+
- name: Checkout code
125+
uses: actions/checkout@v6
126+
with:
127+
submodules: recursive
128+
129+
- name: Set up Docker Buildx
130+
uses: docker/setup-buildx-action@v3
131+
132+
- name: Build Perl container
133+
uses: docker/build-push-action@v6
134+
with:
135+
context: .
136+
file: docker/Dockerfile.perl
137+
push: false
138+
load: true
139+
tags: liblpm-perl:ci
140+
cache-from: type=gha
141+
cache-to: type=gha,mode=max
142+
143+
- name: Run Perl tests
144+
run: |
145+
docker run --rm liblpm-perl:ci
146+
147+
# PHP bindings test
148+
test-php-bindings:
149+
name: Test PHP Bindings
150+
runs-on: ubuntu-latest
151+
152+
steps:
153+
- name: Checkout code
154+
uses: actions/checkout@v6
155+
with:
156+
submodules: recursive
157+
158+
- name: Set up Docker Buildx
159+
uses: docker/setup-buildx-action@v3
160+
161+
- name: Build PHP container
162+
uses: docker/build-push-action@v6
163+
with:
164+
context: .
165+
file: docker/Dockerfile.php
166+
push: false
167+
load: true
168+
tags: liblpm-php:ci
169+
cache-from: type=gha
170+
cache-to: type=gha,mode=max
171+
172+
- name: Run PHP tests
173+
run: |
174+
docker run --rm liblpm-php:ci
175+
118176
# Python bindings test
119177
test-python-bindings:
120178
name: Test Python Bindings
@@ -223,7 +281,7 @@ jobs:
223281
ci-summary:
224282
name: CI Summary
225283
runs-on: ubuntu-latest
226-
needs: [build-and-test, test-cpp-bindings, test-go-bindings, test-python-bindings, code-quality]
284+
needs: [build-and-test, test-cpp-bindings, test-go-bindings, test-perl-bindings, test-php-bindings, test-python-bindings, code-quality]
227285
if: always()
228286

229287
steps:
@@ -233,13 +291,17 @@ jobs:
233291
echo "Build and test: ${{ needs.build-and-test.result }}"
234292
echo "C++ bindings: ${{ needs.test-cpp-bindings.result }}"
235293
echo "Go bindings: ${{ needs.test-go-bindings.result }}"
294+
echo "Perl bindings: ${{ needs.test-perl-bindings.result }}"
295+
echo "PHP bindings: ${{ needs.test-php-bindings.result }}"
236296
echo "Python bindings: ${{ needs.test-python-bindings.result }}"
237297
echo "Code quality: ${{ needs.code-quality.result }}"
238298
239299
# Fail if any required job failed
240300
if [[ "${{ needs.build-and-test.result }}" == "failure" ]] || \
241301
[[ "${{ needs.test-cpp-bindings.result }}" == "failure" ]] || \
242302
[[ "${{ needs.test-go-bindings.result }}" == "failure" ]] || \
303+
[[ "${{ needs.test-perl-bindings.result }}" == "failure" ]] || \
304+
[[ "${{ needs.test-php-bindings.result }}" == "failure" ]] || \
243305
[[ "${{ needs.test-python-bindings.result }}" == "failure" ]]; then
244306
echo "One or more required jobs failed"
245307
exit 1

CMakeLists.txt

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ option(WITH_DPDK_BENCHMARK "Build DPDK comparison benchmark" OFF)
6161
option(WITH_EXTERNAL_LPM_BENCHMARK "Build benchmarks with external LPM libraries" OFF)
6262
option(BUILD_GO_WRAPPER "Build Go wrapper and bindings" OFF)
6363
option(BUILD_CPP_WRAPPER "Build C++ wrapper and bindings" OFF)
64+
option(BUILD_PERL_WRAPPER "Build Perl wrapper and bindings" OFF)
65+
option(BUILD_PHP_WRAPPER "Build PHP wrapper and bindings" OFF)
6466
option(BUILD_PYTHON_WRAPPER "Build Python wrapper and bindings" OFF)
6567
option(LPM_TS_RESOLVERS "Enable thread-safe resolvers (for dlopen contexts)" OFF)
6668

@@ -418,6 +420,93 @@ if(BUILD_GO_WRAPPER)
418420
endif()
419421
endif()
420422

423+
# Perl wrapper
424+
if(BUILD_PERL_WRAPPER)
425+
find_program(PERL_EXECUTABLE perl)
426+
if(PERL_EXECUTABLE)
427+
message(STATUS "Found Perl: ${PERL_EXECUTABLE}")
428+
429+
# Custom target to configure Perl wrapper
430+
add_custom_target(perl_configure
431+
COMMAND ${PERL_EXECUTABLE} Makefile.PL
432+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bindings/perl
433+
DEPENDS lpm
434+
COMMENT "Configuring Perl wrapper"
435+
)
436+
437+
# Custom target to build Perl wrapper
438+
add_custom_target(perl_wrapper ALL
439+
COMMAND make
440+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bindings/perl
441+
DEPENDS perl_configure
442+
COMMENT "Building Perl wrapper and bindings"
443+
)
444+
445+
# Custom target to test Perl wrapper
446+
add_custom_target(perl_test
447+
COMMAND ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}:$ENV{LD_LIBRARY_PATH}" make test
448+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bindings/perl
449+
DEPENDS perl_wrapper
450+
COMMENT "Testing Perl wrapper"
451+
)
452+
453+
message(STATUS "Perl wrapper targets added:")
454+
message(STATUS " make perl_wrapper - Build Perl wrapper")
455+
message(STATUS " make perl_test - Run Perl tests")
456+
else()
457+
message(WARNING "Perl not found. Perl wrapper will not be built.")
458+
message(WARNING "Install Perl to build the wrapper: sudo apt install perl")
459+
endif()
460+
endif()
461+
462+
# PHP wrapper
463+
if(BUILD_PHP_WRAPPER)
464+
find_program(PHP_EXECUTABLE php)
465+
find_program(PHPIZE_EXECUTABLE phpize)
466+
if(PHP_EXECUTABLE AND PHPIZE_EXECUTABLE)
467+
message(STATUS "Found PHP: ${PHP_EXECUTABLE}")
468+
message(STATUS "Found phpize: ${PHPIZE_EXECUTABLE}")
469+
470+
# Custom target to configure PHP extension
471+
add_custom_target(php_configure
472+
COMMAND ${PHPIZE_EXECUTABLE}
473+
COMMAND ./configure --with-liblpm=${CMAKE_INSTALL_PREFIX}
474+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bindings/php
475+
DEPENDS lpm
476+
COMMENT "Configuring PHP extension"
477+
)
478+
479+
# Custom target to build PHP extension
480+
add_custom_target(php_wrapper ALL
481+
COMMAND make
482+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bindings/php
483+
DEPENDS php_configure
484+
COMMENT "Building PHP extension and bindings"
485+
)
486+
487+
# Custom target to test PHP extension
488+
add_custom_target(php_test
489+
COMMAND ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}:$ENV{LD_LIBRARY_PATH}" make test
490+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bindings/php
491+
DEPENDS php_wrapper
492+
COMMENT "Testing PHP extension"
493+
)
494+
495+
message(STATUS "PHP wrapper targets added:")
496+
message(STATUS " make php_wrapper - Build PHP extension")
497+
message(STATUS " make php_test - Run PHP tests")
498+
else()
499+
if(NOT PHP_EXECUTABLE)
500+
message(WARNING "PHP not found. PHP extension will not be built.")
501+
message(WARNING "Install PHP to build the extension: sudo apt install php php-dev")
502+
endif()
503+
if(NOT PHPIZE_EXECUTABLE)
504+
message(WARNING "phpize not found. PHP extension will not be built.")
505+
message(WARNING "Install PHP development tools: sudo apt install php-dev")
506+
endif()
507+
endif()
508+
endif()
509+
421510
# Print configuration summary
422511
message(STATUS "liblpm configuration:")
423512
message(STATUS " Version: ${PROJECT_VERSION}")
@@ -463,6 +552,16 @@ if(BUILD_CPP_WRAPPER)
463552
else()
464553
message(STATUS " Build C++ wrapper: OFF")
465554
endif()
555+
if(BUILD_PERL_WRAPPER AND PERL_EXECUTABLE)
556+
message(STATUS " Build Perl wrapper: ON")
557+
else()
558+
message(STATUS " Build Perl wrapper: OFF")
559+
endif()
560+
if(BUILD_PHP_WRAPPER AND PHP_EXECUTABLE AND PHPIZE_EXECUTABLE)
561+
message(STATUS " Build PHP wrapper: ON")
562+
else()
563+
message(STATUS " Build PHP wrapper: OFF")
564+
endif()
466565
if(BUILD_PYTHON_WRAPPER AND Python_FOUND AND CYTHON_EXECUTABLE)
467566
message(STATUS " Build Python wrapper: ON")
468567
else()

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ docker run --rm --cpus=4 liblpm-fuzz
193193
- **liblpm-fuzz**: AFL++ fuzzing for security testing
194194
- **liblpm-cpp**: C++ bindings development and testing
195195
- **liblpm-go**: Go bindings development and testing
196+
- **liblpm-perl**: Perl XS bindings development and testing
197+
- **liblpm-php**: PHP bindings development and testing
198+
- **liblpm-python**: Python bindings development and testing
196199
- **liblpm-benchmark**: DPDK rte_lpm performance comparison
197200

198201
For complete documentation, see [docs/DOCKER.md](docs/DOCKER.md).
@@ -273,6 +276,9 @@ man lpm_algorithms # Algorithm-specific APIs
273276
- [Byte Order and Data Format](docs/BYTE_ORDER.md) - Endianness, IP address storage, and integration guide
274277
- [C++ API Reference](bindings/cpp/README.md) - C++ wrapper documentation
275278
- [Go API Reference](bindings/go/README.md) - Go bindings documentation
279+
- [Perl API Reference](bindings/perl/README.md) - Perl XS bindings documentation
280+
- [PHP API Reference](bindings/php/README.md) - PHP extension documentation
281+
- [Python API Reference](bindings/python/README.md) - Python bindings documentation
276282

277283
## Security
278284

bindings/perl/LPM.bs

Whitespace-only changes.

0 commit comments

Comments
 (0)