diff options
author | Elinor Fung <elfung@microsoft.com> | 2022-03-16 06:05:50 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-16 06:05:50 +0300 |
commit | d2688883510318aa0114268930fb2022d3dc64cf (patch) | |
tree | 187dce6ec6afbcb180cac35f8ece1e1e8e457c37 | |
parent | c3dbdea91835d67cc461b22125e652ad5063d746 (diff) |
Expose `LibraryImportAttribute` (#66434)
24 files changed, 135 insertions, 73 deletions
diff --git a/eng/generators.targets b/eng/generators.targets index 9ca826c5cc7..24c5c2db8d8 100644 --- a/eng/generators.targets +++ b/eng/generators.targets @@ -44,8 +44,12 @@ <ItemGroup Condition="'@(EnabledGenerators)' != '' and @(EnabledGenerators->AnyHaveMetadataValue('Identity', 'LibraryImportGenerator')) and '$(IncludeLibraryImportGeneratorSources)' == 'true'"> - <Compile Include="$(LibrariesProjectRoot)Common\src\System\Runtime\InteropServices\LibraryImportAttribute.cs" /> - <Compile Include="$(LibrariesProjectRoot)Common\src\System\Runtime\InteropServices\StringMarshalling.cs" /> + + <!-- Only add the following files if we are not on the latest TFM. --> + <Compile Condition="'$(NetCoreAppCurrentTargetFrameworkMoniker)' != '$(TargetFrameworkMoniker)'" + Include="$(CoreLibSharedDir)System\Runtime\InteropServices\LibraryImportAttribute.cs" /> + <Compile Condition="'$(NetCoreAppCurrentTargetFrameworkMoniker)' != '$(TargetFrameworkMoniker)'" + Include="$(CoreLibSharedDir)System\Runtime\InteropServices\StringMarshalling.cs" /> <!-- Only add the following files if we are on the latest TFM (that is, net7). --> <Compile Condition="'$(NetCoreAppCurrentTargetFrameworkMoniker)' == '$(TargetFrameworkMoniker)'" Include="$(LibrariesProjectRoot)Common\src\System\Runtime\InteropServices\GeneratedMarshallingAttribute.cs" /> diff --git a/src/libraries/Common/src/System/Runtime/InteropServices/LibraryImportAttribute.cs b/src/libraries/Common/src/System/Runtime/InteropServices/LibraryImportAttribute.cs deleted file mode 100644 index 0bacf3efad5..00000000000 --- a/src/libraries/Common/src/System/Runtime/InteropServices/LibraryImportAttribute.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#nullable enable - -// -// Types in this file are used for generated p/invokes (docs/design/features/source-generator-pinvokes.md). -// -namespace System.Runtime.InteropServices -{ - /// <summary> - /// Indicates that method will be generated at compile time and invoke into an unmanaged library entry point - /// </summary> - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] -#if LIBRARYIMPORT_GENERATOR_TEST - public -#else - internal -#endif - sealed class LibraryImportAttribute : Attribute - { - public string? EntryPoint { get; set; } - public bool SetLastError { get; set; } - public StringMarshalling StringMarshalling { get; set; } - public Type? StringMarshallingCustomType { get; set; } - - public LibraryImportAttribute(string dllName) - { - LibraryName = dllName; - } - - public string LibraryName { get; private set; } - } -} diff --git a/src/libraries/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj b/src/libraries/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj index fd58dca4e44..9e53ca9054a 100644 --- a/src/libraries/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj +++ b/src/libraries/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj @@ -2,7 +2,7 @@ <PropertyGroup> <AllowUnsafeBlocks>true</AllowUnsafeBlocks> <TargetFrameworks>$(NetCoreAppCurrent);net48</TargetFrameworks> - <!-- + <!-- We wish to test operations that would result in "Operator '-' cannot be applied to operands of type 'ushort' and 'EnumArithmeticTests.UInt16Enum'" --> @@ -11,7 +11,7 @@ <DebuggerSupport Condition="'$(DebuggerSupport)' == '' and '$(TargetOS)' == 'Browser'">true</DebuggerSupport> </PropertyGroup> <ItemGroup> - <Compile Include="$(CommonPath)System\Runtime\CompilerServices\IsExternalInit.cs" Link="Common\System\Runtime\CompilerServices\IsExternalInit.cs" /> + <Compile Include="$(CoreLibSharedDir)System\Runtime\CompilerServices\IsExternalInit.cs" Link="Common\System\Runtime\CompilerServices\IsExternalInit.cs" /> <Compile Include="AccessTests.cs" /> <Compile Include="ArrayHandling.cs" /> <Compile Include="AssignmentTests.cs" /> diff --git a/src/libraries/Microsoft.VisualBasic.Core/tests/Microsoft.VisualBasic.Core.Tests.csproj b/src/libraries/Microsoft.VisualBasic.Core/tests/Microsoft.VisualBasic.Core.Tests.csproj index d1664887f06..89daad4c673 100644 --- a/src/libraries/Microsoft.VisualBasic.Core/tests/Microsoft.VisualBasic.Core.Tests.csproj +++ b/src/libraries/Microsoft.VisualBasic.Core/tests/Microsoft.VisualBasic.Core.Tests.csproj @@ -4,7 +4,7 @@ <TargetFrameworks>$(NetCoreAppCurrent);net48</TargetFrameworks> </PropertyGroup> <ItemGroup> - <Compile Include="$(CommonPath)System\Runtime\CompilerServices\IsExternalInit.cs" Link="Common\System\Runtime\CompilerServices\IsExternalInit.cs" /> + <Compile Include="$(CoreLibSharedDir)System\Runtime\CompilerServices\IsExternalInit.cs" Link="Common\System\Runtime\CompilerServices\IsExternalInit.cs" /> <Compile Include="AssemblyAttributes.cs" /> <Compile Include="ByteTypeTests.cs" /> <Compile Include="CharTypeTests.cs" /> diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSource.csproj b/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSource.csproj index 26879046137..1bbb59baf3e 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSource.csproj +++ b/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSource.csproj @@ -15,8 +15,7 @@ <Compile Include="System.Diagnostics.DiagnosticSource.cs" /> <Compile Include="System.Diagnostics.DiagnosticSourceActivity.cs" /> <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\RequiresUnreferencedCodeAttribute.cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" /> - <Compile Include="$(CommonPath)System\Runtime\CompilerServices\IsExternalInit.cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" - Link="Common\System\Runtime\CompilerServices\IsExternalInit.cs" /> + <Compile Include="$(CoreLibSharedDir)System\Runtime\CompilerServices\IsExternalInit.cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" /> </ItemGroup> <ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'"> diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj index 374e595ad5b..e16a0b83f2e 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj @@ -30,7 +30,7 @@ System.Diagnostics.DiagnosticSource</PackageDescription> <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs" /> <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\RequiresUnreferencedCodeAttribute.cs" /> <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\UnconditionalSuppressMessageAttribute.cs" /> - <Compile Include="$(CommonPath)System\Runtime\CompilerServices\IsExternalInit.cs" Link="Common\System\Runtime\CompilerServices\IsExternalInit.cs" /> + <Compile Include="$(CoreLibSharedDir)System\Runtime\CompilerServices\IsExternalInit.cs" /> </ItemGroup> <ItemGroup> <Compile Include="$(CommonPath)System\HexConverter.cs" Link="Common\System\HexConverter.cs" /> diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 8bf268cecd0..a0f6850e5c7 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -208,6 +208,7 @@ <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\Queue.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\QueueDebugView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\RandomizedStringEqualityComparer.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\ReferenceEqualityComparer.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\NonRandomizedStringEqualityComparer.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\ValueListBuilder.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Collections\HashHelpers.cs" /> @@ -256,6 +257,7 @@ <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMembersAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\CodeAnalysis\DynamicDependencyAttribute.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\CodeAnalysis\ExcludeFromCodeCoverageAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\CodeAnalysis\NullableAttributes.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\CodeAnalysis\RequiresAssemblyFilesAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\CodeAnalysis\RequiresDynamicCodeAttribute.cs" /> @@ -732,6 +734,7 @@ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IntrinsicAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsByRefLikeAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsConst.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsExternalInit.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsReadOnlyAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsVolatile.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\InterpolatedStringHandlerAttribute.cs" /> @@ -845,17 +848,16 @@ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\InvalidOleVariantTypeException.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\LayoutKind.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\LCIDConversionAttribute.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\LibraryImportAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\Marshal.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MarshalAsAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MarshalDirectiveException.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MemoryMarshal.cs" /> - <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\NativeMemory.cs" /> - <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\OSPlatform.cs" /> - <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnmanagedCallConvAttribute.cs" /> - <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnmanagedCallersOnlyAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\NativeLibrary.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\NativeMemory.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\NFloat.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\OptionalAttribute.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\OSPlatform.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\OutAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\PosixSignal.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\PosixSignalContext.cs" /> @@ -869,10 +871,13 @@ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\SafeBuffer.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\SafeHandle.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\SEHException.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\StringMarshalling.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\StructLayoutAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\SuppressGCTransitionAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\TypeIdentifierAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnknownWrapper.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnmanagedCallConvAttribute.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnmanagedCallersOnlyAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnmanagedFunctionPointerAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnmanagedType.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\VarEnum.cs" /> @@ -1230,24 +1235,15 @@ <Compile Include="$(CommonPath)System\Collections\Generic\EnumerableHelpers.cs"> <Link>Common\System\Collections\Generic\EnumerableHelpers.cs</Link> </Compile> - <Compile Include="$(CommonPath)System\Collections\Generic\ReferenceEqualityComparer.cs"> - <Link>Common\System\Collections\Generic\ReferenceEqualityComparer.cs</Link> - </Compile> <Compile Include="$(CommonPath)System\Collections\Generic\BitHelper.cs"> <Link>Common\System\Collections\Generic\BitHelper.cs</Link> </Compile> - <Compile Include="$(CommonPath)System\Diagnostics\CodeAnalysis\ExcludeFromCodeCoverageAttribute.cs"> - <Link>Common\System\Diagnostics\CodeAnalysis\ExcludeFromCodeCoverageAttribute.cs</Link> - </Compile> <Compile Include="$(CommonPath)System\IO\PathInternal.cs"> <Link>Common\System\IO\PathInternal.cs</Link> </Compile> <Compile Include="$(CommonPath)System\IO\PathInternal.CaseSensitivity.cs"> <Link>Common\System\IO\PathInternal.CaseSensitivity.cs</Link> </Compile> - <Compile Include="$(CommonPath)System\Runtime\CompilerServices\IsExternalInit.cs"> - <Link>Common\System\Runtime\CompilerServices\IsExternalInit.cs</Link> - </Compile> <Compile Include="$(CommonPath)System\Runtime\Versioning\NonVersionableAttribute.cs"> <Link>Common\System\Runtime\Versioning\NonVersionableAttribute.cs</Link> </Compile> diff --git a/src/libraries/Common/src/System/Collections/Generic/ReferenceEqualityComparer.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ReferenceEqualityComparer.cs index 41c1e7fc6bb..41c1e7fc6bb 100644 --- a/src/libraries/Common/src/System/Collections/Generic/ReferenceEqualityComparer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ReferenceEqualityComparer.cs diff --git a/src/libraries/Common/src/System/Diagnostics/CodeAnalysis/ExcludeFromCodeCoverageAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/ExcludeFromCodeCoverageAttribute.cs index 7104270c2c5..fa8730a8eeb 100644 --- a/src/libraries/Common/src/System/Diagnostics/CodeAnalysis/ExcludeFromCodeCoverageAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/ExcludeFromCodeCoverageAttribute.cs @@ -4,12 +4,7 @@ namespace System.Diagnostics.CodeAnalysis { [AttributeUsageAttribute(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event, Inherited = false, AllowMultiple = false)] -#if SYSTEM_PRIVATE_CORELIB - public -#else - internal -#endif - sealed class ExcludeFromCodeCoverageAttribute : Attribute + public sealed class ExcludeFromCodeCoverageAttribute : Attribute { public ExcludeFromCodeCoverageAttribute() { } diff --git a/src/libraries/Common/src/System/Runtime/CompilerServices/IsExternalInit.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/IsExternalInit.cs index 0f1bb5d6672..0f1bb5d6672 100644 --- a/src/libraries/Common/src/System/Runtime/CompilerServices/IsExternalInit.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/IsExternalInit.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs new file mode 100644 index 00000000000..7a53ade8da8 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs @@ -0,0 +1,68 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +namespace System.Runtime.InteropServices +{ + /// <summary> + /// Attribute used to indicate a source generator should create a function for marshalling + /// arguments instead of relying on the runtime to generate an equivalent marshalling function at run-time. + /// </summary> + /// <remarks> + /// This attribute is meaningless if the source generator associated with it is not enabled. + /// The current built-in source generator only supports C# and only supplies an implementation when + /// applied to static, partial, non-generic methods. + /// </remarks> + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +#if SYSTEM_PRIVATE_CORELIB + public +#else + internal +#endif + sealed class LibraryImportAttribute : Attribute + { + /// <summary> + /// Initializes a new instance of the <see cref="LibraryImportAttribute"/>. + /// </summary> + /// <param name="libraryName">Name of the library containing the import.</param> + public LibraryImportAttribute(string libraryName) + { + LibraryName = libraryName; + } + + /// <summary> + /// Gets the name of the library containing the import. + /// </summary> + public string LibraryName { get; } + + /// <summary> + /// Gets or sets the name of the entry point to be called. + /// </summary> + public string? EntryPoint { get; set; } + + /// <summary> + /// Gets or sets how to marshal string arguments to the method. + /// </summary> + /// <remarks> + /// If this field is set to a value other than <see cref="StringMarshalling.Custom" />, + /// <see cref="StringMarshallingCustomType" /> must not be specified. + /// </remarks> + public StringMarshalling StringMarshalling { get; set; } + + /// <summary> + /// Gets or sets the <see cref="Type"/> used to control how string arguments to the method are marshalled. + /// </summary> + /// <remarks> + /// If this field is specified, <see cref="StringMarshalling" /> must not be specified + /// or must be set to <see cref="StringMarshalling.Custom" />. + /// </remarks> + public Type? StringMarshallingCustomType { get; set; } + + /// <summary> + /// Gets or sets whether the callee sets an error (SetLastError on Windows or errno + /// on other platforms) before returning from the attributed method. + /// </summary> + public bool SetLastError { get; set; } + } +} diff --git a/src/libraries/Common/src/System/Runtime/InteropServices/StringMarshalling.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StringMarshalling.cs index 36c6adfb441..50a099b41d3 100644 --- a/src/libraries/Common/src/System/Runtime/InteropServices/StringMarshalling.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StringMarshalling.cs @@ -9,7 +9,7 @@ namespace System.Runtime.InteropServices /// <summary> /// Specifies how strings should be marshalled for generated p/invokes /// </summary> -#if LIBRARYIMPORT_GENERATOR_TEST +#if SYSTEM_PRIVATE_CORELIB public #else internal diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj index f2f1c273e5d..467bf762702 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj @@ -27,7 +27,7 @@ <ItemGroup> <!-- Code included from System.Runtime.InteropServices --> - <Compile Include="$(CommonPath)System\Runtime\InteropServices\StringMarshalling.cs" Link="Production\StringMarshalling.cs" /> + <Compile Include="$(CoreLibSharedDir)System\Runtime\InteropServices\StringMarshalling.cs" Link="Production\StringMarshalling.cs" /> </ItemGroup> <ItemGroup> diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index eac47acf63d..72b9191fd88 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -484,6 +484,16 @@ namespace System.Runtime.InteropServices public LCIDConversionAttribute(int lcid) { } public int Value { get { throw null; } } } + [System.AttributeUsageAttribute(System.AttributeTargets.Method, AllowMultiple = false, Inherited=false)] + public sealed partial class LibraryImportAttribute : System.Attribute + { + public LibraryImportAttribute(string libraryName) { } + public string LibraryName { get { throw null; } } + public string? EntryPoint { get { throw null; } set { } } + public bool SetLastError { get { throw null; } set { }} + public System.Runtime.InteropServices.StringMarshalling StringMarshalling { get { throw null; } set { } } + public System.Type? StringMarshallingCustomType { get { throw null; } set { } } + } [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false, AllowMultiple=false)] public sealed partial class ManagedToNativeComInteropStubAttribute : System.Attribute { @@ -994,6 +1004,12 @@ namespace System.Runtime.InteropServices { protected StandardOleMarshalObject() { } } + public enum StringMarshalling + { + Custom = 0, + Utf8 = 1, + Utf16 = 2, + } [System.AttributeUsageAttribute(System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, AllowMultiple=false, Inherited=false)] public sealed partial class TypeIdentifierAttribute : System.Attribute { diff --git a/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/Ancillary.Interop.csproj b/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/Ancillary.Interop.csproj index 60e536023fb..710d935b82f 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/Ancillary.Interop.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/Ancillary.Interop.csproj @@ -11,9 +11,7 @@ </PropertyGroup> <ItemGroup> - <Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/LibraryImportAttribute.cs" Link="LibraryImportAttribute.cs" /> <Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs" Link="GeneratedMarshallingAttribute.cs" /> <Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/ArrayMarshaller.cs" Link="ArrayMarshaller.cs" /> - <Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/StringMarshalling.cs" Link="StringMarshalling.cs" /> </ItemGroup> </Project> diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/TestUtils.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/TestUtils.cs index cabfb327be4..f1d835ce585 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/TestUtils.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/TestUtils.cs @@ -183,7 +183,7 @@ namespace LibraryImportGenerator.UnitTests { // Include the assembly containing the new attribute and all of its references. // [TODO] Remove once the attribute has been added to the BCL - var attrAssem = typeof(LibraryImportAttribute).GetTypeInfo().Assembly; + var attrAssem = typeof(MarshalUsingAttribute).GetTypeInfo().Assembly; return MetadataReference.CreateFromFile(attrAssem.Location); } diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System.Runtime.InteropServices.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System.Runtime.InteropServices.Tests.csproj index 072080790a2..46d0d5d3a6e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System.Runtime.InteropServices.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System.Runtime.InteropServices.Tests.csproj @@ -48,6 +48,7 @@ <Compile Include="System\Runtime\InteropServices\IDispatchImplAttributeTests.cs" /> <Compile Include="System\Runtime\InteropServices\InterfaceTypeAttributeTests.cs" /> <Compile Include="System\Runtime\InteropServices\LCIDConversionAttributeTests.cs" /> + <Compile Include="System\Runtime\InteropServices\LibraryImportAttributeTests.cs" /> <Compile Include="System\Runtime\InteropServices\MarshalAsAttributeTests.cs" /> <Compile Include="System\Runtime\InteropServices\Marshal\Copy\ByteArrayTests.cs" /> <Compile Include="System\Runtime\InteropServices\Marshal\Copy\CharArrayTests.cs" /> diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/LibraryImportAttributeTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/LibraryImportAttributeTests.cs new file mode 100644 index 00000000000..1ebda2c8883 --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/LibraryImportAttributeTests.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Xunit; + +namespace System.Runtime.InteropServices.Tests +{ + public class LibraryImportAttributeTests + { + [Theory] + [InlineData(null)] + [InlineData("LibraryName")] + public void Ctor(string libraryName) + { + var attribute = new LibraryImportAttribute(libraryName); + Assert.Equal(libraryName, attribute.LibraryName); + } + } +} diff --git a/src/libraries/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj b/src/libraries/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj index bb5a72a9fd2..378b38abb93 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj +++ b/src/libraries/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj @@ -29,7 +29,7 @@ Link="Common\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs" /> </ItemGroup> <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'"> - <Compile Include="$(CommonPath)System\Collections\Generic\ReferenceEqualityComparer.cs" + <Compile Include="$(CoreLibSharedDir)System\Collections\Generic\ReferenceEqualityComparer.cs" Link="Common\System\Collections\Generic\ReferenceEqualityComparer.cs" /> </ItemGroup> <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'"> diff --git a/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.targets b/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.targets index f9e1d021b67..511d36441af 100644 --- a/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.targets +++ b/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.targets @@ -25,7 +25,7 @@ </ItemGroup> <ItemGroup> - <Compile Include="$(CommonPath)System\Runtime\CompilerServices\IsExternalInit.cs" Link="Common\System\Runtime\CompilerServices\IsExternalInit.cs" /> + <Compile Include="$(CoreLibSharedDir)System\Runtime\CompilerServices\IsExternalInit.cs" Link="Common\System\Runtime\CompilerServices\IsExternalInit.cs" /> <Compile Include="..\Common\JsonCamelCaseNamingPolicy.cs" Link="Common\System\Text\Json\JsonCamelCaseNamingPolicy.cs" /> <Compile Include="..\Common\JsonNamingPolicy.cs" Link="Common\System\Text\Json\JsonNamingPolicy.cs" /> <Compile Include="..\Common\JsonAttribute.cs" Link="Common\System\Text\Json\Serialization\JsonAttribute.cs" /> diff --git a/src/libraries/System.Text.Json/ref/System.Text.Json.csproj b/src/libraries/System.Text.Json/ref/System.Text.Json.csproj index a468f99d4e1..a1c4a020c16 100644 --- a/src/libraries/System.Text.Json/ref/System.Text.Json.csproj +++ b/src/libraries/System.Text.Json/ref/System.Text.Json.csproj @@ -14,7 +14,7 @@ </ItemGroup> <ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'"> - <Compile Include="$(CommonPath)System\Runtime\CompilerServices\IsExternalInit.cs" Link="Common\System\Runtime\CompilerServices\IsExternalInit.cs" /> + <Compile Include="$(CoreLibSharedDir)System\Runtime\CompilerServices\IsExternalInit.cs" /> <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMembersAttribute.cs" /> <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs" /> <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\RequiresUnreferencedCodeAttribute.cs" /> diff --git a/src/libraries/System.Text.Json/src/System.Text.Json.csproj b/src/libraries/System.Text.Json/src/System.Text.Json.csproj index 1b9fbb39d70..d3cbae4810f 100644 --- a/src/libraries/System.Text.Json/src/System.Text.Json.csproj +++ b/src/libraries/System.Text.Json/src/System.Text.Json.csproj @@ -309,8 +309,8 @@ System.Text.Json.Nodes.JsonValue</PackageDescription> <Compile Include="$(CommonPath)System\Obsoletions.cs" Link="Common\System\Obsoletions.cs" /> </ItemGroup> <ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'"> - <Compile Include="$(CommonPath)System\Collections\Generic\ReferenceEqualityComparer.cs" Link="Common\System\Collections\Generic\ReferenceEqualityComparer.cs" /> - <Compile Include="$(CommonPath)System\Runtime\CompilerServices\IsExternalInit.cs" Link="Common\System\Runtime\CompilerServices\IsExternalInit.cs" /> + <Compile Include="$(CoreLibSharedDir)System\Collections\Generic\ReferenceEqualityComparer.cs" /> + <Compile Include="$(CoreLibSharedDir)System\Runtime\CompilerServices\IsExternalInit.cs" /> <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicDependencyAttribute.cs" /> <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMembersAttribute.cs" /> <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs" /> diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj index a4e2bfd1d78..5c00e46fe34 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj @@ -206,7 +206,7 @@ <Compile Include="..\..\src\System\Text\Json\BitStack.cs" Link="BitStack.cs" /> </ItemGroup> <ItemGroup Condition="'$(TargetFramework)' != '$(NetCoreAppCurrent)'"> - <Compile Include="$(CommonPath)System\Runtime\CompilerServices\IsExternalInit.cs" Link="Common\System\Runtime\CompilerServices\IsExternalInit.cs" /> + <Compile Include="$(CoreLibSharedDir)System\Runtime\CompilerServices\IsExternalInit.cs" /> <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicDependencyAttribute.cs" /> <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs" /> </ItemGroup> diff --git a/src/libraries/System.Text.RegularExpressions/gen/System.Text.RegularExpressions.Generator.csproj b/src/libraries/System.Text.RegularExpressions/gen/System.Text.RegularExpressions.Generator.csproj index 8e910a1e325..ad113612a54 100644 --- a/src/libraries/System.Text.RegularExpressions/gen/System.Text.RegularExpressions.Generator.csproj +++ b/src/libraries/System.Text.RegularExpressions/gen/System.Text.RegularExpressions.Generator.csproj @@ -25,7 +25,7 @@ <ItemGroup> <!-- Common generator support --> <Compile Include="$(CommonPath)Roslyn\GetBestTypeByMetadataName.cs" Link="Common\Roslyn\GetBestTypeByMetadataName.cs" /> - <Compile Include="$(CommonPath)System\Runtime\CompilerServices\IsExternalInit.cs" Link="Common\System\Runtime\CompilerServices\IsExternalInit.cs" /> + <Compile Include="$(CoreLibSharedDir)System\Runtime\CompilerServices\IsExternalInit.cs" Link="Common\System\Runtime\CompilerServices\IsExternalInit.cs" /> <!-- Code included from System.Text.RegularExpressions --> <Compile Include="$(CommonPath)System\HexConverter.cs" Link="Production\HexConverter.cs" /> |