Skip to content

Commit 94fd0df

Browse files
authored
Merge pull request #137 from NuiCpp/feat/replace-traits-dependency
Feat/replace traits dependency
2 parents 39b0757 + 0be1783 commit 94fd0df

File tree

16 files changed

+86
-179
lines changed

16 files changed

+86
-179
lines changed

.github/workflows/macos_13.yml renamed to .github/workflows/macos.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: MacOS 13
1+
name: MacOS
22

33
on:
44
push:
@@ -15,7 +15,7 @@ jobs:
1515
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
1616
# You can convert this to a matrix build if you need cross-platform coverage.
1717
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
18-
runs-on: macos-13
18+
runs-on: macos-latest
1919

2020
steps:
2121
- uses: actions/checkout@v3
@@ -27,7 +27,7 @@ jobs:
2727
node-version: "20"
2828

2929
- name: Install Brew Dependencies
30-
run: brew install cmake llvm@16 boost git openssl@3 cryptopp curl ninja make
30+
run: brew install llvm@19 boost cryptopp make nlohmann-json curl
3131

3232
- name: Tool Version Dump
3333
run: |
@@ -37,13 +37,16 @@ jobs:
3737
brew list --versions boost
3838
3939
- name: Configure CMake
40-
run: cmake -B ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}} -G"Ninja" -DNUI_ENABLE_TESTS=on -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNUI_BUILD_EXAMPLES=on -DCMAKE_CXX_EXTENSIONS=on -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm@16/bin/clang++ -DCMAKE_C_COMPILER=/usr/local/opt/llvm@16/bin/clang -DNUI_NPM=npm -DNUI_NODE=node -DCMAKE_CXX_STANDARD=20
40+
run: |
41+
export PATH="/opt/homebrew/opt/llvm@19/bin:$PATH"
42+
cmake -B ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}} -G"Ninja" -DNUI_ENABLE_TESTS=on -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNUI_BUILD_EXAMPLES=on -DCMAKE_CXX_EXTENSIONS=on -DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm@19/bin/clang++ -DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm@19/bin/clang -DCMAKE_OSX_SYSROOT=$(xcrun --sdk macosx --show-sdk-path) -DCMAKE_EXE_LINKER_FLAGS="-L/opt/homebrew/opt/llvm@19/lib/c++ -L/opt/homebrew/opt/llvm@19/lib/unwind -lunwind" -DNUI_NPM=npm -DNUI_NODE=node -DCMAKE_CXX_STANDARD=20
4143
env:
42-
LDFLAGS: "-L/usr/local/opt/llvm@16/lib"
43-
CPPFLAGS: "-I/usr/local/opt/llvm@16/include -I/opt/homebrew/include"
44+
CPPFLAGS: "-I/opt/homebrew/opt/llvm@19/include"
4445

4546
- name: Build
46-
run: cmake --build ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}} --config ${{env.BUILD_TYPE}}
47+
run: |
48+
export PATH="/opt/homebrew/opt/llvm@19/bin:$PATH"
49+
cmake --build ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}} --config ${{env.BUILD_TYPE}}
4750
4851
- name: Test
4952
working-directory: ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}}

CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/interval_tree.cmake)
1414
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/fmt.cmake)
1515
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/describe.cmake)
1616
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/mp11.cmake)
17+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/nui_traits.cmake)
1718
if (EMSCRIPTEN)
18-
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/libcpppre.cmake)
1919
include(${CMAKE_CURRENT_LIST_DIR}/cmake/frontend/emscripten.cmake)
2020
else()
21-
if (${NUI_ENABLE_TESTS})
22-
include(${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies/libcpppre.cmake)
23-
endif()
2421
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/bin2hpp)
2522
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/parcel_adapter)
2623
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/patch_dotenv)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ Nui uses the following dependencies:
5252
- nlohmann/json https://github.com/nlohmann/json - [MIT LICENSE](https://github.com/nlohmann/json/blob/develop/LICENSE.MIT)
5353
- portable-file-dialogs https://github.com/samhocevar/portable-file-dialogs - [WTFPL LICENSE](https://github.com/samhocevar/portable-file-dialogs/blob/main/COPYING)
5454
- 5cript/roar https://github.com/5cript/roar - [BSL-1.0 LICENSE](https://github.com/5cript/roar/blob/master/LICENSE)
55+
- Nui/traits https://github.com/NuiCpp/traits - [CC0-1.0 LICENSE](https://github.com/NuiCpp/traits/blob/main/LICENSE)

