Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,20 @@ Feel free to stop by our [Slack channel](https://empirehacking.slack.com/) for h
## FAQ

### OSError: [Errno 86] Bad CPU type in executable
`solc` requires Rosetta to be installed. To see whether you have Rosetta installed on your mac, run
```

On newer `solc-select` versions, this might show as `solc binaries for macOS are
Intel-only. Please install Rosetta on your Mac to continue.`

`solc` requires Rosetta to be installed. To see whether you have Rosetta
installed on your Mac, run

```bash
pgrep -q oahd && echo Rosetta is installed || echo Rosetta is NOT installed
```

If it is not installed, it can be installed with the command
```

```bash
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
```

Expand Down
2 changes: 2 additions & 0 deletions solc_select/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
switch_global_version,
current_version,
installed_versions,
halt_incompatible_system,
halt_old_architecture,
upgrade_architecture,
)
Expand Down Expand Up @@ -88,6 +89,7 @@ def solc() -> None:
(version, _) = res
path = ARTIFACTS_DIR.joinpath(f"solc-{version}", f"solc-{version}")
halt_old_architecture(path)
halt_incompatible_system()
try:
subprocess.run(
[str(path)] + sys.argv[1:],
Expand Down
9 changes: 9 additions & 0 deletions solc_select/solc_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
CRYTIC_SOLC_ARTIFACTS,
CRYTIC_SOLC_JSON,
)
from .utils import mac_can_run_intel_binaries

Path.mkdir(ARTIFACTS_DIR, parents=True, exist_ok=True)

Expand All @@ -31,6 +32,14 @@ def halt_old_architecture(path: Path) -> None:
)


def halt_incompatible_system() -> None:
if soliditylang_platform() == MACOSX_AMD64 and not mac_can_run_intel_binaries():
raise argparse.ArgumentTypeError(
"solc binaries for macOS are Intel-only. Please install Rosetta on your Mac to continue. Refer to the solc-select README for instructions."
)
# TODO: check for Linux aarch64 (e.g. RPi), presence of QEMU+binfmt


def upgrade_architecture() -> None:
currently_installed = installed_versions()
if len(currently_installed) > 0:
Expand Down
15 changes: 15 additions & 0 deletions solc_select/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import platform
import subprocess
import sys


def mac_can_run_intel_binaries() -> bool:
"""Check if the Mac is Intel or M1 with available Rosetta. Will throw an exception if run on non-macOS."""
assert sys.platform == "darwin"
if platform.machine() == "arm64":
# M1/M2 Mac
result = subprocess.run(["/usr/bin/pgrep", "-q", "oahd"], capture_output=True, check=False)
return result.returncode == 0

# Intel Mac
return True