Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "none",
"comment": "test bundle build logic, JS function call test",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "none",
"date": "2020-05-01T01:28:03.315Z"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "add ReactNativeHost to Win32 C++/WinRT ABI",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch",
"date": "2020-05-10T00:42:52.866Z"
}
2 changes: 1 addition & 1 deletion vnext/Desktop.ABITests/ActivationFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int32_t __stdcall WINRT_RoGetActivationFactory(void *classId, guid const &iid, v
std::wstring_view const name{*reinterpret_cast<winrt::hstring *>(&classId)};
HMODULE library{nullptr};

if (starts_with(name, L"facebook.react.")) {
if (starts_with(name, L"facebook.react.") || starts_with(name, L"Microsoft.React")) {
library = LoadLibraryExW(RNDLLPATH, NULL, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
} else {
return OS_RoGetActivationFactory(classId, iid, factory);
Expand Down
10 changes: 10 additions & 0 deletions vnext/Desktop.ABITests/ActivationFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#pragma once

#include "pch.h"
#include <Windows.h>
#include <winrt/base.h>

extern int32_t __stdcall WINRT_RoGetActivationFactory(void *classId, winrt::guid const &iid, void **factory) noexcept;
3 changes: 1 addition & 2 deletions vnext/Desktop.ABITests/MemoryTrackerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
#include <winrt/base.h>
#include <winrt/facebook.react.h>

#include "ActivationFactory.h"
#include "MessageQueueShim.h"

using namespace Microsoft::React::Test;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace winrt::facebook::react;

int32_t __stdcall WINRT_RoGetActivationFactory(void *classId, winrt::guid const &iid, void **factory) noexcept;

namespace ABITests {

// We turn clang format off here because it does not work with some of the
Expand Down
3 changes: 1 addition & 2 deletions vnext/Desktop.ABITests/NativeLogEventTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
#include <CppUnitTest.h>
#include <winrt/facebook.react.h>
#include <vector>
#include "ActivationFactory.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace winrt::facebook::react;
using namespace winrt;

int32_t __stdcall WINRT_RoGetActivationFactory(void *classId, winrt::guid const &iid, void **factory) noexcept;

namespace ABITests {

TEST_CLASS (NativeLogEventTests) {
Expand Down
3 changes: 1 addition & 2 deletions vnext/Desktop.ABITests/NativeTraceEventTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
#include <winrt/facebook.react.h>
#include <functional>
#include <stack>
#include "ActivationFactory.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace winrt::facebook::react;
using namespace winrt;

int32_t __stdcall WINRT_RoGetActivationFactory(void *classId, winrt::guid const &iid, void **factory) noexcept;

namespace ABITests {

TEST_CLASS (NativeTraceEventTests) {
Expand Down
5 changes: 5 additions & 0 deletions vnext/Desktop.ABITests/React.Windows.Desktop.ABITests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
<CppWinRTDynamicProjectWinMDReferences Include="$(OutputPath)..\React.Windows.Desktop\facebook.react.winmd">
<WinMDPath>$(OutputPath)..\React.Windows.Desktop\facebook.react.winmd</WinMDPath>
</CppWinRTDynamicProjectWinMDReferences>
<CppWinRTDynamicProjectWinMDReferences Include="$(OutputPath)..\React.Windows.Desktop\Microsoft.ReactNative.winmd">
Copy link
Member

@vmoroz vmoroz May 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CppWinRTDynamicProjectWinMDReferences [](start = 7, length = 37)

We also need to have a build dependency somewhere. The Microsoft.ReactNative.winmd must be created before the test project. #Pending

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should get this indirectly through the dependency on the DLL in line 88.


In reply to: 423290781 [](ancestors = 423290781)

<WinMDPath>$(OutputPath)..\React.Windows.Desktop\Microsoft.ReactNative.winmd</WinMDPath>
</CppWinRTDynamicProjectWinMDReferences>
</ItemGroup>
</Target>
<Target Name="GetRNDllPath" BeforeTargets="ClCompile">
Expand Down Expand Up @@ -133,9 +136,11 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="PerfTests.cpp" />
<ClCompile Include="ReactNativeHostTests.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="MessageQueueShim.h" />
<ClInclude Include="ActivationFactory.h" />
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<ClCompile Include="PerfTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ReactNativeHostTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="MessageQueueShim.h">
Expand All @@ -44,6 +47,9 @@
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ActivationFactory.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
29 changes: 29 additions & 0 deletions vnext/Desktop.ABITests/ReactNativeHostTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include "pch.h"
Copy link
Member

@vmoroz vmoroz May 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#i [](start = 0, length = 2)

nit: please add the copyright header. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


In reply to: 423291311 [](ancestors = 423291311)

#include <CppUnitTest.h>
#include <winrt/Microsoft.ReactNative.h>
#include "ActivationFactory.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace ABITests {

TEST_CLASS (ReactNativeHostTests) {
public:
ReactNativeHostTests() noexcept {
winrt_activation_handler = WINRT_RoGetActivationFactory;
}

TEST_METHOD(Activation_Succeeds) {
try {
winrt::Microsoft::ReactNative::ReactNativeHost host{};
Assert::IsTrue(true);
} catch (...) {
Assert::Fail();
}
}
};

} // namespace ABITests
66 changes: 66 additions & 0 deletions vnext/Desktop/ABI/ReactNativeHost.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include <pch.h>
#include "ReactNativeHost.h"

#include "Microsoft.ReactNative.ReactNativeHost.g.cpp"

using namespace winrt::Windows::Foundation::Collections;

namespace winrt::Microsoft::ReactNative::implementation {

ReactNativeHost::ReactNativeHost() noexcept {
// TODO: implement
}

IVector<IReactPackageProvider> ReactNativeHost::PackageProviders() noexcept {
if (!m_packageProviders) {
m_packageProviders = single_threaded_vector<IReactPackageProvider>();
}

return m_packageProviders;
}

void ReactNativeHost::PackageProviders(IVector<IReactPackageProvider> const &value) noexcept {
m_packageProviders = value;
}

ReactNative::ReactInstanceSettings ReactNativeHost::InstanceSettings() noexcept {
if (!m_instanceSettings) {
// TODO: implement
// m_instanceSettings = make<ReactInstanceSettings>();
}

return m_instanceSettings;
}

void ReactNativeHost::InstanceSettings(ReactNative::ReactInstanceSettings const &value) noexcept {
m_instanceSettings = value;
}

void ReactNativeHost::ReloadInstance() noexcept {
// TODO: implement
}

void ReactNativeHost::OnSuspend() noexcept {
// TODO: implement
}

void ReactNativeHost::OnEnteredBackground() noexcept {
// TODO: implement
}

void ReactNativeHost::OnLeavingBackground() noexcept {
// TODO: implement
}

void ReactNativeHost::OnResume(OnResumeAction const & /*action*/) noexcept {
// TODO: implement
}

void ReactNativeHost::OnBackPressed() noexcept {
// TODO: implement
}

} // namespace winrt::Microsoft::ReactNative::implementation
42 changes: 42 additions & 0 deletions vnext/Desktop/ABI/ReactNativeHost.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#pragma once

#include <winrt/Windows.Foundation.Collections.h>

#include "Microsoft.ReactNative.ReactNativeHost.g.h"

namespace winrt::Microsoft::ReactNative::implementation {

struct ReactNativeHost : ReactNativeHostT<ReactNativeHost> {
Copy link
Member

@vmoroz vmoroz May 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReactNativeHost [](start = 7, length = 15)

It would be nice to reuse files from the Microsoft.ReactNative project in future. #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will attempt this with the next change.


In reply to: 423289186 [](ancestors = 423289186)

ReactNativeHost() noexcept;

// property PackageProviders
Windows::Foundation::Collections::IVector<IReactPackageProvider> PackageProviders() noexcept;
void PackageProviders(Windows::Foundation::Collections::IVector<IReactPackageProvider> const &value) noexcept;

// property InstanceSettings
ReactNative::ReactInstanceSettings InstanceSettings() noexcept;
void InstanceSettings(ReactNative::ReactInstanceSettings const &value) noexcept;

void ReloadInstance() noexcept;

void OnSuspend() noexcept;
void OnEnteredBackground() noexcept;
void OnLeavingBackground() noexcept;
void OnResume(OnResumeAction const &action) noexcept;
void OnBackPressed() noexcept;

private:
ReactNative::ReactInstanceSettings m_instanceSettings{nullptr};
Windows::Foundation::Collections::IVector<IReactPackageProvider> m_packageProviders;
};

} // namespace winrt::Microsoft::ReactNative::implementation

namespace winrt::Microsoft::ReactNative::factory_implementation {

struct ReactNativeHost : ReactNativeHostT<ReactNativeHost, implementation::ReactNativeHost> {};

} // namespace winrt::Microsoft::ReactNative::factory_implementation
22 changes: 22 additions & 0 deletions vnext/Desktop/React.Windows.Desktop.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,27 @@
<AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions>-minpdbpathlen:256</AdditionalOptions>
</Link>
<Midl>
<AdditionalIncludeDirectories>$(ReactNativeWindowsDir)\Microsoft.ReactNative;$(ReactNativeWindowsDir)\Microsoft.ReactNative.Cxx;</AdditionalIncludeDirectories>
Copy link
Member

@vmoroz vmoroz May 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(ReactNativeWindowsDir)\Microsoft.ReactNative.Cxx [](start = 83, length = 50)

I wonder why is it need for the MIDL directories.
It would be better to have this part in the Microsoft.ReactNative.Cxx shared project instead. #Pending

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for
#include "NamespaceRedirect.h"
in Microsoft.ReactNative\IReactContext.idl

I think it's a backwards build dependency we should change.


In reply to: 423288009 [](ancestors = 423288009)

</Midl>
</ItemDefinitionGroup>
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\ReactCommunity.cpp.props" />
<ItemGroup>
<Midl Include="ABI\MemoryTracker.idl" />
<Midl Include="ABI\MessageQueue.idl" />
<Midl Include="ABI\NativeLogging.idl" />
<Midl Include="ABI\NativeTracing.idl" />
<Midl Include="..\Microsoft.ReactNative\ReactNativeHost.idl" />
<Midl Include="..\Microsoft.ReactNative\IReactPackageProvider.idl" />
<Midl Include="..\Microsoft.ReactNative\ReactInstanceSettings.idl" />
<Midl Include="..\Microsoft.ReactNative\IReactPackageBuilder.idl" />
<Midl Include="..\Microsoft.ReactNative\IReactModuleBuilder.idl" />
<Midl Include="..\Microsoft.ReactNative\IJSValueWriter.idl" />
<Midl Include="..\Microsoft.ReactNative\IReactContext.idl" />
<Midl Include="..\Microsoft.ReactNative\IJSValueReader.idl" />
<Midl Include="..\Microsoft.ReactNative\IViewManager.idl" />
<Midl Include="..\Microsoft.ReactNative\IReactPropertyBag.idl" />
<Midl Include="..\Microsoft.ReactNative\RedBoxHandler.idl" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="ABI\MemoryTracker.cpp">
Expand All @@ -115,6 +129,10 @@
<DependentUpon>ABI\NativeTracing.idl</DependentUpon>
<ObjectFileName>$(IntDir)\ABI\</ObjectFileName>
</ClCompile>
<ClCompile Include="ABI\ReactNativeHost.cpp">
<DependentUpon>..\Microsoft.ReactNative\ReactNativeHost.idl</DependentUpon>
<ObjectFileName>$(IntDir)\ABI\</ObjectFileName>
</ClCompile>
<ClCompile Include="CxxReactWin32\JSBigString.cpp" />
<ClCompile Include="DevSupportManager.cpp" />
<ClCompile Include="Executors\WebSocketJSExecutor.cpp" />
Expand Down Expand Up @@ -145,6 +163,10 @@
<ClInclude Include="ABI\NativeTraceEventSource.h">
<DependentUpon>ABI\NativeTracing.idl</DependentUpon>
</ClInclude>
<ClInclude Include="ABI\ReactNativeHost.h">
<DependentUpon>..\Microsoft.ReactNative\ReactNativeHost.idl</DependentUpon>
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="DevSupportManager.h" />
<ClInclude Include="Executors\WebSocketJSExecutor.h" />
<ClInclude Include="LazyDevSupportManager.h" />
Expand Down
33 changes: 33 additions & 0 deletions vnext/Desktop/React.Windows.Desktop.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,39 @@
<Midl Include="ABI\NativeTracing.idl">
<Filter>ABI</Filter>
</Midl>
<Midl Include="..\Microsoft.ReactNative\ReactNativeHost.idl">
<Filter>ABI</Filter>
</Midl>
<Midl Include="..\Microsoft.ReactNative\IReactPackageProvider.idl">
<Filter>ABI</Filter>
</Midl>
<Midl Include="..\Microsoft.ReactNative\ReactInstanceSettings.idl">
<Filter>ABI</Filter>
</Midl>
<Midl Include="..\Microsoft.ReactNative\IReactPackageBuilder.idl">
<Filter>ABI</Filter>
</Midl>
<Midl Include="..\Microsoft.ReactNative\IReactModuleBuilder.idl">
<Filter>ABI</Filter>
</Midl>
<Midl Include="..\Microsoft.ReactNative\IJSValueWriter.idl">
<Filter>ABI</Filter>
</Midl>
<Midl Include="..\Microsoft.ReactNative\IReactContext.idl">
<Filter>ABI</Filter>
</Midl>
<Midl Include="..\Microsoft.ReactNative\IJSValueReader.idl">
<Filter>ABI</Filter>
</Midl>
<Midl Include="..\Microsoft.ReactNative\IViewManager.idl">
<Filter>ABI</Filter>
</Midl>
<Midl Include="..\Microsoft.ReactNative\IReactPropertyBag.idl">
<Filter>ABI</Filter>
</Midl>
<Midl Include="..\Microsoft.ReactNative\RedBoxHandler.idl">
<Filter>ABI</Filter>
</Midl>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ABI\MemoryTracker.cpp">
Expand Down
8 changes: 8 additions & 0 deletions vnext/Desktop/module.g.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// WARNING: Please don't edit this file. It was generated by C++/WinRT v2.0.200316.3

#include "pch.h"
#include "winrt/base.h"
void* winrt_make_Microsoft_ReactNative_ReactNativeHost();
void* winrt_make_facebook_react_MemoryTracker();
void* winrt_make_facebook_react_NativeLogEventSource();
void* winrt_make_facebook_react_NativeTraceEventSource();
Expand All @@ -25,6 +28,11 @@ void* __stdcall winrt_get_activation_factory([[maybe_unused]] std::wstring_view
return std::equal(left.rbegin(), left.rend(), right.rbegin(), right.rend());
};

if (requal(name, L"Microsoft.ReactNative.ReactNativeHost"))
{
return winrt_make_Microsoft_ReactNative_ReactNativeHost();
}

if (requal(name, L"facebook.react.MemoryTracker"))
{
return winrt_make_facebook_react_MemoryTracker();
Expand Down