cmake/backend/emscripten.cmake

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function(nui_add_emscripten_target)
2222

2323
cmake_parse_arguments(
2424
NUI_ADD_EMSCRIPTEN_TARGET_ARGS
25-
"DISABLE_BIN2HPP;DISABLE_PARCEL_ADAPTER;ENABLE_TAILWIND;ENABLE_DOTENV"
25+
"DISABLE_BIN2HPP;DISABLE_PARCEL_ADAPTER;ENABLE_TAILWIND;ENABLE_DOTENV;CONFIGURE_ALWAYS"
2626
"TARGET;PREJS;SOURCE_DIR;BIN2HPP_ENCODING"
2727
"CMAKE_OPTIONS"
2828
${ARGN}
@@ -125,22 +125,33 @@ function(nui_add_emscripten_target)
125125

126126
message(STATUS "C++ standard of frontend subproject: ${TARGET_CXX_STANDARD}")
127127

128+
set(CONFIGURE_COMMAND_PART
129+
${EMCMAKE} cmake
130+
"-DCMAKE_CXX_STANDARD=${TARGET_CXX_STANDARD}"
131+
${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_CMAKE_OPTIONS}
132+
"-DNUI_NPM=${NUI_NPM}"
133+
"-DNUI_NODE=${NUI_NODE}"
134+
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
135+
-DNUI_INLINE_EXTRACTOR_TARGET_FILE=$<TARGET_FILE:inline-parser>
136+
-DNUI_INLINE_INJECTOR_TARGET_FILE=$<TARGET_FILE:inline-injector>
137+
-DNUI_MODULE_BUILD_DIR=${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}
138+
"${SOURCE_DIR}"
139+
)
140+
if(NUI_ADD_EMSCRIPTEN_TARGET_ARGS_CONFIGURE_ALWAYS)
141+
set(CONFIGURE_COMMAND ${CONFIGURE_COMMAND_PART})
142+
else()
143+
set(CONFIGURE_COMMAND
144+
${EMCMAKE} cmake -E md5sum "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/CMakeCache.txt" ||
145+
${CONFIGURE_COMMAND_PART}
146+
)
147+
endif()
148+
128149
include(ExternalProject)
129150
ExternalProject_Add(
130151
"${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-emscripten"
131152
SOURCE_DIR "${SOURCE_DIR}"
132153
# emscripten cmake with passed down Release/Debug build type
133-
CONFIGURE_COMMAND
134-
${EMCMAKE} cmake
135-
"-DCMAKE_CXX_STANDARD=${TARGET_CXX_STANDARD}"
136-
${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_CMAKE_OPTIONS}
137-
"-DNUI_NPM=${NUI_NPM}"
138-
"-DNUI_NODE=${NUI_NODE}"
139-
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
140-
-DNUI_INLINE_EXTRACTOR_TARGET_FILE=$<TARGET_FILE:inline-parser>
141-
-DNUI_INLINE_INJECTOR_TARGET_FILE=$<TARGET_FILE:inline-injector>
142-
-DNUI_MODULE_BUILD_DIR=${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}
143-
"${SOURCE_DIR}"
154+
CONFIGURE_COMMAND ${CONFIGURE_COMMAND}
144155
# copy over package.json and fill parcel options that do not exist on it
145156
${BUILD_COMMAND}
146157
# patch .env file if needed

cmake/dependencies/libcpppre.cmake

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
option(NUI_FETCH_TRAITS "Fetch nui traits" ON)
2+
set(NUI_TRAITS_GIT_REPOSITORY "https://github.com/NuiCpp/traits.git" CACHE STRING "nui traits git repository")
3+
set(NUI_TRAITS_GIT_TAG "9a9de09ac0eaab4f9e0869a2f4004a5e3e6915ca" CACHE STRING "nui traits git tag")
4+
5+
if(NUI_FETCH_TRAITS)
6+
include(FetchContent)
7+
FetchContent_Declare(
8+
traits-library
9+
GIT_REPOSITORY ${NUI_TRAITS_GIT_REPOSITORY}
10+
GIT_TAG ${NUI_TRAITS_GIT_TAG}
11+
)
12+
13+
FetchContent_MakeAvailable(traits-library)
14+
endif()

cmake/dependencies/portable_file_dialog.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ if(NUI_FETCH_PORTABLE_FILE_DIALOG)
1010
GIT_TAG ${NUI_PORTABLE_FILE_DIALOG_TAG}
1111
)
1212

13+
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
1314
FetchContent_MakeAvailable(portable_file_dialogs)
1415
endif()

nui/include/nui/backend/rpc_hub.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
#include <nui/window.hpp>
44
#include <nui/data_structures/selectables_registry.hpp>
5-
#include <nui/utility/meta/function_traits.hpp>
65
#include <nui/utility/meta/pick_first.hpp>
76
#include <nui/shared/on_destroy.hpp>
7+
8+
#include <traits/functions.hpp>
89
#include <nlohmann/json.hpp>
910
#include <fmt/format.h>
1011

@@ -69,8 +70,8 @@ namespace Nui
6970
template <typename FunctionT>
7071
struct FunctionWrapper
7172
: public FunctionWrapperImpl2<
72-
FunctionReturnType_t<std::decay_t<FunctionT>>,
73-
FunctionArgumentTypes_t<std::decay_t<FunctionT>>>
73+
typename Traits::FunctionTraits<std::decay_t<FunctionT>>::ReturnType,
74+
typename Traits::FunctionTraits<std::decay_t<FunctionT>>::ArgsTuple>
7475
{};
7576
}
7677

