Skip to content

Commit

Permalink
Use new JsRuntimeHost BABYLON_API calling convention macro (#1374)
Browse files Browse the repository at this point in the history
Without explicit calling convention modifers, consumers are required to
compile with the same calling convention used in the released binaries.
If a consumer compiles with the `__stdcall` calling convention, the
linker won't resolve the function calls because the released binaries
are built with the default `__cdecl` calling convention.

This change fixes the issue using an overridable `BABYLON_API` macro
defined as `__cdecl` by default on Windows platforms or defined as empty
on non-Windows platforms.

See also BabylonJS/JsRuntimeHost#86.
  • Loading branch information
docEdub authored Apr 10, 2024
1 parent 19c01a5 commit e204ba7
Show file tree
Hide file tree
Showing 23 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ FetchContent_Declare(ios-cmake
GIT_TAG 4.4.1)
FetchContent_Declare(JsRuntimeHost
GIT_REPOSITORY https://github.com/BabylonJS/JsRuntimeHost.git
GIT_TAG ef3bb85d2e8e1ec314aaa2ff0df7fba360acd1b1)
GIT_TAG 66c863be8cedf2869a4e59ce99144417c78af73c)
FetchContent_Declare(OpenXR-MixedReality
GIT_REPOSITORY https://github.com/microsoft/OpenXR-MixedReality.git
GIT_TAG 67424511525b96a36847f2a96d689d99e5879503)
Expand Down
2 changes: 2 additions & 0 deletions Install/Install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ install_targets(UrlLib)
# ----------------
# Core
# ----------------
install_include_for_targets(Foundation)

install_targets(JsRuntime)
install_include_for_targets(JsRuntime)

Expand Down
3 changes: 2 additions & 1 deletion Plugins/NativeCamera/Include/Babylon/Plugins/NativeCamera.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <napi/env.h>
#include <Babylon/Api.h>

namespace Babylon::Plugins::NativeCamera
{
void Initialize(Napi::Env env);
void BABYLON_API Initialize(Napi::Env env);
}
2 changes: 1 addition & 1 deletion Plugins/NativeCamera/Source/NativeCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace Babylon::Plugins::Internal

