Skip to content

Commit

Permalink
💚 Some stuff to make the CI builds a bit better
Browse files Browse the repository at this point in the history
- Thanks, blobthing & zasz!
  • Loading branch information
ThePhD committed May 7, 2021
1 parent 7aae1aa commit 80ede90
Show file tree
Hide file tree
Showing 28 changed files with 285 additions and 280 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ name: Windows
on: [push]

env:
CTEST_OUTPUT_ON_FAILURE: 1
CTEST_OUTPUT_ON_FAILURE: true
UseMultiToolTask: true
EnforceProcessCountAcrossBuilds: true


jobs:
build:
Expand All @@ -17,10 +20,12 @@ jobs:

- name: configure
run: |
$env:MultiProcMaxCount = ((Get-CimInstance -ClassName Win32_Processor | Measure-Object -Property NumberOfLogicalProcessors -Sum).Sum + 1)
cmake -B build/debug -D CMAKE_BUILD_TYPE:STRING=Debug "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM:STRING=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=ON -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON
cmake -B build/release -D CMAKE_BUILD_TYPE:STRING=Release "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM:STRING=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=ON -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON
- name: build
run: |
$env:MultiProcMaxCount = ((Get-CimInstance -ClassName Win32_Processor | Measure-Object -Property NumberOfLogicalProcessors -Sum).Sum + 1)
cmake --build build/debug --config Debug
cmake --build build/release --config Release
- name: test
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ endif()
# # Sources everyone is going to need
# Header files
file(GLOB SOL2_HEADER_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/include/sol*.hpp)
source_group(sol2 FILES ${SOL2_HEADER_SOURCES})

# # # sol2 Library
# # Add a target for sol2's library to be included by external users
Expand Down
9 changes: 4 additions & 5 deletions cmake/Modules/CheckCompilerDiagnostic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,18 @@ function (check_compiler_diagnostic diagnostic)
string(CONCAT diagnostic_flag
$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:${diagnostic_MSVC}>
$<$<COMPILE_LANG_AND_ID:C,MSVC>:${diagnostic_MSVC}>
$<$<COMPILE_LANG_AND_ID:CXX,GCC>:${diagnostic_GCC}>
$<$<COMPILE_LANG_AND_ID:C,GCC>:${diagnostic_GCC}>
$<$<COMPILE_LANG_AND_ID:CXX,GNU>:${diagnostic_GCC}>
$<$<COMPILE_LANG_AND_ID:C,GNU>:${diagnostic_GCC}>
$<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:${diagnostic_CLANG}>
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:${diagnostic_CLANG}>
)
set(forbid_prefix $<IF:$<BOOL:${MSVC}>,-we,-Werror=>)
set(allow_prefix $<IF:$<BOOL:${MSVC}>,-wd,-Wno->)
set(warn_prefix $<IF:$<BOOL:${MSVC}>,-w1,-W>)

set(--forbid-${diagnostic} $<${when}:${forbid_prefix}${diagnostic_flag}> PARENT_SCOPE)
set(--deny-${diagnostic} ${--forbid-${diagnostic}} PARENT_SCOPE)
set(--allow-${diagnostic} $<${when}:${allow_prefix}${diagnostic_flag}> PARENT_SCOPE)
# Set these warnings to level 1 warnings, so they appear by default
set(--warn-${diagnostic} $<${when}:${warn_prefix}${diagnostic_flag}> PARENT_SCOPE)

set(--deny-${diagnostic} ${--forbid-${diagnostic_flag}} PARENT_SCOPE)
endfunction()
4 changes: 2 additions & 2 deletions cmake/Modules/CheckCompilerFlag.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ function (check_compiler_flag flag_name)
string(CONCAT compiler_flag
$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:${flag_MSVC}>
$<$<COMPILE_LANG_AND_ID:C,MSVC>:${flag_MSVC}>
$<$<COMPILE_LANG_AND_ID:CXX,GCC>:${flag_GCC}>
$<$<COMPILE_LANG_AND_ID:C,GCC>:${flag_GCC}>
$<$<COMPILE_LANG_AND_ID:CXX,GNU>:${flag_GCC}>
$<$<COMPILE_LANG_AND_ID:C,GNU>:${flag_GCC}>
$<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:${flag_CLANG}>
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:${flag_CLANG}>
)
Expand Down
2 changes: 1 addition & 1 deletion documentation/source/safety.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Feature Config
* Includes ``<iostream>`` and prints all exceptions and errors to ``std::cerr``, for you to see
* **Not** turned on by default under any settings: *this MUST be turned on manually*

``SOL_GET_FUNCTION_POINTERS_UNSAFE`` triggers the following change:
``SOL_GET_FUNCTION_POINTER_UNSAFE`` triggers the following change:
* Allows function pointers serialized into Lua as a callable to be retrieved back from Lua in a semi-proper manner
* **This is under NO circumstances type safe**
- It **WILL** break ``sol::overload`` type checking and will not discriminate properly between function types
Expand Down
4 changes: 1 addition & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ function(sol2_add_example_properties target-name)
PRIVATE
${--template-debugging-mode}
${--big-obj}
${--no-unknown-warning}
${--disable-permissive}
${--pedantic}
${--warn-all}
Expand All @@ -44,7 +43,7 @@ function(sol2_add_example_properties target-name)
${--allow-unknown-warning}
${--allow-unknown-warning-option}
${--allow-noexcept-type}
${--allow-microsoft-casts}
${--allow-microsoft-cast}
)

target_compile_definitions(${target-name}
Expand Down Expand Up @@ -83,7 +82,6 @@ add_subdirectory(customization)
# # single-source compilable examples

file(GLOB sol2.examples.sources source/*.cpp source/tutorials/*.cpp source/tutorials/quick_n_dirty/*.cpp source/docs/*.cpp)
source_group(examples FILES ${sol2.examples.sources})

function (MAKE_EXAMPLE example_source_file example_prefix target_sol)
get_filename_component(example_name ${example_source_file} NAME_WE)
Expand Down
14 changes: 8 additions & 6 deletions examples/source/customization_base_object_catch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,32 @@ sol::object BaseObject::getAsRetyped(
case 1:
std::cout << "Retyping as armor." << std::endl;
switch (Lifetime) {
case BaseObjectLifetime::Value:
return sol::make_object(
L, *static_cast<const Armor*>(this));
case BaseObjectLifetime::Pointer:
return sol::make_object(
L, static_cast<const Armor*>(this));
case BaseObjectLifetime::Shared:
return sol::make_object(L,
std::make_shared<Armor>(
*static_cast<const Armor*>(this)));
case BaseObjectLifetime::Value:
default:
return sol::make_object(
L, *static_cast<const Armor*>(this));
}
case 2:
std::cout << "Retyping as weapon." << std::endl;
switch (Lifetime) {
case BaseObjectLifetime::Value:
return sol::make_object(
L, *static_cast<const Weapon*>(this));
case BaseObjectLifetime::Pointer:
return sol::make_object(
L, static_cast<const Weapon*>(this));
case BaseObjectLifetime::Shared:
return sol::make_object(L,
std::make_shared<Weapon>(
*static_cast<const Weapon*>(this)));
case BaseObjectLifetime::Value:
default:
return sol::make_object(
L, *static_cast<const Weapon*>(this));
}
default:
std::cout
Expand Down
5 changes: 3 additions & 2 deletions examples/source/usertype_bitfields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ namespace itsy_bitsy {

#if defined(_MSC_VER) || defined(__MINGW32__)
#pragma pack(1)
struct flags_t {
struct alignas(sizeof(uint32_t)) flags_t {
#else
struct __attribute__((packed, aligned(1))) flags_t {
struct __attribute__((packed, aligned(sizeof(uint32_t))))
flags_t {
#endif
uint8_t C : 1;
uint8_t N : 1;
Expand Down
6 changes: 6 additions & 0 deletions include/sol/stack_check_unqualified.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,12 @@ namespace sol { namespace stack {
}
#endif // interop extensibility
tracking.use(1);
#if SOL_IS_ON(SOL_GET_FUNCTION_POINTER_UNSAFE_I_)
if (lua_iscfunction(L, index) != 0) {
// a potential match...
return true;
}
#endif
if (indextype != type::userdata) {
handler(L, index, type::userdata, indextype, "value is not a valid userdata");
return false;
Expand Down
10 changes: 8 additions & 2 deletions include/sol/stack_get_unqualified.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,14 @@ namespace sol { namespace stack {
lua_pop(L, 2);
}
}
T* obj = static_cast<T*>(udata);
return obj;
if constexpr (std::is_function_v<T>) {
T* func = reinterpret_cast<T*>(udata);
return func;
}
else {
T* obj = static_cast<T*>(udata);
return obj;
}
}

static T& get(lua_State* L, int index, record& tracking) {
Expand Down
2 changes: 1 addition & 1 deletion single/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ find_package(PythonInterp 3 REQUIRED)

# to generate, need all of the existing header files
file(GLOB sol2_generated_header_sources ${CMAKE_CURRENT_SOURCE_DIR}/../include/**/*.*)
source_group(sol2_single FILES ${SOL2_SINGLE_HEADER_SOURCES})

# generate the single header if we can find the python3 interpreter
add_custom_command(
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/include/sol"
Expand Down
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function(sol2_add_test_properties target-name)
${--allow-unknown-warning}
${--allow-unknown-warning-option}
${--allow-noexcept-type}
${--allow-microsoft-casts}
${--allow-microsoft-cast}
)

target_compile_definitions(${target-name}
Expand All @@ -71,6 +71,7 @@ endfunction()

function(sol2_create_basic_test test_target_name target_sol)
set(test_target_name ${test_target_name})
set(sources ${ARGN})
add_executable(${test_target_name} ${sources})
sol2_add_test_properties(${test_target_name})
target_link_libraries(${test_target_name}
Expand Down
82 changes: 11 additions & 71 deletions tests/config_tests/function_pointers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,81 +20,21 @@
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# # # # sol2 tests - simple regression tests
# # # # sol2 tests - special configurations - unsafe function pointers

file(GLOB test_sources
file(GLOB sources
LIST_DIRECTORIES FALSE
CONFIGURE_DEPENDS
source/*.cpp)
source_group(sources FILES ${test_sources})

function(CREATE_TEST test_target_name test_name target_sol)
add_executable(${test_target_name} ${test_sources})
set_target_properties(${test_target_name}
PROPERTIES
OUTPUT_NAME ${test_name}
EXPORT_NAME sol2::${test_name})
target_link_libraries(${test_target_name}
PUBLIC Threads::Threads ${LUA_LIBRARIES} ${target_sol} ${CMAKE_DL_LIBS})
target_compile_definitions(${test_target_name}
PRIVATE SOL_GET_FUNCTION_POINTER_UNSAFE=1 SOL_ALL_SAFETIES_ON=1)
target_include_directories(${test_target_name}
PRIVATE ../../../examples/include)

if (MSVC)
if (NOT CMAKE_COMPILER_ID MATCHES "Clang")
target_compile_options(${test_target_name}
PRIVATE /bigobj /W4)
endif()
else()
target_compile_options(${test_target_name}
PRIVATE -std=c++1z -pthread
-Wno-unknown-warning -Wno-unknown-warning-option
-Wall -Wpedantic -Werror -pedantic -pedantic-errors
-Wno-noexcept-type)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# For another day, when C++ is not so crap
# and we have time to audit the entire lib
# for all uses of `detail::swallow`...
#target_compile_options(${test_target_name}
# PRIVATE -Wcomma)
endif()

if (IS_X86)
if(MINGW)
set_target_properties(${test_target_name}
PROPERTIES
LINK_FLAGS -static-libstdc++)
endif()
endif()
endif()
if (MSVC)
target_compile_options(${test_target_name}
PRIVATE /EHsc /std:c++latest)
target_compile_definitions(${test_target_name}
PRIVATE UNICODE _UNICODE
_CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE)
else()
target_compile_options(${test_target_name}
PRIVATE -std=c++1z -Wno-unknown-warning -Wno-unknown-warning-option
-Wall -Wextra -Wpedantic -pedantic -pedantic-errors)
endif()

if (SOL2_CI)
target_compile_definitions(${test_target_name}
PRIVATE SOL2_CI)
endif()

add_test(NAME ${test_name} COMMAND ${test_target_name})
if(SOL2_ENABLE_INSTALL)
install(TARGETS ${test_target_name} RUNTIME DESTINATION bin)
endif()
endfunction(CREATE_TEST)

if (SOL2_TESTS)
CREATE_TEST(config_function_pointers_tests "config_function_pointers_tests" sol2::sol2)
endif()
sol2_create_basic_test(sol2.tests.config_function_pointers sol2::sol2 ${sources})
sol2_create_basic_test(sol2.tests.config_function_pointers.SOL_ALL_SAFETIES_ON sol2::sol2 ${sources})
target_compile_definitions(sol2.tests.config_function_pointers PRIVATE
SOL_GET_FUNCTION_POINTER_UNSAFE=1)
target_compile_definitions(sol2.tests.config_function_pointers.SOL_ALL_SAFETIES_ON PRIVATE
SOL_ALL_SAFETIES_ON=1 SOL_GET_FUNCTION_POINTER_UNSAFE=1)
if (SOL2_TESTS_SINGLE)
CREATE_TEST(config_function_pointers_tests_single "config_function_pointers_tests.single" sol2::sol2::single)
sol2_create_basic_test(sol2.single.tests.config_function_pointers sol2::sol2::single ${sources})
target_compile_definitions(sol2.single.tests.config_function_pointers PRIVATE
SOL_GET_FUNCTION_POINTER_UNSAFE=1)
endif()
87 changes: 22 additions & 65 deletions tests/config_tests/function_pointers/source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,73 +1,30 @@
#include <sol/sol.hpp>
// sol2

// The MIT License (MIT)

#include <iostream>
// Copyright (c) 2013-2021 Rapptz, ThePhD and contributors

inline constexpr int magic_value = 24;
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:

using zero_arg_type = int (*)();
using one_arg_type = int (*)(int);
using callback_type = int (*)(one_arg_type);
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

int free_function(int value) {
return value + 1;
}

int callback(one_arg_type f) {
return f(magic_value) + 1;
}

int main() {
constexpr int expected_value = magic_value;
constexpr int expected_free_function_value = magic_value + 1;
constexpr int expected_callback_value = magic_value + 1 + 1;

sol::state lua;
lua.open_libraries(sol::lib::base);

auto lambda = []() { return magic_value; };
auto lambda_ptr = static_cast<zero_arg_type>(lambda);

lua["magic_value"] = magic_value;
lua["expected_value"] = expected_value;
lua["expected_free_function_value"] = expected_free_function_value;
lua["expected_callback_value"] = expected_callback_value;

lua["lambda"] = sol::as_function_reference(lambda);
lua["lambda_ptr"] = lambda_ptr;
lua["free_function"] = &free_function;
lua["callback"] = &callback;

zero_arg_type lambda_f = lua["lambda"];
zero_arg_type lambda_ptr_f = lua["lambda_ptr"];
one_arg_type free_function_f = lua["free_function"];
callback_type callback_f = lua["callback"];
sol::function lua_callback_f = lua["callback"];

int lambda_f_result = lambda_f();
int lambda_ptr_f_result = lambda_ptr_f();
int free_function_f_result = free_function_f(magic_value);
int callback_f_result = callback_f(&free_function);
int lua_callback_f_result = lua_callback_f(&free_function);
sol_c_assert(lambda_f_result == expected_value);
sol_c_assert(lambda_ptr_f_result == expected_value);
sol_c_assert(free_function_f_result == expected_free_function_value);
sol_c_assert(callback_f_result == expected_callback_value);
sol_c_assert(lua_callback_f_result == expected_callback_value);

const char code[] = R"(
assert(lambda() == expected_value)
assert(lambda_ptr() == expected_value)
assert(free_function(magic_value) == expected_free_function_value)
assert(callback(free_function) == expected_callback_value)
)";
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

sol::optional<sol::error> err = lua.safe_script(code, sol::script_pass_on_error);
if (err.has_value()) {
std::cerr << err.value().what() << std::endl;
return 1;
}
sol_c_assert(!err.has_value());
#define CATCH_CONFIG_RUNNER
#include <catch2/catch.hpp>

return 0;
int main(int argc, char* argv[]) {
int result = Catch::Session().run(argc, argv);
return result;
}
Loading

0 comments on commit 80ede90

Please sign in to comment.