nui/include/nui/frontend/rpc_client.hpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include <nui/frontend/val.hpp>
44

5+
#include <traits/functions.hpp>
56
#include <nui/frontend/api/console.hpp>
67
#include <nui/frontend/utility/functions.hpp>
7-
#include <nui/utility/meta/function_traits.hpp>
88
#include <nui/frontend/utility/val_conversion.hpp>
99
#include <nui/shared/on_destroy.hpp>
1010

@@ -39,7 +39,7 @@ namespace Nui
3939
template <typename FunctionT>
4040
constexpr static auto wrapFunction(FunctionT&& func)
4141
{
42-
return [func = std::move(func)](Nui::val const& args) mutable {
42+
return [func = std::forward<FunctionT>(func)](Nui::val const& args) mutable {
4343
func(args);
4444
};
4545
}
@@ -51,7 +51,7 @@ namespace Nui
5151
template <typename FunctionT>
5252
constexpr static auto wrapFunction(FunctionT&& func)
5353
{
54-
return [func = std::move(func)](Nui::val const& arg) mutable {
54+
return [func = std::forward<FunctionT>(func)](Nui::val const& arg) mutable {
5555
func(extractMember<ArgType>(arg));
5656
};
5757
}
@@ -63,7 +63,7 @@ namespace Nui
6363
template <typename FunctionT>
6464
constexpr static auto wrapFunction(FunctionT&& func)
6565
{
66-
return [func = std::move(func)](Nui::val const& args) mutable {
66+
return [func = std::forward<FunctionT>(func)](Nui::val const& args) mutable {
6767
func(extractMember<ArgsTypes>(args[Is])...);
6868
};
6969
}
@@ -81,8 +81,8 @@ namespace Nui
8181
template <typename FunctionT>
8282
struct FunctionWrapper
8383
: public FunctionWrapperImpl2<
84-
FunctionReturnType_t<std::decay_t<FunctionT>>,
85-
FunctionArgumentTypes_t<std::decay_t<FunctionT>>>
84+
typename Traits::FunctionTraits<std::decay_t<FunctionT>>::ReturnType,
85+
typename Traits::FunctionTraits<std::decay_t<FunctionT>>::ArgsTuple>
8686
{};
8787
}
8888

@@ -103,8 +103,7 @@ namespace Nui
103103
}
104104
if (backChannel_.empty())
105105
return callable_(convertToVal(args)...);
106-
else
107-
return callable_(convertToVal(backChannel_), convertToVal(args)...);
106+
return callable_(convertToVal(backChannel_), convertToVal(args)...);
108107
}
109108
auto operator()(Nui::val val) const
110109
{
@@ -116,8 +115,7 @@ namespace Nui
116115
}
117116
if (backChannel_.empty())
118117
return callable_(val);
119-
else
120-
return callable_(convertToVal(backChannel_), val);
118+
return callable_(convertToVal(backChannel_), val);
121119
}
122120

