diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1beaa17..db2ac19 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -11,7 +11,7 @@ "version": "3.31.9" }, "ghcr.io/msclock/features/vcpkg:2": { - "version": "stable", + "version": "latest", "vcpkgAutoUpdate": true } }, diff --git a/.gitignore b/.gitignore index 1af4635..6ed3480 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,12 @@ testcontainers-c/testcontainers-c.so testcontainers-c/testcontainers.so testcontainers-c/testcontainers.dll testcontainers-c/testcontainers.h +testcontainers-bridge/testcontainers-bridge.h + +# VCPKG +**/vcpkg_installed/** + + *.so *.out *.exe diff --git a/CMakeLists.txt b/CMakeLists.txt index 14a4c5e..65eae64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required (VERSION 3.26) -project (TESTCONTAINERS-C +project (TESTCONTAINERS-NATIVE VERSION 0.1.0 DESCRIPTION "Testcontainers for C and other native languages" LANGUAGES C CXX diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5d5af6a..c1c770e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,6 +46,15 @@ To skip the demo builds and tests, use the `SKIP_DEMOS` variable: cmake -DSKIP_DEMOS=true . ``` +## Building the VCPKG + +To build the VCPkg for the local environment, use the following: + +```shell +vcpkg install testcontainers-bridge --overlay-ports=$(pwd)/ports/ +vcpkg install testcontainers-c --overlay-ports=$(pwd)/ports/ +``` + ## Contributing to the Documentation The documentation is structured in the MkDocs format and uses Material for MkDocs. diff --git a/modules/wiremock/CMakeLists.txt b/modules/wiremock/CMakeLists.txt index 6527ca6..94ad052 100644 --- a/modules/wiremock/CMakeLists.txt +++ b/modules/wiremock/CMakeLists.txt @@ -1,6 +1,6 @@ set(TARGET testcontainers-c-wiremock) set(TARGET_NAME ${TARGET}) -set(TARGET_DESCRIPTION "Wiremock testcontainer abstractions for C") +set(TARGET_DESCRIPTION "WireMock Testcontainers abstractions for C") set(TARGET_VERSION ${PROJECT_VERSION}) add_library(${TARGET} SHARED diff --git a/ports/testcontainers-bridge/usage b/ports/testcontainers-bridge/usage new file mode 100644 index 0000000..b677acf --- /dev/null +++ b/ports/testcontainers-bridge/usage @@ -0,0 +1,4 @@ +testcontainers-bridge provides CMake targets: + +find_package(testcontainers-bridge CONFIG REQUIRED) +target_link_libraries(main PRIVATE testcontainers-bridge::testcontainers-bridge) diff --git a/ports/testcontainers-bridge/vcpkg.json b/ports/testcontainers-bridge/vcpkg.json new file mode 100644 index 0000000..ddee380 --- /dev/null +++ b/ports/testcontainers-bridge/vcpkg.json @@ -0,0 +1,17 @@ +{ + "name": "testcontainers-bridge", + "version-string": "0.1.0", + "description": "Testcontainers Go bridge library for native languages", + "homepage": "https://github.com/testcontainers/testcontainers-native", + "license": "MIT", + "dependencies":[ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ] +} diff --git a/ports/testcontainers-c/portfile.cmake b/ports/testcontainers-c/portfile.cmake new file mode 100644 index 0000000..a8af854 --- /dev/null +++ b/ports/testcontainers-c/portfile.cmake @@ -0,0 +1,27 @@ +# Build using the port directory as source. We expect this repository to be +# available to the vcpkg build as a submodule or local path. If building from +# a remote registry, replace this with vcpkg_from_github / vcpkg_from_git. + +set(ROOT_SRC ${CURRENT_PORT_DIR}/../../testcontainers-c) + + +# Configure from repository root so that testcontainers-bridge is built first +vcpkg_cmake_configure( + SOURCE_PATH ${ROOT_SRC} + GENERATOR "Unix Makefiles" + OPTIONS + -DCMAKE_POSITION_INDEPENDENT_CODE=ON +) + +vcpkg_build_cmake() + +# Install from CMake install rules +vcpkg_install_cmake() + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") + +# Add a short README to the package to indicate local build origin +file(WRITE ${CURRENT_PACKAGES_DIR}/debug/share/${PORT}/README "This package was built from local repo source.\n") + +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") diff --git a/ports/testcontainers-c/usage b/ports/testcontainers-c/usage new file mode 100644 index 0000000..145525e --- /dev/null +++ b/ports/testcontainers-c/usage @@ -0,0 +1,4 @@ +testcontainers-c provides CMake targets: + +find_package(testcontainers-c CONFIG REQUIRED) +target_link_libraries(main PRIVATE testcontainers-c::testcontainers-c) diff --git a/ports/testcontainers-c/vcpkg.json b/ports/testcontainers-c/vcpkg.json new file mode 100644 index 0000000..b1badf6 --- /dev/null +++ b/ports/testcontainers-c/vcpkg.json @@ -0,0 +1,21 @@ +{ + "name": "testcontainers-c", + "version-string": "0.1.0", + "description": "Testcontainers library for C - C API and shared library", + "homepage": "https://github.com/testcontainers/testcontainers-native", + "license": "MIT", + "dependencies": [ + { + "name": "testcontainers-bridge", + "host": true + }, + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ] +} diff --git a/testcontainers-bridge/CMakeLists.txt b/testcontainers-bridge/CMakeLists.txt index fff34e4..9326b47 100644 --- a/testcontainers-bridge/CMakeLists.txt +++ b/testcontainers-bridge/CMakeLists.txt @@ -1,3 +1,11 @@ +cmake_minimum_required (VERSION 3.26) +project (TESTCONTAINERS-BRIDGE + VERSION 0.1.0 + DESCRIPTION "Testcontainers Go library for native languages" + LANGUAGES C +) +include(GNUInstallDirs) + set(SRCS testcontainers-bridge.go) set(SHIM_TARGET testcontainers-bridge-shim) @@ -16,7 +24,7 @@ add_custom_target(${SHIM_TARGET} DEPENDS ${SHIM_TARGET_LIB} ${SHIM_TARGET_HEADER set(TARGET testcontainers-bridge) set(TARGET_NAME ${TARGET}) -set(TARGET_DESCRIPTION "Go to C bridge for Testcontainers functionality") +set(TARGET_DESCRIPTION "Go to C bridge for Testcontainers Go functionality") set(TARGET_VERSION ${PROJECT_VERSION}) add_library(${TARGET} STATIC IMPORTED GLOBAL) @@ -27,3 +35,9 @@ set_target_properties(${TARGET} PROPERTIES PUBLIC_HEADER ${SHIM_TARGET_HEADER} IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${SHIM_TARGET_LIB} INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}) + +# Install library and header files +configure_file(cmake.pc.in ${TARGET}.pc @ONLY) +install(FILES ${SHIM_TARGET_LIB} DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install(FILES ${SHIM_TARGET_HEADER} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(FILES ${CMAKE_BINARY_DIR}/${TARGET}.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) diff --git a/testcontainers-bridge/cmake.pc.in b/testcontainers-bridge/cmake.pc.in new file mode 100644 index 0000000..8c83ec9 --- /dev/null +++ b/testcontainers-bridge/cmake.pc.in @@ -0,0 +1,12 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ + +Name: @TARGET_NAME@ +Description: @TARGET_DESCRIPTION@ +Version: @TARGET_VERSION@ + +Requires: +Libs: -L${libdir} +Cflags: -I${includedir} diff --git a/testcontainers-bridge/testcontainers-bridge-config.cmake.in b/testcontainers-bridge/testcontainers-bridge-config.cmake.in new file mode 100644 index 0000000..7609289 --- /dev/null +++ b/testcontainers-bridge/testcontainers-bridge-config.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/testcontainers-bridge-targets.cmake") + +check_required_components(testcontainers-bridge) diff --git a/testcontainers-c/CMakeLists.txt b/testcontainers-c/CMakeLists.txt index 611e326..6003821 100644 --- a/testcontainers-c/CMakeLists.txt +++ b/testcontainers-c/CMakeLists.txt @@ -1,8 +1,25 @@ +cmake_minimum_required (VERSION 3.26) +project (TESTCONTAINERS-C + VERSION 0.1.0 + DESCRIPTION "Testcontainers library for C" + LANGUAGES C +) +include(GNUInstallDirs) + set(TARGET testcontainers-c) set(TARGET_NAME ${TARGET}) -set(TARGET_DESCRIPTION "Testcontainer library for C") +set(TARGET_DESCRIPTION "Testcontainers library for C") set(TARGET_VERSION ${PROJECT_VERSION}) +# Try to find testcontainers-bridge via find_package (for vcpkg/installed case) +# If not found, assume it's built in the same project (source build) +find_package(testcontainers-bridge QUIET) +if(NOT testcontainers-bridge_FOUND) + if(NOT TARGET testcontainers-bridge) + message(FATAL_ERROR "testcontainers-bridge not found. Will assume the local presence.") + endif() +endif() + add_library(${TARGET} SHARED src/container.c ) @@ -16,8 +33,6 @@ target_sources(${TARGET} target_link_libraries(${TARGET} PRIVATE testcontainers-bridge) configure_file(cmake.pc.in ${TARGET}.pc @ONLY) -install(FILES ${SHIM_TARGET_LIB} - DESTINATION ${CMAKE_INSTALL_LIBDIR}) -install(FILES ${SHIM_TARGET_HEADER} - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(FILES ${SHIM_TARGET_LIB} DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install(FILES ${SHIM_TARGET_HEADER} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install(FILES ${CMAKE_BINARY_DIR}/${TARGET}.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)