Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update build system to CMake
Browse files Browse the repository at this point in the history
Vipul-Cariappa committed Jan 12, 2025
1 parent 39a447d commit 61dcb88
Showing 7 changed files with 49 additions and 149 deletions.
16 changes: 0 additions & 16 deletions .github/build.sh

This file was deleted.

24 changes: 0 additions & 24 deletions .github/premake5.lua

This file was deleted.

59 changes: 0 additions & 59 deletions .github/test.sh

This file was deleted.

35 changes: 26 additions & 9 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -10,34 +10,51 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: '3.10'
- uses: Vipul-Cariappa/lua-setup-action@main

- name: Install Requirements
run: |
sudo apt-get update
sudo apt-get install lua5.4 liblua5.4-dev make cmake gcc -y
which python3
which lua
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: cpp
queries: security-and-quality

- name: Build
run: bash .github/build.sh
run: |
cmake . -DCMAKE_BUILD_TYPE=Debug
make -j
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2

- name: Test (setup)
run: |
cp lib/libpylua.so tests/pylua.so
cd tests
wget https://raw.githubusercontent.com/bluebird75/luaunit/master/luaunit.lua
cd ..
- name: Test
run: bash .github/test.sh
run: |
cd tests
lua test0.lua
lua test1.lua
lua test2.lua
lua test3.lua
lua test4.lua
python3 testA.py
cd ..
- name: Code Coverage
run: |
gcov -abcfu obj/Debug/lua_py.c
gcov -abcfu obj/Debug/py_lua.c
gcov -abcfu obj/Debug/convert.c
gcov -abcfu CMakeFiles/pylua.dir/src/lua_py.c
gcov -abcfu CMakeFiles/pylua.dir/src/py_lua.c
gcov -abcfu CMakeFiles/pylua.dir/src/convert.c
- name: Upload Code Coverage
uses: codecov/codecov-action@v1

25 changes: 18 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -2,21 +2,32 @@ cmake_minimum_required (VERSION 3.10)

project(pylua)

find_package(PkgConfig REQUIRED)
find_package(Python COMPONENTS Interpreter Development)
find_package(Lua REQUIRED)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib")

pkg_check_modules(LUA REQUIRED lua)
pkg_check_modules(PYTHON REQUIRED python3)

add_library(pylua SHARED src/convert.c src/py_lua.c src/lua_py.c)

message(STATUS "Python_INCLUDE_DIRS = ${Python_INCLUDE_DIRS}")
message(STATUS "Python_CFLAGS_OTHER = ${Python_CFLAGS_OTHER}")
message(STATUS "Python_LIBRARIES = ${Python_LIBRARIES}")
message(STATUS "LUA_LIBRARIES = ${LUA_LIBRARIES}")
message(STATUS "LUA_INCLUDE_DIRS = ${LUA_INCLUDE_DIRS}")
message(STATUS "LUA_CFLAGS_OTHER = ${LUA_CFLAGS_OTHER}")

if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT WIN32)
message(STATUS "Building in Debug, Therefore compiling with code coverage")
target_compile_options(pylua PRIVATE -coverage)
target_link_options(pylua PRIVATE -coverage)
endif()

target_include_directories(pylua PRIVATE "src/")

target_include_directories(pylua PRIVATE ${PYTHON_INCLUDE_DIRS})
target_link_libraries(pylua python3)
target_compile_options(pylua PRIVATE ${PYTHON_CFLAGS_OTHER})
target_include_directories(pylua PRIVATE ${Python_INCLUDE_DIRS})
target_link_libraries(pylua ${Python_LIBRARIES})
target_compile_options(pylua PRIVATE ${Python_CFLAGS_OTHER})

target_link_libraries(pylua ${LUA_LIBRARIES})
target_include_directories(pylua PRIVATE ${LUA_INCLUDE_DIRS})
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -91,29 +91,22 @@ print(f"{ctf_40 = }, {ftc_n40 = }") # ctf_40 = 104.0, ftc_n40 = -40.0032
To compile py-lua. First install the required dependencies:
- python3
- lua5.4
- premake5
- gcc (linux)
- Visual Studio Code (windows)

Clone the repository

```bash
git clone https://github.com/Vipul-Cariappa/py-lua.git
```

Update `premake5.lua` file: Replace `/path/to/python/header` and `/path/to/lua/header` with actual header paths and replace `/path/to/python/shared_libraries` and `/path/to/lua/shared_libraries` with actual paths to shared libraries.
You should be able to build it with CMake


After updating paths run premake with desired action:
```bash
premake5 [action]
```bash
cmake . -DCMAKE_BUILD_TYPE=Release
```
You can now use compiler of your choice to build the pylua shared library.

Copy the shared library pylua.so file to the working directory of your project.

If you face any problems while building please ask for help [here](https://github.com/Vipul-Cariappa/py-lua/discussions/new).
Followed by `make` in Unix.

You will then need to copy `lib/libpylua.so` to your working directory as `pylua.so`.

## Contribution
All contributions are welcomed.
22 changes: 0 additions & 22 deletions premake5.lua

This file was deleted.

0 comments on commit 61dcb88

Please sign in to comment.