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

Build for arm64 on amd64 #1

Closed
wants to merge 1 commit into from
Closed

Conversation

kiminuo
Copy link
Owner

@kiminuo kiminuo commented Jun 7, 2022

Related to bitcoin-core#345
Related to WalletWasabi/WalletWasabi#4051 (comment)

This PR just shows how to do a deterministic build for arm64 architecture. It's not finished, polished, etc. The hope is HWI's support for arm64 will improve a bit.

Setup

To set up your environment, install:

sudo apt install qemu-user-static 

Build for arm64

Use docker buildx to replicate deterministic build instructions for the arm64 build:

docker buildx build --no-cache --platform linux/arm64 -t hwi-builder -f contrib/build.Dockerfile .

# Note: build_wine.sh was removed.
docker run --platform linux/arm64 -it --rm --name hwi-builder -v $PWD:/opt/hwi  --workdir /opt/hwi hwi-builder /bin/bash -c "contrib/build_bin.sh && contrib/build_dist.sh"

i.e. the change is:

-docker build --no-cache -t hwi-builder -f contrib/build.Dockerfile .
-docker run -it --name hwi-builder -v $PWD:/opt/hwi --rm  --workdir /opt/hwi hwi-builder /bin/bash -c "contrib/build_bin.sh && contrib/build_dist.sh && contrib/build_wine.sh"
+docker buildx build --no-cache --platform linux/arm64 -t hwi-builder -f contrib/build.Dockerfile .
+docker run --platform linux/arm64 -it --rm --name hwi-builder -v $PWD:/opt/hwi  --workdir /opt/hwi hwi-builder /bin/bash -c "contrib/build_bin.sh"

Limitations

So far I had no luck with building hwi-qt because I get the following error

Installing dependencies from lock file

Package operations: 14 installs, 0 updates, 0 removals

  • Installing shiboken2 (5.15.2): Failed

  RuntimeError

  Unable to find installation candidates for shiboken2 (5.15.2)

  at ~/.pyenv/versions/3.9.7/lib/python3.9/site-packages/poetry/installation/chooser.py:72 in choose_for
       68│ 
       69│             links.append(link)
       70│ 
       71│         if not links:
    →  72│             raise RuntimeError(
       73│                 "Unable to find installation candidates for {}".format(package)
       74│             )
       75│ 
       76│         # Get the best link

during execution of poetry install -E qt

What about Cirrus CI and an ARM64 dockerfile...?

https://cirrus-ci.org/guide/docker-builder-vm/#dockerfile-as-a-ci-environment says

With Docker Builder there is no need to build and push custom containers so they can be used as an environment to run CI tasks in.
Cirrus CI can do it for you! Just declare a path to a Dockerfile with the dockerfile field for your container (arm_containers are not supported yet) declaration in your .cirrus.yml like this:

i.e. "arm_containers are not supported yet" is important!

=> Not possible at the moment, I believe.

@kiminuo kiminuo marked this pull request as ready for review June 7, 2022 19:37
@kiminuo kiminuo force-pushed the feature/2022-06-07-HWI-arm64 branch 2 times, most recently from 06a1946 to 5c573fe Compare June 12, 2022 20:34
@kiminuo kiminuo force-pushed the feature/2022-06-07-HWI-arm64 branch from 5c573fe to 3a2089f Compare June 13, 2022 07:07
@kiminuo kiminuo changed the title Try arm64 Build for arm64 on amd64 Jun 13, 2022
@kiminuo kiminuo changed the title Build for arm64 on amd64 Build for arm64 on amd64 Jun 13, 2022
@kiminuo
Copy link
Owner Author

kiminuo commented Jun 13, 2022

cc @achow101

@achow101
Copy link

achow101 commented Jun 13, 2022

Interesting, I had not considered using qemu before. I was going to just do the builds on actual hardware.

What is the difference between docker buildx and normal docker build? Are you using it just to be able to start container for a different platform?

It's probably fine to not ship hwi-qt for arm builds, but it would be nice if that would work.

@kiminuo
Copy link
Owner Author

kiminuo commented Jun 13, 2022

What is the difference between docker buildx and normal docker build?

As https://docs.docker.com/buildx/working-with-buildx/ says

Docker Buildx is a CLI plugin [..]. It provides the same user experience as docker build with many new features like creating scoped builder instances and building against multiple nodes concurrently.

It's basically a more powerful wrapper if I'm not mistaken.

Are you using it just to be able to start container for a different platform?

Yes, that's exactly the reason I use it.

It's probably fine to not ship hwi-qt for arm builds, but it would be nice if that would work.

So I would be happy to make it work though at the moment I don't have an idea how to fix it. Any idea how to fix it would be much appreciated. Anyway, I will try to spend a bit more time and I'll try to fix it but I have only limited time budget for this unfortunately and I don't know poetry, python and qt all that good.

@kiminuo
Copy link
Owner Author

kiminuo commented Jun 13, 2022

Ok, so I believe it's simply because https://pypi.org/project/shiboken2/#files does not provide arm64 wheel.

@kiminuo
Copy link
Owner Author

kiminuo commented Jun 13, 2022

