Skip to content

Commit 883ba13

Browse files
authored
Build and code cleanup (#1226)
- Separate `JsRuntimeDispatcher` into its own target `JsRuntimeInternal` as it will depend on arcana in a future PR. - Make the build style more consistent across different CMakeLists.txt
1 parent a676d6d commit 883ba13

File tree

49 files changed

+169
-177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+169
-177
lines changed

Apps/Playground/Android/app/CMakeLists.txt

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,28 @@ set(BABYLON_NATIVE_PLAYGROUND_DIR "${CMAKE_CURRENT_LIST_DIR}/../..")
4141
add_subdirectory(${BABYLON_NATIVE_PLAYGROUND_DIR}/../../ ${BABYLON_NATIVE_PLAYGROUND_DIR}/../../build/Android_${CMAKE_ANDROID_ARCH_ABI}/)
4242

4343
add_library(BabylonNativeJNI SHARED
44-
src/main/cpp/BabylonNativeJNI.cpp)
44+
src/main/cpp/BabylonNativeJNI.cpp)
4545

4646
target_include_directories(BabylonNativeJNI
47-
PRIVATE
48-
${BABYLON_NATIVE_PLAYGROUND_DIR}/Shared)
47+
PRIVATE ${BABYLON_NATIVE_PLAYGROUND_DIR}/Shared)
4948

5049
target_link_libraries(BabylonNativeJNI
51-
GLESv3
52-
android
53-
EGL
54-
log
55-
-lz
56-
AppRuntime
57-
NativeEngine
58-
NativeInput
59-
NativeXr
60-
NativeOptimizations
61-
Console
62-
Canvas
63-
Window
64-
ScriptLoader
65-
XMLHttpRequest
66-
NativeCamera
67-
AndroidExtensions
68-
ChromeDevTools
69-
)
50+
GLESv3
51+
android
52+
EGL
53+
log
54+
-lz
55+
AndroidExtensions
56+
AppRuntime
57+
Canvas
58+
Console
59+
ChromeDevTools
60+
GraphicsDevice
61+
NativeCamera
62+
NativeEngine
63+
NativeInput
64+
NativeOptimizations
65+
NativeXr
66+
ScriptLoader
67+
XMLHttpRequest
68+
Window)

Apps/Playground/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,17 @@ target_include_directories(Playground PRIVATE "Source" ".")
108108

109109
target_link_to_dependencies(Playground
110110
PRIVATE AppRuntime
111-
PRIVATE NativeCapture
111+
PRIVATE Canvas
112112
PRIVATE ChromeDevTools
113+
PRIVATE Console
114+
PRIVATE GraphicsDevice
115+
PRIVATE NativeCapture
113116
PRIVATE NativeEngine
114117
PRIVATE NativeInput
115118
PRIVATE NativeOptimizations
116-
PRIVATE Console
117-
PRIVATE Window
118119
PRIVATE ScriptLoader
120+
PRIVATE Window
119121
PRIVATE XMLHttpRequest
120-
PRIVATE Canvas
121122
${ADDITIONAL_LIBRARIES}
122123
${BABYLON_NATIVE_PLAYGROUND_EXTENSION_LIBRARIES})
123124

