Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot compile all-clusters-app on M1 Mac #19134

Closed
phonnakasturi-apple opened this issue Jun 2, 2022 · 18 comments · Fixed by #19737
Closed

Cannot compile all-clusters-app on M1 Mac #19134

phonnakasturi-apple opened this issue Jun 2, 2022 · 18 comments · Fixed by #19737

Comments

@phonnakasturi-apple
Copy link

With SHA 6c4b54e

all-clusters-app cannot be complied on on-network device (mac)

Steps to reproduce the issue;

  1. cd ~/connectedhomeip
  2. git reset --hard 6c4b54e
  3. source scripts/activate.sh
  4. scripts/examples/gn_build_example.sh examples/all-clusters-app/linux out/debug chip_config_network_layer_ble=false

Error:

FAILED: address-resolve-tool address-resolve-tool.map
g++ -target x86_64-apple-macos10.15 -O0 -fPIC -Werror -fdiagnostics-color -Wl,-dead_strip -L/opt/homebrew/Cellar/openssl@3/3.0.3/lib -Wl,-map,./address-resolve-tool.map @./address-resolve-tool.rsp -o ./address-resolve-tool
ld: warning: ignoring file /opt/homebrew/Cellar/openssl@3/3.0.3/lib/libcrypto.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/openssl@3/3.0.3/lib/libssl.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
"_RAND_priv_bytes", referenced from:
chip::Crypto::DRBG_get_bytes(unsigned char*, unsigned long) in libChipCrypto.a(libChipCrypto.CHIPCryptoPALOpenSSL.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[440/455] ar libCHIPAppServer.a
ninja: build stopped: subcommand failed.

Attaching the complete error log:

on-netwrok_logs.txt

@bzbarsky-apple
Copy link
Contributor

bzbarsky-apple commented Jun 2, 2022

This is being built on an M1, right? And you are building x86-64 (for Rosetta) but do not have the relevant OpenSSL installed, just the ARM version.

You should either install the x86-64 version of OpenSSL or do a native ARM build...

That said, I'm a little surprised we are not defaulting to a native ARM build to start with. @mspang @andy31415 any idea why that's happening?

@phonnakasturi-apple
Copy link
Author

@bzbarsky-apple Yes.. This is on M1 Mac
What is the version that we need to use?
I currently export ;
/opt/homebrew/opt/openssl@3/lib/pkgconfig

@bzbarsky-apple
Copy link
Contributor

@phonnakasturi-apple The point is you need to install the x86-64 version of openssl, not the ARM version.

I do not have an M1, so have no idea how to do this, unfortunately. The internet suggests that

arch -x86_64 brew install openssl

might work...

But again, it's not clear why you are ending up building the x86-64 version of Matter to start with.

@phonnakasturi-apple
Copy link
Author

@bzbarsky-apple I tried with arch -x86_64 brew install openssl

and it says;
arch -x86_64 brew install openssl

Running `brew update --auto-update`...
Warning: openssl@3 3.0.3 is already installed and up-to-date.
To reinstall 3.0.3, run:
  brew reinstall openssl@3

And throws the same error when I try to compile it

@bzbarsky-apple bzbarsky-apple changed the title Cannot compile all-clusters-app with on-network device Cannot compile all-clusters-app on M1 Mac Jun 7, 2022
@bzbarsky-apple
Copy link
Contributor

Warning: openssl@3 3.0.3 is already installed and up-to-date.

That does not sound like it installed the x64-64 version, then....

@ReneJosefsen
Copy link
Contributor

What happens if you add 'current_cpu="arm64"' as a build parameter?

Not sure if it is related, but it sounds a bit like the problem discussed in this issue: #16759

@bzbarsky-apple
Copy link
Contributor

This definitely sounds like #16759 got broken again.

@chadnorwell @rgoliver @mspang did something change again on the pigweed side here?

@bzbarsky-apple
Copy link
Contributor

@keir

@raman325
Copy link

raman325 commented Jun 7, 2022

adding the build parameter allowed me to build Matter. I tried also building the python CHIP controller by adding the same parameter to the build script here: https://github.com/project-chip/connectedhomeip/blob/master/scripts/build_python.sh#L116

But I get ERROR: chip-0.0-cp37-abi3-macosx_11_0_arm64.whl is not a supported wheel on this platform. Note that I tried to change the target OS version to 12.0 but that resulted in the same error.

@ReneJosefsen
Copy link
Contributor

ReneJosefsen commented Jun 7, 2022

Weird, with no modification I got some SSL errors and was not able to build, if I added the "current_cpu" parameter I was able to build but got a few warnings since the target is macOS 11. Forcing it to set the target to macOS 12, which I also noticed removed the errors in the earlier mentioned issue, I have no issue or warnings when running scripts/build_python.sh.

My line 116 looks like this:
gn --root="$CHIP_ROOT" gen "$OUTPUT_ROOT" --args="chip_detail_logging=$chip_detail_logging enable_pylib=$enable_pybindings enable_rtti=$enable_pybindings chip_project_config_include_dirs=[\"//config/python\"] $chip_mdns_arg $chip_case_retry_arg "current_cpu=\"arm64\"" "mac_deployment_target=\"12.0\"""

@raman325
Copy link

raman325 commented Jun 8, 2022

yeah unfortunately that's not working for me and I'm not sure how to troubleshoot it

@agners
Copy link
Contributor

agners commented Jun 9, 2022

@raman325

But I get ERROR: chip-0.0-cp37-abi3-macosx_11_0_arm64.whl is not a supported wheel on this platform. Note that I tried to change the target OS version to 12.0 but that resulted in the same error.

We did some investigation in that today, and the reason is that Pigweed uses Rosetta by default on M1 currently (see https://pigweed.dev/docs/faq.html#host-platforms-that-we-are-likely-to-support-in-the-future).

But pigweed got you quite far: It essentially built the whole Matter stack, and created a wheel for you for MacOSX/arm64. It's just that installing it using the pigweed Python/pip environment doesn't work since that's a x86-64 Python.

The solution to that is to not pass -i separate to scripts/build_python.sh. Instead, just open a new terminal, and create a venv and pip install the wheel.

@mspang
Copy link
Contributor

mspang commented Jun 15, 2022

There may need to be a Matter side change to account for
https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/94380

@mspang
Copy link
Contributor

mspang commented Jun 15, 2022

Probably this:

diff --git a/scripts/environment.json b/scripts/environment.json
index afe568101..f68d976de 100644
--- a/scripts/environment.json
+++ b/scripts/environment.json
@@ -9,5 +9,6 @@
         "gn_targets": [":python_packages.install"]
     },
     "required_submodules": ["third_party/pigweed/repo"],
+    "rosetta": "never",
     "gni_file": "build_overrides/pigweed_environment.gni"
 }

