polyplug-loaders-dotnet 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- polyplug_loaders_dotnet/__init__.py +86 -0
- polyplug_loaders_dotnet/_native/linux-x64/libpolyplug_dotnet.so +0 -0
- polyplug_loaders_dotnet/_native/macos-arm64/libpolyplug_dotnet.dylib +0 -0
- polyplug_loaders_dotnet/_native/windows-x64/polyplug_dotnet.dll +0 -0
- polyplug_loaders_dotnet-0.1.1.dist-info/METADATA +7 -0
- polyplug_loaders_dotnet-0.1.1.dist-info/RECORD +8 -0
- polyplug_loaders_dotnet-0.1.1.dist-info/WHEEL +5 -0
- polyplug_loaders_dotnet-0.1.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
""".NET loader registration for polyplug."""
|
|
2
|
+
|
|
3
|
+
import ctypes
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
import platform
|
|
7
|
+
from polyplug.runtime import Runtime
|
|
8
|
+
|
|
9
|
+
_lib = None
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _platform_id() -> str:
|
|
13
|
+
machine: str = platform.machine().lower()
|
|
14
|
+
if sys.platform == "linux":
|
|
15
|
+
if machine in ("x86_64", "amd64"):
|
|
16
|
+
return "linux-x64"
|
|
17
|
+
if machine == "aarch64":
|
|
18
|
+
return "linux-arm64"
|
|
19
|
+
elif sys.platform == "darwin":
|
|
20
|
+
if machine == "arm64":
|
|
21
|
+
return "macos-arm64"
|
|
22
|
+
if machine in ("x86_64", "amd64"):
|
|
23
|
+
return "macos-x64"
|
|
24
|
+
elif sys.platform == "win32":
|
|
25
|
+
if machine in ("x86_64", "amd64"):
|
|
26
|
+
return "windows-x64"
|
|
27
|
+
raise RuntimeError(f"polyplug: unsupported platform {sys.platform}/{machine}")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _lib_filename(base: str) -> str:
|
|
31
|
+
if sys.platform == "darwin":
|
|
32
|
+
return f"lib{base}.dylib"
|
|
33
|
+
if sys.platform == "win32":
|
|
34
|
+
return f"{base}.dll"
|
|
35
|
+
return f"lib{base}.so"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _resolve_lib_path(env_var: str, base: str) -> str:
|
|
39
|
+
# An explicit env override (set by the test/CI harness) always wins so the
|
|
40
|
+
# loader cdylib matches the freshly built tree.
|
|
41
|
+
override: str = os.environ.get(env_var, "")
|
|
42
|
+
if override and os.path.exists(override):
|
|
43
|
+
return override
|
|
44
|
+
# Native staged into the wheel under <package>/_native/<platform>/.
|
|
45
|
+
embedded: str = os.path.join(
|
|
46
|
+
os.path.dirname(__file__), "_native", _platform_id(), _lib_filename(base)
|
|
47
|
+
)
|
|
48
|
+
if os.path.exists(embedded):
|
|
49
|
+
return embedded
|
|
50
|
+
# Fall back to the bare soname on the system library path.
|
|
51
|
+
return _lib_filename(base)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _get_lib() -> ctypes.CDLL:
|
|
55
|
+
global _lib
|
|
56
|
+
if _lib is None:
|
|
57
|
+
lib_path: str = _resolve_lib_path("POLYPLUG_DOTNET_LIB", "polyplug_dotnet")
|
|
58
|
+
_lib = ctypes.CDLL(lib_path)
|
|
59
|
+
_lib.polyplug_dotnet_loader_create.restype = ctypes.c_void_p
|
|
60
|
+
_lib.polyplug_dotnet_loader_create.argtypes = [ctypes.c_void_p]
|
|
61
|
+
return _lib
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class _DotnetConfig(ctypes.Structure):
|
|
65
|
+
_fields_ = [
|
|
66
|
+
("min_framework_ptr", ctypes.c_char_p),
|
|
67
|
+
("min_framework_len", ctypes.c_size_t),
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
_RUNTIME_NAME: str = "dotnet"
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def register_dotnet_loader(runtime: Runtime, min_framework: str = "10.0") -> None:
|
|
75
|
+
"""Register the .NET loader with the runtime via HostApi.register_loader."""
|
|
76
|
+
lib: ctypes.CDLL = _get_lib()
|
|
77
|
+
framework_bytes: bytes = min_framework.encode("utf-8")
|
|
78
|
+
cfg = _DotnetConfig(framework_bytes, len(framework_bytes))
|
|
79
|
+
loader_ptr: int = lib.polyplug_dotnet_loader_create(ctypes.byref(cfg))
|
|
80
|
+
if not loader_ptr:
|
|
81
|
+
raise RuntimeError("polyplug: dotnet loader create failed")
|
|
82
|
+
|
|
83
|
+
runtime.register_loader(loader_ptr)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
__all__ = ["register_dotnet_loader"]
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
polyplug_loaders_dotnet/__init__.py,sha256=6Wkp4FsiKDFV5WwBV7HT_sflM79AnPYu5KcYeh2QYCE,2713
|
|
2
|
+
polyplug_loaders_dotnet/_native/linux-x64/libpolyplug_dotnet.so,sha256=y2mj6hj3CckEjXAasU18DmTbod9lcErEShWo4BSjmTA,988280
|
|
3
|
+
polyplug_loaders_dotnet/_native/macos-arm64/libpolyplug_dotnet.dylib,sha256=WakmEgxmfkuXuXr57sJsdKmmvItYS27j85Lpj6gnWDk,833296
|
|
4
|
+
polyplug_loaders_dotnet/_native/windows-x64/polyplug_dotnet.dll,sha256=0oTLbQd0lGT07Uv1_G0-yJELsWubRoyta0S7_vkwn68,939520
|
|
5
|
+
polyplug_loaders_dotnet-0.1.1.dist-info/METADATA,sha256=udfvB7UG3DU8jasLCzTmhxlq9L9fB1zbQLbTd8N-tYY,183
|
|
6
|
+
polyplug_loaders_dotnet-0.1.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
+
polyplug_loaders_dotnet-0.1.1.dist-info/top_level.txt,sha256=vkAnQmuaSXZuf520r0qSFYRzjUzVMr_TXIhIEdyRbRg,24
|
|
8
|
+
polyplug_loaders_dotnet-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
polyplug_loaders_dotnet
|