Skip to content

Commit 447bd86

Browse files
Merge branch '73378-macos-support' into 'main'
[#73378] Add support for macOS See merge request repositories/pyrenode3!36
2 parents 3892655 + 8f34e9a commit 447bd86

2 files changed

Lines changed: 51 additions & 12 deletions

File tree

.ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,14 @@ test-mono-build:
106106
- export PYRENODE_RUNTIME=mono
107107
- export PYRENODE_BUILD_DIR=$(pwd)/renode
108108
- *run_tests
109+
110+
test-macos-mono-build:
111+
stage: build
112+
tags: ['renode-macos']
113+
script:
114+
- *init_python
115+
- git clone https://github.com/antmicro/renode.git
116+
- pushd renode && ./build.sh && popd
117+
- export PYRENODE_RUNTIME=mono
118+
- export PYRENODE_BUILD_DIR=$(pwd)/renode
119+
- *run_tests

src/pyrenode3/loader.py

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,49 @@ def ensure_symlink(src, dst, relative=False, verbose=False):
3434
logging.warning(f"{dst.name} is not in the expected location. Created symlink.")
3535
logging.warning(f"{src} -> {dst}")
3636

37+
# Returns the runtime identifier (RID) of the current platform,
38+
# only handle targets Renode supports
39+
def get_RID():
40+
aarch64_names = set(("arm64", "aarch64"))
41+
if platform.machine() in aarch64_names:
42+
arch = "arm64"
43+
else:
44+
arch = "x64"
45+
kernel_name = platform.system()
46+
if kernel_name == "Linux":
47+
os = "linux"
48+
elif kernel_name == "Darwin":
49+
os = "osx"
50+
elif kernel_name == "Windows":
51+
os = "win"
52+
else:
53+
msg = "Operating system " + os + " not recognized"
54+
raise InitializationError(msg)
55+
return os + '-' + arch
56+
57+
def get_library_ext():
58+
kernel_name = platform.system()
59+
if kernel_name == "Linux":
60+
return ".so"
61+
elif kernel_name == "Darwin":
62+
return ".dylib"
63+
elif kernel_name == "Windows":
64+
return ".dll"
65+
else:
66+
msg = "Operating system " + os + " not recognize"
67+
raise InitializationError(msg)
68+
3769

3870
def ensure_additional_libs(renode_bin_dir):
3971
# libMono.Unix does not exists on Windows, so just return empty if we are on Windows
4072
if platform.system() == "Windows":
4173
return []
42-
# HACK: move libMonoPosixHelper.so to path where it is searched for
43-
bindll_dir = renode_bin_dir / "runtimes/linux-x64"
74+
# HACK: move libMonoPosixHelper to path where it is searched for
75+
bindll_dir = renode_bin_dir / "runtimes" / get_RID()
4476
# Updating to Mono.Posix changed the name of this file
4577
# so we check for the new one, and fall back on the old one if it is not found
46-
lib_new = "libMono.Unix.so"
47-
lib_old = "libMonoPosixHelper.so"
78+
lib_new = "libMono.Unix" + get_library_ext()
79+
lib_old = "libMonoPosixHelper" + get_library_ext()
4880
src_new = bindll_dir / "native" / lib_new
4981
src_old = bindll_dir / "native" / lib_old
5082

@@ -254,12 +286,8 @@ def from_net_bin(cls, path: "Union[str, pathlib.Path]"):
254286
# },
255287
# "Microsoft.VisualBasic.Core.dll": { ... },
256288
# }}}}}
257-
if platform.system() == "Windows":
258-
SYSTEM_RUNTIME = "runtimepack.Microsoft.NETCore.App.Runtime.win-x64"
259-
LIB_EXT = ".dll"
260-
else:
261-
SYSTEM_RUNTIME = "runtimepack.Microsoft.NETCore.App.Runtime.linux-x64"
262-
LIB_EXT = ".so"
289+
SYSTEM_RUNTIME = "runtimepack.Microsoft.NETCore.App.Runtime." + get_RID()
290+
LIB_EXT = get_library_ext()
263291

264292
deps = json.load(open(binaries / "Renode.deps.json", "rb"))
265293
target = deps["targets"][deps["runtimeTarget"]["name"]]
@@ -270,7 +298,7 @@ def from_net_bin(cls, path: "Union[str, pathlib.Path]"):
270298
system_dlls = list(dlls["runtime"])
271299
break
272300
else:
273-
tfm_full = "6.0.0"
301+
tfm_full = "8.0.0"
274302
system_dlls = [dll.name for dll in binaries.glob("*.dll")]
275303
logging.warning(f"Could not find {SYSTEM_RUNTIME} in deps.json. "
276304
f"Assuming framework version {tfm_full}.")
@@ -286,7 +314,7 @@ def from_net_bin(cls, path: "Union[str, pathlib.Path]"):
286314
if platform.system() == "Windows":
287315
ensure_symlink(renode_dir / "hostfxr.dll", binaries / "hostfxr.dll")
288316
else:
289-
ensure_symlink(renode_dir / "libhostfxr.so", binaries / "libhostfxr.so")
317+
ensure_symlink(renode_dir / ("libhostfxr" + LIB_EXT), binaries / ("libhostfxr" + LIB_EXT))
290318
ensure_symlink(binaries / "Renode.deps.json", runtime / "Microsoft.NETCore.App.deps.json", relative=True)
291319

292320
loader = cls()

0 commit comments

Comments
 (0)