Skip to content

Commit

Permalink
Fix link between cmd and shared libraries (MacOS).
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Jan 31, 2024
1 parent e0352bb commit b7d0f2b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
31 changes: 30 additions & 1 deletion multiversx_sdk_cli/localnet/step_build_software.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,13 +23,15 @@ 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...")

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...")
Expand Down Expand Up @@ -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
])
2 changes: 1 addition & 1 deletion multiversx_sdk_cli/localnet/step_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions multiversx_sdk_cli/workstation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def is_windows():
return get_platform() == "windows"


def is_osx():
return get_platform() == "osx"


def get_platform():
platforms = {
"linux": "linux",
Expand Down

0 comments on commit b7d0f2b

Please sign in to comment.