123121
bool isValid() const
@@ -130,7 +128,7 @@ namespace Nui
130128
return isValid();
131129
}
132130

133-
RemoteCallable(std::string name)
131+
explicit RemoteCallable(std::string name)
134132
: name_{std::move(name)}
135133
, backChannel_{}
136134
, callable_{Nui::val::undefined()}
@@ -236,9 +234,9 @@ namespace Nui
236234
Nui::val::global("nui_rpc")["frontend"].set(
237235
tempIdString,
238236
Nui::bind(
239-
[func = Detail::FunctionWrapper<FunctionT>::wrapFunction(std::forward<FunctionT>(func)),
237+
[funcInner = Detail::FunctionWrapper<FunctionT>::wrapFunction(std::forward<FunctionT>(func)),
240238
tempIdString](Nui::val param) mutable {
241-
func(param);
239+
funcInner(param);
242240
Nui::val::global("nui_rpc")["frontend"].delete_(tempIdString);
243241
},
244242
std::placeholders::_1));
@@ -263,9 +261,9 @@ namespace Nui
263261
Nui::val::global("nui_rpc")["frontend"].set(
264262
name.c_str(),
265263
Nui::bind(
266-
[func = Detail::FunctionWrapper<FunctionT>::wrapFunction(std::forward<FunctionT>(func))](
264+
[funcInner = Detail::FunctionWrapper<FunctionT>::wrapFunction(std::forward<FunctionT>(func))](
267265
Nui::val param) mutable {
268-
func(param);
266+
funcInner(param);
269267
},
270268
std::placeholders::_1));
271269
}
@@ -291,19 +289,19 @@ namespace Nui
291289
AutoUnregister()
292290
: OnDestroy{[]() {}}
293291
{}
294-
AutoUnregister(std::string name)
292+
explicit AutoUnregister(std::string name)
295293
: OnDestroy{[name = std::move(name)]() {
296294
unregisterFunction(name);
297295
}}
298296
{}
299297
~AutoUnregister() = default;
300298

301299
AutoUnregister(AutoUnregister const&) = delete;
302-
AutoUnregister(AutoUnregister&& other)
300+
AutoUnregister(AutoUnregister&& other) noexcept
303301
: OnDestroy{std::move(other)}
304302
{}
305303
AutoUnregister& operator=(AutoUnregister const&) = delete;
306-
AutoUnregister& operator=(AutoUnregister&& other)
304+
AutoUnregister& operator=(AutoUnregister&& other) noexcept
307305
{
308306
OnDestroy::operator=(std::move(other));
309307
return *this;

nui/include/nui/frontend/utility/functions.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
#include <emscripten/bind.h>
1111
#include <emscripten/val.h>
1212

13+
#include <traits/functions.hpp>
14+
1315
#include <boost/preprocessor/repetition/repeat.hpp>
1416
#include <boost/preprocessor/punctuation/comma_if.hpp>
1517
#include <boost/preprocessor/stringize.hpp>
1618

17-
#include <pre/type_traits/function_traits.hpp>
18-
1919
#ifndef JS_BIND_MAX_ARITY
2020
/**
2121
* \brief JS_BIND_MAX_ARITY Defines how many arguments the javascript
@@ -98,9 +98,8 @@ namespace Nui
9898
emscripten::val bind(F&& f, Args&&... args)
9999
{
100100
using emscripten::val;
101-
using pre::type_traits::function_traits;
102101

103-
using result_type = typename function_traits<std::decay_t<F>>::result_type;
102+
using result_type = typename Traits::FunctionTraits<std::decay_t<F>>::ReturnType;
104103
auto bind_result = std::bind(std::forward<decltype(f)>(f), JS_BIND_DETAIL_FWD(args)...);
105104

106105
using callback_t =

0 commit comments

Comments
 (0)