Add macOS ARM build (universal or additional binaries) #20371

issue jonasschnelli openend this issue on November 11, 2020
  1. jonasschnelli commented at 2:03 pm on November 11, 2020: contributor

    First ARM based Macs are available now. See the porting guide https://developer.apple.com/documentation/xcode/porting_your_macos_apps_to_apple_silicon and the architectural differences: https://developer.apple.com/documentation/apple_silicon/addressing_architectural_differences_in_your_macos_code

    Things to do:

    • fix depends build on ARM with macOS 10.16 (done in merged #20482)
    • fix CRC32 build issue (fix in #20603)
    • update macOS build readme (if required)
    • allow cross compiling ARM64 Mac on linux/gitian
    • fix make deploy on ARM64
  2. jonasschnelli added the label Feature on Nov 11, 2020
  3. fanquake added the label macOS on Nov 11, 2020
  4. decryp2kanon commented at 4:20 pm on November 12, 2020: contributor
    apple ARM is running aarch64 binary?
  5. jonasschnelli commented at 2:53 pm on November 24, 2020: contributor
    Support for AArch64 NI SHA2 instructions should/could also be added.
  6. jonasschnelli commented at 8:30 pm on November 25, 2020: contributor

    Building on a ARM Mac with M1 via the depends build systems works with a few tweaks (https://github.com/bitcoin/bitcoin/pull/20482 plus crc32 getauxval fix).

    The harder part is now to get cross compilation to work. It probably requires a newer clang then the just merged upgrade to 8 (we need arm-apple-darwin). The Xcode 12.12 SDK is probably required (here). Qt 5.9 works for cross compilation but has visual glitches on macOS11. Update to Qt LTS 5.15 might be a good idea (#19716).

  7. satindergrewal commented at 4:03 pm on November 26, 2020: none

    I got error at with make command in root of bitcoin directory after manually applying patch to qt.mk. These are the steps I followed:

    Installed Homebrew with this script: https://gist.github.com/nrubin29/bea5aa83e8dfa91370fe83b62dad6dfa

    command:

    0/bin/bash -c "$(curl -fsSL https://gist.githubusercontent.com/nrubin29/bea5aa83e8dfa91370fe83b62dad6dfa/raw/48f48f7fef21abb308e129a80b3214c2538fc611/homebrew_m1.sh)"
    1source ~/.zshrc
    

    bitcoin install steps

     0git clone https://github.com/bitcoin/bitcoin
     1cd bitcoin/
     2
     3# manually edited depends/packages/qt.mk file as per this git PR:
     4# https://github.com/bitcoin/bitcoin/pull/20482/files
     5
     6cd depends/
     7make
     8cd ..
     9./configure --prefix=$(pwd)/depends/arm-apple-darwin20.1.0  --with-gui=yes --disable-tests --disable-bench --enable-upnp-default --enable-experimental-asm --enable-static --disable-shared
    10make
    

    got this error:

     0  CXX      leveldb/helpers/memenv/libmemenv_a-memenv.o
     1  AR       leveldb/libmemenv.a
     2gcc -I. -I./src -Wall -Wextra -Wno-unused-function -g -O2 -c src/gen_context.c -o gen_context.o
     3gcc -Wall -Wextra -Wno-unused-function -g -O2  gen_context.o -o gen_context
     4./gen_context
     5  CC       src/libsecp256k1_la-secp256k1.lo
     6  CCLD     libsecp256k1.la
     7  CXXLD    bitcoind
     8Undefined symbols for architecture arm64:
     9  "_getauxval", referenced from:
    10      crc32c::Extend(unsigned int, unsigned char const*, unsigned long) in libcrc32c.a(libcrc32c_a-crc32c.o)
    11ld: symbol(s) not found for architecture arm64
    12clang: error: linker command failed with exit code 1 (use -v to see invocation)
    13make[2]: *** [bitcoind] Error 1
    14make[1]: *** [all-recursive] Error 1
    15make: *** [all-recursive] Error 1
    

    Is that expected? or did I miss anything?

  8. jonasschnelli commented at 6:26 pm on November 26, 2020: contributor

    @satindergrewal Yes. Somehow the crc32 library thinks we are on ARM linux and tries to use getauxval.

    A quick fix is to change getauxval(AT_HWCAP); to getauxval1(AT_HWCAP); in configure.ac (I know a very lame fix!). I’ll do a proper PR soon.

  9. jonasschnelli commented at 4:39 pm on December 8, 2020: contributor
    Related #20603
  10. dongcarl commented at 0:12 am on December 10, 2020: member

    I think we might have to bump to Qt 6.1 for this: https://bugreports.qt.io/browse/QTBUG-85279 There exists a qt5commpat layer which might be helpful for the transition: https://www.qt.io/blog/porting-from-qt-5-to-qt-6-using-qt5compat-library

    Qt 6 also replaced qmake with cmake, which is much nicer to work with.

  11. jonasschnelli commented at 7:36 am on December 10, 2020: contributor

    @dongcarl: With the current master, building depends (as it is) works on an ARM64 Mac. Do you think we have to bump Qt to make cross compiling arm-apple-dawrin on a x86 linux host work?

    I really have little understanding about cross compiling. Would appreciate if someone could look into building depends for HOST=arm-apple-darwin20

  12. awesome-doge commented at 9:28 am on January 6, 2021: none

    I have referenced the above solution and successfully compiled bitcoin. But I have a problem with the last command make deploy.

    https://gist.github.com/awesome-doge/9bfbd1d3fd9b725c4df224433fa3596e#file-build-apple-m1-version-of-bitcoin-md

     0  bitcoin git:(master) make deploy
     1
     2build-aux/install-sh -c -d Bitcoin-Qt.app/Contents
     3build-aux/install-sh -c -d Bitcoin-Qt.app/Contents/Resources
     4build-aux/install-sh -c -d Bitcoin-Qt.app/Contents/Resources
     5/usr/bin/install -c -m 644 src/qt/res/icons/bitcoin.icns Bitcoin-Qt.app/Contents/Resources/bitcoin.icns
     6build-aux/install-sh -c -d Bitcoin-Qt.app/Contents
     7/usr/bin/install -c -m 644 share/qt/Info.plist Bitcoin-Qt.app/Contents/Info.plist
     8Making all in src
     9Making all in doc/man
    10make[1]: Nothing to be done for `all'.
    11make[1]: Nothing to be done for `all-am'.
    12build-aux/install-sh -c -d Bitcoin-Qt.app/Contents/MacOS
    13STRIPPROG="/usr/bin/strip" /bin/sh /Users/doge/bitcoin/build-aux/install-sh -c -s  ./src/qt/bitcoin-qt Bitcoin-Qt.app/Contents/MacOS/Bitcoin-Qt
    14build-aux/install-sh -c -d Bitcoin-Qt.app/Contents/Resources/Base.lproj
    15echo '{	CFBundleDisplayName = "Bitcoin Core"; CFBundleName = "Bitcoin Core"; }' > Bitcoin-Qt.app/Contents/Resources/Base.lproj/InfoPlist.strings
    16/opt/homebrew/bin/python3.9 ./contrib/macdeploy/macdeployqtplus Bitcoin-Qt.app Bitcoin-Core -translations-dir=/Users/doge/bitcoin/depends/arm-apple-darwin20.2.0/translations -dmg
    17Traceback (most recent call last):
    18  File "/Users/doge/bitcoin/./contrib/macdeploy/macdeployqtplus", line 22, in <module>
    19    from ds_store import DSStore
    20  File "/Users/doge/bitcoin/depends/arm-apple-darwin20.2.0/native/lib/python3/dist-packages/ds_store/__init__.py", line 1, in <module>
    21    from .store import DSStore, DSStoreEntry
    22  File "/Users/doge/bitcoin/depends/arm-apple-darwin20.2.0/native/lib/python3/dist-packages/ds_store/store.py", line 8, in <module>
    23    import mac_alias
    24  File "/Users/doge/bitcoin/depends/arm-apple-darwin20.2.0/native/lib/python3/dist-packages/mac_alias/__init__.py", line 1, in <module>
    25    from .alias import *
    26  File "/Users/doge/bitcoin/depends/arm-apple-darwin20.2.0/native/lib/python3/dist-packages/mac_alias/alias.py", line 16, in <module>
    27    from . import osx
    28  File "/Users/doge/bitcoin/depends/arm-apple-darwin20.2.0/native/lib/python3/dist-packages/mac_alias/osx.py", line 424, in <module>
    29    _statfs = libc['statfs$INODE64']
    30  File "/opt/homebrew/Cellar/python@3.9/3.9.1_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 392, in __getitem__
    31    func = self._FuncPtr((name_or_ordinal, self))
    32AttributeError: dlsym(0x102b9d810, statfs$INODE64): symbol not found
    33make: *** [Bitcoin-Core.dmg] Error 1
    

    The compiled bitcoin can be executed. But there will be some color problems on the setting page.

  13. jonasschnelli commented at 9:42 am on January 6, 2021: contributor
    @awesome-doge make deploy currently doesn’t work on Apple M1 (ARM64) due to missing support in the dmg tools area (ds_store AFAIK). I added it to the PR descriptions list (as open task).
  14. awesome-doge commented at 7:53 am on January 8, 2021: none

    It seems that someone opened a related issue

    build: make deploy fails on macOS Big Sur 11.1 #20878

    https://github.com/bitcoin/bitcoin/issues/20878

  15. fanquake referenced this in commit 708ef4424a on Jan 10, 2021
  16. sidhujag referenced this in commit 1cd3c7b845 on Jan 10, 2021
  17. sgulls commented at 11:25 pm on March 30, 2021: contributor
    Changing mac_alias to 2.2.0 fixes make deploy
  18. sgulls commented at 1:24 am on April 29, 2021: contributor
    @jonasschnelli make deploy fix has been committed to master
  19. michaelbship commented at 10:56 pm on April 29, 2021: none

    @jonasschnelli make deploy fix has been committed to master

    So, is this update meaning master should build on ARM now? (newbie here just trying to run bitcoin on my new Mac)

  20. sgulls commented at 11:00 pm on April 29, 2021: contributor
    @michaelsblank yes, that’s what “committed to master” means
  21. michaelbship commented at 11:04 pm on April 29, 2021: none

    @michaelsblank yes, that’s what “committed to master” means

    Yes, yes I know. I’m a developer. But, I should have been more precise. Does this now mean we can use the normal MacOS readme guide but for this latest commit and everything should build and run? I just found it odd that when I previewed the commit the change was just a version number and a hash change. If that got it running awesome, I just didn’t know if there was more work to be done. Excuse me for my poor wording before. @sgulls

  22. sgulls commented at 11:11 pm on April 29, 2021: contributor

    @michaelsblank

    I mentioned the pertinent issue with one of the packages and in the issue, the maintainer said they fixed the issue that was encountered when building the app bundle and dmg. That fix was included in their version bump.

  23. jsarenik commented at 10:23 am on May 2, 2021: none
    @michaelsblank You seem to be one of few who have M1 hardware. Hands-on experience is welcome so feel free to write more here. Thanks!
  24. ipa-tys commented at 10:56 am on May 21, 2021: none

    Hi, I also have a Mac Mini M1 (up-to-date with Big Sur 11.3.1) and was able to previously compile 0.21.0. But now, when trying to update to 0.21.1, I ran into an error when compiling the dependencies by running ‘make’ in /depends subdirectory:

    0ERROR: Feature 'system-zlib' was enabled, but the pre-condition 'libs.zlib' failed. make: *** [/Users/xxx/bitcoin/depends/work/build/arm-apple-darwin20.2.0/qt/5.9.8-82a1b93ac0c/qtbase/.stamp_configured] Error 3
    

    I thought maybe zlib was not installed, so I ran “brew install zlib”, producing this output:

     0==> Pouring zlib--1.2.11.arm64_big_sur.bottle.tar.gz
     1==> Caveats
     2zlib is keg-only, which means it was not symlinked into /opt/homebrew,
     3because macOS already provides this software and installing another version in
     4parallel can cause all kinds of trouble.
     5
     6For compilers to find zlib you may need to set:
     7  export LDFLAGS="-L/opt/homebrew/opt/zlib/lib"
     8  export CPPFLAGS="-I/opt/homebrew/opt/zlib/include"
     9
    10For pkg-config to find zlib you may need to set:
    11  export PKG_CONFIG_PATH="/opt/homebrew/opt/zlib/lib/pkgconfig"
    

    Even when adding these environment variables, I got the same error as shown above when trying to compile the dependencies, so I guess that attempt did not help.

    Any advice?

  25. ipa-tys commented at 4:45 pm on May 31, 2021: none
    Since it’s been 10 days, I hope it’s ok to give this a small bump, @jonasschnelli. As written above, I’d be happy to help testing on M1 architecture, but from the lack of feedback it seems there is currently not so much interest in it?
  26. fanquake commented at 2:07 am on June 1, 2021: member

    @ipa-tys building depends on an M1 machine should work fine at the moment. I know there are multiple people successfully building that way. If you are still having problems, then please open an issue with all the relevant info/logs. Make sure you’ve tried building depends from scratch etc.

    If you’re interested in cross-compilation for M1, you can check out #21851.

  27. ipa-tys commented at 3:30 pm on June 1, 2021: none
    Thanks! Yes I tried building depends from scratch (which, as I mentioned above, had worked for me in 0.21.0). I will file a separate issue, as you suggested.
  28. sgulls commented at 4:42 am on June 30, 2021: contributor
    @jonasschnelli I’ve managed to cross compile from x86_64-linux-gnu to aarch64-apple-darwin20.4. I built osxcross against the latest stable SDK (SDK version 11.3 from Xcode 12.5), added osxcross binaries to $PATH built the depends folder with make HOST=aarch64-apple-darwin20.4 FORCE_USE_SYSTEM_CLANG=1 XCODE_VERSION=12.5 XCODE_BUILD_ID=12E262 and successfully compiled a working GUI app bundle that ran on my arm64 Mac
  29. prusnak commented at 11:00 pm on January 23, 2022: contributor

    Support for AArch64 NI SHA2 instructions should/could also be added.

    Added in https://github.com/bitcoin/bitcoin/pull/24115

  30. sipa commented at 11:15 pm on January 23, 2022: member
    Does Apple M1 have the “rng” extension (true RNG built into the CPU)?
  31. prusnak commented at 8:05 pm on March 18, 2022: contributor
    Since #21851 and others are merged already and 23.0 will have native arm64-darwin build I think we can close this issue?
  32. fanquake added this to the milestone 23.0 on Mar 18, 2022
  33. fanquake closed this on Mar 18, 2022

  34. prusnak commented at 8:08 pm on March 18, 2022: contributor

    Does Apple M1 have the “rng” extension (true RNG built into the CPU)? @sipa It seems it does - https://support.apple.com/en-gb/guide/security/sec59b0b31ff/web (search for “True Random Number Generator”)

  35. DrahtBot locked this on Mar 18, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me