Skip to content

Commit

Permalink
Js runtime host integration (#1238)
Browse files Browse the repository at this point in the history
Co-authored-by: Andy Fillebrown <[email protected]>
  • Loading branch information
CedricGuillemet and docEdub authored Jun 23, 2023
1 parent 10bf14c commit 4ee84e3
Show file tree
Hide file tree
Showing 127 changed files with 37 additions and 27,369 deletions.
2 changes: 1 addition & 1 deletion .github/jobs/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- script: |
mkdir buildiOS
cd buildiOS
cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=../Dependencies/ios-cmake/ios.toolchain.cmake -DPLATFORM=OS64COMBINED -DENABLE_ARC=0 -DDEPLOYMENT_TARGET=${{ parameters.deploymentTarget }} -DENABLE_GLSLANG_BINARIES=OFF -DSPIRV_CROSS_CLI=OFF -DCMAKE_UNITY_BUILD=${UNITY_BUILD}
cmake .. -G Xcode -D IOS=ON -D DEPLOYMENT_TARGET=${{ parameters.deploymentTarget }} -D CMAKE_UNITY_BUILD=${UNITY_BUILD}
displayName: 'Generate iOS solution'
- task: Xcode@5
Expand Down
2 changes: 1 addition & 1 deletion .github/jobs/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- script: |
mkdir build
cd build
cmake .. -GNinja -DJSCORE_LIBRARY=/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.0.so -DNAPI_JAVASCRIPT_ENGINE=${{ parameters.JSEngine }} -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBGFX_CONFIG_DEBUG=ON -DCMAKE_UNITY_BUILD=${UNITY_BUILD}
cmake .. -G Ninja -D JAVASCRIPTCORE_LIBRARY=/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.0.so -D NAPI_JAVASCRIPT_ENGINE=${{ parameters.JSEngine }} -D CMAKE_BUILD_TYPE=RelWithDebInfo -D BGFX_CONFIG_DEBUG=ON -D CMAKE_UNITY_BUILD=${UNITY_BUILD}
ninja
displayName: 'Build X11'
Expand Down
2 changes: 1 addition & 1 deletion .github/jobs/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- script: |
mkdir buildmacOS
cd buildmacOS
cmake .. -GXcode -DCMAKE_UNITY_BUILD=${UNITY_BUILD}
cmake .. -G Xcode -D CMAKE_UNITY_BUILD=${UNITY_BUILD}
displayName: 'Generate macOS solution'
- task: Xcode@5
Expand Down
2 changes: 1 addition & 1 deletion .github/jobs/uwp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- script: |
mkdir build${{ variables.solutionName }}
cd build${{ variables.solutionName }}
cmake .. -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ${{ variables.jsEngineDefine }} -A ${{ parameters.platform }} -DCMAKE_UNITY_BUILD=${UNITY_BUILD}
cmake .. -D CMAKE_SYSTEM_NAME=WindowsStore -D CMAKE_SYSTEM_VERSION=10.0 ${{ variables.jsEngineDefine }} -A ${{ parameters.platform }} -D CMAKE_UNITY_BUILD=${UNITY_BUILD}
displayName: 'Generate ${{ variables.solutionName }} solution'
- task: VSBuild@1
Expand Down
2 changes: 1 addition & 1 deletion .github/jobs/win32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- script: |
mkdir build${{ variables.solutionName }}
cd build${{ variables.solutionName }}
cmake -A ${{ parameters.platform }} ${{ variables.jsEngineDefine }} -DBGFX_CONFIG_DEBUG=ON -DGRAPHICS_API=${{ parameters.graphics_api }} -DCMAKE_UNITY_BUILD=${UNITY_BUILD} ..
cmake -A ${{ parameters.platform }} ${{ variables.jsEngineDefine }} -D BGFX_CONFIG_DEBUG=ON -D GRAPHICS_API=${{ parameters.graphics_api }} -D CMAKE_UNITY_BUILD=${UNITY_BUILD} ..
displayName: 'Generate ${{ variables.solutionName }} solution'
- task: MSBuild@1
Expand Down
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "base-n"]
path = Dependencies/base-n
url = https://github.com/azawadzki/base-n
[submodule "arcana.cpp"]
path = Dependencies/arcana.cpp
url = https://github.com/microsoft/arcana.cpp
[submodule "glslang"]
path = Dependencies/glslang
url = https://github.com/KhronosGroup/glslang
Expand All @@ -13,9 +10,6 @@
[submodule "bgfx.cmake"]
path = Dependencies/bgfx.cmake
url = https://github.com/BabylonJS/bgfx.cmake
[submodule "Dependencies/ios-cmake"]
path = Dependencies/ios-cmake
url = https://github.com/leetal/ios-cmake.git
[submodule "Dependencies/xr/Dependencies/OpenXR-SDK"]
path = Dependencies/xr/Dependencies/OpenXR-SDK
url = https://github.com/KhronosGroup/OpenXR-SDK
Expand Down
2 changes: 1 addition & 1 deletion Apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ if((WIN32 AND NOT WINDOWS_STORE) OR (APPLE AND NOT IOS) OR (UNIX AND NOT ANDROID
endif()

# NPM install
npm(install)
npm(install ${CMAKE_CURRENT_SOURCE_DIR} "Apps module")
1 change: 0 additions & 1 deletion Apps/Playground/Android/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ target_link_libraries(BabylonNativeJNI
AppRuntime
Canvas
Console
ChromeDevTools
GraphicsDevice
NativeCamera
NativeEngine
Expand Down
9 changes: 0 additions & 9 deletions Apps/Playground/Android/app/src/main/cpp/BabylonNativeJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <Babylon/Plugins/NativeXr.h>
#include <Babylon/Plugins/NativeCamera.h>
#include <Babylon/Plugins/NativeOptimizations.h>
#include <Babylon/Plugins/ChromeDevTools.h>
#include <Babylon/Polyfills/Console.h>
#include <Babylon/Polyfills/Window.h>
#include <Babylon/Polyfills/XMLHttpRequest.h>
Expand All @@ -29,7 +28,6 @@ namespace
std::optional<Babylon::Graphics::Device> device{};
std::optional<Babylon::Graphics::DeviceUpdate> deviceUpdate{};
std::optional<Babylon::AppRuntime> runtime{};
std::optional<Babylon::Plugins::ChromeDevTools> chromeDevTools{};
std::optional<Babylon::Plugins::NativeXr> nativeXr{};
Babylon::Plugins::NativeInput* nativeInput{};
std::optional<Babylon::Polyfills::Canvas> nativeCanvas{};
Expand Down Expand Up @@ -58,7 +56,6 @@ extern "C"
scriptLoader.reset();

nativeInput = {};
chromeDevTools.reset();
nativeXr.reset();
scriptLoader.reset();
runtime.reset();
Expand Down Expand Up @@ -126,12 +123,6 @@ extern "C"

Babylon::Polyfills::XMLHttpRequest::Initialize(env);
nativeCanvas.emplace(Babylon::Polyfills::Canvas::Initialize(env));

chromeDevTools.emplace(Babylon::Plugins::ChromeDevTools::Initialize(env));
if (chromeDevTools->SupportsInspector())
{
chromeDevTools->StartInspector(5643, "BabylonNative Playground");
}
});

scriptLoader.emplace(*runtime);
Expand Down
14 changes: 7 additions & 7 deletions Apps/Playground/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set(SCRIPTS
"Scripts/config.json")

if(APPLE)
find_library(JSCORE_LIBRARY JavaScriptCore)
find_library(JAVASCRIPTCORE_LIBRARY JavaScriptCore)
if(IOS)
set(PLIST_FILE
"${CMAKE_CURRENT_LIST_DIR}/iOS/Info.plist")
Expand Down Expand Up @@ -54,7 +54,7 @@ if(APPLE)
set_source_files_properties(${REFERENCE_IMAGES} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/ReferenceImages")
endif()
set(ADDITIONAL_LIBRARIES ${ADDITIONAL_LIBRARIES}
PRIVATE ${JSCORE_LIBRARY}
PRIVATE ${JAVASCRIPTCORE_LIBRARY}
PRIVATE NativeCamera)
set(RESOURCE_FILES ${STORYBOARD})
elseif(UNIX)
Expand Down Expand Up @@ -115,7 +115,6 @@ target_include_directories(Playground PRIVATE "Source" ".")
target_link_to_dependencies(Playground
PRIVATE AppRuntime
PRIVATE Canvas
PRIVATE ChromeDevTools
PRIVATE Console
PRIVATE GraphicsDevice
PRIVATE NativeCapture
Expand All @@ -129,10 +128,10 @@ target_link_to_dependencies(Playground
${ADDITIONAL_LIBRARIES}
${BABYLON_NATIVE_PLAYGROUND_EXTENSION_LIBRARIES})

if(WIN32)
target_link_to_dependencies(Playground
PRIVATE "shlwapi.lib")
endif()
# See https://gitlab.kitware.com/cmake/cmake/-/issues/23543
# If we can set minimum required to 3.26+, then we can use the `copy -t` syntax instead.
add_custom_command(TARGET Playground POST_BUILD
COMMAND ${CMAKE_COMMAND} -E $<IF:$<BOOL:$<TARGET_RUNTIME_DLLS:Playground>>,copy,true> $<TARGET_RUNTIME_DLLS:Playground> $<TARGET_FILE_DIR:Playground>)

if (UNIX AND NOT APPLE AND NOT ANDROID)
# Ubuntu mixes old experimental header and new runtime libraries
Expand Down Expand Up @@ -176,6 +175,7 @@ if(APPLE)
RESOURCE "${RESOURCE_FILES}"
FOLDER "Playground")
endif()
set_property(TARGET Playground PROPERTY UNITY_BUILD false)
endif()

if(WINDOWS_STORE)
Expand Down
7 changes: 0 additions & 7 deletions Apps/Playground/UWP/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ void App::Uninitialize()
}

m_nativeInput = {};
m_chromeDevTools.reset();
m_nativeCanvas.reset();
m_runtime.reset();
m_update.reset();
Expand Down Expand Up @@ -398,12 +397,6 @@ void App::RestartRuntime(Windows::Foundation::Rect bounds)
Babylon::Plugins::NativeXr::Initialize(env);

m_nativeInput = &Babylon::Plugins::NativeInput::CreateForJavaScript(env);

m_chromeDevTools.emplace(Babylon::Plugins::ChromeDevTools::Initialize(env));
if (m_chromeDevTools->SupportsInspector())
{
m_chromeDevTools->StartInspector(5643, "BabylonNative Playground");
}
});