namespace Babylon::Plugins::NativeCamera
{
void Initialize(Napi::Env env)
void BABYLON_API Initialize(Napi::Env env)
{
Babylon::Plugins::NativeVideo::Initialize(env);
Babylon::Plugins::MediaDevices::Initialize(env);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <napi/env.h>
#include <Babylon/Api.h>

namespace Babylon::Plugins::NativeCapture
{
void Initialize(Napi::Env env);
void BABYLON_API Initialize(Napi::Env env);
}
2 changes: 1 addition & 1 deletion Plugins/NativeCapture/Source/NativeCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ namespace Babylon::Plugins::Internal

namespace Babylon::Plugins::NativeCapture
{
void Initialize(Napi::Env env)
void BABYLON_API Initialize(Napi::Env env)
{
Babylon::Plugins::Internal::NativeCapture::Initialize(env);
}
Expand Down
3 changes: 2 additions & 1 deletion Plugins/NativeEngine/Include/Babylon/Plugins/NativeEngine.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <napi/env.h>
#include <Babylon/Api.h>

namespace Babylon::Plugins::NativeEngine
{
void Initialize(Napi::Env env);
void BABYLON_API Initialize(Napi::Env env);
}
2 changes: 1 addition & 1 deletion Plugins/NativeEngine/Source/NativeEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ namespace Babylon
using CommandFunctionPointerT = void (NativeEngine::*)(NativeDataStream::Reader&);
}

void NativeEngine::Initialize(Napi::Env env)
void BABYLON_API NativeEngine::Initialize(Napi::Env env)
{
// Initialize the JavaScript side.
Napi::HandleScope scope{env};
Expand Down
5 changes: 3 additions & 2 deletions Plugins/NativeInput/Include/Babylon/Plugins/NativeInput.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <napi/env.h>
#include <Babylon/Api.h>

namespace Babylon::Plugins
{
Expand All @@ -9,8 +10,8 @@ namespace Babylon::Plugins
public:
// TODO: Ideally instances of these should be scoped to individual views within an env, but we don't yet support multi-view.
// See https://github.com/BabylonJS/BabylonNative/issues/147
static NativeInput& CreateForJavaScript(Napi::Env);
static NativeInput& GetFromJavaScript(Napi::Env);
static NativeInput& BABYLON_API CreateForJavaScript(Napi::Env);
static NativeInput& BABYLON_API GetFromJavaScript(Napi::Env);

void MouseDown(uint32_t buttonIndex, int32_t x, int32_t y);
void MouseUp(uint32_t buttonIndex, int32_t x, int32_t y);
Expand Down
4 changes: 2 additions & 2 deletions Plugins/NativeInput/Source/Shared/NativeInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ namespace Babylon::Plugins
env.Global().Set(JS_NATIVE_INPUT_NAME, nativeInput);
}

NativeInput& NativeInput::CreateForJavaScript(Napi::Env env)
NativeInput& BABYLON_API NativeInput::CreateForJavaScript(Napi::Env env)
{
auto* nativeInput = new NativeInput(env);
return *nativeInput;
}

NativeInput& NativeInput::GetFromJavaScript(Napi::Env env)
NativeInput& BABYLON_API NativeInput::GetFromJavaScript(Napi::Env env)
{
return *env.Global().Get(JS_NATIVE_INPUT_NAME).As<Napi::External<NativeInput>>().Data();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <napi/env.h>
#include <Babylon/Api.h>

namespace Babylon::Plugins::NativeOptimizations
{
void Initialize(Napi::Env env);
void BABYLON_API Initialize(Napi::Env env);
}
2 changes: 1 addition & 1 deletion Plugins/NativeOptimizations/Source/NativeOptimizations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ namespace

namespace Babylon::Plugins::NativeOptimizations
{
void Initialize(Napi::Env env)
void BABYLON_API Initialize(Napi::Env env)
{
auto nativeObject{JsRuntime::NativeObject::GetFromJavaScript(env)};
nativeObject.Set("_TransformVector3Coordinates", Napi::Function::New(env, TransformVector3Coordinates, "_TransformVector3Coordinates"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <napi/env.h>
#include <Babylon/Api.h>

namespace Babylon::Plugins::NativeTracing
{
void Initialize(Napi::Env env);
void BABYLON_API Initialize(Napi::Env env);
}
2 changes: 1 addition & 1 deletion Plugins/NativeTracing/Source/NativeTracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace

namespace Babylon::Plugins::NativeTracing
{
void Initialize(Napi::Env env)
void BABYLON_API Initialize(Napi::Env env)
{
auto nativeObject{JsRuntime::NativeObject::GetFromJavaScript(env)};
nativeObject.Set("startPerformanceCounter", Napi::Function::New(env, StartPerformanceCounter, "startPerformanceCounter"));
Expand Down
3 changes: 2 additions & 1 deletion Plugins/NativeXr/Include/Babylon/Plugins/NativeXr.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <napi/env.h>
#include <Babylon/Api.h>

namespace Babylon::Plugins
{
Expand All @@ -17,7 +18,7 @@ namespace Babylon::Plugins

~NativeXr();

static NativeXr Initialize(Napi::Env env);
static NativeXr BABYLON_API Initialize(Napi::Env env);

void UpdateWindow(void* windowPtr);
void SetSessionStateChangedCallback(std::function<void(bool)> callback);
Expand Down
2 changes: 1 addition & 1 deletion Plugins/NativeXr/Source/NativeXr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3517,7 +3517,7 @@ namespace Babylon
{
}

NativeXr NativeXr::Initialize(Napi::Env env)
NativeXr BABYLON_API NativeXr::Initialize(Napi::Env env)
{
auto impl{std::make_shared<Impl>(env)};

Expand Down
2 changes: 1 addition & 1 deletion Plugins/TestUtils/Include/Babylon/Plugins/TestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
namespace Babylon::Plugins::TestUtils
{
extern int errorCode;
void Initialize(Napi::Env env, Graphics::WindowT window);
void BABYLON_API Initialize(Napi::Env env, Graphics::WindowT window);
}
2 changes: 1 addition & 1 deletion Plugins/TestUtils/Source/Win32/TestUtilsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace Babylon::Plugins::Internal

namespace Babylon::Plugins::TestUtils
{
void Initialize(Napi::Env env, Graphics::WindowT window)
void BABYLON_API Initialize(Napi::Env env, Graphics::WindowT window)
{
auto implData{std::make_shared<Internal::TestUtils::ImplData>(window)};
Internal::TestUtils::CreateInstance(env, implData);
Expand Down
2 changes: 1 addition & 1 deletion Plugins/TestUtils/Source/WinRT/TestUtilsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Babylon::Plugins::Internal

namespace Babylon::Plugins::TestUtils
{
void Initialize(Napi::Env env, Graphics::WindowT window)
void BABYLON_API Initialize(Napi::Env env, Graphics::WindowT window)
{
auto implData{std::make_shared<Internal::TestUtils::ImplData>(window)};
Internal::TestUtils::CreateInstance(env, implData);
Expand Down
3 changes: 2 additions & 1 deletion Polyfills/Canvas/Include/Babylon/Polyfills/Canvas.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <napi/env.h>
#include <Babylon/Api.h>

namespace Babylon::Polyfills
{
Expand All @@ -20,7 +21,7 @@ namespace Babylon::Polyfills
// This instance must live as long as the JS Runtime.
// If JSRuntime is attached/detached (BabylonReactNative),
// then this instance must live forever.
[[nodiscard]] static Canvas Initialize(Napi::Env env);
[[nodiscard]] static Canvas BABYLON_API Initialize(Napi::Env env);

void FlushGraphicResources();

Expand Down
2 changes: 1 addition & 1 deletion Polyfills/Canvas/Source/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ namespace Babylon::Polyfills
{
}

Canvas Canvas::Initialize(Napi::Env env)
Canvas BABYLON_API Canvas::Initialize(Napi::Env env)
{
auto impl{std::make_shared<Canvas::Impl>(env)};

Expand Down
3 changes: 2 additions & 1 deletion Polyfills/Window/Include/Babylon/Polyfills/Window.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <napi/env.h>
#include <Babylon/Api.h>

namespace Babylon::Polyfills::Window
{
void Initialize(Napi::Env env);
void BABYLON_API Initialize(Napi::Env env);
}
2 changes: 1 addition & 1 deletion Polyfills/Window/Source/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace Babylon::Polyfills::Internal

namespace Babylon::Polyfills::Window
{
void Initialize(Napi::Env env)
void BABYLON_API Initialize(Napi::Env env)
{
Internal::Window::Initialize(env);
}
Expand Down

0 comments on commit e204ba7

Please sign in to comment.