-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Install rust globally #331
Changes from 26 commits
a5b0c84
7250ffa
69fba5e
0bb5667
5295378
2845d07
6906afa
cad2cbd
47c897e
7ef887f
6c22bac
e9542fe
67defe7
45e9698
362cb9b
edb1c59
0c9aaa9
d7681dd
87df9d4
84ce195
b3c6a0c
3cbff95
c597e34
485bfaf
d5999e9
837b794
39f1b77
177d263
648cb4c
340e5e1
fc8609a
8eea743
ad585ea
851bd30
d2af8f5
d8bb7a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,53 +5,54 @@ name: build | |
|
||
on: | ||
pull_request: | ||
branches: [ main, feat/* ] | ||
branches: [main, feat/*] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: Build and Test mxpy for ${{ matrix.os }}, python ${{ matrix.python-version }} | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest] | ||
python-version: [3.8, 3.11] | ||
python-version: [3.11] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python3 -m pip install --upgrade pip | ||
pip3 install -r requirements.txt | ||
pip3 install pytest | ||
- name: Install libtinfo5 | ||
if: ${{ matrix.os != 'macos-latest' }} | ||
run: | | ||
sudo apt update | ||
sudo apt install -y libtinfo5 | ||
- name: Set github_api_token | ||
run: | | ||
mkdir ~/multiversx-sdk | ||
export PYTHONPATH=. | ||
python3 -m multiversx_sdk_cli.cli config new test | ||
python3 -m multiversx_sdk_cli.cli config set github_api_token ${{ secrets.GITHUB_TOKEN }} | ||
- name: Setup test dependencies | ||
run: | | ||
python3 -m multiversx_sdk_cli.cli deps install testwallets | ||
python3 -m multiversx_sdk_cli.cli deps install wasm-opt | ||
- name: Run unit tests | ||
run: | | ||
export PYTHONPATH=. | ||
pytest . | ||
- name: Run CLI tests | ||
run: | | ||
python3 -m multiversx_sdk_cli.cli config set dependencies.vmtools.tag v1.4.60 | ||
cd ./multiversx_sdk_cli/tests | ||
source ./test_cli_contracts.sh && testAll || return 1 | ||
source ./test_cli_dns.sh && testOffline || return 1 | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python3 -m pip install --upgrade pip | ||
pip3 install -r requirements.txt | ||
pip3 install pytest | ||
- name: Install libtinfo5 | ||
if: ${{ matrix.os != 'macos-latest' }} | ||
run: | | ||
sudo apt update | ||
sudo apt install -y libtinfo5 | ||
- name: Set github_api_token | ||
run: | | ||
mkdir ~/multiversx-sdk | ||
export PYTHONPATH=. | ||
python3 -m multiversx_sdk_cli.cli config new test | ||
python3 -m multiversx_sdk_cli.cli config set github_api_token ${{ secrets.GITHUB_TOKEN }} | ||
- name: Setup test dependencies | ||
run: | | ||
python3 -m multiversx_sdk_cli.cli deps install testwallets | ||
python3 -m multiversx_sdk_cli.cli deps install wasm-opt | ||
python3 -m multiversx_sdk_cli.cli deps install rust --overwrite | ||
- name: Run unit tests | ||
run: | | ||
export PYTHONPATH=. | ||
pytest . | ||
- name: Run CLI tests | ||
run: | | ||
python3 -m multiversx_sdk_cli.cli config set dependencies.vmtools.tag v1.4.60 | ||
cd ./multiversx_sdk_cli/tests | ||
source ./test_cli_contracts.sh && testAll || return 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come that we don't need to install clang / llvm, as well? No C smart contracts in our tests? If so, we should add some tests for C contracts in the next PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we only use rust contracts in our tests |
||
source ./test_cli_dns.sh && testOffline || return 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
myprocess, utils, workstation) | ||
from multiversx_sdk_cli.dependencies.resolution import ( | ||
DependencyResolution, get_dependency_resolution) | ||
from multiversx_sdk_cli.ux import show_warning | ||
|
||
logger = logging.getLogger("modules") | ||
|
||
|
@@ -34,7 +35,6 @@ | |
logger.info("Already exists. Skip install.") | ||
return | ||
|
||
self._guard_cannot_install_on_host() | ||
self.uninstall(tag) | ||
self._do_install(tag) | ||
|
||
|
@@ -66,10 +66,6 @@ | |
def get_resolution(self) -> DependencyResolution: | ||
return get_dependency_resolution(self.key) | ||
|
||
def _guard_cannot_install_on_host(self): | ||
if self.get_resolution() == DependencyResolution.Host: | ||
raise errors.KnownError(f"Installation of {self.key} on the host machine is not supported. Perhaps set 'dependencies.{self.key}.resolution' to 'SDK' in config?") | ||
|
||
|
||
class StandaloneModule(DependencyModule): | ||
def __init__(self, | ||
|
@@ -256,6 +252,29 @@ | |
|
||
|
||
class Rust(DependencyModule): | ||
def is_installed(self, tag: str) -> bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've thought about it, but the other modules need the parameter. I think. We can further look into this. |
||
which_rustc = shutil.which("rustc") | ||
which_cargo = shutil.which("cargo") | ||
logger.info(f"which rustc: {which_rustc}") | ||
logger.info(f"which cargo: {which_cargo}") | ||
|
||
return which_rustc is not None and which_cargo is not None | ||
|
||
def install(self, tag: str, overwrite: bool) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, here we completely override the function |
||
# Fallback to default tag if not provided | ||
tag = tag or config.get_dependency_tag(self.key) | ||
|
||
logger.info(f"install: key={self.key}, tag={tag}, overwrite={overwrite}") | ||
|
||
if overwrite: | ||
logger.info("Overwriting the current rust version...") | ||
elif self._is_installed_and_set_to_nightly(): | ||
return | ||
|
||
self._do_install(tag) | ||
self._install_sc_meta() | ||
self._post_install(tag) | ||
|
||
def _do_install(self, tag: str) -> None: | ||
installer_url = self._get_installer_url() | ||
installer_path = self._get_installer_path() | ||
|
@@ -269,12 +288,14 @@ | |
toolchain = "nightly" | ||
|
||
args = [str(installer_path), "--verbose", "--default-toolchain", toolchain, "--profile", | ||
"minimal", "--target", "wasm32-unknown-unknown", "--no-modify-path", "-y"] | ||
output = myprocess.run_process(args, env=self.get_env_for_install()) | ||
"minimal", "--target", "wasm32-unknown-unknown", "-y"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 |
||
|
||
myprocess.run_process(args) | ||
|
||
if output: | ||
sc_meta_args = ["cargo", "install", "multiversx-sc-meta"] | ||
myprocess.run_process(sc_meta_args, env=self.get_env_for_install()) | ||
def _install_sc_meta(self): | ||
logger.info("Installing multiversx-sc-meta") | ||
args = ["cargo", "install", "multiversx-sc-meta"] | ||
myprocess.run_process(args) | ||
|
||
def _get_installer_url(self) -> str: | ||
if workstation.is_windows(): | ||
|
@@ -293,73 +314,27 @@ | |
if os.path.isdir(directory): | ||
shutil.rmtree(directory) | ||
|
||
def is_installed(self, tag: str) -> bool: | ||
resolution = self.get_resolution() | ||
def _is_installed_and_set_to_nightly(self) -> bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function seems to be a clone of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. Removed it. |
||
# the method parameter is not used in this specific module | ||
is_rust_installed = self.is_installed("") | ||
|
||
if resolution == DependencyResolution.Host: | ||
which_rustc = shutil.which("rustc") | ||
which_cargo = shutil.which("cargo") | ||
logger.info(f"which rustc: {which_rustc}") | ||
logger.info(f"which cargo: {which_cargo}") | ||
|
||
return which_rustc is not None and which_cargo is not None | ||
if resolution == DependencyResolution.SDK: | ||
try: | ||
env = self._get_env_for_is_installed_in_sdk() | ||
myprocess.run_process(["rustc", "--version"], env=env) | ||
return True | ||
except Exception: | ||
return False | ||
if not is_rust_installed: | ||
return is_rust_installed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can say |
||
else: | ||
self._recommend_default_rust_version() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, let's move this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally, you can directly inline the implementation of Can also stay as it is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved it inside the |
||
return True | ||
|
||
raise errors.BadDependencyResolution(self.key, resolution) | ||
def _recommend_default_rust_version(self): | ||
module = dependencies.get_module_by_key("rust") | ||
default_tag: str = config.get_dependency_tag(module.key) | ||
Check warning on line 329 in multiversx_sdk_cli/dependencies/modules.py GitHub Actions / runner / mypy
|
||
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`.") | ||
|
||
def get_directory(self, tag: str) -> Path: | ||
tools_folder = workstation.get_tools_folder() | ||
return tools_folder / "vendor-rust" | ||
|
||
def get_env(self): | ||
directory = self.get_directory("") | ||
resolution = self.get_resolution() | ||
|
||
if resolution == DependencyResolution.Host: | ||
return { | ||
"PATH": os.environ.get("PATH", ""), | ||
"RUSTUP_HOME": os.environ.get("RUSTUP_HOME", ""), | ||
"CARGO_HOME": os.environ.get("CARGO_HOME", "") | ||
} | ||
if resolution == DependencyResolution.SDK: | ||
return { | ||
# At this moment, cc (build-essential) is sometimes required by the meta crate (e.g. for reports) | ||
"PATH": f"{path.join(directory, 'bin')}:{os.environ['PATH']}", | ||
"RUSTUP_HOME": str(directory), | ||
"CARGO_HOME": str(directory) | ||
} | ||
|
||
raise errors.BadDependencyResolution(self.key, resolution) | ||
|
||
def _get_env_for_is_installed_in_sdk(self) -> Dict[str, str]: | ||
directory = self.get_directory("") | ||
|
||
return { | ||
"PATH": str(directory / "bin"), | ||
"RUSTUP_HOME": str(directory), | ||
"CARGO_HOME": str(directory) | ||
} | ||
|
||
def get_env_for_install(self): | ||
directory = self.get_directory("") | ||
|
||
env = { | ||
# For installation, wget (or curl) and cc (build-essential) are also required. | ||
"PATH": f"{path.join(directory, 'bin')}:{os.environ['PATH']}", | ||
"RUSTUP_HOME": str(directory), | ||
"CARGO_HOME": str(directory) | ||
} | ||
|
||
if workstation.is_windows(): | ||
env["RUSTUP_USE_HYPER"] = "1" | ||
|
||
return env | ||
def get_env(self) -> Dict[str, str]: | ||
return dict(os.environ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. |
||
|
||
def get_latest_release(self) -> str: | ||
raise errors.UnsupportedConfigurationValue("Rust tag must either be explicit, empty or 'nightly'") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import logging | ||
import shutil | ||
import subprocess | ||
from pathlib import Path | ||
from typing import Any, Dict, List, Set, cast | ||
|
@@ -53,7 +54,14 @@ def prepare_build_wasm_args(self, args: List[str]): | |
self.get_output_folder() | ||
]) | ||
|
||
def check_if_sc_meta_is_installed(self): | ||
which_sc_meta = shutil.which("sc-meta") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about checking if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
if which_sc_meta is None: | ||
raise errors.KnownError("'sc-meta' is not installed. Run 'cargo install multiversx-sc-meta' then try again.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
def run_meta(self): | ||
self.check_if_sc_meta_is_installed() | ||
env = self.get_env() | ||
|
||
with_wasm_opt = not self.options.get("no-wasm-opt") | ||
|
@@ -123,6 +131,8 @@ def get_env(self): | |
return dependencies.get_module_by_key("rust").get_env() | ||
|
||
def build_wasm_with_debug_symbols(self, build_options: Dict[str, Any]): | ||
self.check_if_sc_meta_is_installed() | ||
|
||
cwd = self.path | ||
env = self.get_env() | ||
target_dir: str = build_options.get("target-dir", "") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some unrelated whitespace changes in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll blame it on the formatter.