@mspang
Copy link
Contributor

mspang commented Jun 15, 2022

Can someone with access to an M1 host test the above change?

@ReneJosefsen
Copy link
Contributor

Hmm, I tried adding in the change and bootstrap it. It seems like it still throws the error when I try to build chip-tool.

chip::Crypto::P256Keypair::ECDH_derive_secret(chip::Crypto::P256PublicKey const&, chip::Crypto::CapacityBoundBuffer<32ul>&) const in libChipCrypto.a(libChipCrypto.CHIPCryptoPALOpenSSL.cpp.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I did notice that before it stated "_PW_ROSETTA=1" and after the change it reported "_PW_ROSETTA=0".

@mspang
Copy link
Contributor

mspang commented Jun 15, 2022

Can you provide the build command and the rest of the output ?

FWIW you can set chip_crypto="mbedtls" to avoid the openssl via brew hassle

@ReneJosefsen
Copy link
Contributor

ReneJosefsen commented Jun 16, 2022

I did not know about the mbedtls crypto, that might be useful. I ended up using the 'current_cpu="arm64"' 'mac_deployment_target="12.0"' parameters, which have worked great for me, so had not changed that yet.

Sure no problem, I re-added the change and tried again. This time I deleted my .environment folder since bootstrap for some reason failed and now it seems to be working so maybe my environment had not gotten the change properly yesterday, but a "vanilla" chip-tool build seems to work ok now:

scripts/examples/gn_build_example.sh examples/chip-tool out/chip-tool/

WELCOME TO...

           ░▓░
           ▓█▓
           ▓█▓                                                     ▒█     ▒█
      ▒██▒▒▓██▒███▒                ░▒▓▒░  ░▒▓▒░       ░░▓█▒░ ░█  █████████████░    ░▒█▒░       ░░▒░
       ░▓█████▓██░               ▒█▒░░▒▓██▓▒░░▒█▒   ░█▓▒░░▒████    █▓░    █▓░    ▒█▒░░░▒█▓░   ██▒░░
    ▒█▒░         ░██▒           ░█░     █▓     ░█░ ░▓▒      ░▓█    █▓     █▓    ▒█░░    ░██  ▒▓
    ░▓██▓░     ░██▓█░           ░█      ▓█      █░ ░█░       ██    █▓     █▓    ▓██████████  ▒█
     ░▓███▒   ▒███▒░            ░█      ▓█      █░  ██░    ░███    █▓     █▓    ░█▒░         ▒█
 ░▒████████░ ░███▓▓█▓▓▒         ░█      ▒▒      █░   ░█▓██▓█░▒█    ░▓▓█░  ░▓▓█░   ▒▓▓██▓█░   ▒▓
 ░██▒░  ▒██▒ ▒██░  ░▒█▓
         ░▓░ ░▓░

  ACTIVATOR! This sets your shell environment variables.

Activating environment (setting environment variables):

  Setting environment variables for CIPD package manager...done
  Setting environment variables for Python environment.....done
  Setting environment variables for pw packages............skipped
  Setting environment variables for Host tools.............done

Checking the environment:

20220616 08:47:51 WRN Current uname (21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000 arm64) does not match Bootstrap uname (21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000 arm64), you may need to rerun bootstrap on this system
20220616 08:47:51 INF Environment passes all checks!

Environment looks good, you are ready to go!

+ env
PW_PIGWEED_CIPD_INSTALL_DIR=/Users/renejosefsen/Developer/GitData/connectedhomeip/.environment/cipd/packages/pigweed
MANPATH=/opt/local/share/man:/opt/homebrew/share/man::
TERM_PROGRAM=Apple_Terminal
SHELL=/bin/zsh
TERM=xterm-256color
HOMEBREW_REPOSITORY=/opt/homebrew
TMPDIR=/var/folders/1p/rs5yf35d0ql8ldqm2q2w1l_m0000gn/T/
TERM_PROGRAM_VERSION=445
TERM_SESSION_ID=E8A1990D-1CF5-4EFC-942E-0D12C6A2DDFC
USER=renejosefsen
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.qtQWmEtrit/Listeners
_PW_ENVIRONMENT_CONFIG_FILE=/Users/renejosefsen/Developer/GitData/connectedhomeip/scripts/environment.json
VIRTUAL_ENV=/Users/renejosefsen/Developer/GitData/connectedhomeip/.environment/pigweed-venv
PATH=/Users/renejosefsen/Developer/GitData/connectedhomeip/third_party/pigweed/repo/out/host/host_tools:/Users/renejosefsen/Developer/GitData/connectedhomeip/.environment/pigweed-venv/bin:/Users/renejosefsen/Developer/GitData/connectedhomeip/.environment/cipd/packages/pigweed/bin:/Users/renejosefsen/Developer/GitData/connectedhomeip/.environment/cipd/packages/pigweed:/Users/renejosefsen/Developer/GitData/connectedhomeip/.environment/cipd:/Library/Frameworks/Python.framework/Versions/3.9/bin:/opt/local/bin:/opt/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
PW_ROOT=/Users/renejosefsen/Developer/GitData/connectedhomeip/third_party/pigweed/repo
PW_ARM_CIPD_INSTALL_DIR=/Users/renejosefsen/Developer/GitData/connectedhomeip/.environment/cipd/packages/arm
__CFBundleIdentifier=com.apple.Terminal
PWD=/Users/renejosefsen/Developer/GitData/connectedhomeip
LANG=da_DK.UTF-8
XPC_FLAGS=0x0
_PW_ACTUAL_ENVIRONMENT_ROOT=/Users/renejosefsen/Developer/GitData/connectedhomeip/.environment
XPC_SERVICE_NAME=0
SHLVL=2
HOME=/Users/renejosefsen
_PW_ROSETTA=0
HOMEBREW_PREFIX=/opt/homebrew
LOGNAME=renejosefsen
PW_PYTHON_CIPD_INSTALL_DIR=/Users/renejosefsen/Developer/GitData/connectedhomeip/.environment/cipd/packages/python
PKG_CONFIG_PATH=:/opt/homebrew/opt/openssl@3/lib/pkgconfig
PW_PROJECT_ROOT=/Users/renejosefsen/Developer/GitData/connectedhomeip
INFOPATH=/opt/homebrew/share/info:
HOMEBREW_CELLAR=/opt/homebrew/Cellar
PW_BOOTSTRAP_USE_ROSETTA=false
_=/usr/bin/env
+ gn gen --check --fail-on-unused-args --root=examples/chip-tool out/chip-tool/ --args=
Done. Made 94 targets from 97 files in 825ms
+ ninja -C out/chip-tool/
ninja: Entering directory `out/chip-tool/'
[424/425] ld ./chip-tool
ld: warning: dylib (/opt/homebrew/Cellar/openssl@3/3.0.2/lib/libssl.dylib) was built for newer macOS version (12.0) than being linked (11.0)
ld: warning: dylib (/opt/homebrew/Cellar/openssl@3/3.0.2/lib/libcrypto.dylib) was built for newer macOS version (12.0) than being linked (11.0)
[425/425] stamp obj/default.stamp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants