From b7d0f2bf4df5331a3db60a579a31826c42bd7e28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 31 Jan 2024 23:40:11 +0200 Subject: [PATCH] Fix link between cmd and shared libraries (MacOS). --- .../localnet/step_build_software.py | 31 ++++++++++++++++++- multiversx_sdk_cli/localnet/step_start.py | 2 +- multiversx_sdk_cli/workstation.py | 4 +++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/multiversx_sdk_cli/localnet/step_build_software.py b/multiversx_sdk_cli/localnet/step_build_software.py index 5665cf05..5ec67f89 100644 --- a/multiversx_sdk_cli/localnet/step_build_software.py +++ b/multiversx_sdk_cli/localnet/step_build_software.py @@ -3,7 +3,7 @@ from pathlib import Path from typing import Dict, List -from multiversx_sdk_cli import dependencies, utils +from multiversx_sdk_cli import dependencies, utils, workstation from multiversx_sdk_cli.errors import KnownError from multiversx_sdk_cli.localnet import libraries from multiversx_sdk_cli.localnet.config_root import ConfigRoot @@ -23,6 +23,7 @@ def build(configfile: Path, software_components: List[str]): cmd_node = config.software.mx_chain_go.get_cmd_node_folder() _do_build(cmd_node, golang_env) _copy_wasmer_libs(config, cmd_node) + _fix_link_between_cmd_and_shared_libraries(cmd_node / "node") if "seednode" in software_components: logger.info("Building seednode...") @@ -30,6 +31,7 @@ def build(configfile: Path, software_components: List[str]): cmd_seednode = config.software.mx_chain_go.get_cmd_seednode_folder() _do_build(cmd_seednode, golang_env) _copy_wasmer_libs(config, cmd_seednode) + _fix_link_between_cmd_and_shared_libraries(cmd_seednode / "seednode") if "proxy" in software_components: logger.info("Building proxy...") @@ -61,3 +63,30 @@ def _get_chain_vm_go_folder_name(config: ConfigRoot) -> str: line = [line for line in lines if "github.com/multiversx/mx-chain-vm-go" in line][0] parts = line.split() return f"{parts[0]}@{parts[1]}" + + +def _fix_link_between_cmd_and_shared_libraries(cmd_path: Path): + if not workstation.is_osx(): + return + + cmd_folder = cmd_path.parent.resolve() + libs = list(cmd_folder.glob("*.dylib")) + libs = [shared_lib.resolve() for shared_lib in libs] + + for shared_lib in libs: + logger.debug(f"Patching {shared_lib}") + + subprocess.check_call([ + "install_name_tool", + "-id", + f"@rpath/{shared_lib.name}", + shared_lib + ]) + + # Also patch the executable + subprocess.check_call([ + "install_name_tool", + "-add_rpath", + "@loader_path", + cmd_path + ]) diff --git a/multiversx_sdk_cli/localnet/step_start.py b/multiversx_sdk_cli/localnet/step_start.py index 14491576..11dd41eb 100644 --- a/multiversx_sdk_cli/localnet/step_start.py +++ b/multiversx_sdk_cli/localnet/step_start.py @@ -135,7 +135,7 @@ async def run(args: List[str], cwd: Path, delay: int = 0): if workstation.is_linux(): env["LD_LIBRARY_PATH"] = str(cwd) else: - # For MacOS, libwasmer is directly found near the binary (no workaround needed) + # For MacOS, dylibs are directly found near the binary (no workaround needed) pass process = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, diff --git a/multiversx_sdk_cli/workstation.py b/multiversx_sdk_cli/workstation.py index 01996d9d..af1b5142 100644 --- a/multiversx_sdk_cli/workstation.py +++ b/multiversx_sdk_cli/workstation.py @@ -18,6 +18,10 @@ def is_windows(): return get_platform() == "windows" +def is_osx(): + return get_platform() == "osx" + + def get_platform(): platforms = { "linux": "linux",