https://doc.qt.io/qt-5/linux.html makes me think that linux/arm64 support is not officially supported. So that might be a plausible explanation why the python wheel for arm64 does not exist.

https://wiki.qt.io/Qt_for_Python seems to indicate the same thing.

@SomberNight
Copy link

Ok, so I believe it's simply because https://pypi.org/project/shiboken2/#files does not provide arm64 wheel.

Maybe try installing PySide2 (or PyQt5) with apt (in build.Dockerfile), instead of pip.
Debian has arm64 builds of these packages. See e.g. https://packages.debian.org/bullseye/python3-pyside2.qtgui

@kiminuo
Copy link
Owner Author

kiminuo commented Jun 14, 2022

Ok, so I believe it's simply because https://pypi.org/project/shiboken2/#files does not provide arm64 wheel.

Maybe try installing PySide2 (or PyQt5) with apt (in build.Dockerfile), instead of pip. Debian has arm64 builds of these packages. See e.g. https://packages.debian.org/bullseye/python3-pyside2.qtgui

Yes, I have tried to do that but Debian Stretch does not have that package by default (it has some older version). Your link links Debian Bullseye version of Debian. If I'm mistaken feel free to correct me.

@kiminuo
Copy link
Owner Author

kiminuo commented Jun 16, 2022

-> bitcoin-core#615

@kiminuo kiminuo closed this Jun 16, 2022
@kiminuo kiminuo deleted the feature/2022-06-07-HWI-arm64 branch June 16, 2022 09:50
achow101 added a commit to bitcoin-core/HWI that referenced this pull request Jan 30, 2024
3d3c02d Improve (Kiminuo)
ee3cf5f Add release instructions (Kiminuo)
d93c8f7 Add support for arm64 (Kiminuo)

Pull request description:

  Related to #345
  Related to WalletWasabi/WalletWasabi#4051 (comment)
  Discussion: Some discussion here: kiminuo#1

  This PR just shows how to do a deterministic build for `arm64` architecture. The hope is HWI's support for `arm64` will improve a bit.

  ### Setup

  To set up your environment, install:

  ```s
  sudo apt install qemu-user-static
  ```

  ### Build for arm64

  Use [docker buildx](https://docs.docker.com/buildx/working-with-buildx/) to replicate [deterministic build instructions](https://github.com/bitcoin-core/HWI/blob/master/docs/development/release-process.rst#deterministic-builds-with-docker) for the arm64 build:

  ```s
  docker buildx build --no-cache --platform linux/arm64 -t hwi-builder -f contrib/build.Dockerfile .

  # Note the use of "--without-gui".
  docker run --platform linux/arm64 -it --rm --name hwi-builder -v $PWD:/opt/hwi  --workdir /opt/hwi hwi-builder /bin/bash -c "contrib/build_bin.sh --without-gui && contrib/build_dist.sh --without-gui"
  ```

  i.e. the change is:

  ```diff
  -docker build --no-cache -t hwi-builder -f contrib/build.Dockerfile .
  -docker run -it --name hwi-builder -v $PWD:/opt/hwi --rm  --workdir /opt/hwi hwi-builder /bin/bash -c "contrib/build_bin.sh && contrib/build_dist.sh && contrib/build_wine.sh"
  +docker buildx build --no-cache --platform linux/arm64 -t hwi-builder -f contrib/build.Dockerfile .
  +docker run --platform linux/arm64 -it --rm --name hwi-builder -v $PWD:/opt/hwi  --workdir /opt/hwi hwi-builder /bin/bash -c "contrib/build_bin.sh --without-gui && contrib/build_dist.sh --without-gui"
  ```

  ### Resources

  * https://docs.docker.com/build/building/multi-platform/#building-multi-platform-images
  * https://medium.com/@artur.klauser/building-multi-architecture-docker-images-with-buildx-27d80f7e2408

  ## Limitations

  ### No GUI support

  So far I had no luck with building `hwi-qt` because I get the following error

  ```
  Installing dependencies from lock file

  Package operations: 14 installs, 0 updates, 0 removals

    • Installing shiboken2 (5.15.2): Failed

    RuntimeError

    Unable to find installation candidates for shiboken2 (5.15.2)

    at ~/.pyenv/versions/3.9.7/lib/python3.9/site-packages/poetry/installation/chooser.py:72 in choose_for
         68│
         69│             links.append(link)
         70│
         71│         if not links:
      →  72│             raise RuntimeError(
         73│                 "Unable to find installation candidates for {}".format(package)
         74│             )
         75│
         76│         # Get the best link
  ```

  during execution of [`poetry install -E qt`](https://github.com/kiminuo/HWI/blob/a025af3ee3fdf0bac8dbdbc51b9e82ab946660b4/contrib/build_bin.sh#L12)

  That's why I use `build_bin.sh --without-gui` (see #655)

ACKs for top commit:
  achow101:
    ACK 3d3c02d

Tree-SHA512: 3df877ec3da07997c8281722ea0ec4687d850f1fec33cb5664e3f03cd8854cb02a90ce799da2123a88058b681fbb2bad31bdacbb485474d19fa88b60a4b73d83
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 this pull request may close these issues.

3 participants