From ad51bd9e50be9db66662b017722cf2956b0566b9 Mon Sep 17 00:00:00 2001 From: "D. Ror" Date: Mon, 26 Feb 2024 16:20:28 -0500 Subject: [PATCH] Add MacOSX-case library filenames --- source/icu.net/NativeMethods/NativeMethods.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source/icu.net/NativeMethods/NativeMethods.cs b/source/icu.net/NativeMethods/NativeMethods.cs index 2f5788d4..75c0fd85 100644 --- a/source/icu.net/NativeMethods/NativeMethods.cs +++ b/source/icu.net/NativeMethods/NativeMethods.cs @@ -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 { @@ -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) @@ -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)) @@ -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);