platformio / platformio-core

Your Gateway to Embedded Software Development Excellence :alien:
https://platformio.org
Apache License 2.0
7.95k stars 792 forks source link

Bad CPU type in executable clang-tidy on Apple M3 Pro #4833

Open jonathanfoster opened 10 months ago

jonathanfoster commented 10 months ago

What kind of issue is this?

You can erase any parts of this template not applicable to your Issue.


Configuration

Operating system:

PlatformIO Version (platformio --version):

Description of problem

When running pio check with clangtidy on an Apple M3 Pro, the following error is returned:

OSError: [Errno 86] Bad CPU type in executable: '/Users/jonathanfoster/.platformio/packages/tool-clangtidy/clang-tidy'

It appears the incorrect architecture is choosen when installing tool-clangtidy.

$ arch
arm64
$ lipo -info /Users/jonathanfoster/.platformio/packages/tool-clangtidy/clang-tidy
Non-fat file: /Users/jonathanfoster/.platformio/packages/tool-clangtidy/clang-tidy is architecture: x86_64

Uninstalling and reinstalling tool-clandtidy produces the same error.

Steps to Reproduce

  1. Configure platformio.ini to use clang-tidy.

      check_tool = clangtidy
  2. Run static code analysis.

      pio check

Actual Results


$ pio check
Checking lilygo-t-display-s3 > clangtidy (board: lilygo-t-display-s3; platform: espressif32; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
OSError: Traceback (most recent call last):
  File "/opt/homebrew/Cellar/platformio/6.1.13/libexec/lib/python3.12/site-packages/platformio/__main__.py", line 103, in main
    cli()  # pylint: disable=no-value-for-parameter
    ^^^^^
  File "/opt/homebrew/opt/python-click/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/opt/python-click/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/platformio/6.1.13/libexec/lib/python3.12/site-packages/platformio/cli.py", line 85, in invoke
    return super().invoke(ctx)
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/opt/python-click/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/opt/python-click/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/opt/python-click/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/platformio/6.1.13/libexec/lib/python3.12/site-packages/platformio/check/cli.py", line 144, in cli
    rc = ct.check(
         ^^^^^^^^^
  File "/opt/homebrew/Cellar/platformio/6.1.13/libexec/lib/python3.12/site-packages/platformio/check/tools/base.py", line 239, in check
    self.execute_check_cmd(cmd)
  File "/opt/homebrew/Cellar/platformio/6.1.13/libexec/lib/python3.12/site-packages/platformio/check/tools/base.py", line 192, in execute_check_cmd
    result = proc.exec_command(
             ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/platformio/6.1.13/libexec/lib/python3.12/site-packages/platformio/proc.py", line 114, in exec_command
    with subprocess.Popen(*args, **kwargs) as p:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/subprocess.py", line 1950, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 86] Bad CPU type in executable: '/Users/jonathanfoster/.platformio/packages/tool-clangtidy/clang-tidy'

============================================================

An unexpected error occurred. Further steps:

* Verify that you have the latest version of PlatformIO using
  `python -m pip install -U platformio` command

* Try to find answer in FAQ Troubleshooting section
  https://docs.platformio.org/page/faq/index.html

* Report this problem to the developers
  https://github.com/platformio/platformio-core/issues

============================================================

Expected Results

pio check should run without error.

jonathanfoster commented 10 months ago

Looks like the issue is with the tool-clangtidy registry config, the files for darwin_amd46 appear to be misconfigured. darwin_arm64 should be a different download URL than darwin_x86_64.

"files": [
  {
    "name": "tool-clangtidy-darwin_x86_64-1.150005.0.tar.gz",
    "size": 19220346,
    "checksum": {
      "sha256": "dd2b0f982558194a4d0bda3fd15e084af42fabe495aac7805e458b496ea6587d"
    },
    "system": [
      "darwin_x86_64",
      "darwin_arm64"
    ],
    "download_url": "https://dl.registry.platformio.org/download/platformio/tool/tool-clangtidy/1.150005.0/tool-clangtidy-darwin_x86_64-1.150005.0.tar.gz"
  }
]
ivankravets commented 10 months ago

There is no native binary for Mac ARM.

Do you have Rosetta installed?

jonathanfoster commented 10 months ago

@ivankravets It looks like LLVM does have native binaries for Mac ARM now.

I can install Rosetta or even copy an arm64 binary from LLVM's repo as a work around, but it would be a better experience if this was supported in the registry. Any idea what's required to update the package config and provide an arm64 download URL?

ivankravets commented 10 months ago

I agree with you. There is another problem. 95% of all toolchains are NOT native ARM. You will still need Rosetta.

jonathanfoster commented 10 months ago

In my case, I'm using the espressif toolchain and clang-tidy is the only tool that isn't native ARM. Would it make sense to update packages incrementally as arm64 is supported?

What's required to update the tool-clangtidy package config and provide an arm64 download URL? Is there anywhere I can make the change and submit a PR? I'm happy to help however I can.