Skip to content

Commit

Permalink
wip: build a shared library for now
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Oct 9, 2023
1 parent 33d75a5 commit ec4c152
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 82 deletions.
38 changes: 25 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
cmake_minimum_required(VERSION 3.19...3.26)
project(kaitai_awkward_runtime CXX)
project(${SKBUILD_PROJECT_NAME} CXX)

set(KSY "" CACHE STRING "Specify the KSY file path")

string(REGEX MATCH "([^/]+)$" package_name ${KSY})
string(REGEX REPLACE "\\.ksy$" "" package_name ${package_name})
set(PACKAGE_NAME ${package_name})

set(BUILD_SHARED_LIBS ON)
set(BUILD_STATIC_LIBS OFF)

find_package(pybind11 CONFIG REQUIRED)

add_subdirectory(kaitai_struct_cpp_stl_runtime)
# Setup the RPATH for built libraries
if(APPLE)
set(CMAKE_INSTALL_RPATH "@loader_path")
else()
SET(CMAKE_INSTALL_RPATH "$ORIGIN")
endif()

add_subdirectory(kaitai_struct_cpp_stl_runtime EXCLUDE_FROM_ALL)

# Download awkward headers
include(FetchContent)
Expand All @@ -36,13 +37,24 @@ execute_process(
)

execute_process(
COMMAND ./kaitai-struct-compiler -t awkward --outdir src-${PACKAGE_NAME} ${KSY} #package name should be declared as a string
COMMAND ./kaitai-struct-compiler -t awkward --outdir src-${SKBUILD_PROJECT_NAME} ${KSY} #package name should be declared as a string
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY
)

pybind11_add_module(awkward_${PACKAGE_NAME} src-${PACKAGE_NAME}/${PACKAGE_NAME}_main.cpp src-${PACKAGE_NAME}/${PACKAGE_NAME}.cpp)
target_link_libraries(awkward_${PACKAGE_NAME} PRIVATE awkward::layout-builder kaitai_struct_cpp_stl_runtime)
string(REGEX MATCH "([^/]+)$" KSY_MODULE ${KSY})
string(REGEX REPLACE "\\.ksy$" "" KSY_MODULE ${KSY_MODULE})

pybind11_add_module(awkward_${KSY_MODULE} src-${SKBUILD_PROJECT_NAME}/${KSY_MODULE}_main.cpp src-${SKBUILD_PROJECT_NAME}/${KSY_MODULE}.cpp)
target_link_libraries(awkward_${KSY_MODULE} PRIVATE awkward::layout-builder kaitai_struct_cpp_stl_runtime)

# Install pure-python files
file(GLOB_RECURSE PYTHON_SOURCES "src/${SKBUILD_PROJECT_NAME}/*.py")

install(
TARGETS awkward_${KSY_MODULE} kaitai_struct_cpp_stl_runtime
LIBRARY DESTINATION "${SKBUILD_PROJECT_NAME}/lib"
RUNTIME DESTINATION "${SKBUILD_PROJECT_NAME}/lib"
ARCHIVE DESTINATION "${SKBUILD_PROJECT_NAME}/lib")

# Install into wheel
install(TARGETS awkward_${PACKAGE_NAME} DESTINATION .)
install(FILES ${PYTHON_SOURCES} DESTINATION ${SKBUILD_PROJECT_NAME})
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# kaitai_awkward_runtime

# awkward-kaitai
Building Awkward Arrays using Kaitai binary file descriptors.

Steps for reproducing the environment:
Expand All @@ -16,9 +15,9 @@ cd kaitai_awkward_runtime
```
<!--- if we want to set up the package_name as ksy name we can just skip the PACKAGE_NAME argument -->

3. Install the library, specifying the schema, and open Python:
3. Install the library, and open Python:
```
pip install . --config-settings 'cmake.define.KSY=schemas/animal.ksy'
pip install .
python
```

Expand All @@ -29,3 +28,6 @@ awkward_array = awkward_animal.load("data/animal.raw")
print(awkward_array)
```


> **Info**
> `kaitai_awkward_runtime` depends upon `sbt`, and `gtest` dependencies.
3 changes: 3 additions & 0 deletions src/kaitai_awkward_runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
from ._version import version as __version__

__all__ = ("__version__",)


from .lib.awkward_animal import *
66 changes: 0 additions & 66 deletions src/main.cpp

This file was deleted.

0 comments on commit ec4c152

Please sign in to comment.