Skip to content

Commit

Permalink
Version 2.1.0 (#57)
Browse files Browse the repository at this point in the history
feat: add_filename_decorations and no_filename_decorations constants
feat: get_symbol public member function and 2.1.0 version setup
feat: CI now checks both c++11 and c++17
fix: protected dylib members have been renamed
fix: timeout issues on windows CI
fix: cleaner documentation

Signed-off-by: Martin Olivier <[email protected]>
  • Loading branch information
martin-olivier authored Jun 22, 2022
1 parent 657cd9f commit 99aa061
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 126 deletions.
124 changes: 73 additions & 51 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,96 @@ name: CI
on: [push, pull_request]

defaults:
run:
shell: bash
run:
shell: bash

jobs:
unit_tests:
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
unit_tests_cpp11:
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]

name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} (C++11)
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
steps:
- uses: actions/checkout@v2

- name: Generate project files
run: cmake . -B build -DBUILD_TESTS=ON
- name: Generate project files
run: cmake . -B build -DCMAKE_CXX_STANDARD=11 -DBUILD_TESTS=ON

- name: Build dynamic library and unit tests
run: cmake --build build
- name: Build dynamic library and unit tests
run: cmake --build build

- name: Run unit tests
working-directory: build
run: ctest
- name: Run unit tests
working-directory: build
run: ctest

- name: Generate code coverage
if: ${{ matrix.os == 'ubuntu-latest' }}
run: gcov -abcfu build/CMakeFiles/unit_tests.dir/tests/tests.cpp.gcda
unit_tests_cpp17:
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]

- name: Send coverage to codecov.io
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: codecov/codecov-action@v2
with:
files: dylib.hpp.gcov
name: ${{ matrix.os }} (C++17)
runs-on: ${{ matrix.os }}

memory_check:
name: memory check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

steps:
- uses: actions/checkout@v2
- name: Generate project files
run: cmake . -B build -DCMAKE_CXX_STANDARD=17 -DBUILD_TESTS=ON

- name: Update packages
run: sudo apt update
- name: Build dynamic library and unit tests
run: cmake --build build

- name: Install valgrind
run: sudo apt install -y valgrind
- name: Run unit tests
working-directory: build
run: ctest

- name: Generate tests build file
run: cmake . -B build -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug
- name: Generate code coverage
if: ${{ matrix.os == 'ubuntu-latest' }}
run: gcov -abcfu build/CMakeFiles/unit_tests.dir/tests/tests.cpp.gcda

- name: Build unit tests
run: cmake --build build
- name: Send coverage to codecov.io
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: codecov/codecov-action@v2
with:
files: dylib.hpp.gcov

- name: Run unit tests with valgrind
working-directory: build
run: valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./unit_tests
memory_check:
name: memory check
runs-on: ubuntu-latest

linter:
name: linter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

steps:
- uses: actions/checkout@v2
- name: Update packages
run: sudo apt update

- name: Install cpplint
run: pip install cpplint
- name: Install valgrind
run: sudo apt install -y valgrind

- name: Run cpplint
run: cpplint --linelength=140 --filter=-whitespace/indent,-whitespace/parens include/dylib.hpp
- name: Generate tests build file
run: cmake . -B build -DCMAKE_CXX_STANDARD=17 -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug

- name: Build unit tests
run: cmake --build build

- name: Run unit tests with valgrind
working-directory: build
run: valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./unit_tests

linter:
name: linter
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install cpplint
run: pip install cpplint

- name: Run cpplint
run: cpplint --linelength=140 --filter=-whitespace/indent,-whitespace/parens include/dylib.hpp
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.14)

project(dylib CXX)

set(CMAKE_CXX_STANDARD 11)
if(NOT "${CMAKE_CXX_STANDARD}")
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_library(dylib INTERFACE)
Expand Down Expand Up @@ -49,6 +51,6 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
endif()

include(GoogleTest)
gtest_discover_tests(unit_tests WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
gtest_discover_tests(unit_tests PROPERTIES TIMEOUT 600 WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
endif()
endif()
50 changes: 33 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<p align="center">
<img height="200" src="https://repository-images.githubusercontent.com/354428648/5ef81a00-95b1-11eb-88a1-e1760bd99ab2" alt="dylib"/>
<img height=60% width=350 src="https://repository-images.githubusercontent.com/354428648/5ef81a00-95b1-11eb-88a1-e1760bd99ab2" alt="dylib"/>
</p>

<p align="center">
<a href="https://github.com/martin-olivier/dylib/releases/tag/v2.0.0">
<img src="https://img.shields.io/badge/Version-2.0.0-blue.svg" alt="version"/>
<a href="https://github.com/martin-olivier/dylib/releases/tag/v2.1.0">
<img src="https://img.shields.io/badge/Version-2.1.0-blue.svg" alt="version"/>
</a>
<a href="https://github.com/martin-olivier/dylib/blob/main/LICENSE">
<img src="https://img.shields.io/badge/License-MIT-orange.svg" alt="license"/>
Expand Down Expand Up @@ -41,13 +41,13 @@ include(FetchContent)
FetchContent_Declare(
dylib
GIT_REPOSITORY "https://github.com/martin-olivier/dylib"
GIT_TAG "v2.0.0"
GIT_TAG "v2.1.0"
)
FetchContent_MakeAvailable(dylib)
```

You can also click [HERE](https://github.com/martin-olivier/dylib/releases/download/v2.0.0/dylib.hpp) to download the `dylib` header file.
You can also click [HERE](https://github.com/martin-olivier/dylib/releases/download/v2.1.0/dylib.hpp) to download the `dylib` header file.

# Documentation

Expand All @@ -61,28 +61,28 @@ dylib lib("foo");
```
The `dylib` class can also load a dynamic library from a specific path
```c++
// Load "foo" lib from relative path "./libs"
// Load "foo" library from relative path "./libs"
dylib lib("./libs", "foo");
// Load "foo" lib from full path "/usr/lib"
// Load "foo" library from full path "/usr/lib"
dylib lib("/usr/lib", "foo");
```

The `dylib` class will automatically add os decorations to the library name, but you can disable that by setting `decorations` parameter to false
The `dylib` class will automatically add the filename decorations of the current os to the library name, but you can disable that by setting `decorations` parameter to `dylib::no_filename_decorations`
```c++
// Windows -> "foo.dll"
// MacOS: -> "libfoo.dylib"
// Linux: -> "libfoo.so"
// MacOS -> "libfoo.dylib"
// Linux -> "libfoo.so"

dylib lib("foo");

// Windows -> "foo.lib"
// MacOS: -> "foo.lib"
// Linux: -> "foo.lib"
// MacOS -> "foo.lib"
// Linux -> "foo.lib"

dylib lib("foo.lib", false);
dylib lib("foo.lib", dylib::no_filename_decorations);
```
## Get a function or a variable
Expand Down Expand Up @@ -113,15 +113,20 @@ double result = adder(pi, pi);
## Miscellaneous tools

`has_symbol`
Returns true if the symbol passed as parameter exists in the dynamic library, false otherwise
Returns true if the symbol passed as parameter exists in the dynamic library, false otherwise

`get_symbol`
Get a symbol from the dynamic library currently loaded in the object

`native_handle`
Returns the dynamic library handle
Returns the dynamic library handle
```c++
void example(dylib &lib)
{
if (lib.has_symbol("GetModule"))
std::cout << "GetModule symbol has been found" << std::endl;
dylib::native_symbol_type sym = lib.get_symbol("GetModule");
else
std::cout << "GetModule symbol could not be found" << std::endl;

dylib::native_handle_type handle = lib.native_handle();
void *sym = dlsym(handle, "GetModule");
Expand All @@ -144,7 +149,7 @@ try {
std::cout << pi_value << std::endl;
}
catch (const dylib::load_error &e) {
// failed loading "foo" lib
// failed loading "foo" library
}
catch (const dylib::symbol_error &e) {
// failed loading "pi_value" symbol
Expand All @@ -167,3 +172,14 @@ To run unit tests, enter the following command inside "build" directory:
```sh
ctest
```

# Community

If you have any question about the usage of the library, do not hesitate to open a [discussion](https://github.com/martin-olivier/dylib/discussions)

If you want to report a bug or provide a feature, do not hesitate to open an [issue](https://github.com/martin-olivier/dylib/issues) or submit a [pull request](https://github.com/martin-olivier/dylib/pulls)

> Do not forget to sign your commits and use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) when providing a pull request
```sh
git commit -s -m "feat: ..."
```
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include(FetchContent)
FetchContent_Declare(
dylib
GIT_REPOSITORY "https://github.com/martin-olivier/dylib"
GIT_TAG "v2.0.0"
GIT_TAG "v2.1.0"
)

FetchContent_MakeAvailable(dylib)
Expand Down
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ include(FetchContent)
FetchContent_Declare(
dylib
GIT_REPOSITORY "https://github.com/martin-olivier/dylib"
GIT_TAG "v2.0.0"
GIT_TAG "v2.1.0"
)
FetchContent_MakeAvailable(dylib)
Expand Down
Loading

0 comments on commit 99aa061

Please sign in to comment.