diff --git a/change/react-native-windows-2020-04-30-18-28-03-abi-safety.json b/change/react-native-windows-2020-04-30-18-28-03-abi-safety.json new file mode 100644 index 00000000000..7cf31717cd8 --- /dev/null +++ b/change/react-native-windows-2020-04-30-18-28-03-abi-safety.json @@ -0,0 +1,8 @@ +{ + "type": "none", + "comment": "test bundle build logic, JS function call test", + "packageName": "react-native-windows", + "email": "aeulitz@microsoft.com", + "dependentChangeType": "none", + "date": "2020-05-01T01:28:03.315Z" +} diff --git a/change/react-native-windows-2020-05-09-17-42-52-abi-safety.json b/change/react-native-windows-2020-05-09-17-42-52-abi-safety.json new file mode 100644 index 00000000000..ef25becd822 --- /dev/null +++ b/change/react-native-windows-2020-05-09-17-42-52-abi-safety.json @@ -0,0 +1,8 @@ +{ + "type": "prerelease", + "comment": "add ReactNativeHost to Win32 C++/WinRT ABI", + "packageName": "react-native-windows", + "email": "aeulitz@microsoft.com", + "dependentChangeType": "patch", + "date": "2020-05-10T00:42:52.866Z" +} diff --git a/vnext/Desktop.ABITests/ActivationFactory.cpp b/vnext/Desktop.ABITests/ActivationFactory.cpp index 81ff78b6cf7..19915c7e683 100644 --- a/vnext/Desktop.ABITests/ActivationFactory.cpp +++ b/vnext/Desktop.ABITests/ActivationFactory.cpp @@ -26,7 +26,7 @@ int32_t __stdcall WINRT_RoGetActivationFactory(void *classId, guid const &iid, v std::wstring_view const name{*reinterpret_cast(&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); diff --git a/vnext/Desktop.ABITests/ActivationFactory.h b/vnext/Desktop.ABITests/ActivationFactory.h new file mode 100644 index 00000000000..e53f76d24ce --- /dev/null +++ b/vnext/Desktop.ABITests/ActivationFactory.h @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#pragma once + +#include "pch.h" +#include +#include + +extern int32_t __stdcall WINRT_RoGetActivationFactory(void *classId, winrt::guid const &iid, void **factory) noexcept; diff --git a/vnext/Desktop.ABITests/MemoryTrackerTests.cpp b/vnext/Desktop.ABITests/MemoryTrackerTests.cpp index ce3da0f7549..79ad888716c 100644 --- a/vnext/Desktop.ABITests/MemoryTrackerTests.cpp +++ b/vnext/Desktop.ABITests/MemoryTrackerTests.cpp @@ -7,14 +7,13 @@ #include #include +#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 diff --git a/vnext/Desktop.ABITests/NativeLogEventTests.cpp b/vnext/Desktop.ABITests/NativeLogEventTests.cpp index d23fd4ae2ad..859b84dca56 100644 --- a/vnext/Desktop.ABITests/NativeLogEventTests.cpp +++ b/vnext/Desktop.ABITests/NativeLogEventTests.cpp @@ -5,13 +5,12 @@ #include #include #include +#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) { diff --git a/vnext/Desktop.ABITests/NativeTraceEventTests.cpp b/vnext/Desktop.ABITests/NativeTraceEventTests.cpp index 371589c30a1..16348920fa3 100644 --- a/vnext/Desktop.ABITests/NativeTraceEventTests.cpp +++ b/vnext/Desktop.ABITests/NativeTraceEventTests.cpp @@ -6,13 +6,12 @@ #include #include #include +#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) { diff --git a/vnext/Desktop.ABITests/React.Windows.Desktop.ABITests.vcxproj b/vnext/Desktop.ABITests/React.Windows.Desktop.ABITests.vcxproj index ec0af2a58ba..c4972ba5924 100644 --- a/vnext/Desktop.ABITests/React.Windows.Desktop.ABITests.vcxproj +++ b/vnext/Desktop.ABITests/React.Windows.Desktop.ABITests.vcxproj @@ -103,6 +103,9 @@ $(OutputPath)..\React.Windows.Desktop\facebook.react.winmd + + $(OutputPath)..\React.Windows.Desktop\Microsoft.ReactNative.winmd + @@ -133,9 +136,11 @@ Create + + diff --git a/vnext/Desktop.ABITests/React.Windows.Desktop.ABITests.vcxproj.filters b/vnext/Desktop.ABITests/React.Windows.Desktop.ABITests.vcxproj.filters index 49daa4eb2a2..76bd4b11819 100644 --- a/vnext/Desktop.ABITests/React.Windows.Desktop.ABITests.vcxproj.filters +++ b/vnext/Desktop.ABITests/React.Windows.Desktop.ABITests.vcxproj.filters @@ -36,6 +36,9 @@ Source Files + + Source Files + @@ -44,6 +47,9 @@ Header Files + + Header Files + diff --git a/vnext/Desktop.ABITests/ReactNativeHostTests.cpp b/vnext/Desktop.ABITests/ReactNativeHostTests.cpp new file mode 100644 index 00000000000..7206f5b8daf --- /dev/null +++ b/vnext/Desktop.ABITests/ReactNativeHostTests.cpp @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include "pch.h" +#include +#include +#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 diff --git a/vnext/Desktop/ABI/ReactNativeHost.cpp b/vnext/Desktop/ABI/ReactNativeHost.cpp new file mode 100644 index 00000000000..4486d9a209f --- /dev/null +++ b/vnext/Desktop/ABI/ReactNativeHost.cpp @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include +#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 ReactNativeHost::PackageProviders() noexcept { + if (!m_packageProviders) { + m_packageProviders = single_threaded_vector(); + } + + return m_packageProviders; +} + +void ReactNativeHost::PackageProviders(IVector const &value) noexcept { + m_packageProviders = value; +} + +ReactNative::ReactInstanceSettings ReactNativeHost::InstanceSettings() noexcept { + if (!m_instanceSettings) { + // TODO: implement + // m_instanceSettings = make(); + } + + 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 diff --git a/vnext/Desktop/ABI/ReactNativeHost.h b/vnext/Desktop/ABI/ReactNativeHost.h new file mode 100644 index 00000000000..f1596c4b49b --- /dev/null +++ b/vnext/Desktop/ABI/ReactNativeHost.h @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#pragma once + +#include + +#include "Microsoft.ReactNative.ReactNativeHost.g.h" + +namespace winrt::Microsoft::ReactNative::implementation { + +struct ReactNativeHost : ReactNativeHostT { + ReactNativeHost() noexcept; + + // property PackageProviders + Windows::Foundation::Collections::IVector PackageProviders() noexcept; + void PackageProviders(Windows::Foundation::Collections::IVector 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 m_packageProviders; +}; + +} // namespace winrt::Microsoft::ReactNative::implementation + +namespace winrt::Microsoft::ReactNative::factory_implementation { + +struct ReactNativeHost : ReactNativeHostT {}; + +} // namespace winrt::Microsoft::ReactNative::factory_implementation diff --git a/vnext/Desktop/React.Windows.Desktop.vcxproj b/vnext/Desktop/React.Windows.Desktop.vcxproj index 556cb33f4db..304f44e661b 100644 --- a/vnext/Desktop/React.Windows.Desktop.vcxproj +++ b/vnext/Desktop/React.Windows.Desktop.vcxproj @@ -90,6 +90,9 @@ Shlwapi.lib;%(AdditionalDependencies) -minpdbpathlen:256 + + $(ReactNativeWindowsDir)\Microsoft.ReactNative;$(ReactNativeWindowsDir)\Microsoft.ReactNative.Cxx; + @@ -97,6 +100,17 @@ + + + + + + + + + + + @@ -115,6 +129,10 @@ ABI\NativeTracing.idl $(IntDir)\ABI\ + + ..\Microsoft.ReactNative\ReactNativeHost.idl + $(IntDir)\ABI\ + @@ -145,6 +163,10 @@ ABI\NativeTracing.idl + + ..\Microsoft.ReactNative\ReactNativeHost.idl + Code + diff --git a/vnext/Desktop/React.Windows.Desktop.vcxproj.filters b/vnext/Desktop/React.Windows.Desktop.vcxproj.filters index e150e18d4fa..6a4be8c5886 100644 --- a/vnext/Desktop/React.Windows.Desktop.vcxproj.filters +++ b/vnext/Desktop/React.Windows.Desktop.vcxproj.filters @@ -42,6 +42,39 @@ ABI + + ABI + + + ABI + + + ABI + + + ABI + + + ABI + + + ABI + + + ABI + + + ABI + + + ABI + + + ABI + + + ABI + diff --git a/vnext/Desktop/module.g.cpp b/vnext/Desktop/module.g.cpp index 84d71805b03..a1ed4613ebe 100644 --- a/vnext/Desktop/module.g.cpp +++ b/vnext/Desktop/module.g.cpp @@ -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(); @@ -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();