tintinweb/vscode-vyper

Cannot compile vyper from the extension on M1

Opened this issue · 2 comments

Compiling the Example ERC20 works just fine via the cli, but when I save in the vscode it fails with this message:

[{
	"resource": "/Users/t11s/Desktop/vyper/test.vy",
	"owner": "Vyper Compiler",
	"severity": 8,
	"message": "Error executing vyper:",
	"source": "Error executing vyper:\nTraceback (most recent call last):\n  File \"/Library/Frameworks/Python.framework/Versions/3.10/bin/vyper\", line 5, in <module>\n    from vyper.cli.vyper_compile import _parse_cli_args\n  File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/vyper/__init__.py\", line 1, in <module>\n    from vyper.compiler import compile_code, compile_codes  # noqa: F401\n  File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/vyper/compiler/__init__.py\", line 4, in <module>\n    from vyper.compiler import output\n  File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/vyper/compiler/output.py\", line 7, in <module>\n    from vyper.ast import ast_to_dict, parse_natspec\n  File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/vyper/ast/__init__.py\", line 6, in <module>\n    from . import nodes, validation\n  File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/vyper/ast/nodes.py\", line 18, in <module>\n    from vyper.utils import MAX_DECIMAL_PLACES, SizeLimits, annotate_source_code\n  File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/vyper/utils.py\", line 22, in <module>\n    from Crypto.Hash import keccak  # type: ignore\n  File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Crypto/Hash/keccak.py\", line 39, in <module>\n    _raw_keccak_lib = load_pycryptodome_raw_lib(\"Crypto.Hash._keccak\",\n  File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Crypto/Util/_raw_api.py\", line 309, in load_pycryptodome_raw_lib\n    raise OSError(\"Cannot load native module '%s': %s\" % (name, \", \".join(attempts)))\nOSError: Cannot load native module 'Crypto.Hash._keccak': Not found '_keccak.cpython-310-darwin.so', Cannot load '_keccak.abi3.so': cannot load library '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Crypto/Util/../Hash/_keccak.abi3.so': dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Crypto/Util/../Hash/_keccak.abi3.so, 0x0002): tried: '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Crypto/Util/../Hash/_keccak.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/_keccak.abi3.so' (no such file), '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Crypto/Hash/_keccak.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/_keccak.abi3.so' (no such file).  Additionally, ctypes.util.find_library() did not manage to locate a library called '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Crypto/Util/../Hash/_keccak.abi3.so', Not found '_keccak.so'\n",
	"startLineNumber": 5,
	"startColumn": 1,
	"endLineNumber": 5,
	"endColumn": 256
}]

i believe this is because my terminal runs in rosetta mode but vscode will run vyper raw? is there a way i can get the extension to use rosetta as well

temporary workaround is to set the vyper command to arch -x86_64 vyper

hey @transmissions11,

sorry for the late reply. yeah, the default vyper command is set to vyper (whatever your system-wide vyper command is configured for) and it's executed using child_process.exec() which spawns /bin/sh by default.

"vyper.command": {
"type": "string",
"default": "vyper",
"description": "Defines how to invoke the vyper compiler command. This can by any shell command and the vyper arguments will be passed to this command as <vyper.command> <args>. Default is to assume vyper is installed in PATH and executable as `vyper`"

I suggest documenting this for now unless this is an issue for more people. Open to other way to fix this. In general, the vyper.command can be anything, including a shell invocation, however, setting the arch before launching vyper may be the best way forward for now. Another idea would be to force exec() to use env.SHELL (instead of the default /bin/sh) assuming that your default shell is set up correctly to execute vyper. However, I would like to avoid adding code that has to auto-figure user envs :)

hope that helps. added a note to the readme (1bac179).

cheers,
tin