Skip to content

Commit

Permalink
Merge pull request #3 from agoose77/main
Browse files Browse the repository at this point in the history
fix: simplify CMakeLists.txt
  • Loading branch information
ManasviGoyal authored Oct 9, 2023
2 parents 885804b + ec4c152 commit 78727bf
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 114 deletions.
63 changes: 28 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
cmake_minimum_required(VERSION 3.15...3.26)
project(kaitai_awkward_runtime CXX)
cmake_minimum_required(VERSION 3.19...3.26)
project(${SKBUILD_PROJECT_NAME} CXX)

set(KSY "" CACHE STRING "Specify the KSY file path")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")

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

set(BUILD_SHARED_LIBS OFF)
set(BUILD_STATIC_LIBS ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(BUILD_SHARED_LIBS ON)

find_package(pybind11 CONFIG REQUIRED)

add_subdirectory(kaitai_struct_cpp_stl_runtime)

set (MAIN_HEADERS
kaitai_struct_cpp_stl_runtime/kaitai/kaitaistream.h
kaitai_struct_cpp_stl_runtime/kaitai/kaitaistruct.h
kaitai_struct_cpp_stl_runtime/kaitai/exceptions.h
)

set (MAIN_SOURCES
kaitai_struct_cpp_stl_runtime/kaitai/kaitaistream.cpp
)
# Setup the RPATH for built libraries
if(APPLE)
set(CMAKE_INSTALL_RPATH "@loader_path")
else()
SET(CMAKE_INSTALL_RPATH "$ORIGIN")
endif()

add_library (${PROJECT_NAME} ${MAIN_HEADERS} ${MAIN_SOURCES})
add_subdirectory(kaitai_struct_cpp_stl_runtime EXCLUDE_FROM_ALL)

# Download awkward headers
include(FetchContent)
Expand All @@ -43,25 +29,32 @@ if(NOT awkward-headers_POPULATED)
add_subdirectory(${awkward-headers_SOURCE_DIR} ${awkward-headers_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR}/_deps/awkward-headers-src/layout-builder)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR}/_deps/awkward-headers-src/builder-options)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR}/_deps/awkward-headers-src/growable-buffer)

# Run sbt package command to compile kaitai_struct_compiler code
execute_process(
COMMAND sbt package
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/kaitai_struct_compiler
COMMAND_ERROR_IS_FATAL ANY
)

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)
target_include_directories(awkward_${PACKAGE_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/kaitai_struct_cpp_stl_runtime)
target_link_libraries(awkward_${PACKAGE_NAME} PUBLIC 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})
15 changes: 8 additions & 7 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 @@ -10,23 +9,25 @@ Steps for reproducing the environment:
git clone --recursive https://github.com/ManasviGoyal/kaitai_awkward_runtime.git
```

2. Change directory to `kaitai_awkward_runtime` and run CMake:
2. Change directory to `kaitai_awkward_runtime`:
```
cd kaitai_awkward_runtime
export CMAKE_ARGS="-DKSY=schemas/animal.ksy -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON"
```
<!--- if we want to set up the package_name as ksy name we can just skip the PACKAGE_NAME argument -->

3. Install the library and open Python:
3. Install the library, and open Python:
```
pip install .
pip install .
python
```

4. Print the returned `ak.Array`:
```python
import animal
awkward_array = animal.load("../data/animal.raw")
import awkward_animal
awkward_array = awkward_animal.load("data/animal.raw")
print(awkward_array)
```


> **Info**
> `kaitai_awkward_runtime` depends upon `sbt`, and `gtest` dependencies.
Empty file modified kaitai-struct-compiler
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion kaitai_struct_compiler
16 changes: 11 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ classifiers = [
"Typing :: Typed",
]
dynamic = ["version"]
dependencies = []
dependencies = [
"awkward>2.4.3"
]

[project.optional-dependencies]
test = [
Expand All @@ -50,17 +52,21 @@ docs = [
]

[project.urls]
Homepage = "https://github.com/org/kaitai_awkward_runtime"
"Bug Tracker" = "https://github.com/org/kaitai_awkward_runtime/issues"
Discussions = "https://github.com/org/kaitai_awkward_runtime/discussions"
Changelog = "https://github.com/org/kaitai_awkward_runtime/releases"
Homepage = "https://github.com/ManasviGoyal/kaitai_awkward_runtime"
"Bug Tracker" = "https://github.com/ManasviGoyal/kaitai_awkward_runtime/issues"


[tool.scikit-build]
minimum-version = "0.4"
build-dir = "build/{wheel_tag}"
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
sdist.include = ["src/kaitai_awkward_runtime/_version.py"]
cmake.verbose = true
logging.level = "INFO"
cmake.build-type = "Debug"

[tool.scikit-build.cmake.define]
KSY = "schemas/animal.ksy"


[tool.setuptools_scm]
Expand Down
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 78727bf

Please sign in to comment.