Apps/UnitTests/CMakeLists.txt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ set(NPM_SCRIPTS
1717
set(HEADERS
1818
"Shared/Tests.h")
1919

20-
set(ADDITIONAL_LIBRARIES "")
21-
2220
if(APPLE)
2321
find_library(JSCORE_LIBRARY JavaScriptCore)
24-
set(ADDITIONAL_LIBRARIES ${JSCORE_LIBRARY})
22+
set(ADDITIONAL_LIBRARIES PRIVATE ${JSCORE_LIBRARY})
2523
set(TEST_APP "Apple/App.mm")
2624
elseif(UNIX AND NOT ANDROID)
2725
set(TEST_APP "X11/App.cpp")
@@ -32,14 +30,15 @@ endif()
3230
add_executable(UnitTests ${LOCAL_SCRIPTS} ${NPM_SCRIPTS} ${TEST_APP} ${HEADERS})
3331

3432
target_link_to_dependencies(UnitTests
35-
UrlLib
36-
AppRuntime
37-
XMLHttpRequest
38-
NativeEngine
39-
ScriptLoader
40-
Console
41-
Window
42-
Canvas
33+
PRIVATE AppRuntime
34+
PRIVATE Canvas
35+
PRIVATE Console
36+
PRIVATE GraphicsDevice
37+
PRIVATE NativeEngine
38+
PRIVATE ScriptLoader
39+
PRIVATE UrlLib
40+
PRIVATE Window
41+
PRIVATE XMLHttpRequest
4342
${ADDITIONAL_LIBRARIES})
4443

4544
add_test(NAME UnitTests COMMAND UnitTests)

Apps/ValidationTests/Android/app/CMakeLists.txt

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ cmake_minimum_required(VERSION 3.13.2)
2121
project(BabylonNative)
2222
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
2323
set(BABYLON_NATIVE_PLATFORM "Android")
24-
set(CMAKE_CXX_EXTENSIONS OFF)
25-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
24+
set(CMAKE_CXX_STANDARD 17)
2625

2726
if (${ANDROID_JSENGINE_LIBNAME} STREQUAL "jsc")
2827
set(NAPI_JAVASCRIPT_ENGINE "JavaScriptCore" CACHE STRING "JavaScript engine for N-API.")
@@ -42,29 +41,22 @@ set(BABYLON_NATIVE_VALIDATIONTESTS_DIR "${CMAKE_CURRENT_LIST_DIR}/../..")
4241
add_subdirectory(${BABYLON_NATIVE_VALIDATIONTESTS_DIR}/../../ ${BABYLON_NATIVE_VALIDATIONTESTS_DIR}/../../build/Android_${CMAKE_ANDROID_ARCH_ABI}/)
4342

4443
add_library(BabylonNativeJNI SHARED
45-
src/main/cpp/BabylonNativeJNI.cpp)
46-
47-
add_definitions(-DANDROID_STL=c++_shared)
44+
src/main/cpp/BabylonNativeJNI.cpp)
4845

4946
target_link_libraries(BabylonNativeJNI
50-
GLESv3
51-
android
52-
EGL
53-
log
54-
-lz
55-
AndroidExtensions
56-
AppRuntime
57-
NativeEngine
58-
NativeOptimizations
59-
NativeXr
60-
Console
61-
Window
62-
ScriptLoader
63-
bgfx
64-
XMLHttpRequest
65-
TestUtils)
66-
67-
configure_file(
68-
"${ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/${ANDROID_ABI}/libc++_shared.so"
69-
"${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${CMAKE_ANDROID_ARCH_ABI}/libc++_shared.so"
70-
COPYONLY)
47+
GLESv3
48+
android
49+
EGL
50+
log
51+
-lz
52+
AndroidExtensions
53+
AppRuntime
54+
Console
55+
GraphicsDevice
56+
NativeEngine
57+
NativeOptimizations
58+
NativeXr
59+
ScriptLoader
60+
TestUtils
61+
XMLHttpRequest
62+
Window)

Apps/ValidationTests/CMakeLists.txt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,17 @@ if(WINDOWS_STORE)
110110
endif()
111111

112112
target_link_to_dependencies(ValidationTests
113-
PRIVATE bgfx
114-
PRIVATE bimg
115-
PRIVATE bx
116113
PRIVATE AppRuntime
114+
PRIVATE Canvas
115+
PRIVATE Console
116+
PRIVATE GraphicsDevice
117117
PRIVATE NativeEngine
118118
PRIVATE NativeOptimizations
119-
PRIVATE Console
120-
PRIVATE Window
121119
PRIVATE ScriptLoader
122-
PRIVATE Canvas
123120
PRIVATE TestUtils
124-
${ADDITIONAL_LIBRARIES}
125-
PRIVATE XMLHttpRequest)
121+
PRIVATE Window
122+
PRIVATE XMLHttpRequest
123+
${ADDITIONAL_LIBRARIES})
126124