Babylon::ScriptLoader loader{*m_runtime};
Expand Down
2 changes: 0 additions & 2 deletions Apps/Playground/UWP/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <Babylon/Plugins/NativeInput.h>
#include <Babylon/AppRuntime.h>
#include <Babylon/Graphics/Device.h>
#include <Babylon/Plugins/ChromeDevTools.h>
#include <Babylon/Polyfills/Canvas.h>

#include <optional>
Expand Down Expand Up @@ -48,7 +47,6 @@ ref class App sealed : public Windows::ApplicationModel::Core::IFrameworkView
std::optional<Babylon::Graphics::DeviceUpdate> m_update{};
std::optional<Babylon::AppRuntime> m_runtime{};
std::optional<Babylon::Polyfills::Canvas> m_nativeCanvas{};
std::optional<Babylon::Plugins::ChromeDevTools> m_chromeDevTools{};
Babylon::Plugins::NativeInput* m_nativeInput{};

Windows::Foundation::Collections::IVectorView<Windows::Storage::IStorageItem^>^ m_files;
Expand Down
8 changes: 0 additions & 8 deletions Apps/Playground/Win32/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <Babylon/Plugins/NativeCapture.h>
#include <Babylon/Plugins/NativeEngine.h>
#include <Babylon/Plugins/NativeOptimizations.h>
#include <Babylon/Plugins/ChromeDevTools.h>
#include <Babylon/Plugins/NativeXr.h>
#include <Babylon/Plugins/NativeCamera.h>
#include <Babylon/Plugins/NativeInput.h>
Expand All @@ -36,7 +35,6 @@ std::optional<Babylon::AppRuntime> runtime{};
std::optional<Babylon::Graphics::Device> device{};
std::optional<Babylon::Graphics::DeviceUpdate> update{};
Babylon::Plugins::NativeInput* nativeInput{};
std::optional<Babylon::Plugins::ChromeDevTools> chromeDevTools{};
std::optional<Babylon::Polyfills::Canvas> nativeCanvas{};
bool minimized{false};
int buttonRefCount{0};
Expand Down Expand Up @@ -92,7 +90,6 @@ namespace
}

nativeCanvas.reset();
chromeDevTools.reset();
nativeInput = {};
runtime.reset();
update.reset();
Expand Down Expand Up @@ -154,11 +151,6 @@ namespace

nativeInput = &Babylon::Plugins::NativeInput::CreateForJavaScript(env);

chromeDevTools.emplace(Babylon::Plugins::ChromeDevTools::Initialize(env));
if (chromeDevTools->SupportsInspector())
{
chromeDevTools->StartInspector(5643, "BabylonNative Playground");
}
Babylon::Plugins::TestUtils::Initialize(env, hWnd);
});

Expand Down
10 changes: 8 additions & 2 deletions Apps/UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ set(HEADERS
"Shared/Tests.h")

if(APPLE)
find_library(JSCORE_LIBRARY JavaScriptCore)
set(ADDITIONAL_LIBRARIES PRIVATE ${JSCORE_LIBRARY})
find_library(JAVASCRIPTCORE_LIBRARY JavaScriptCore)
set(ADDITIONAL_LIBRARIES PRIVATE ${JAVASCRIPTCORE_LIBRARY})
set(TEST_APP "Apple/App.mm")
elseif(UNIX AND NOT ANDROID)
set(TEST_APP "X11/App.cpp")
Expand All @@ -28,6 +28,7 @@ elseif(WIN32)
endif()

add_executable(UnitTests ${LOCAL_SCRIPTS} ${NPM_SCRIPTS} ${TEST_APP} ${HEADERS})
set_property(TARGET UnitTests PROPERTY UNITY_BUILD false)

target_link_to_dependencies(UnitTests
PRIVATE AppRuntime
Expand All @@ -43,6 +44,11 @@ target_link_to_dependencies(UnitTests

add_test(NAME UnitTests COMMAND UnitTests)

# See https://gitlab.kitware.com/cmake/cmake/-/issues/23543
# If we can set minimum required to 3.26+, then we can use the `copy -t` syntax instead.
add_custom_command(TARGET UnitTests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E $<IF:$<BOOL:$<TARGET_RUNTIME_DLLS:UnitTests>>,copy,true> $<TARGET_RUNTIME_DLLS:UnitTests> $<TARGET_FILE_DIR:UnitTests>)

foreach(SCRIPT ${LOCAL_SCRIPTS} ${NPM_SCRIPTS})
get_filename_component(SCRIPT_NAME "${SCRIPT}" NAME)
add_custom_command(
Expand Down
66 changes: 0 additions & 66 deletions Apps/UnitTests/Scripts/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,74 +17,8 @@ function BabylonReporter(runner) {

mocha.setup({ ui: "bdd", reporter: BabylonReporter });

function createRequest(method, url) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.addEventListener("loadend", () => resolve(xhr));
xhr.send();
});
}

const expect = chai.expect;

describe("XMLHTTPRequest", function () {
this.timeout(0);
it("should have readyState=4 when load ends", async function () {
const xhr = await createRequest("GET", "https://github.com/");
expect(xhr.readyState).to.equal(4);
});
it("should have status=200 for a file that exists", async function () {
const xhr = await createRequest("GET", "https://github.com/");
expect(xhr.status).to.equal(200);
});
it("should load URLs with escaped unicode characters", async function () {
const xhr = await createRequest("GET", "https://raw.githubusercontent.com/BabylonJS/Assets/master/meshes/%CF%83%CF%84%CF%81%CE%BF%CE%B3%CE%B3%CF%85%CE%BB%CE%B5%CE%BC%CE%AD%CE%BD%CE%BF%CF%82%20%25%20%CE%BA%CF%8D%CE%B2%CE%BF%CF%82.glb");
expect(xhr.status).to.equal(200);
});
it("should load URLs with unescaped unicode characters", async function () {
const xhr = await createRequest("GET", "https://raw.githubusercontent.com/BabylonJS/Assets/master/meshes/στρογγυλεμένος%20%25%20κύβος.glb");
expect(xhr.status).to.equal(200);
});
it("should load URLs with unescaped unicode characters and spaces", async function () {
const xhr = await createRequest("GET", "https://raw.githubusercontent.com/BabylonJS/Assets/master/meshes/στρογγυλεμένος %25 κύβος.glb");
expect(xhr.status).to.equal(200);
});
it("should have status=404 for a file that does not exist", async function () {
const xhr = await createRequest("GET", "https://github.com/babylonJS/BabylonNative404");
expect(xhr.status).to.equal(404);
});
it("should throw something when opening //", async function () {
function openDoubleSlash() {
const xhr = new XMLHttpRequest();
xhr.open("GET", "//");
xhr.send();
}
expect(openDoubleSlash).to.throw();
});
it("should throw something when opening a url with no scheme", function () {
function openNoProtocol() {
const xhr = new XMLHttpRequest();
xhr.open("GET", "noscheme.glb");
xhr.send();
}
expect(openNoProtocol).to.throw();
});
it("should throw something when sending before opening", function () {
function sendWithoutOpening() {
const xhr = new XMLHttpRequest();
xhr.send();
}
expect(sendWithoutOpening).to.throw();
});
it("should open a local file", async function () {
const xhr = await createRequest("GET", "app:///Scripts/tests.js");
expect(xhr).to.have.property('readyState', 4);
expect(xhr).to.have.property('status', 200);
expect(xhr).to.have.property('responseText').with.lengthOf.above(0);
});
});

describe("RequestFile", function () {
this.timeout(0);
it("should throw when requesting a URL with no protocol", function () {
Expand Down
2 changes: 1 addition & 1 deletion BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ sudo apt-get install libjavascriptcoregtk-4.0-dev
Then, run cmake targetting a Ninja make file:

```
cmake -G Ninja -D JSCORE_LIBRARY=/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.0.so -D NAPI_JAVASCRIPT_ENGINE=JavaScriptCore
cmake -G Ninja -D JAVASCRIPTCORE_LIBRARY=/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.0.so -D NAPI_JAVASCRIPT_ENGINE=JavaScriptCore
```

### V8
Expand Down
Loading

0 comments on commit 4ee84e3

Please sign in to comment.