-
Notifications
You must be signed in to change notification settings - Fork 0
Migrate to using Diplomat for FFI #75
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
da5d914
Initial migration to diplomat ffi
alextac98 f514d3e
complete migration, not sure if I want to continue this though
alextac98 27856d5
Rework where everything is located
alextac98 a55fe24
Support many different Python versions
alextac98 123ea2f
Changes from PR comments
alextac98 2e278b4
fix build issue from adding error capability
alextac98 f24b217
fix builds for cmake and python, remove intel mac support
alextac98 d83ec3d
Another fix for python builds on windows
alextac98 8f33f8b
Another fix for python builds on windows
alextac98 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 |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ __pycache__/ | |
|
|
||
| # CMake Build Directories | ||
| build/ | ||
| build-*/ | ||
|
|
||
| # VSCode Settings | ||
| .vscode/ | ||
| .vscode/ | ||
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 |
|---|---|---|
| @@ -1,52 +1,89 @@ | ||
| cmake_minimum_required(VERSION 3.20) | ||
| project(dv LANGUAGES C CXX) | ||
|
|
||
| # Options | ||
| option(DV_BUILD_SHARED "Build shared library" ON) | ||
|
|
||
| # Build Rust C-ABI via Cargo. We use ExternalProject for portability. | ||
| include(ExternalProject) | ||
| set(DV_RUST_DIR ${CMAKE_CURRENT_LIST_DIR}/cpp/capi) | ||
| set(DV_BUILD_CMD cargo build --manifest-path ${DV_RUST_DIR}/Cargo.toml --release) | ||
|
|
||
| ExternalProject_Add(dv_capi_ext | ||
| SOURCE_DIR ${DV_RUST_DIR} | ||
| find_program(BAZEL_EXECUTABLE bazel REQUIRED) | ||
| find_program(CARGO_EXECUTABLE cargo REQUIRED) | ||
|
|
||
| set(DV_BRIDGE_DIR ${CMAKE_CURRENT_LIST_DIR}/core/ffi/diplomat) | ||
| set(DV_BRIDGE_ENTRY ${DV_BRIDGE_DIR}/src/lib.rs) | ||
| set(DV_CODEGEN_ROOT ${CMAKE_BINARY_DIR}/generated/diplomat) | ||
| set(DV_CODEGEN_C_DIR ${DV_CODEGEN_ROOT}/c) | ||
| set(DV_CODEGEN_CPP_DIR ${DV_CODEGEN_ROOT}/cpp) | ||
|
|
||
| file(MAKE_DIRECTORY ${DV_CODEGEN_C_DIR} ${DV_CODEGEN_CPP_DIR}) | ||
|
|
||
| set(DV_GEN_C_HEADERS | ||
| ${DV_CODEGEN_C_DIR}/BaseUnits.d.h | ||
| ${DV_CODEGEN_C_DIR}/BaseUnits.h | ||
| ${DV_CODEGEN_C_DIR}/DvError.d.h | ||
| ${DV_CODEGEN_C_DIR}/DvError.h | ||
| ${DV_CODEGEN_C_DIR}/DimensionalVariable.d.h | ||
| ${DV_CODEGEN_C_DIR}/DimensionalVariable.h | ||
| ${DV_CODEGEN_C_DIR}/diplomat_runtime.h | ||
| ) | ||
| set(DV_GEN_CPP_HEADERS | ||
| ${DV_CODEGEN_CPP_DIR}/BaseUnits.d.hpp | ||
| ${DV_CODEGEN_CPP_DIR}/BaseUnits.hpp | ||
| ${DV_CODEGEN_CPP_DIR}/DvError.d.hpp | ||
| ${DV_CODEGEN_CPP_DIR}/DvError.hpp | ||
| ${DV_CODEGEN_CPP_DIR}/DimensionalVariable.d.hpp | ||
| ${DV_CODEGEN_CPP_DIR}/DimensionalVariable.hpp | ||
| ${DV_CODEGEN_CPP_DIR}/diplomat_runtime.hpp | ||
| ) | ||
|
|
||
| add_custom_command( | ||
| OUTPUT ${DV_GEN_C_HEADERS} | ||
| COMMAND ${CMAKE_COMMAND} -E make_directory ${DV_CODEGEN_C_DIR} | ||
| COMMAND ${BAZEL_EXECUTABLE} run //tools/diplomat_codegen:diplomat_codegen -- c ${DV_CODEGEN_C_DIR} --entry ${DV_BRIDGE_ENTRY} | ||
| DEPENDS ${DV_BRIDGE_ENTRY} | ||
| WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} | ||
| VERBATIM | ||
| ) | ||
|
|
||
| add_custom_command( | ||
| OUTPUT ${DV_GEN_CPP_HEADERS} | ||
| COMMAND ${CMAKE_COMMAND} -E make_directory ${DV_CODEGEN_CPP_DIR} | ||
| COMMAND ${BAZEL_EXECUTABLE} run //tools/diplomat_codegen:diplomat_codegen -- cpp ${DV_CODEGEN_CPP_DIR} --entry ${DV_BRIDGE_ENTRY} | ||
| DEPENDS ${DV_BRIDGE_ENTRY} | ||
| WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} | ||
| VERBATIM | ||
| ) | ||
|
|
||
| add_custom_target(dv_diplomat_codegen DEPENDS ${DV_GEN_C_HEADERS} ${DV_GEN_CPP_HEADERS}) | ||
|
|
||
| set(DV_CARGO_TARGET_DIR ${DV_BRIDGE_DIR}/target) | ||
| set(DV_CARGO_BUILD_CMD | ||
| ${CARGO_EXECUTABLE} build | ||
| --manifest-path ${DV_BRIDGE_DIR}/Cargo.toml | ||
| --release | ||
| ) | ||
|
|
||
| ExternalProject_Add(dv_diplomat_bridge_ext | ||
| SOURCE_DIR ${DV_BRIDGE_DIR} | ||
| BUILD_IN_SOURCE 1 | ||
| CONFIGURE_COMMAND "" | ||
| BUILD_COMMAND ${DV_BUILD_CMD} | ||
| BUILD_COMMAND ${DV_CARGO_BUILD_CMD} | ||
| INSTALL_COMMAND "" | ||
| BUILD_BYPRODUCTS | ||
| ${DV_RUST_DIR}/target/release/libdv_capi.a | ||
| ${DV_RUST_DIR}/target/release/libdv_capi.dylib | ||
| BUILD_BYPRODUCTS | ||
| ${DV_BRIDGE_DIR}/target/release/libdv_diplomat_bridge.a | ||
| ) | ||
|
|
||
| # Library artifact path | ||
| if(APPLE) | ||
| set(DV_CAPI_SHARED ${DV_RUST_DIR}/target/release/libdv_capi.dylib) | ||
| elseif(UNIX) | ||
| set(DV_CAPI_SHARED ${DV_RUST_DIR}/target/release/libdv_capi.so) | ||
| elseif(WIN32) | ||
| set(DV_CAPI_SHARED ${DV_RUST_DIR}/target/release/dv_capi.dll) | ||
| endif() | ||
| set(DV_CAPI_STATIC ${DV_RUST_DIR}/target/release/libdv_capi.a) | ||
| set(DV_DIPLOMAT_STATIC ${DV_BRIDGE_DIR}/target/release/libdv_diplomat_bridge.a) | ||
|
|
||
| add_library(dv_c STATIC IMPORTED GLOBAL) | ||
| set_target_properties(dv_c PROPERTIES | ||
| IMPORTED_LOCATION ${DV_CAPI_STATIC} | ||
| INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/cpp/include | ||
| IMPORTED_LOCATION ${DV_DIPLOMAT_STATIC} | ||
| INTERFACE_INCLUDE_DIRECTORIES ${DV_CODEGEN_C_DIR} | ||
| ) | ||
| add_dependencies(dv_c dv_capi_ext) | ||
|
|
||
| # Help executables find the dylib at runtime on macOS when running from build tree | ||
| if(APPLE) | ||
| set_property(TARGET dv_c PROPERTY INTERFACE_LINK_DIRECTORIES ${DV_RUST_DIR}/target/release) | ||
| endif() | ||
| target_link_libraries(dv_c INTERFACE $<$<PLATFORM_ID:Linux>:m>) | ||
| add_dependencies(dv_c dv_diplomat_bridge_ext dv_diplomat_codegen) | ||
|
|
||
| add_library(dv_cpp INTERFACE) | ||
| target_include_directories(dv_cpp INTERFACE ${CMAKE_CURRENT_LIST_DIR}/cpp/include) | ||
| target_include_directories(dv_cpp INTERFACE ${DV_CODEGEN_CPP_DIR}) | ||
| target_link_libraries(dv_cpp INTERFACE dv_c) | ||
|
|
||
| add_subdirectory(cpp) | ||
| add_dependencies(dv_cpp dv_diplomat_codegen) | ||
|
|
||
| add_subdirectory(examples/c) | ||
| add_subdirectory(examples/cpp) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The imported static library path is hard-coded to
libdv_diplomat_bridge.a. On Windows, Cargo typically produces a.lib(and different naming conventions), so this CMake build will fail there. Add platform-specific handling for the produced static artifact (and consider wiringCARGO_TARGET_DIRif you want predictable output locations).