Skip to content

Commit

Permalink
imp - prt - Migrated to delegates (pt. 1)
Browse files Browse the repository at this point in the history
---

We've updated all the necessary libraries (Terminaux, SpecProbe, and NativeLand) to use the new way of loading the native libraries.

This commit is not final, because we still need to ACTUALLY merge the p/invokes to the delegates so that Linux can cope with this situation.

---

Type: imp
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/2
  • Loading branch information
AptiviCEO committed Jul 27, 2024
1 parent 85e4be0 commit d45795e
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 81 deletions.
2 changes: 1 addition & 1 deletion BassBoom.Basolia/BassBoom.Basolia.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net48</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down
2 changes: 1 addition & 1 deletion BassBoom.Basolia/Format/AudioInfoTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using SpecProbe.Platform;
using SpecProbe.Software.Platform;
using BassBoom.Basolia.Enumerations;
using BassBoom.Native;

Expand Down
2 changes: 1 addition & 1 deletion BassBoom.Basolia/Format/FormatTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
using BassBoom.Native.Interop.Analysis;
using SpecProbe.Platform;
using SpecProbe.Software.Platform;
using BassBoom.Native;

namespace BassBoom.Basolia.Format
Expand Down
4 changes: 2 additions & 2 deletions BassBoom.Cli/BassBoom.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Terminaux" Version="4.3.1.3" />
<PackageReference Include="Terminaux.ResizeListener" Version="4.3.1.3" />
<PackageReference Include="Terminaux" Version="4.3.3" />
<PackageReference Include="Terminaux.ResizeListener" Version="4.3.3" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion BassBoom.Cli/CliBase/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
using BassBoom.Basolia.Format;
using BassBoom.Basolia.Playback;
using BassBoom.Cli.Tools;
using SpecProbe.Platform;
using SpecProbe.Software.Platform;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
6 changes: 3 additions & 3 deletions BassBoom.Native/BassBoom.Native.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net48</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down Expand Up @@ -33,8 +33,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NativeLand" Version="1.0.1" Condition="'$(TargetFramework)' == 'net48'" />
<PackageReference Include="SpecProbe.Software" Version="1.5.0" />
<PackageReference Include="NativeLand" Version="2.0.0.1" />
<PackageReference Include="SpecProbe.Software" Version="1.6.0.1" />
</ItemGroup>

</Project>
97 changes: 25 additions & 72 deletions BassBoom.Native/MpgNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using SpecProbe.Platform;

#if !NETCOREAPP
using SpecProbe.Software.Platform;
using NativeLand;
using NativeLand.Tools;
#endif

