Skip to content

Commit

Permalink
Update build system to CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
Vipul-Cariappa committed Jan 12, 2025
1 parent 39a447d commit 21eea2e
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 148 deletions.
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Steps to reproduce the behavior:
A clear and concise description of what you expected to happen.

**System Environment (please complete the following information):**
- OS: [e.g. windows, linux]
- Python Version: [e.g. 3.7, 3.8, 3.9, 3.10]
- Lua Version: [e.g. 5.4]

Expand Down
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
Expand Up @@ -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: 19 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,34 @@ cmake_minimum_required (VERSION 3.10)

project(pylua)

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

pkg_check_modules(LUA REQUIRED lua)

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})
Expand Down
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,26 @@ 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)
- cmake
- pkg-config

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.
Followed by `make` in Unix.

If you face any problems while building please ask for help [here](https://github.com/Vipul-Cariappa/py-lua/discussions/new).
You will then need to copy `lib/libpylua.so` to your working directory as `pylua.so`.

> Building py-lua on Windows is not yet tested.
## Contribution
All contributions are welcomed.
Expand Down
22 changes: 0 additions & 22 deletions premake5.lua

This file was deleted.

0 comments on commit 21eea2e

Please sign in to comment.