Compare commits

...

6 commits

Author SHA1 Message Date
2bb283e335 Minor tweaks to actions/workflows files (unittest)
All checks were successful
Run UnitTests / build-and-run-tests (push) Successful in 4m48s
2024-07-13 11:43:01 +09:00
125ef0aaf5 Add example CMake project that uses UDPC 2024-07-13 11:43:01 +09:00
2adfb03b12 Update github workflow to use conan 2024-07-13 11:43:01 +09:00
13899404ec Update forgejo workflow to use conan 2024-07-13 11:43:01 +09:00
35db9faeeb Add conan related files and adapt CMakeLists.txt
This is put in a new "conan" branch. Changes to the conan build process
will only occur on this branch.
2024-07-13 11:43:01 +09:00
bc6c1e4ca1 Update README.md
All checks were successful
Publish doxygen documentation to seodisparate.com / doxygen-gen-and-publish (push) Successful in 2s
Run UnitTests / build-and-run-tests (push) Successful in 16s
2024-07-13 11:42:53 +09:00
15 changed files with 210 additions and 52 deletions

View file

@ -0,0 +1,28 @@
name: Run UnitTests
on:
push:
branches:
- 'conan'
jobs:
build-and-run-tests:
runs-on: docker_arch
steps:
- run: pacman-key --init && pacman-key --populate
name: Init pacman keyring
- run: pacman --noconfirm --needed -Sy archlinux-keyring
name: Update pacman keyring
- run: pacman --noconfirm --needed -Su git cmake libsodium python
name: Update and get dependencies
- run: python -m venv conan_venv && source conan_venv/bin/activate && pip install conan
name: Get conan
- run: source conan_venv/bin/activate && conan profile detect --force
name: Set up conan profile
- run: git clone --depth=1 --no-single-branch https://git.seodisparate.com/stephenseo/UDPConnection.git UDPC
name: Get repository
- run: cd UDPC && git checkout $GITHUB_REF_NAME
name: Checkout git repository
- run: source conan_venv/bin/activate && conan build UDPC -of buildConan --settings=build_type=Debug --build=missing
name: Build with conan
- run: find buildConan -name UnitTest -execdir './{}' ';'
name: Test

View file

@ -1,14 +0,0 @@
name: Run UnitTests
on:
push:
branches:
- '*'
jobs:
build-and-run-tests:
runs-on: any_archLinux
steps:
- run: git clone --depth=1 --no-single-branch https://git.seodisparate.com/stephenseo/UDPConnection.git UDPC
- run: cd UDPC && git checkout $GITHUB_REF_NAME
- run: cd UDPC && cmake -S . -B buildDebug -DCMAKE_BUILD_TYPE=Debug
- run: make -C UDPC/buildDebug && ./UDPC/buildDebug/UnitTest

22
.github/workflows/conan_unittests.yml vendored Normal file
View file

@ -0,0 +1,22 @@
name: Run UnitTests
on:
push:
branches:
- 'conan'
jobs:
build-and-run-tests:
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: sudo /usr/bin/env DEBIAN_FRONTEND=noninteractive apt-get install cmake git python3
- name: Get sources
run: git clone --depth=1 --no-single-branch https://github.com/Stephen-Seo/UDPConnection.git UDPC && cd UDPC && git checkout $GITHUB_REF_NAME
- name: Get Conan
run: python -m venv venv_conan && source venv_conan/bin/activate && pip install conan
- name: Set up conan
run: source venv_conan/bin/activate && conan profile detect --force
- name: Build with conan
run: source venv_conan/bin/activate && conan build UDPC -of buildConan --settings=build_type=Debug --build=missing
- name: Run tests
run: find buildConan -name UnitTest -execdir './{}' ';'

View file

@ -1,18 +0,0 @@
name: Run UnitTests
on:
push:
branches:
- '*'
jobs:
build-and-run-tests:
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: sudo /usr/bin/env DEBIAN_FRONTEND=noninteractive apt-get install cmake git libsodium-dev
- name: Get sources
run: git clone --depth=1 --no-single-branch https://github.com/Stephen-Seo/UDPConnection.git UDPC && cd UDPC && git checkout $GITHUB_REF_NAME
- name: Build sources
run: cd UDPC && cmake -S . -B buildDebug -DCMAKE_BUILD_TYPE=Debug && make -C buildDebug
- name: Run tests
run: ./UDPC/buildDebug/UnitTest

2
.gitignore vendored
View file

@ -4,3 +4,5 @@ compile_commands.json
*.o
doxygen_out/
/tags
CMakeUserPresets.json

View file

