Skip to content

Commit 25db559

Browse files
authored
Metadata of native assemblies is now generated and exposed in virtual device (#3023)
1 parent 12d611b commit 25db559

14 files changed

+638
-81
lines changed

.editorconfig

+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
# EditorConfig for Visual Studio 2022: https://learn.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2022
2+
3+
# This is a top-most .editorconfig file
4+
root = true
5+
6+
#=====================================================
7+
#
8+
# nanoFramework specific settings
9+
#
10+
#
11+
#=====================================================
12+
[*]
13+
# Generic EditorConfig settings
14+
end_of_line = crlf
15+
charset = utf-8-bom
16+
17+
# Visual Studio spell checker
18+
spelling_languages = en-us
19+
spelling_checkable_types = strings,identifiers,comments
20+
spelling_error_severity = information
21+
spelling_exclusion_path = spelling_exclusion.dic
22+
23+
#=====================================================
24+
#
25+
# Settings copied from the .NET runtime
26+
#
27+
# https://github.com/dotnet/runtime
28+
#
29+
#=====================================================
30+
# Default settings:
31+
# A newline ending every file
32+
# Use 4 spaces as indentation
33+
insert_final_newline = true
34+
indent_style = space
35+
indent_size = 4
36+
trim_trailing_whitespace = true
37+
38+
# Generated code
39+
[*{_AssemblyInfo.cs,.notsupported.cs,AsmOffsets.cs}]
40+
generated_code = true
41+
42+
# C# files
43+
[*.cs]
44+
# New line preferences
45+
csharp_new_line_before_open_brace = all
46+
csharp_new_line_before_else = true
47+
csharp_new_line_before_catch = true
48+
csharp_new_line_before_finally = true
49+
csharp_new_line_before_members_in_object_initializers = true
50+
csharp_new_line_before_members_in_anonymous_types = true
51+
csharp_new_line_between_query_expression_clauses = true
52+
53+
# Indentation preferences
54+
csharp_indent_block_contents = true
55+
csharp_indent_braces = false
56+
csharp_indent_case_contents = true
57+
csharp_indent_case_contents_when_block = false
58+
csharp_indent_switch_labels = true
59+
csharp_indent_labels = one_less_than_current
60+
61+
# Modifier preferences
62+
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async:suggestion
63+
64+
# avoid this. unless absolutely necessary
65+
dotnet_style_qualification_for_field = false:suggestion
66+
dotnet_style_qualification_for_property = false:suggestion
67+
dotnet_style_qualification_for_method = false:suggestion
68+
dotnet_style_qualification_for_event = false:suggestion
69+
70+
# Types: use keywords instead of BCL types, and permit var only when the type is clear
71+
csharp_style_var_for_built_in_types = false:suggestion
72+
csharp_style_var_when_type_is_apparent = false:none
73+
csharp_style_var_elsewhere = false:suggestion
74+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
75+
dotnet_style_predefined_type_for_member_access = true:suggestion
76+
77+
# name all constant fields using PascalCase
78+
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
79+
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
80+
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
81+
dotnet_naming_symbols.constant_fields.applicable_kinds = field
82+
dotnet_naming_symbols.constant_fields.required_modifiers = const
83+
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
84+
85+
# static fields should have s_ prefix
86+
dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
87+
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
88+
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
89+
dotnet_naming_symbols.static_fields.applicable_kinds = field
90+
dotnet_naming_symbols.static_fields.required_modifiers = static
91+
dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected
92+
dotnet_naming_style.static_prefix_style.required_prefix = s_
93+
dotnet_naming_style.static_prefix_style.capitalization = camel_case
94+
95+
# internal and private fields should be _camelCase
96+
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
97+
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
98+
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
99+
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
100+
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
101+
dotnet_naming_style.camel_case_underscore_style.required_prefix = _
102+
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
103+
104+
# Code style defaults
105+
csharp_using_directive_placement = outside_namespace:suggestion
106+
dotnet_sort_system_directives_first = true
107+
csharp_prefer_braces = true:silent
108+
csharp_preserve_single_line_blocks = true:none
109+
csharp_preserve_single_line_statements = false:none
110+
csharp_prefer_static_local_function = true:suggestion
111+
csharp_prefer_simple_using_statement = false:none
112+
csharp_style_prefer_switch_expression = true:suggestion
113+
dotnet_style_readonly_field = true:suggestion
114+
115+
# Expression-level preferences
116+
dotnet_style_object_initializer = true:suggestion
117+
dotnet_style_collection_initializer = true:suggestion
118+
dotnet_style_prefer_collection_expression = when_types_exactly_match
119+
dotnet_style_explicit_tuple_names = true:suggestion
120+
dotnet_style_coalesce_expression = true:suggestion
121+
dotnet_style_null_propagation = true:suggestion
122+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
123+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
124+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
125+
dotnet_style_prefer_auto_properties = true:suggestion
126+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
127+
dotnet_style_prefer_conditional_expression_over_return = true:silent
128+
csharp_prefer_simple_default_expression = true:suggestion
129+
130+
# Expression-bodied members
131+
csharp_style_expression_bodied_methods = true:silent
132+
csharp_style_expression_bodied_constructors = true:silent
133+
csharp_style_expression_bodied_operators = true:silent
134+
csharp_style_expression_bodied_properties = true:silent
135+
csharp_style_expression_bodied_indexers = true:silent
136+
csharp_style_expression_bodied_accessors = true:silent
137+
csharp_style_expression_bodied_lambdas = true:silent
138+
csharp_style_expression_bodied_local_functions = true:silent
139+
140+
# Pattern matching
141+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
142+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
143+
csharp_style_inlined_variable_declaration = true:suggestion
144+
145+
# Null checking preferences
146+
csharp_style_throw_expression = true:suggestion
147+
csharp_style_conditional_delegate_call = true:suggestion
148+
149+
# Other features
150+
csharp_style_prefer_index_operator = false:none
151+
csharp_style_prefer_range_operator = false:none
152+
csharp_style_pattern_local_over_anonymous_function = false:none
153+
154+
# Space preferences
155+
csharp_space_after_cast = false
156+
csharp_space_after_colon_in_inheritance_clause = true
157+
csharp_space_after_comma = true
158+
csharp_space_after_dot = false
159+
csharp_space_after_keywords_in_control_flow_statements = true
160+
csharp_space_after_semicolon_in_for_statement = true
161+
csharp_space_around_binary_operators = before_and_after
162+
csharp_space_around_declaration_statements = do_not_ignore
163+
csharp_space_before_colon_in_inheritance_clause = true
164+
csharp_space_before_comma = false
165+
csharp_space_before_dot = false
166+
csharp_space_before_open_square_brackets = false
167+
csharp_space_before_semicolon_in_for_statement = false
168+
csharp_space_between_empty_square_brackets = false
169+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
170+
csharp_space_between_method_call_name_and_opening_parenthesis = false
171+
csharp_space_between_method_call_parameter_list_parentheses = false
172+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
173+
csharp_space_between_method_declaration_name_and_open_parenthesis = false
174+
csharp_space_between_method_declaration_parameter_list_parentheses = false
175+
csharp_space_between_parentheses = false
176+
csharp_space_between_square_brackets = false
177+
178+
# License header
179+
file_header_template = Licensed to the .NET Foundation under one or more agreements.\nThe .NET Foundation licenses this file to you under the MIT license.
180+
181+
# C++ Files
182+
[*.{cpp,h,in}]
183+
curly_bracket_next_line = true
184+
indent_brace_style = Allman
185+
186+
# Xml project files
187+
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]
188+
indent_size = 2
189+
190+
[*.{csproj,vbproj,proj,nativeproj,locproj}]
191+
charset = utf-8
192+
193+
# Xml build files
194+
[*.builds]
195+
indent_size = 2
196+
197+
# Xml files
198+
[*.{xml,stylecop,resx,ruleset}]
199+
indent_size = 2
200+
201+
# Xml config files
202+
[*.{props,targets,config,nuspec}]
203+
indent_size = 2
204+
205+
# YAML config files
206+
[*.{yml,yaml}]
207+
indent_size = 2
208+
209+
# Shell scripts
210+
[*.sh]
211+
end_of_line = lf
212+
[*.{cmd,bat}]
213+
end_of_line = crlf

