Skip to content

Commit

Permalink
Reduce System.Data.Odbc build configurations (#92570)
Browse files Browse the repository at this point in the history
Contributes to #53900
  • Loading branch information
jkotas authored Sep 25, 2023
1 parent a644443 commit 20a3350
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ internal static partial class Interop
{
internal static partial class Libraries
{
internal const string Odbc32 = "libodbc.so.2";
internal const string MsQuic = "libmsquic.so";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ internal static partial class Libraries
// Duplicated from Android for Linux Bionic
internal const string Liblog = "liblog";

internal const string Odbc32 = "libodbc.so.2";
internal const string OpenLdap = "libldap-2.5.so.0";
internal const string MsQuic = "libmsquic.so";
}
Expand Down
1 change: 0 additions & 1 deletion src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ internal static partial class Libraries
internal const string CFNetworkLibrary = "/System/Library/Frameworks/CFNetwork.framework/CFNetwork";
internal const string libobjc = "/usr/lib/libobjc.dylib";
internal const string libproc = "/usr/lib/libproc.dylib";
internal const string Odbc32 = "libodbc.2.dylib";
internal const string OpenLdap = "libldap.dylib";
internal const string SystemConfigurationLibrary = "/System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration";
internal const string AppleCryptoNative = "libSystem.Security.Cryptography.Native.Apple";
Expand Down
38 changes: 38 additions & 0 deletions src/libraries/Common/src/Interop/Unix/Interop.Odbc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Reflection;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Libraries
{
internal const string Odbc32 = "libodbc";
}

internal static partial class Odbc
{
internal static string GetNativeLibraryName()
{
if (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || OperatingSystem.IsTvOS() || OperatingSystem.IsWatchOS())
{
return "libodbc.2.dylib";
}
return "libodbc.so.2";
}

static Odbc()
{
NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), (libraryName, assembly, searchPath) =>
{
if (libraryName == Libraries.Odbc32)
{
return NativeLibrary.Load(GetNativeLibraryName(), assembly, default);
}
return default;
});
}
}
}
13 changes: 4 additions & 9 deletions src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-freebsd;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-solaris;$(NetCoreAppCurrent)-linux;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)-freebsd;$(NetCoreAppPrevious)-illumos;$(NetCoreAppPrevious)-solaris;$(NetCoreAppPrevious)-linux;$(NetCoreAppPrevious)-osx;$(NetCoreAppPrevious)-ios;$(NetCoreAppPrevious)-tvos;$(NetCoreAppPrevious);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum)-freebsd;$(NetCoreAppMinimum)-linux;$(NetCoreAppMinimum)-osx;$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)-unix;$(NetCoreAppPrevious);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum)-unix;netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);CA2249;CA1838</NoWarn>
<EnableAOTAnalyzer>false</EnableAOTAnalyzer>
Expand Down Expand Up @@ -136,14 +136,9 @@ System.Data.Odbc.OdbcTransaction</PackageDescription>
Link="Common\System\Runtime\InteropServices\HandleRefMarshaller.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'linux' or '$(TargetPlatformIdentifier)' == 'freebsd' or '$(TargetPlatformIdentifier)' == 'illumos' or '$(TargetPlatformIdentifier)' == 'solaris'">
<Compile Include="$(CommonPath)Interop\Linux\Interop.Libraries.cs"
Link="Common\Interop\Linux\Interop.Libraries.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'osx' or '$(TargetPlatformIdentifier)' == 'ios' or '$(TargetPlatformIdentifier)' == 'tvos'">
<Compile Include="$(CommonPath)Interop\OSX\Interop.Libraries.cs"
Link="Common\Interop\OSX\Interop.Libraries.cs" />
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'unix'">
<Compile Include="$(CommonPath)Interop\Unix\Interop.Odbc.cs"
Link="Common\Interop\Unix\Interop.Odbc.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Data.Odbc/tests/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private static bool CheckOdbcIsAvailable() =>
#if TargetsWindows
!PlatformDetection.IsWindowsNanoServer && (!PlatformDetection.IsWindowsServerCore || Environment.Is64BitProcess);
#else
NativeLibrary.TryLoad(Interop.Libraries.Odbc32, out _);
NativeLibrary.TryLoad(Interop.Odbc.GetNativeLibraryName(), out _);
#endif
}
}
20 changes: 4 additions & 16 deletions src/libraries/System.Data.Odbc/tests/System.Data.Odbc.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-freebsd;$(NetCoreAppCurrent)-linux;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetFrameworkMinimum)</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetFrameworkMinimum)</TargetFrameworks>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
Expand All @@ -19,21 +19,9 @@
<Compile Include="TestCommon\CheckConnStrSetupFactAttribute.cs" />
<Compile Include="OdbcParameterTests.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != 'windows' and '$(TargetFrameworkIdentifier)' != '.NETFramework'">
<Compile Include="$(CommonPath)Interop\Unix\Interop.Libraries.cs"
Link="Common\Interop\Unix\Interop.Libraries.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'linux'">
<Compile Include="$(CommonPath)Interop\Linux\Interop.Libraries.cs"
Link="Common\Interop\Linux\Interop.Libraries.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'osx' or '$(TargetPlatformIdentifier)' == 'ios' or '$(TargetPlatformIdentifier)' == 'tvos'">
<Compile Include="$(CommonPath)Interop\OSX\Interop.Libraries.cs"
Link="Common\Interop\OSX\Interop.Libraries.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'freebsd'">
<Compile Include="$(CommonPath)Interop\FreeBSD\Interop.Libraries.cs"
Link="Common\Interop\FreeBSD\Interop.Libraries.cs" />
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'unix'">
<Compile Include="$(CommonPath)Interop\Unix\Interop.Odbc.cs"
Link="Common\Interop\Unix\Interop.Odbc.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows' or '$(TargetFrameworkIdentifier)' == '.NETFramework'">
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Expand Down

0 comments on commit 20a3350

Please sign in to comment.