namespace BassBoom.Native
{
Expand Down Expand Up @@ -119,70 +115,39 @@ internal static void InitializeLibrary(string libPath, string libPathOut, string
string oldLibPathOut = out123LibPath;
mpg123LibPath = libPath;
out123LibPath = libPathOut;
#if NETCOREAPP
NativeLibrary.SetDllImportResolver(typeof(NativeInit).Assembly, ResolveLibrary);
#else
var bytesMpg = File.ReadAllBytes(mpg123LibPath);
var libManagerMpg = new LibraryManager(
new LibraryItem(Platform.Windows, Architecture.X86,
new LibraryFile("mpg123.dll", bytesMpg)),
new LibraryItem(Platform.Windows, Architecture.X64,
new LibraryFile("mpg123.dll", bytesMpg)),
new LibraryItem(Platform.Windows, Architecture.Arm,
new LibraryFile("mpg123.dll", bytesMpg)),
new LibraryItem(Platform.Windows, Architecture.Arm64,
new LibraryFile("mpg123.dll", bytesMpg)),
new LibraryItem(Platform.MacOS, Architecture.X64,
new LibraryFile("libmpg123.dylib", bytesMpg)),
new LibraryItem(Platform.MacOS, Architecture.Arm64,
new LibraryFile("libmpg123.dylib", bytesMpg)),
new LibraryItem(Platform.Linux, Architecture.X64,
new LibraryFile("libmpg123.so", bytesMpg)),
new LibraryItem(Platform.Linux, Architecture.X86,
new LibraryFile("libmpg123.so", bytesMpg)),
new LibraryItem(Platform.Linux, Architecture.Arm,
new LibraryFile("libmpg123.so", bytesMpg)),
new LibraryItem(Platform.Linux, Architecture.Arm64,
new LibraryFile("libmpg123.so", bytesMpg)));
var bytesOut = File.ReadAllBytes(out123LibPath);
new LibraryItem(Platform.Windows, Architecture.X86, new LibraryFile(mpg123LibPath)),
new LibraryItem(Platform.Windows, Architecture.X64, new LibraryFile(mpg123LibPath)),
new LibraryItem(Platform.Windows, Architecture.Arm, new LibraryFile(mpg123LibPath)),
new LibraryItem(Platform.Windows, Architecture.Arm64, new LibraryFile(mpg123LibPath)),
new LibraryItem(Platform.MacOS, Architecture.X64, new LibraryFile(mpg123LibPath)),
new LibraryItem(Platform.MacOS, Architecture.Arm64, new LibraryFile(mpg123LibPath)),
new LibraryItem(Platform.Linux, Architecture.X64, new LibraryFile(mpg123LibPath)),
new LibraryItem(Platform.Linux, Architecture.X86, new LibraryFile(mpg123LibPath)),
new LibraryItem(Platform.Linux, Architecture.Arm, new LibraryFile(mpg123LibPath)),
new LibraryItem(Platform.Linux, Architecture.Arm64, new LibraryFile(mpg123LibPath)));
var libManagerOut = new LibraryManager(
new LibraryItem(Platform.Windows, Architecture.X86,
new LibraryFile("out123.dll", bytesOut)),
new LibraryItem(Platform.Windows, Architecture.X64,
new LibraryFile("out123.dll", bytesOut)),
new LibraryItem(Platform.Windows, Architecture.Arm,
new LibraryFile("out123.dll", bytesOut)),
new LibraryItem(Platform.Windows, Architecture.Arm64,
new LibraryFile("out123.dll", bytesOut)),
new LibraryItem(Platform.MacOS, Architecture.X64,
new LibraryFile("libout123.dylib", bytesOut)),
new LibraryItem(Platform.MacOS, Architecture.Arm64,
new LibraryFile("libout123.dylib", bytesOut)),
new LibraryItem(Platform.Linux, Architecture.X64,
new LibraryFile("libout123.so", bytesOut)),
new LibraryItem(Platform.Linux, Architecture.X86,
new LibraryFile("libout123.so", bytesOut)),
new LibraryItem(Platform.Linux, Architecture.Arm,
new LibraryFile("libout123.so", bytesOut)),
new LibraryItem(Platform.Linux, Architecture.Arm64,
new LibraryFile("libout123.so", bytesOut)));
new LibraryItem(Platform.Windows, Architecture.X86, new LibraryFile(out123LibPath)),
new LibraryItem(Platform.Windows, Architecture.X64, new LibraryFile(out123LibPath)),
new LibraryItem(Platform.Windows, Architecture.Arm, new LibraryFile(out123LibPath)),
new LibraryItem(Platform.Windows, Architecture.Arm64, new LibraryFile(out123LibPath)),
new LibraryItem(Platform.MacOS, Architecture.X64, new LibraryFile(out123LibPath)),
new LibraryItem(Platform.MacOS, Architecture.Arm64, new LibraryFile(out123LibPath)),
new LibraryItem(Platform.Linux, Architecture.X64, new LibraryFile(out123LibPath)),
new LibraryItem(Platform.Linux, Architecture.X86, new LibraryFile(out123LibPath)),
new LibraryItem(Platform.Linux, Architecture.Arm, new LibraryFile(out123LibPath)),
new LibraryItem(Platform.Linux, Architecture.Arm64, new LibraryFile(out123LibPath)));
if (PlatformHelper.IsOnWindows())
{
var bytesWinpthread = File.ReadAllBytes(winpthreadsLibPath);
var libManagerWinpthread = new LibraryManager(
new LibraryItem(Platform.Windows, Architecture.X86,
new LibraryFile("libwinpthread-1.dll", bytesWinpthread)),
new LibraryItem(Platform.Windows, Architecture.X64,
new LibraryFile("libwinpthread-1.dll", bytesWinpthread)),
new LibraryItem(Platform.Windows, Architecture.Arm,
new LibraryFile("libwinpthread-1.dll", bytesWinpthread)),
new LibraryItem(Platform.Windows, Architecture.Arm64,
new LibraryFile("libwinpthread-1.dll", bytesWinpthread)));
new LibraryItem(Platform.Windows, Architecture.X86, new LibraryFile(winpthreadsLibPath)),
new LibraryItem(Platform.Windows, Architecture.X64, new LibraryFile(winpthreadsLibPath)),
new LibraryItem(Platform.Windows, Architecture.Arm, new LibraryFile(winpthreadsLibPath)),
new LibraryItem(Platform.Windows, Architecture.Arm64, new LibraryFile(winpthreadsLibPath)));
libManagerWinpthread.LoadNativeLibrary();
}
libManagerMpg.LoadNativeLibrary();
libManagerOut.LoadNativeLibrary();
#endif
string libPluginsPath = Path.GetDirectoryName(mpg123LibPath) + "/plugins/";
if (PlatformHelper.IsOnWindows())
Environment.SetEnvironmentVariable("MPG123_MODDIR", libPluginsPath);
Expand Down Expand Up @@ -222,18 +187,6 @@ internal static void InitializeLibrary(string libPath, string libPathOut, string
}
}

#if NETCOREAPP
private static nint ResolveLibrary(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
{
nint libHandle = nint.Zero;
if (libraryName == LibraryName)
libHandle = NativeLibrary.Load(mpg123LibPath);
else if (libraryName == LibraryNameOut)
libHandle = NativeLibrary.Load(out123LibPath);
return libHandle;
}
#endif

internal static string GetAppropriateMpg123LibraryPath() =>
GetAppropriateMpg123LibraryPath(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));

Expand Down

0 comments on commit d45795e

Please sign in to comment.