Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MacOSX-case library filenames #188

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading