diff --git a/protostar.spec b/protostar.spec index c7f7e54344..95666c3a57 100644 --- a/protostar.spec +++ b/protostar.spec @@ -7,6 +7,7 @@ block_cipher = None extra_files = [ ("protostar_cairo", "protostar_cairo"), ("cairo/corelib", "cairo/corelib"), + ("cairo/Cargo.toml", "cairo"), ('templates', 'templates'), ('constants.json', 'info'), ] + collect_data_files('starkware') diff --git a/protostar/protostar_cli.py b/protostar/protostar_cli.py index 553fceeb72..61519d4ad9 100644 --- a/protostar/protostar_cli.py +++ b/protostar/protostar_cli.py @@ -61,7 +61,7 @@ def __init__( name="version", short_name="v", type="bool", - description="Show Protostar and Cairo-lang version.", + description="Show Protostar, Cairo-lang and Cairo 1 compiler versions.", ), ProtostarArgument( name="no-color", diff --git a/protostar/self/protostar_directory.py b/protostar/self/protostar_directory.py index 4b51be01bd..dbfd34751e 100644 --- a/protostar/self/protostar_directory.py +++ b/protostar/self/protostar_directory.py @@ -7,6 +7,8 @@ from packaging import version from packaging.version import Version +from tomlkit import parse + from protostar.git import get_git_version, ProtostarGitException from .protostar_compatibility_with_project_checker import ( @@ -14,6 +16,7 @@ parse_protostar_version, ) + RuntimeConstantName = Literal["PROTOSTAR_VERSION", "CAIRO_VERSION"] RuntimeConstantValue = str RuntimeConstantsDict = dict[RuntimeConstantName, RuntimeConstantValue] @@ -52,6 +55,11 @@ def protostar_cairo1_corelib_path(self) -> Path: assert self.protostar_binary_dir_path is not None return self.protostar_binary_dir_path / "cairo" / "corelib" + @property + def protostar_cairo1_compiler_path(self) -> Path: + assert self.protostar_binary_dir_path is not None + return self.protostar_binary_dir_path / "cairo" + def _read_runtime_constants(self) -> Optional[RuntimeConstantsDict]: constants_str = ( self.info_dir_path / ProtostarDirectory.RUNTIME_CONSTANTS_FILE_NAME @@ -109,6 +117,20 @@ def git_version(self) -> Optional[Version]: pass return None + @property + def cairo1_compiler_version(self) -> Optional[Version]: + try: + compiler_cargo = ( + self._protostar_directory.protostar_cairo1_compiler_path / "Cargo.toml" + ) + with open(compiler_cargo, "r") as file: + cargo = parse(file.read()) + version_str: str = cargo["workspace"]["package"]["version"] # type: ignore + return version.parse(version_str) + except BaseException: + return None + def print_current_version(self) -> None: print(f"Protostar version: {self.protostar_version or 'unknown'}") print(f"Cairo-lang version: {self.cairo_version or 'unknown'}") + print(f"Cairo 1 compiler version: {self.cairo1_compiler_version or 'unknown'}") diff --git a/tests/e2e/test_misc_commands.py b/tests/e2e/test_misc_commands.py index ef884b9556..ba873b2914 100644 --- a/tests/e2e/test_misc_commands.py +++ b/tests/e2e/test_misc_commands.py @@ -22,6 +22,7 @@ def test_versions(protostar: ProtostarFixture): result = protostar(["-v"]) assert "Protostar" in result assert "Cairo-lang" in result + assert "Cairo 1 compiler" in result def test_init(init_project: ProjectInitializer, project_name: str): diff --git a/website/docs/cli-reference.md b/website/docs/cli-reference.md index 691e26e740..97bda81008 100644 --- a/website/docs/cli-reference.md +++ b/website/docs/cli-reference.md @@ -5,7 +5,7 @@ Disable colors. #### `-p` `--profile STRING` Specifies active configuration profile defined in the configuration file. #### `-v` `--version` -Show Protostar and Cairo-lang version. +Show Protostar, Cairo-lang and Cairo 1 compiler versions. ## Commands ### `build` ```shell diff --git a/website/docs/tutorials/05-compiling.md b/website/docs/tutorials/05-compiling.md index 80c4b5c5c4..8b9a3a25c8 100644 --- a/website/docs/tutorials/05-compiling.md +++ b/website/docs/tutorials/05-compiling.md @@ -49,4 +49,5 @@ Protostar ships with its own version of Cairo-lang and formatter, so you don't n $ protostar -v Protostar version: X.Y.Z Cairo-lang version: A.B.C +Cairo 1 compiler version: J.K.L ```