Skip to content

Commit f4262b2

Browse files
committed
Simplify the main functions a bit, allow different hostfxr versions
1 parent 35a5718 commit f4262b2

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

clr_loader/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ def __getitem__(self, path):
5050
return self.get_assembly(path)
5151

5252

53-
def get_mono(cls, domain=None):
53+
def get_mono(domain=None):
5454
from .mono import Mono
5555

5656
impl = Mono(domain=domain)
57-
return cls(impl)
57+
return Runtime(impl)
5858

5959

60-
def get_coreclr(cls, runtime_config, dotnet_root=None):
60+
def get_coreclr(runtime_config, dotnet_root=None):
6161
from .hostfxr import HostFxr
6262

6363
impl = HostFxr(runtime_config=runtime_config, dotnet_root=dotnet_root)
64-
return cls(impl)
64+
return Runtime(impl)
6565

6666

67-
def get_netfx(cls, name=None, config_file=None):
67+
def get_netfx(name=None, config_file=None):
6868
from .netfx import NetFx
6969

7070
impl = NetFx(name=name, config_file=config_file)
71-
return cls(impl)
71+
return Runtime(impl)

clr_loader/ffi/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import sys
1+
import glob
22
import os
33
import shutil
4+
import sys
45

56
import cffi
67

@@ -21,13 +22,16 @@ def load_coreclr(runtime):
2122

2223

2324
def load_hostfxr(dotnet_root):
24-
hostfxr_version = "3.0.0"
2525
hostfxr_name = _get_dll_name("hostfxr")
26-
hostfxr_path = os.path.join(
27-
dotnet_root, "host", "fxr", hostfxr_version, hostfxr_name
28-
)
26+
hostfxr_path = os.path.join(dotnet_root, "host", "fxr", "3.*", hostfxr_name)
27+
28+
for hostfxr_path in reversed(sorted(glob.glob(hostfxr_path))):
29+
try:
30+
return ffi.dlopen(hostfxr_path)
31+
except Exception:
32+
pass
2933

30-
return ffi.dlopen(hostfxr_path)
34+
raise RuntimeError(f"Could not find a suitable hostfxr library in {dotnet_root}")
3135

3236

3337
def load_mono(path=None, gc=None):

0 commit comments

Comments
 (0)