diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 52a9967..1514a8f 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -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] diff --git a/.github/build.sh b/.github/build.sh deleted file mode 100644 index 07d189e..0000000 --- a/.github/build.sh +++ /dev/null @@ -1,16 +0,0 @@ -FILE=premake5 - -echo "Finding $FILE" - -if [ -f "$FILE" ]; then - echo "$FILE exists." -else - echo "$FILE does not exist." - echo "Downloading $FILE" - wget https://github.com/premake/premake-core/releases/download/v5.0.0-alpha16/premake-5.0.0-alpha16-linux.tar.gz - tar -xf premake-5.0.0-alpha16-linux.tar.gz -fi - -cp .github/premake5.lua ./premake5.lua -./premake5 gmake -make diff --git a/.github/premake5.lua b/.github/premake5.lua deleted file mode 100644 index ceb95bc..0000000 --- a/.github/premake5.lua +++ /dev/null @@ -1,24 +0,0 @@ -workspace "py-lua" - configurations { "Debug", "Release" } - -project "pylua" - kind "SharedLib" - language "C" - targetdir "bin" - - includedirs { "/usr/include/python3.10", "/usr/include/lua5.4" } - files { "src/**.h", "src/**.c" } - - filter { "system:linux" } - links { "python3.10", "lua" } - - filter "configurations:Debug" - buildoptions { "-ftest-coverage", "-fprofile-arcs" } - linkoptions { "-lgcov" } - defines { "DEBUG" } - symbols "On" - optimize "Off" - - filter "configurations:Release" - defines { "NDEBUG" } - optimize "On" diff --git a/.github/test.sh b/.github/test.sh deleted file mode 100644 index ade953d..0000000 --- a/.github/test.sh +++ /dev/null @@ -1,59 +0,0 @@ -cp bin/libpylua.so tests/pylua.so -cp bin/libpylua.so tests/pylua.pyd -cd tests - -FILE=luaunit.lua - -echo "Finding $FILE" - -if [ -f "$FILE" ]; then - echo "$FILE exists." -else - echo "$FILE does not exist." - echo "Downloading $FILE" - wget https://raw.githubusercontent.com/bluebird75/luaunit/master/luaunit.lua -fi - -printf "Running Lua Side Tests\n" - -printf "\nTest Case 1\n" -if ! lua test0.lua; then - echo "Error" - exit -1 -fi - -printf "\nTest Case 2\n" -if ! lua test1.lua; then - echo "Error" - exit -1 -fi - -printf "\nTest Case 3\n" -if ! lua test2.lua; then - echo "Error" - exit -1 -fi - -printf "\nTest Case 4\n" -if ! lua test3.lua; then - echo "Error" - exit -1 -fi - -printf "\nTest Case 5\n" -if ! lua test4.lua; then - echo "Error" - exit -1 -fi - - -printf "\n\nRunning Python Side Tests\n" - -printf "\nTest Case 1\n" -if ! python3 testA.py; then - echo "Error" - exit -1 -fi - - -printf "\n\nFinished Running all tests\n" diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 3e2ea2b..638ab8f 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -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 - diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fb4492..27e8d3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/README.md b/README.md index 0aac32f..e498310 100644 --- a/README.md +++ b/README.md @@ -91,9 +91,8 @@ 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 @@ -101,19 +100,17 @@ Clone the repository 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. diff --git a/premake5.lua b/premake5.lua deleted file mode 100644 index 25d184e..0000000 --- a/premake5.lua +++ /dev/null @@ -1,22 +0,0 @@ ----@diagnostic disable: undefined-global -workspace "py-lua" - configurations { "Debug", "Release" } - -project "pylua" - kind "SharedLib" - language "C" - targetdir "bin/%{cfg.buildcfg}" - - files { "src/**.h", "src/**.c" } - - filter "configurations:Debug" - includedirs { "/usr/local/include/python3.10", "/usr/include/lua5.4" } - links { "python3.10", "lua5.4" } - defines { "DEBUG", "Py_DEBUG" } - symbols "On" - - filter "configurations:Release" - includedirs { "/usr/include/python3.10", "/usr/include/lua5.4" } - links { "python3.10", "lua5.4" } - defines { "NDEBUG" } - optimize "On"