127125
if(APPLE)
128126
target_link_libraries(ValidationTests PRIVATE "-framework MetalKit")

Core/AppRuntime/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ endif()
2424

2525
target_link_to_dependencies(AppRuntime
2626
PRIVATE arcana
27-
PUBLIC JsRuntime)
27+
PRIVATE JsRuntime)
2828

2929
target_compile_definitions(AppRuntime
3030
PRIVATE NOMINMAX)

Core/AppRuntime/Include/Babylon/AppRuntime.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#pragma once
22

33
#include "Dispatchable.h"
4-
5-
#include <Babylon/JsRuntime.h>
4+
#include <napi/napi.h>
65

76
#include <memory>
87
#include <functional>
@@ -11,6 +10,7 @@
1110
namespace Babylon
1211
{
1312
class WorkQueue;
13+
1414
class AppRuntime final
1515
{
1616
public:

Core/AppRuntime/Source/AppRuntime.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "AppRuntime.h"
22
#include "WorkQueue.h"
3+
#include <Babylon/JsRuntime.h>
34

45
namespace Babylon
56
{

Core/AppRuntime/Source/AppRuntime_Chakra.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "AppRuntime.h"
22

3+
#include <napi/env.h>
4+
35
#include <jsrt.h>
46

57
#include <gsl/gsl>
@@ -21,28 +23,29 @@ namespace Babylon
2123
void AppRuntime::RunEnvironmentTier(const char*)
2224
{
2325
using DispatchFunction = std::function<void(std::function<void()>)>;
24-
DispatchFunction dispatchFunction{
26+
DispatchFunction dispatchFunction =
2527
[this](std::function<void()> action) {
2628
Dispatch([action = std::move(action)](Napi::Env) {
2729
action();
2830
});
29-
}};
31+
};
3032

3133
JsRuntimeHandle jsRuntime;
3234
ThrowIfFailed(JsCreateRuntime(JsRuntimeAttributeNone, nullptr, &jsRuntime));
3335
JsContextRef context;
3436
ThrowIfFailed(JsCreateContext(jsRuntime, &context));
3537
ThrowIfFailed(JsSetCurrentContext(context));
36-
ThrowIfFailed(JsSetPromiseContinuationCallback([](JsValueRef task, void* callbackState) {
37-
ThrowIfFailed(JsAddRef(task, nullptr));
38-
auto* dispatch = reinterpret_cast<DispatchFunction*>(callbackState);
39-
dispatch->operator()([task]() {
40-
JsValueRef undefined;
41-
ThrowIfFailed(JsGetUndefinedValue(&undefined));
42-
ThrowIfFailed(JsCallFunction(task, &undefined, 1, nullptr));
43-
ThrowIfFailed(JsRelease(task, nullptr));
44-
});
45-
},
38+
ThrowIfFailed(JsSetPromiseContinuationCallback(
39+
[](JsValueRef task, void* callbackState) {
40+
ThrowIfFailed(JsAddRef(task, nullptr));
41+
auto* dispatch = reinterpret_cast<DispatchFunction*>(callbackState);
42+
dispatch->operator()([task]() {
43+
JsValueRef undefined;
44+
ThrowIfFailed(JsGetUndefinedValue(&undefined));
45+
ThrowIfFailed(JsCallFunction(task, &undefined, 1, nullptr));
46+
ThrowIfFailed(JsRelease(task, nullptr));
47+
});
48+
},
4649
&dispatchFunction));
4750
ThrowIfFailed(JsProjectWinRTNamespace(L"Windows"));
4851

Core/AppRuntime/Source/AppRuntime_JSI.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "AppRuntime.h"
22
#include "WorkQueue.h"
33

4-
#include <napi/env.h>
4+
#include <Babylon/JsRuntime.h>
5+
56
#include <V8JsiRuntime.h>
67
#include <ScriptStore.h>
78

0 commit comments

Comments
 (0)