Skip to content

Commit

Permalink
(#11826) luau: add recipe
Browse files Browse the repository at this point in the history
* luau: add recipe

* set CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS

* link Ast to VM

* drop support MSVC shared build

* fix typo
  • Loading branch information
toge authored Jul 22, 2022
1 parent cd873f2 commit 6fc2573
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 0 deletions.
99 changes: 99 additions & 0 deletions recipes/luau/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
cmake_minimum_required(VERSION 3.8)
project(conan_wrapper CXX)

include(conanbuildinfo.cmake)
conan_basic_setup(TARGETS KEEP_RPATHS)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

add_subdirectory(source_subfolder)

## installer
include(GNUInstallDirs)

install(
TARGETS Luau.Ast
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(DIRECTORY "source_subfolder/Ast/include/Luau" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

install(
TARGETS Luau.Compiler
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(DIRECTORY "source_subfolder/Compiler/include/Luau" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(FILES
"source_subfolder/Compiler/include/luacode.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

install(
TARGETS Luau.CodeGen
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(DIRECTORY "source_subfolder/CodeGen/include/Luau" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")


install(
TARGETS Luau.Analysis
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(DIRECTORY "source_subfolder/Analysis/include/Luau" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

install(
TARGETS Luau.VM
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(FILES
"source_subfolder/VM/include/lua.h"
"source_subfolder/VM/include/luaconf.h"
"source_subfolder/VM/include/lualib.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

if(LUAU_BUILD_CLI)
install(
TARGETS Luau.Repl.CLI
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(
TARGETS Luau.Analyze.CLI
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(
TARGETS Luau.Ast.CLI
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()

if(LUAU_BUILD_WEB)
install(
TARGETS Luau.Web
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()
11 changes: 11 additions & 0 deletions recipes/luau/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sources:
"0.536":
url: "https://github.com/Roblox/luau/archive/refs/tags/0.536.tar.gz"
sha256: "e6de36e83e9c537d92bcc94852ab498e3c15a310fd2c4cc4e21c616d8ae1a84f"

patches:
"0.536":
- patch_file: "patches/0.536-0001-fix-cmake.patch"
base_path: "source_subfolder"
- patch_file: "patches/0.536-0002-rename-lerp.patch"
base_path: "source_subfolder"
134 changes: 134 additions & 0 deletions recipes/luau/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
from conans import ConanFile, CMake, tools
from conan.tools.microsoft import is_msvc
import os
import functools

required_conan_version = ">=1.43.0"

class LuauConan(ConanFile):
name = "luau"
description = "A fast, small, safe, gradually typed embeddable scripting language derived from Lua "
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://luau-lang.org/"
topics = ("lua", "scripting", "typed", "embed")
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [False, True],
"fPIC": [True, False],
"with_cli": [True, False],
"with_web": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_cli": False,
"with_web": False,
}
generators = "cmake"

@property
def _source_subfolder(self):
return "source_subfolder"

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

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

def configure(self):
if self.options.shared:
del self.options.fPIC

@property
def _compiler_required_cpp17(self):
return {
"Visual Studio": "16",
"gcc": "8",
"clang": "7",
"apple-clang": "12.0",
}

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 17)

minimum_version = self._compiler_required_cpp17.get(str(self.settings.compiler), False)
if minimum_version:
if tools.Version(self.settings.compiler.version) < minimum_version:
raise tools.ConanInvalidConfiguration("{} requires C++17, which your compiler does not support.".format(self.name))
else:
self.output.warn("{0} requires C++17. Your compiler is unknown. Assuming it supports C++17.".format(self.name))

if is_msvc(self) and self.options.shared:
raise tools.ConanInvalidConfiguration("{} does not support shared build in MSVC".format(self.name))

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

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["LUAU_BUILD_CLI"] = self.options.with_cli
cmake.definitions["LUAU_BUILD_TESTS"] = False
cmake.definitions["LUAU_BUILD_WEB"] = self.options.with_web
cmake.definitions["LUAU_WERROR"] = False
cmake.definitions["LUAU_STATIC_CRT"] = False
cmake.configure()
return cmake

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy(pattern="lua_LICENSE*", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "Luau")
self.cpp_info.set_property("cmake_target_name", "Luau::Luau")

self.cpp_info.filenames["cmake_find_package"] = "Luau"
self.cpp_info.filenames["cmake_find_package_multi"] = "Luau"
self.cpp_info.names["cmake_find_package_multi"] = "Luau"
self.cpp_info.names["cmake_find_package"] = "Luau"

self.cpp_info.components["Ast"].libs = ["Luau.Ast"]
self.cpp_info.components["Ast"].set_property("cmake_target_name", "Luau::Ast")

self.cpp_info.components["VM"].libs = ["Luau.VM"]
self.cpp_info.components["VM"].set_property("cmake_target_name", "Luau::VM")
self.cpp_info.components["VM"].requires = ["Ast"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["VM"].system_libs = ["m"]

self.cpp_info.components["Analysis"].libs = ["Luau.Analysis"]
self.cpp_info.components["Analysis"].set_property("cmake_target_name", "Luau::Analysis")
self.cpp_info.components["Analysis"].requires = ["Ast"]

self.cpp_info.components["Compiler"].libs = ["Luau.Compiler"]
self.cpp_info.components["Compiler"].set_property("cmake_target_name", "Luau::Compiler")
self.cpp_info.components["Compiler"].requires = ["Ast"]

self.cpp_info.components["CodeGen"].libs = ["Luau.CodeGen"]
self.cpp_info.components["CodeGen"].set_property("cmake_target_name", "Luau::CodeGen")
self.cpp_info.components["CodeGen"].requires = ["Ast"]

if self.options.with_cli:
bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bin_path))
self.env_info.PATH.append(bin_path)

if self.options.with_web:
self.cpp_info.components["Web"].libs = ["Luau.Web"]
self.cpp_info.components["Web"].set_property("cmake_target_name", "Luau::Web")
self.cpp_info.components["Web"].requires = ["Compiler", "VM"]
23 changes: 23 additions & 0 deletions recipes/luau/all/patches/0.536-0001-fix-cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9200634..c1cca12 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,12 +21,12 @@ endif()

project(Luau LANGUAGES CXX C)
add_library(Luau.Common INTERFACE)
-add_library(Luau.Ast STATIC)
-add_library(Luau.Compiler STATIC)
-add_library(Luau.Analysis STATIC)
-add_library(Luau.CodeGen STATIC)
-add_library(Luau.VM STATIC)
-add_library(isocline STATIC)
+add_library(Luau.Ast)
+add_library(Luau.Compiler)
+add_library(Luau.Analysis)
+add_library(Luau.CodeGen)
+add_library(Luau.VM)
+add_library(isocline)

if(LUAU_BUILD_CLI)
add_executable(Luau.Repl.CLI)
28 changes: 28 additions & 0 deletions recipes/luau/all/patches/0.536-0002-rename-lerp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/VM/src/lmathlib.cpp b/VM/src/lmathlib.cpp
index a6e7b49..7c3e3c6 100644
--- a/VM/src/lmathlib.cpp
+++ b/VM/src/lmathlib.cpp
@@ -300,7 +300,7 @@ static float fade(float t)
return t * t * t * (t * (t * 6 - 15) + 10);
}

-static float lerp(float t, float a, float b)
+static float lerp_l(float t, float a, float b)
{
return a + t * (b - a);
}
@@ -342,10 +342,10 @@ static float perlin(float x, float y, float z)
int ba = p[b] + zi;
int bb = p[b + 1] + zi;

- return lerp(w,
- lerp(v, lerp(u, grad(p[aa], xf, yf, zf), grad(p[ba], xf - 1, yf, zf)), lerp(u, grad(p[ab], xf, yf - 1, zf), grad(p[bb], xf - 1, yf - 1, zf))),
- lerp(v, lerp(u, grad(p[aa + 1], xf, yf, zf - 1), grad(p[ba + 1], xf - 1, yf, zf - 1)),
- lerp(u, grad(p[ab + 1], xf, yf - 1, zf - 1), grad(p[bb + 1], xf - 1, yf - 1, zf - 1))));
+ return lerp_l(w,
+ lerp_l(v, lerp_l(u, grad(p[aa], xf, yf, zf), grad(p[ba], xf - 1, yf, zf)), lerp_l(u, grad(p[ab], xf, yf - 1, zf), grad(p[bb], xf - 1, yf - 1, zf))),
+ lerp_l(v, lerp_l(u, grad(p[aa + 1], xf, yf, zf - 1), grad(p[ba + 1], xf - 1, yf, zf - 1)),
+ lerp_l(u, grad(p[ab + 1], xf, yf - 1, zf - 1), grad(p[bb + 1], xf - 1, yf - 1, zf - 1))));
}

static int math_noise(lua_State* L)
11 changes: 11 additions & 0 deletions recipes/luau/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.8)
project(test_package)

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

find_package(Luau REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} Luau::Luau)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
17 changes: 17 additions & 0 deletions recipes/luau/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os

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

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

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

#include <string>

int main(int argc, char* argv[]) {
lua_State* L = luaL_newstate();
lua_close(L);
return 0;
}
3 changes: 3 additions & 0 deletions recipes/luau/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.536":
folder: all

0 comments on commit 6fc2573

Please sign in to comment.