Skip to content

Commit

Permalink
remove clang installation
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Sep 27, 2023
1 parent 648cb4c commit 340e5e1
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 46 deletions.
4 changes: 1 addition & 3 deletions multiversx_sdk_cli/cli_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def setup_parser(subparsers: Any) -> Any:
sub = cli_shared.add_command_subparser(subparsers, "deps", "install", "Install dependencies or multiversx-sdk modules.")
sub.add_argument("name", choices=choices, help="the dependency to install")
sub.add_argument("--overwrite", action="store_true", default=False, help="whether to overwrite an existing installation")
sub.add_argument("--tag", help="the tag or version to install")
sub.set_defaults(func=install)

sub = cli_shared.add_command_subparser(subparsers, "deps", "check", "Check whether a dependency is installed.")
Expand All @@ -30,9 +29,8 @@ def setup_parser(subparsers: Any) -> Any:

def install(args: Any):
name: str = args.name
tag: str = args.tag
overwrite: bool = args.overwrite
dependencies.install_module(name, tag, overwrite)
dependencies.install_module(name, overwrite)


def check(args: Any):
Expand Down
4 changes: 0 additions & 4 deletions multiversx_sdk_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ def get_defaults() -> Dict[str, Any]:
"dependencies.vmtools.urlTemplate.linux": "https://github.com/multiversx/mx-chain-vm-go/archive/{TAG}.tar.gz",
"dependencies.vmtools.urlTemplate.osx": "https://github.com/multiversx/mx-chain-vm-go/archive/{TAG}.tar.gz",
"dependencies.vmtools.urlTemplate.windows": "https://github.com/multiversx/mx-chain-vm-go/archive/{TAG}.tar.gz",
"dependencies.llvm.tag": "v9-19feb",
# ide.elrond.com will be removed, TBD if clang will still be downloaded
"dependencies.llvm.urlTemplate.linux": "https://ide.elrond.com/vendor-llvm/{TAG}/linux-amd64.tar.gz?t=19feb",
"dependencies.llvm.urlTemplate.osx": "https://ide.elrond.com/vendor-llvm/{TAG}/darwin-amd64.tar.gz?t=19feb",
"dependencies.rust.tag": "nightly-2023-05-26",
"dependencies.golang.resolution": "SDK",
"dependencies.golang.tag": "go1.20.7",
Expand Down
23 changes: 4 additions & 19 deletions multiversx_sdk_cli/dependencies/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
from multiversx_sdk_cli import config, errors
from multiversx_sdk_cli.dependencies.modules import (DependencyModule,
GolangModule, Rust,
StandaloneModule,
TestWalletsModule,
VMToolsModule)

logger = logging.getLogger("install")


def install_module(key: str, tag: str = "", overwrite: bool = False):
def install_module(key: str, overwrite: bool = False):

Check warning on line 14 in multiversx_sdk_cli/dependencies/install.py

View workflow job for this annotation

GitHub Actions / runner / mypy

[mypy] reported by reviewdog 🐶 "install_module" defined here Raw Output: /home/runner/work/mx-sdk-py-cli/mx-sdk-py-cli/multiversx_sdk_cli/dependencies/install.py:14:1: note: "install_module" defined here
if key == 'all':
modules = _get_implicitly_installable_deps()
modules = _get_all_deps()
else:
modules = [get_module_by_key(key)]

for module in modules:
module.install(tag, overwrite)
module.install(overwrite)


def get_module_directory(key: str) -> Path:
Expand Down Expand Up @@ -49,24 +48,10 @@ def get_deps_dict() -> Dict[str, DependencyModule]:


def _get_all_deps() -> List[DependencyModule]:
return _get_explicitly_installable_deps() + _get_implicitly_installable_deps()


def _get_explicitly_installable_deps() -> List[DependencyModule]:
return [
StandaloneModule(key="llvm", aliases=["clang", "cpp"]),
Rust(key="rust"),
GolangModule(key="golang")
]


def _get_implicitly_installable_deps() -> List[DependencyModule]:
# See: https://github.com/multiversx/mx-sdk-py-cli/pull/55

return [
GolangModule(key="golang"),
VMToolsModule(key="vmtools"),
StandaloneModule(key="mx_chain_go", repo_name="mx-chain-go", organisation="multiversx"),
StandaloneModule(key="mx_chain_proxy_go", repo_name="mx-chain-proxy-go", organisation="multiversx"),
TestWalletsModule(key="testwallets")
]

Expand Down
24 changes: 9 additions & 15 deletions multiversx_sdk_cli/dependencies/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def __init__(self, key: str, aliases: List[str] = []):
def get_directory(self, tag: str) -> Path:
raise NotImplementedError()

def install(self, tag: str, overwrite: bool) -> None:
# Fallback to default tag if not provided
tag = tag or config.get_dependency_tag(self.key)
def install(self, overwrite: bool) -> None:
# We install the default tag
tag = config.get_dependency_tag(self.key)

if tag == 'latest':
tag = self.get_latest_release()
Expand Down Expand Up @@ -267,10 +267,11 @@ def is_installed(self, tag: str) -> bool:
dependencies = [which_rustc, which_cargo, which_sc_meta, which_wasm_opt, which_twiggy]
return all(dependency is not None for dependency in dependencies)

def install(self, tag: str, overwrite: bool) -> None:
# Fallback to default tag if not provided
tag = tag or config.get_dependency_tag(self.key)
def install(self, overwrite: bool) -> None:
module = dependencies.get_module_by_key("rust")
tag: str = config.get_dependency_tag(module.key)

show_warning(f"We recommend using rust {tag}. If you'd like to overwrite your current version please run `mxpy deps install rust --overwrite`.")
logger.info(f"install: key={self.key}, tag={tag}, overwrite={overwrite}")

