Skip to content

Commit

Permalink
Add System.Runtime.Serialization (#2492)
Browse files Browse the repository at this point in the history
***NO_CI***
  • Loading branch information
josesimoes authored Dec 13, 2022
1 parent cad52c0 commit 1bed5b1
Show file tree
Hide file tree
Showing 21 changed files with 1,579 additions and 805 deletions.
13 changes: 12 additions & 1 deletion CMake/Modules/FindNF_CoreCLR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ set(NF_CoreCLR_SRCS

# Core stubs
RPC_stub.cpp
BinaryFormatter_stub.cpp

# CLR stubs
Debugger_stub.cpp
Expand Down Expand Up @@ -181,6 +180,18 @@ if(NF_FEATURE_SUPPORT_REFLECTION)
list(APPEND NF_CoreCLR_SRCS corlib_native_System_Reflection_RuntimeMethodInfo.cpp)
list(APPEND NF_CoreCLR_SRCS corlib_native_System_RuntimeType.cpp)
list(APPEND NF_CoreCLR_SRCS corlib_native_System_Type.cpp)

# should we include binary serialization support?
if(NF_FEATURE_BINARY_SERIALIZATION)
list(APPEND NF_CoreCLR_SRCS BinaryFormatter.cpp)
else()
# binary serialization stubs because we're not supporting reflection
list(APPEND NF_CoreCLR_SRCS BinaryFormatter_stub.cpp)
endif()

else()
# binary serialization stubs because we're not supporting reflection
list(APPEND NF_CoreCLR_SRCS BinaryFormatter_stub.cpp)
endif()

# include Collection support files depending on build option
Expand Down
7 changes: 7 additions & 0 deletions CMake/Modules/FindNF_NativeAssemblies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ option(API_System.Device.I2s "option for System.Device.I2s AP
option(API_System.Device.Pwm "option for System.Device.Pwm API")
option(API_System.IO.Ports "option for System.IO.Ports API")
option(API_System.Device.Spi "option for System.Device.Spi API")
option(API_System.Runtime.Serialization "option for System.Runtime.Serialization API")
option(API_Windows.Storage "option for Windows.Storage")
option(API_nanoFramework.Graphics "option for nanoFramework.Graphics")
option(API_nanoFramework.Device.Bluetooth "option for nanoFramework.Device.Bluetooth")
Expand Down Expand Up @@ -318,6 +319,12 @@ if(API_System.Device.Spi)
PerformSettingsForApiEntry("System.Device.Spi")
endif()

# System.Runtime.Serialization
if(API_System.Runtime.Serialization)
##### API name here (doted name)
PerformSettingsForApiEntry("System.Runtime.Serialization")
endif()

# System.Device.Wifi
if(API_System.Device.Wifi)
##### API name here (doted name)
Expand Down
50 changes: 50 additions & 0 deletions CMake/Modules/FindSystem.Runtime.Serialization.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Copyright (c) .NET Foundation and Contributors
# See LICENSE file in the project root for full license information.
#

# native code directory
set(BASE_PATH_FOR_THIS_MODULE ${BASE_PATH_FOR_CLASS_LIBRARIES_MODULES}/System.Runtime.Serialization)


# set include directories
list(APPEND System.Runtime.Serialization_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Core)
list(APPEND System.Runtime.Serialization_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Include)
list(APPEND System.Runtime.Serialization_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/HAL/Include)
list(APPEND System.Runtime.Serialization_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/PAL/Include)
list(APPEND System.Runtime.Serialization_INCLUDE_DIRS ${BASE_PATH_FOR_THIS_MODULE})
list(APPEND System.Runtime.Serialization_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/System.Runtime.Serialization)

# source files
set(System.Runtime.Serialization_SRCS

nf_system_runtime_serialization.cpp

nf_system_runtime_serialization_System_Runtime_Serialization_Formatters_Binary_BinaryFormatter.cpp

)

foreach(SRC_FILE ${System.Runtime.Serialization_SRCS})

set(System.Runtime.Serialization_SRC_FILE SRC_FILE-NOTFOUND)

find_file(System.Runtime.Serialization_SRC_FILE ${SRC_FILE}
PATHS
${BASE_PATH_FOR_THIS_MODULE}
${TARGET_BASE_LOCATION}
${PROJECT_SOURCE_DIR}/src/System.Runtime.Serialization

CMAKE_FIND_ROOT_PATH_BOTH
)

if (BUILD_VERBOSE)
message("${SRC_FILE} >> ${System.Runtime.Serialization_SRC_FILE}")
endif()

list(APPEND System.Runtime.Serialization_SOURCES ${System.Runtime.Serialization_SRC_FILE})

endforeach()

include(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(System.Runtime.Serialization DEFAULT_MSG System.Runtime.Serialization_INCLUDE_DIRS System.Runtime.Serialization_SOURCES)
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,30 @@ option(NF_NETWORKING_ENC28J60 "option to use ENC28J60 network driver")
# handles inclusion of System.Reflection API
#############################################

# set default option for SNTP to ON
# set default option for Reflection API to ON
option(NF_FEATURE_SUPPORT_REFLECTION "option to add support for System.Reflection API" ON)
# set default option for Serialization API to ON
option(NF_FEATURE_BINARY_SERIALIZATION "option to add support for binary serialization" ON)

if(NF_FEATURE_SUPPORT_REFLECTION)
set(TARGET_NANOCLR_REFLECTION TRUE CACHE INTERNAL "enable support for System.Reflection API")
message(STATUS "Support for System.Reflection API enabled")

if(NF_FEATURE_BINARY_SERIALIZATION)
set(API_System.Runtime.Serialization TRUE CACHE INTERNAL "enable support for System.Runtime.Serialization API")
message(STATUS "Support for binary serialization enabled")
else()
set(API_System.Runtime.Serialization FALSE CACHE INTERNAL "disable support for System.Runtime.Serialization API")
message(STATUS "Support for binary serialization **IS NOT** enabled")
endif()

else()
set(TARGET_NANOCLR_REFLECTION FALSE CACHE INTERNAL "DISABLE support for System.Reflection API")
message(STATUS "Support for System.Reflection API **IS NOT** enabled")

# disable binary serialization if Reflection is disabled
set(API_System.Runtime.Serialization FALSE CACHE INTERNAL "disable support for System.Runtime.Serialization API")
message(STATUS "Support for binary serialization **IS NOT** enabled")
endif()

#################################################################
Expand Down
3 changes: 2 additions & 1 deletion CMakeUserPresets.TEMPLATE.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
],
"cacheVariables": {
"TARGET_BOARD": "${presetName}",
"NF_INTEROP_ASSEMBLIES": null
"NF_INTEROP_ASSEMBLIES": null,
"NF_FEATURE_BINARY_SERIALIZATION": "OFF"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion nf.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>VIRTUAL_DEVICE;SUPPORT_ANY_BASE_CONVERSION;NANOCLR_REFLECTION=TRUE;NANOCLR_SYSTEM_COLLECTIONS=TRUE;</PreprocessorDefinitions>
<PreprocessorDefinitions>VIRTUAL_DEVICE;NANOCLR_BINARY_SERIALIZATION;SUPPORT_ANY_BASE_CONVERSION;NANOCLR_REFLECTION=TRUE;NANOCLR_SYSTEM_COLLECTIONS=TRUE;</PreprocessorDefinitions>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
</ClCompile>
Expand Down
2 changes: 1 addition & 1 deletion src/CLR/CorLib/corlib_native_System_WeakReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ HRESULT CLR_RT_HeapBlock_WeakReference::GetTarget(CLR_RT_HeapBlock &targetRefere
CLR_RT_ProtectFromGC gcInput(input);
CLR_RT_ProtectFromGC gcOutput(output);

if (FAILED(CLR_RT_BinaryFormatter::Deserialize(output, input, NULL, NULL, 0)))
if (FAILED(CLR_RT_BinaryFormatter::Deserialize(output, input, NULL, 0)))
{
output.SetObjectReference(NULL);
}
Expand Down
Loading

0 comments on commit 1bed5b1

Please sign in to comment.