tintinweb / vscode-vyper

Ethereum Vyper language support for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=tintinweb.vscode-vyper
MIT License
59 stars 17 forks source link

Cannot compile vyper from the extension on M1 #18

Open transmissions11 opened 2 years ago

transmissions11 commented 2 years ago

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

transmissions11 commented 2 years ago

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

tintinweb commented 1 year ago

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.

https://github.com/tintinweb/vscode-vyper/blob/6afe29bc6138f5d135d863dc12e0c4af7c98720d/package.json#L91-L94

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 (https://github.com/tintinweb/vscode-vyper/pull/24/commits/1bac179b0bb5b5de013025cb5b9c5b5d215a9467).

cheers, tin