# Cross compiling a Hush full node daemon from AMD64 to ARM64(aarch64) CPU architecture with Docker.
# Cross compiling a Hush full node daemon from AMD64 to ARM64(aarch64) CPU architecture with Docker
**Requirements:** Docker-Engine & arm64(aarch64) architecture with Debian operating system like a <ahref="https://www.raspberrypi.org/products/raspberry-pi-400/specifications/">Raspberry Pi 400</a>
**Requirements:** Docker-Engine & arm64(aarch64) architecture with Debian operating system like a <ahref="https://www.raspberrypi.org/products/raspberry-pi-400/specifications/">Raspberry Pi 400</a>
*For this documentation, I setup <ahref="https://dietpi.com/">DietPi</a> It is a Debian:buster OS build.*
0. ## Summary
## Summary
Cross compiling a Hush full node daemon from **AMD64** to **ARM64(aarch64)** CPU architecture with Docker.
Cross compiling a Hush full node daemon from **AMD64**(also known as x86 architecture) to **ARM64(aarch64)** CPU architecture with Docker.
The following instructions enables a smoother transition between your desktop/laptop to the raspberry pi device.
The following instructions enables a smoother transition between your desktop/laptop to the raspberry pi device.
Some issues I encountered *without* the virtual environment was **glibc** version differences on two different machines. Initially, I tested the installation by building & compiling on the **Broadcom BCM2711** quad-core Cortex-A72 (ARM v8) 64-bit SoC @ 1.8GHz device by itself through the normal hush3 instructions provided, but I ran into another set of problems with <ahref="https://gcc.gnu.org/">gcc(g++)</a><ahref="https://packages.debian.org/sid/g++-multilib">**g++-multilib**</a> for the arm64(aarch64) architecture; there are no multilib packages for the arm64(aarch64) architecture.
Some issues I encountered *without* the virtual environment was **glibc** version differences on two different machines. Initially, I tested the installation by building & compiling on the **Broadcom BCM2711** quad-core Cortex-A72 (ARM v8) 64-bit SoC @ 1.8GHz device by itself through the normal hush3 instructions provided, but I ran into another set of problems with <ahref="https://gcc.gnu.org/">gcc(g++)</a><ahref="https://packages.debian.org/sid/g++-multilib">**g++-multilib**</a> for the arm64(aarch64) architecture; there are no multilib packages for the arm64(aarch64) architecture.
@ -15,58 +14,59 @@ Some issues I encountered *without* the virtual environment was **glibc** versio
`sudo docker run -it --rm -v /tmp:/tmp debian:buster`
`sudo docker run -it --rm -v /tmp:/tmp debian:bullseye`
*Note: we chose this debian type because it has the same ldd --version (glibc) on it. At the moment, there is no DietPi docker image to pull from.*
This creates a container with the latest version of Debian. A bind mount is created mapping the /tmp directory on the host machine to the /tmp directory on the container. The additional options mean the container will run in interactive mode with a terminal, and the container will be destroyed when you stop(exit) it.
This creates a container with the latest version of Debian. A bind mount is created mapping the /tmp directory on the host machine to the /tmp directory on the container. The additional options mean the container will run in interactive mode with a terminal, and the container will be destroyed when you stop(exit) it.
`apt-get -y update && apt-get -y upgrade`
`apt-get -y update && apt-get -y upgrade`
2. ### Install Hush build depedencies
2. ### Install Hush build dependencies
*Note: the dependencies for arm64(aarch64) are slightly different; the extra deps are **libboost-dev**, **libdb++-dev**, **libwolssl-dev** and **g++-aarch64-linux-gnu**; libwolf and g++-arch-linux-gnu will be installed later*
*Note: the dependencies for arm64(aarch64) are slightly different; the extra deps are **libboost-dev**, **libdb++-dev**, **libwolssl-dev** and **g++-aarch64-linux-gnu** *
CTRL + X then Y for Yes to confirm and save changes.
4. ### Build and compile for aarch64-linux-gnu device
`HOST=aarch64-linux-gnu ./build.sh -j$(nproc)`
`apt-get -y update`
Relax and let the code flow. It normally takes 15-30min to compile successfully for me.
5. ### Prepare binaries for our ARM64(aarch64) device
On success of building the Hush binaries, we first want to "prepare" them. We do this so we don't end up with a 311 MB hushd binary and instead get the proper size of 15 MB.
#### Install mo dependencies:
The following commands are used in the **Docker container terminal**:
*Note: We install these deps later because of other dep requirements.*
`aarch64-linux-gnu-strip src/hushd`
`apt-get -y install libwolfssl-dev`
`aarch64-linux-gnu-strip src/hush-cli`
`aarch64-linux-gnu-strip src/hush-tx`
- Install GNU C++ compiler for the arm64(aarch64) architecture
6. ### Copy binaries from Docker container to our desktop
`apt-get -y install g++-aarch64-linux-gnu`
Next we will copy these new binaries from our Docker container to our desktop and exit the Docker container.
4. ### Pull or clone latest hush3 from git.hush.is
The following cp command used in the **Docker container terminal** copies from the docker container to actual desktop machine environment into the /tmp/hush-arm64 directory.
`git clone https://git.hush.is/hush/hush3.git && cd hush3`
5. ### Build and compile for aarch64-linux-gnu device
`mkdir /tmp/hush-arm64`
`HOST=aarch64-linux-gnu ./build.sh -j$(nproc)`
`cp src/hushd /tmp/hush-arm64/`
`cp src/hush-cli /tmp/hush-arm64/`
`cp src/hush-tx /tmp/hush-arm64/`
`cp src/hush-smart-chain /tmp/hush-arm64/`
`cp asmap.dat /tmp/hush-arm64/`
`cp sapling-output.params /tmp/hush-arm64/`
`cp sapling-spend.params /tmp/hush-arm64/`
Relax and let the code flow [cat drinking coffee meme] [matrix meme] It normally takes 15-30min to compile successfully for me.
Then you can type exit in the docker container when you are done.
`exit`***Note: on `exit`, the docker container will be completely destroyed!***.
6. ### Copy binaries to ARM64(aarch64) device.
On success of building the Hush binaries, we copy them to our ARM64(aarch64) device and exit the Docker container.
7. ### Copy binaries to ARM64(aarch64) device
Next we will copy these new binaries to our ARM64(aarch64) device. Now that these are on our **actual desktop machine**, we will next copy them to the raspberry pi.
The following cp command used in the **Docker container terminal** copies from docker container to actual machine environment.
`cp -rv ../hush3/ /tmp/hush-arm64`
The installation location is up to you, but for this example we will use **/home/username/hush3-folder** and assume that you have the raspberry pi media mounted on your desktop system. If you have a GUI, you can simply drag / drop or CTRL + C and CTRL + V the folder to the drive if copying between drives is troublesome. Remember though, if copying with GUI, you may run into permission problems.
On the actual **machine environment terminal** we copy all folders and files to raspberry pi drive. The installation location is up to you, but for simplicity sake, I added **/home/user/hush3-foler-name** as a placeholder. If you have a GUI, you can simply drag / drop or CTRL + C and CTRL + V the folder to the drive if copying between drives is troublesome. Remember though, if copying with GUI, you may run into permission problems.
`exit`***Note: on `exit`, the docker container will be completely destroyed!***.
7. ### Launch a fresh hush daemon(node) puppy on ARM64(aarch64)
8. ### Launch a fresh hush daemon(node) puppy on ARM64(aarch64)
`./src/hushd --version`
`./hushd --version`
We have successfully cross-compiled a hushd for a arm64(aarch64) from amd64 or other architecture.
We have successfully cross-compiled a hushd for a arm64(aarch64) from amd64 or other architecture.
*Note: this has only been tested from amd64 architecture; we will update this list later for other tested hardware; the process will almost be identical, but other deps may be needed*
*Note: this has only been tested from amd64 architecture; we will update this list later for other tested hardware; the process will almost be identical, but other dependencies may be needed*