CMake/Modules/FindNF_NativeAssemblies.cmake

+65-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#
1+
#
22
# Copyright (c) .NET Foundation and Contributors
33
# See LICENSE file in the project root for full license information.
44
#
@@ -62,6 +62,53 @@ option(API_Hardware.GiantGecko "option for Hardware.Gia
6262

6363
###################################
6464

65+
#################################################################
66+
# macro to find the version of an API or Interop assembly
67+
macro(AddNativeAssemblyVersion apiNamespace apiNamespaceWithoutDots nativeAssemblySources)
68+
69+
# find the source file that contains the value of CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_${apiNamespaceWithoutDots}
70+
foreach(apiSourceFile ${nativeAssemblySources})
71+
72+
file(READ "${apiSourceFile}" sourceCode)
73+
74+
string(REGEX MATCH "[ \t\r\n]+CLR_RT_NativeAssemblyData[ \t\r\n]+g_CLR_AssemblyNative_${apiNamespaceWithoutDots}[ \t\r\n]*=[^{]+{[^0]+0x([0-9A-Za-z]+)[^{]+{[ \t\r\n]*([0-9]+)[ \t\r\n]*,[ \t\r\n]*([0-9]+)[ \t\r\n]*,[ \t\r\n]*([0-9]+)[ \t\r\n]*,[ \t\r\n]*([0-9]+)" _ "${sourceCode}")
75+
76+
if(NOT "${CMAKE_MATCH_1}" STREQUAL "")
77+
list(APPEND NF_NativeAssemblies_VERSIONS "${apiNamespace},${CMAKE_MATCH_2}.${CMAKE_MATCH_3}.${CMAKE_MATCH_4}.${CMAKE_MATCH_5},0x${CMAKE_MATCH_1}")
78+
break()
79+
endif()
80+
81+
endforeach()
82+
83+
endmacro()
84+
#################################################################
85+
86+
#################################################################
87+
# macro to find the version of the CorLib assembly
88+
macro(AddCorLibAssemblyVersion apiNamespace apiNamespaceWithoutDots nativeAssemblySources)
89+
90+
# find the source file that contains the value of CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_${apiNamespaceWithoutDots}
91+
foreach(apiSourceFile ${nativeAssemblySources})
92+
93+
file(READ "${apiSourceFile}" sourceCode)
94+
95+
string(REGEX MATCH "[ \t\r\n]+CLR_RT_NativeAssemblyData[ \t\r\n]+g_CLR_AssemblyNative_${apiNamespaceWithoutDots}[ \t\r\n]*=[^{]+{[^0]+0x([0-9A-Za-z]+)[^0]+0x([0-9A-Za-z]+)[^{]+{[ \t\r\n]*([0-9]+)[ \t\r\n]*,[ \t\r\n]*([0-9]+)[ \t\r\n]*,[ \t\r\n]*([0-9]+)[ \t\r\n]*,[ \t\r\n]*([0-9]+)" _ "${sourceCode}")
96+
97+
if(NOT "${CMAKE_MATCH_1}" STREQUAL "")
98+
if (NF_FEATURE_SUPPORT_REFLECTION)
99+
list(APPEND NF_NativeAssemblies_VERSIONS "${apiNamespace},${CMAKE_MATCH_3}.${CMAKE_MATCH_4}.${CMAKE_MATCH_5}.${CMAKE_MATCH_6},0x${CMAKE_MATCH_1}")
100+
else()
101+
list(APPEND NF_NativeAssemblies_VERSIONS "${apiNamespace},${CMAKE_MATCH_3}.${CMAKE_MATCH_4}.${CMAKE_MATCH_5}.${CMAKE_MATCH_6},0x${CMAKE_MATCH_2}")
102+
endif()
103+
104+
break()
105+
endif()
106+
107+
endforeach()
108+
109+
endmacro()
110+
#################################################################
111+
65112
#################################################################
66113
# macro to perform individual settings to add an API to the build
67114
macro(PerformSettingsForApiEntry apiNamespace)
@@ -85,10 +132,12 @@ macro(PerformSettingsForApiEntry apiNamespace)
85132
list(APPEND NF_NativeAssemblies_INCLUDE_DIRS "${${apiNamespace}_INCLUDE_DIRS}")
86133
list(REMOVE_DUPLICATES NF_NativeAssemblies_INCLUDE_DIRS)
87134

88-
# append source files to list wiht source files for all the APIs
135+
# append source files to list with source files for all the APIs
89136
list(APPEND NF_NativeAssemblies_SOURCES "${${apiNamespace}_SOURCES}")
90137
list(REMOVE_DUPLICATES NF_NativeAssemblies_SOURCES)
91138

139+
# add the assembly version to the list
140+
AddNativeAssemblyVersion("${apiNamespace}" "${apiNamespaceWithoutDots}" "${${apiNamespace}_SOURCES}")
92141
endmacro()
93142
#################################################################
94143

@@ -123,6 +172,8 @@ macro(PerformSettingsForInteropEntry interopAssemblyName)
123172
list(APPEND NF_NativeAssemblies_SOURCES "${${interopAssemblyName}_SOURCES}")
124173
list(REMOVE_DUPLICATES NF_NativeAssemblies_SOURCES)
125174

175+
# add the assembly version to the list
176+
AddNativeAssemblyVersion("${interopAssemblyName}" "${interopAssemblyNameWithoutDots}" "${${interopAssemblyName}_SOURCES}")
126177
endmacro()
127178

128179
#################################################################
@@ -172,6 +223,14 @@ macro(ParseInteropAssemblies)
172223

173224
endmacro()
174225

226+
############################################################################################
227+
# Add versions of native assemblies that are always included
228+
############################################################################################
229+
230+
AddCorLibAssemblyVersion("mscorlib" "mscorlib" "${CMAKE_SOURCE_DIR}/src/CLR/CorLib/corlib_native.cpp")
231+
232+
AddNativeAssemblyVersion("nanoFramework.Runtime.Native" "nanoFramework_Runtime_Native" "${CMAKE_SOURCE_DIR}/src/nanoFramework.Runtime.Native/nf_rt_native.cpp")
233+
175234
############################################################################################
176235
# WHEN ADDING A NEW API add the corresponding block below
177236
# required changes:
@@ -424,6 +483,10 @@ configure_file("${CMAKE_SOURCE_DIR}/InteropAssemblies/CLR_RT_InteropAssembliesTa
424483
# ... now add Interop Assemblies table to ChibiOS nanoCLR sources list
425484
list(APPEND NF_NativeAssemblies_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/CLR_RT_InteropAssembliesTable.cpp")
426485

486+
# create a .csv file with native assembly versions in the output directory
487+
string(REPLACE ";" "\r\n" NF_NativeAssemblies_CSV "${NF_NativeAssemblies_VERSIONS}")
488+
file(WRITE "${CMAKE_BINARY_DIR}/native_assemblies.csv" "${NF_NativeAssemblies_CSV}")
489+
427490
# output the list of APIs included
428491
list(LENGTH apiListing apiListingLenght)
429492

spelling_exclusion.dic

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nano
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
//
2-
// Copyright (c) .NET Foundation and Contributors
3-
// See LICENSE file in the project root for full license information.
4-
//
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
53

64
using CommandLine;
75

@@ -10,14 +8,20 @@ namespace nanoFramework.nanoCLR.CLI
108
[Verb(
119
"instance",
1210
HelpText = "Operations with the current nanoCLR instance.")]
13-
public class ClrInstanceOperationsOptions
11+
public class ClrInstanceOperationsOptions : CommonOptions
1412
{
1513
[Option(
1614
"getversion",
1715
Required = false,
1816
HelpText = "Gets the version of the current nanoCLR instance.")]
1917
public bool GetCLRVersion { get; set; }
2018

19+
[Option(
20+
"getnativeassemblies",
21+
Required = false,
22+
HelpText = "Gets the names and versions of the native assemblies.")]
23+
public bool GetNativeAssemblies { get; set; }
24+
2125
[Option(
2226
"update",
2327
Required = false,
@@ -37,21 +41,5 @@ public class ClrInstanceOperationsOptions
3741
Default = null,
3842
HelpText = "Specify a version of nanoCRL to install.")]
3943
public string TargetVersion { get; set; }
40-
41-
/// <summary>
42-
/// Allowed values:
43-
/// q[uiet]
44-
/// m[inimal]
45-
/// n[ormal]
46-
/// d[etailed]
47-
/// diag[nostic]
48-
/// </summary>
49-
[Option(
50-
'v',
51-
"verbosity",
52-
Required = false,
53-
Default = "n",
54-
HelpText = "Sets the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]. Not supported in every command; see specific command page to determine if this option is available.")]
55-
public string Verbosity { get; set; }
5644
}
5745
}

0 commit comments

Comments
 (0)