Skip to content

Commit

Permalink
Add MacOSX-case library filenames (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored Mar 13, 2024
1 parent ec6f567 commit c785c97
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions source/icu.net/NativeMethods/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ private enum LoadLibraryFlags : uint
private static IntPtr _IcuI18NLibHandle;

private static bool IsWindows => Platform.OperatingSystem == OperatingSystemType.Windows;
private static bool IsMac => Platform.OperatingSystem == OperatingSystemType.MacOSX;

private static IntPtr IcuCommonLibHandle
{
Expand Down Expand Up @@ -210,7 +211,11 @@ private static bool CheckDirectoryForIcuBinaries(string directory, string librar
return false;
}

var filePattern = IsWindows ? libraryName + "*.dll" : "lib" + libraryName + ".so.*";
var filePattern = IsWindows
? libraryName + "*.dll"
: IsMac
? "lib" + libraryName + ".*.dylib"
: "lib" + libraryName + ".so.*";
var files = Directory.EnumerateFiles(directory, filePattern).ToList();
Trace.WriteLineIf(Verbose, $"icu.net: {files.Count} files in '{directory}' match the pattern '{filePattern}'");
if (files.Count > 0)
Expand All @@ -220,6 +225,8 @@ private static bool CheckDirectoryForIcuBinaries(string directory, string librar
var filePath = files[0];
var version = IsWindows
? Path.GetFileNameWithoutExtension(filePath).Substring(5) // strip icuuc
: IsMac
? Path.GetFileNameWithoutExtension(filePath).Substring(9) // strip libicuuc.
: Path.GetFileName(filePath).Substring(12); // strip libicuuc.so.
Trace.WriteLineIf(Verbose, $"icu.net: Extracted version '{version}' from '{filePath}'");
if (int.TryParse(version, out var icuVersion))
Expand Down Expand Up @@ -333,7 +340,7 @@ private static IntPtr GetIcuLibHandle(string basename, int icuVersion)
}
else
{
var libName = $"lib{basename}.so.{icuVersion}";
var libName = IsMac ? $"lib{basename}.{icuVersion}.dylib" : $"lib{basename}.so.{icuVersion}";
libPath = string.IsNullOrEmpty(_IcuPath) ? libName : Path.Combine(_IcuPath, libName);

handle = dlopen(libPath, RTLD_NOW);
Expand Down

0 comments on commit c785c97

Please sign in to comment.