Skip to content

Commit b4e1051

Browse files
committed
Address eserscor review feedback: add debug logging, tighten shell guard, fix brace style
1 parent 09ccd47 commit b4e1051

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.shared.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -932,21 +932,30 @@ private static IntPtr DllImportResolver(string libraryName, Assembly assembly, D
932932
// Probe the specific RID first, then common fallbacks for the current OS
933933
string[] ridsToTry;
934934
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
935+
{
935936
ridsToTry = new[] { rid, "win-x64", "win-arm64" };
937+
}
936938
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
939+
{
937940
ridsToTry = new[] { rid, "linux-x64", "linux-arm64" };
941+
}
938942
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
943+
{
939944
// We no longer provide osx-x64 in official package since 1.24.
940945
// However, we keep it in the list for build-from-source users.
941946
ridsToTry = new[] { rid, "osx-arm64", "osx-x64" };
947+
}
942948
else
949+
{
943950
ridsToTry = new[] { rid };
951+
}
944952

945953
foreach (var tryRid in ridsToTry)
946954
{
947955
string probePath = System.IO.Path.Combine(assemblyDir, "runtimes", tryRid, "native", mappedName);
948956
if (System.IO.File.Exists(probePath) && NativeLibrary.TryLoad(probePath, assembly, searchPath, out handle))
949957
{
958+
LogLibLoad($"[DllImportResolver] Loaded {mappedName} from: {probePath}");
950959
return handle;
951960
}
952961
}
@@ -959,26 +968,36 @@ private static IntPtr DllImportResolver(string libraryName, Assembly assembly, D
959968
string probePath = System.IO.Path.Combine(baseDir, mappedName);
960969
if (NativeLibrary.TryLoad(probePath, assembly, searchPath, out handle))
961970
{
971+
LogLibLoad($"[DllImportResolver] Loaded {mappedName} from: {probePath}");
962972
return handle;
963973
}
964974

965975
string rid = RuntimeInformation.RuntimeIdentifier;
966976
probePath = System.IO.Path.Combine(baseDir, "runtimes", rid, "native", mappedName);
967977
if (NativeLibrary.TryLoad(probePath, assembly, searchPath, out handle))
968978
{
979+
LogLibLoad($"[DllImportResolver] Loaded {mappedName} from: {probePath}");
969980
return handle;
970981
}
971982
}
972983

973-
#if DEBUG
974-
System.Console.WriteLine($"[DllImportResolver] Failed loading {mappedName} (RID: {RuntimeInformation.RuntimeIdentifier}, Assembly: {assemblyLocation})");
975-
#endif
984+
LogLibLoad($"[DllImportResolver] Failed loading {mappedName} (RID: {RuntimeInformation.RuntimeIdentifier}, Assembly: {assemblyLocation})");
985+
976986
}
977987
}
978988

979989
// Fall back to default resolution
980990
return IntPtr.Zero;
981991
}
992+
993+
private static void LogLibLoad(string message)
994+
{
995+
System.Diagnostics.Trace.WriteLine(message);
996+
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ORT_LOADER_VERBOSITY")))
997+
{
998+
Console.WriteLine(message);
999+
}
1000+
}
9821001
#endif
9831002

9841003
[DllImport(NativeLib.DllName, CharSet = CharSet.Ansi)]

tools/ci_build/github/azure-pipelines/nuget/templates/test_macos.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ stages:
7676
DisableContribOps: $(DisableContribOps)
7777
DisableMlOps: $(DisableMlOps)
7878
IsReleaseBuild: $(IsReleaseBuild)
79+
ORT_LOADER_VERBOSITY: 1

tools/ci_build/github/linux/copy_strip_binary.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ then
3232
# because the versioned library is excluded by the nuspec generation script.
3333
# We explicitly overwrite the symlink with the real file to ensure 'nuget pack' (especially on Windows)
3434
# doesn't pack an empty/broken symlink.
35-
if [[ "$LIB_NAME" != "libonnxruntime.dylib" && -L "$BINARY_DIR/$ARTIFACT_NAME/lib/libonnxruntime.dylib" ]]; then
35+
# Only applies to versioned libonnxruntime libraries (e.g. libonnxruntime.1.24.0.dylib).
36+
if [[ "$LIB_NAME" =~ ^libonnxruntime\..*\.dylib$ && -L "$BINARY_DIR/$ARTIFACT_NAME/lib/libonnxruntime.dylib" ]]; then
3637
rm "$BINARY_DIR/$ARTIFACT_NAME/lib/libonnxruntime.dylib"
3738
cp "$BINARY_DIR/$ARTIFACT_NAME/lib/$LIB_NAME" "$BINARY_DIR/$ARTIFACT_NAME/lib/libonnxruntime.dylib"
3839
fi

0 commit comments

Comments
 (0)