-
Notifications
You must be signed in to change notification settings - Fork 185
New C++ API #8741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New C++ API #8741
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Doxygen configuration for Vortex C++ API documentation. | ||
| # XML output is consumed by Sphinx via the Breathe extension. | ||
|
|
||
| PROJECT_NAME = "Vortex C++" | ||
| OUTPUT_DIRECTORY = _build/doxygen-cpp | ||
|
|
||
| # Input sources | ||
| INPUT = ../lang/cpp/include/vortex | ||
| FILE_PATTERNS = *.hpp | ||
| RECURSIVE = NO | ||
|
|
||
| # We only care about XML output for Breathe | ||
|
myrrc marked this conversation as resolved.
|
||
| GENERATE_XML = YES | ||
| GENERATE_HTML = NO | ||
| GENERATE_LATEX = NO | ||
| XML_PROGRAMLISTING = YES | ||
|
|
||
| # Extract everything, even if not fully documented yet | ||
| EXTRACT_ALL = YES | ||
| EXTRACT_PRIVATE = NO | ||
| EXTRACT_STATIC = YES | ||
|
|
||
| # Preprocessing — resolve includes but don't expand macros | ||
| ENABLE_PREPROCESSING = YES | ||
| MACRO_EXPANSION = NO | ||
|
|
||
| # Suppress warnings about undocumented members (WIP API) | ||
| WARN_IF_UNDOCUMENTED = NO | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| cmake_minimum_required(VERSION 3.10) | ||
| project(VortexCXX | ||
| VERSION 0.0.1 | ||
| LANGUAGES CXX) | ||
|
|
||
| include(FetchContent) | ||
|
|
||
| set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
| set(CMAKE_CXX_STANDARD 20) | ||
|
myrrc marked this conversation as resolved.
|
||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
|
||
| find_program(SCCACHE_PROGRAM sccache) | ||
|
myrrc marked this conversation as resolved.
|
||
| if (SCCACHE_PROGRAM) | ||
| set(CMAKE_C_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}") | ||
| set(CMAKE_CXX_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}") | ||
| message(STATUS "Sccache found: ${SCCACHE_PROGRAM}") | ||
| else () | ||
| message(STATUS "Sccache not found") | ||
| endif () | ||
|
|
||
| set(SANITIZER "" CACHE STRING "Build with sanitizers") | ||
| set(TARGET_TRIPLE "" CACHE STRING "Rust target triple for FFI library") | ||
| set(RUST_BUILD_PROFILE "" CACHE STRING "Cargo profile name for Rust FFI library") | ||
|
|
||
| if (NOT CMAKE_BUILD_TYPE) | ||
|
myrrc marked this conversation as resolved.
|
||
| set(CMAKE_BUILD_TYPE Debug) | ||
| endif() | ||
|
|
||
| if (NOT SANITIZER STREQUAL "") | ||
| message(NOTICE "Sanitizer: ${SANITIZER}") | ||
| if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
| message(FATAL_ERROR "Only debug build is supported for sanitizer builds") | ||
| endif() | ||
|
|
||
| if (SANITIZER STREQUAL "asan") | ||
| set(SANITIZER_FLAGS "-fsanitize=address,undefined,leak") | ||
| elseif (SANITIZER STREQUAL "tsan") | ||
| set(SANITIZER_FLAGS "-fsanitize=thread") | ||
| else() | ||
| message(FATAL_ERROR "Unknown sanitizer ${SANITIZER}") | ||
| endif() | ||
| set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_FLAGS}") | ||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZER_FLAGS}") | ||
| set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS}") | ||
| endif() | ||
|
|
||
| if (RUST_BUILD_PROFILE STREQUAL "") | ||
| if (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") | ||
| set(RUST_BUILD_PROFILE "release_debug") | ||
| else() | ||
| string(TOLOWER "${CMAKE_BUILD_TYPE}" RUST_BUILD_PROFILE) | ||
| endif() | ||
| endif() | ||
|
|
||
| set(VORTEX_FFI_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../vortex-ffi") | ||
| set(VORTEX_FFI_LIB_DIR "${VORTEX_FFI_DIR}/../target/${TARGET_TRIPLE}/${RUST_BUILD_PROFILE}") | ||
| set(VORTEX_FFI_HEADERS "${VORTEX_FFI_DIR}/cinclude") | ||
|
myrrc marked this conversation as resolved.
|
||
|
|
||
| if(APPLE) | ||
| set(VORTEX_FFI_STATIC "${VORTEX_FFI_LIB_DIR}/libvortex_ffi.a") | ||
| set(VORTEX_FFI_SHARED "${VORTEX_FFI_LIB_DIR}/libvortex_ffi.dylib") | ||
| elseif(WIN32) | ||
| set(VORTEX_FFI_STATIC "${VORTEX_FFI_LIB_DIR}/libvortex_ffi.lib") | ||
| set(VORTEX_FFI_SHARED "${VORTEX_FFI_LIB_DIR}/libvortex_ffi.dll") | ||
| else() | ||
| set(VORTEX_FFI_STATIC "${VORTEX_FFI_LIB_DIR}/libvortex_ffi.a") | ||
| set(VORTEX_FFI_SHARED "${VORTEX_FFI_LIB_DIR}/libvortex_ffi.so") | ||
| endif() | ||
|
|
||
| if(NOT EXISTS "${VORTEX_FFI_STATIC}") | ||
| message(FATAL_ERROR | ||
| "vortex-ffi static library not found at ${VORTEX_FFI_STATIC}. " | ||
| "Run: cargo build --profile <profile> -p vortex-ffi") | ||
| endif() | ||
|
|
||
| add_library(vortex_ffi STATIC IMPORTED) | ||
| set_target_properties(vortex_ffi PROPERTIES | ||
| IMPORTED_LOCATION "${VORTEX_FFI_STATIC}" | ||
| INTERFACE_INCLUDE_DIRECTORIES "${VORTEX_FFI_HEADERS}") | ||
|
|
||
| if(EXISTS "${VORTEX_FFI_SHARED}") | ||
| add_library(vortex_ffi_shared SHARED IMPORTED) | ||
| set_target_properties(vortex_ffi_shared PROPERTIES | ||
| IMPORTED_LOCATION "${VORTEX_FFI_SHARED}" | ||
| INTERFACE_INCLUDE_DIRECTORIES "${VORTEX_FFI_HEADERS}" | ||
| INTERFACE_LINK_OPTIONS "LINKER:-rpath,${VORTEX_FFI_LIB_DIR}") | ||
| endif() | ||
|
|
||
| file(GLOB VORTEX_CXX_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") | ||
| add_library(vortex_cxx STATIC ${VORTEX_CXX_SOURCES}) | ||
| target_include_directories(vortex_cxx PUBLIC | ||
| ${CMAKE_CURRENT_SOURCE_DIR} | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/include | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/../vortex-ffi/cinclude | ||
| ) | ||
| target_link_libraries(vortex_cxx PUBLIC vortex_ffi) | ||
| add_library(vortex::cxx ALIAS vortex_cxx) | ||
| target_compile_features(vortex_cxx PUBLIC cxx_std_20) | ||
|
|
||
| set(APPLE_LINK_FLAGS "-framework CoreFoundation -framework Security") | ||
|
|
||
| if(APPLE) | ||
| target_link_libraries(vortex_cxx PRIVATE ${APPLE_LINK_FLAGS}) | ||
| endif() | ||
|
|
||
| if(TARGET vortex_ffi_shared) | ||
| add_library(vortex_cxx_shared SHARED ${VORTEX_CXX_SOURCES}) | ||
|
0ax1 marked this conversation as resolved.
|
||
| set_target_properties(vortex_cxx_shared PROPERTIES POSITION_INDEPENDENT_CODE ON) | ||
| target_include_directories(vortex_cxx_shared PUBLIC | ||
| ${CMAKE_CURRENT_SOURCE_DIR} | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/include | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/../vortex-ffi/cinclude | ||
| ) | ||
| target_link_libraries(vortex_cxx_shared PUBLIC vortex_ffi_shared) | ||
| add_library(vortex::cxx_shared ALIAS vortex_cxx_shared) | ||
| target_compile_features(vortex_cxx_shared PUBLIC cxx_std_20) | ||
|
|
||
| if(APPLE) | ||
| target_link_libraries(vortex_cxx_shared PRIVATE ${APPLE_LINK_FLAGS}) | ||
| endif() | ||
| endif() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Vortex C++ bindings | ||
|
|
||
| For a usage guide, see docs/api/cpp/index.rst. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - CMake 3.10+ | ||
| - C++20 compiler (C++23 compiler for tests). | ||
| - Rust toolchain for building `vortex-ffi`. | ||
|
|
||
| ## Build | ||
|
|
||
| ```sh | ||
| cargo build --release -p vortex-ffi | ||
| cmake -Bbuild -DCMAKE_BUILD_TYPE=Release | ||
| cmake --build build -j | ||
| ``` | ||
|
|
||
| This will generate `libvortex_cxx` shared and static libraries. | ||
| You can use `vortex_cxx` and `vortex_cxx_shared` CMake targets. | ||
|
|
||
| ## Test | ||
|
|
||
| ```sh | ||
| cargo build --release -p vortex-ffi | ||
| cmake -Bbuild -DBUILD_TESTS=ON | ||
| cmake --build build -j | ||
| ctest --test-dir build -j "$(nproc)" | ||
| ``` | ||
|
|
||
| ## Run examples | ||
|
|
||
| ```sh | ||
| cmake -Bbuild -DBUILD_EXAMPLES=ON | ||
| cmake --build build -j | ||
| ./build/examples/hello-vortex | ||
| ``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.