@ -37,26 +37,9 @@ if(WIN32)
endif()
endif()
if(UDPC_DISABLE_LIBSODIUM)
message(STATUS "libsodium disabled")
elseif(DEFINED M_LIBSODIUM_LIBRARIES AND DEFINED M_LIBSODIUM_INCLUDE_DIRS)
message(STATUS "libsodium manual paths detected, using them")
find_package(libsodium REQUIRED)
target_compile_definitions(UDPC PUBLIC UDPC_LIBSODIUM_ENABLED)
target_link_libraries(UDPC PUBLIC ${M_LIBSODIUM_LIBRARIES})
target_include_directories(UDPC PUBLIC ${M_LIBSODIUM_INCLUDE_DIRS})
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBSODIUM QUIET libsodium)
if(LIBSODIUM_FOUND)
target_compile_definitions(UDPC PUBLIC UDPC_LIBSODIUM_ENABLED)
target_link_libraries(UDPC PUBLIC ${LIBSODIUM_LIBRARIES})
target_include_directories(UDPC PUBLIC ${LIBSODIUM_INCLUDE_DIRS})
target_compile_options(UDPC PUBLIC ${LIBSODIUM_CFLAGS_OTHER})
message(STATUS "libsodium enabled")
else()
message(STATUS "libsodium not found, UDPC will be compiled without libsodium support")
endif()
endif()
target_link_libraries(UDPC PUBLIC libsodium::libsodium)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
set(UDPC_UnitTest_SOURCES

View file

@ -91,3 +91,6 @@ conan packages of this library are [available here](https://git.seodisparate.com
The `conan` branch contains the necessary changes to publish this library as a
conan package. Expect the `conan` branch to rebase on `master` in the future.
An example project is [available here](https://git.seodisparate.com/stephenseo/UDPConnection/src/branch/conan/conan_usage_example)
to use this project with conan.

View file

@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.7)
project(UDPC_NetworkTest C)
set(UDPC_NetworkTest_SOURCES
src/UDPC_NetworkTest.c
)
add_compile_options(
-Wall -Wextra -Wpedantic -Wno-missing-braces
$<$<COMPILE_LANGUAGE:CXX>:-Weffc++>
$<$<CONFIG:DEBUG>:-Og>
)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Debug', none was specified.")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif()
find_package(udpc CONFIG REQUIRED)
add_executable(UDPC_NetworkTest
${UDPC_NetworkTest_SOURCES}
)
target_link_libraries(UDPC_NetworkTest udpc::udpc)

View file

@ -0,0 +1,9 @@
[requires]
udpc/1.0
[generators]
CMakeDeps
CMakeToolchain
[options]
udpc*:shared=True

View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
cd "$(dirname "$0")"
set -ve
if ! [[ -e "${HOME}/.conan2/profiles/default" ]]; then
conan profile detect
fi
if ! grep stephens_forgejo "${HOME}/.conan2/remotes.json" >&/dev/null; then
conan remote add stephens_forgejo "https://git.seodisparate.com/api/packages/stephenseo/conan"
fi
conan install . -r stephens_forgejo -r conancenter --output-folder=buildConan --build=missing
cmake -S . -B buildConan -DCMAKE_TOOLCHAIN_FILE=buildConan/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build buildConan

View file

@ -0,0 +1 @@
../../src/test/UDPC_NetworkTest.c

57
conanfile.py Normal file
View file

@ -0,0 +1,57 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
import os
class udpcRecipe(ConanFile):
name = "udpc"
version = "1.0"
package_type = "library"
# Optional metadata
license = "MIT"
author = "Stephen Seo stephen@seodisparate.com"
url = "https://git.seodisparate.com/stephenseo/UDPConnection"
description = "Implements a connection over UDP"
topics = ("UDPC", "UDP", "Network", "Network Connection")
# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = "CMakeLists.txt", "src/*"
def config_options(self):
if self.settings.os == "Windows":
self.options.rm_safe("fPIC")
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires("libsodium/cci.20220430")
def generate(self):
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def package(self):
cmake = CMake(self)
cmake.install()
def package_info(self):
self.cpp_info.libs = ["UDPC"]

View file

@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(PackageTest CXX)
find_package(udpc CONFIG REQUIRED)
add_executable(example src/test.cpp)
target_link_libraries(example udpc::udpc)

26
test_package/conanfile.py Normal file
View file

@ -0,0 +1,26 @@
import os
from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import can_run
class udpcTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain"
def requirements(self):
self.requires(self.tested_reference_str)
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def layout(self):
cmake_layout(self)
def test(self):
if can_run(self):
cmd = os.path.join(self.cpp.build.bindir, "example")
self.run(cmd, env="conanrun")

10
test_package/src/test.cpp Normal file
View file

@ -0,0 +1,10 @@
#include "UDPC.h"
int main() {
auto ctx = UDPC_init(UDPC_create_id_easy("127.0.0.1", 0), 1, 1);
if (UDPC_is_valid_context(ctx) == 0) {
return 1;
}
UDPC_destroy(ctx);
return 0;
}