if overwrite:
Expand Down Expand Up @@ -343,15 +344,8 @@ def _is_installed_and_set_to_nightly(self) -> bool:
is_rust_installed = self.is_installed("")

if not is_rust_installed:
return is_rust_installed
else:
self._recommend_default_rust_version()
return True

def _recommend_default_rust_version(self):
module = dependencies.get_module_by_key("rust")
default_tag: str = config.get_dependency_tag(module.key)
show_warning(f"We recommend using rust {default_tag}. If you'd like to overwrite your current version please run `mxpy deps install rust --overwrite`.")
return False
return True

def get_directory(self, tag: str) -> Path:
tools_folder = workstation.get_tools_folder()
Expand Down
2 changes: 2 additions & 0 deletions multiversx_sdk_cli/projects/project_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def clean(self):
def _ensure_dependencies_installed(self):
module_keys = self.get_dependencies()
for module_key in module_keys:
if module_key == "":
continue
dependencies.install_module(module_key)

def get_dependencies(self) -> List[str]:
Expand Down
9 changes: 8 additions & 1 deletion multiversx_sdk_cli/projects/project_clang.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import logging
import subprocess
import sys
from os import path
from pathlib import Path
from typing import List

from multiversx_sdk_cli import dependencies, errors, myprocess, utils
from multiversx_sdk_cli.projects.project_base import Project, rename_wasm_files
from multiversx_sdk_cli.projects.shared import \
are_clang_and_cpp_dependencies_installed

logger = logging.getLogger('ProjectClang')

Expand All @@ -26,6 +29,10 @@ def perform_build(self):
self.file_output = self.unit.with_suffix('.wasm')

try:
is_installed = are_clang_and_cpp_dependencies_installed()
if not is_installed:
sys.exit(1)

self.do_clang()
self.do_llvm_link()
self.do_llc()
Expand Down Expand Up @@ -151,4 +158,4 @@ def get_source_files_from_folder(self):
return list(map(str, self.path.rglob('*.c')))

def get_dependencies(self):
return ['llvm']
return [""]
13 changes: 10 additions & 3 deletions multiversx_sdk_cli/projects/project_cpp.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import logging
import os
from pathlib import Path
import subprocess
import sys
from os import path
from pathlib import Path
from typing import List

from multiversx_sdk_cli import dependencies, errors, myprocess, utils
from multiversx_sdk_cli.projects.project_base import Project, rename_wasm_files
from multiversx_sdk_cli.projects.shared import \
are_clang_and_cpp_dependencies_installed

logger = logging.getLogger("ProjectCpp")

Expand All @@ -23,6 +26,10 @@ def perform_build(self):
self.file_export = self.unit.with_suffix(".export")

try:
is_installed = are_clang_and_cpp_dependencies_installed()
if not is_installed:
sys.exit(1)

self._do_clang()
self._do_llc()
self._do_wasm()
Expand Down Expand Up @@ -87,15 +94,15 @@ def _do_after_build_custom(self) -> List[Path]:
os.remove(source_file.with_suffix(".wasm"))
os.remove(source_file.with_suffix(".ll"))
os.remove(source_file.with_suffix(".o"))

paths = rename_wasm_files([output_wasm_file], self.options.get("wasm-name"))
return paths

def _get_llvm_path(self):
return dependencies.get_module_directory("llvm")

def get_dependencies(self):
return ["llvm"]
return [""]


class CppBuildConfiguration:
Expand Down
2 changes: 1 addition & 1 deletion multiversx_sdk_cli/projects/project_rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def check_if_sc_meta_is_installed(self):
which_sc_meta = shutil.which("sc-meta")

if which_sc_meta is None:
raise errors.KnownError("'sc-meta' is not installed. Run 'cargo install multiversx-sc-meta' then try again.")
raise errors.KnownError("'sc-meta' is not installed. Install it manually or simply run `mxpy deps install rust --overwrite` then try again.")

def run_meta(self):
self.check_if_sc_meta_is_installed()
Expand Down
32 changes: 32 additions & 0 deletions multiversx_sdk_cli/projects/shared.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import logging
import shutil
from pathlib import Path

from multiversx_sdk_cli.ux import show_critical_error

logger = logging.getLogger("projects.shared")


def is_source_clang(directory: Path) -> bool:
return _directory_contains_file(directory, ".c")
Expand All @@ -22,3 +28,29 @@ def _directory_contains_file(directory: Path, name_suffix: str) -> bool:
if str(file).lower().endswith(name_suffix.lower()):
return True
return False


def are_clang_and_cpp_dependencies_installed() -> bool:
which_clang = shutil.which("clang")
which_llc = shutil.which("llc")
which_wasm_ld = shutil.which("wasm-ld")
which_llvm_link = shutil.which("llvm-link")

logger.info(f"which_clang: {which_clang}")
logger.info(f"which_llc: {which_llc}")
logger.info(f"which_wasm_ld: {which_wasm_ld}")
logger.info(f"which_llvm_link: {which_llvm_link}")

dependencies = [which_clang, which_llc, which_wasm_ld, which_llvm_link]
is_installed = all(dependency is not None for dependency in dependencies)
if is_installed:
return True

message = """
`clang` is not installed. Please install it manually, then try again.
How to install on Ubuntu: https://linux.how2shout.com/how-to-install-clang-on-ubuntu-linux/
How to install on MacOS: https://www.incredibuild.com/integrations/clang
For more details check out this page: https://clang.llvm.org/get_started.html"""

show_critical_error(message)
return False

0 comments on commit 340e5e1

Please sign in to comment.