Building anything that is more than a couple of files of code on my mac has been really annoying and tedious. I have a compact pc for these cases, but I do not have a monitor for it. Now I just use a docker container.

I created this docker compose file in a folder:

version: "1"
    image: amd64/ubuntu
    platform: linux/amd64
      - .:/root/myfolder2
    working_dir: /root
    cpus: 2
    network_mode: host
      - seccomp:unconfined
    privileged: true
      - ALL

In the same directory as my docker-compose.yml (~/myfolder/):

docker compose run --name=mycontainer dev bash

Then make the mounted folder writable:

sudo chmod +w ~/myfolder

In the container:

apt update
apt install build-essentials vim

Now I can just build things and run in the container or cross compile for the host machine.

Useful commands:

# start the container when the docker daemon is running
docker start -i mycontainer

# stop the container
docker stop mycontainer

# opens a bash container in the running container
docker exec -it mycontainer bash

# remove all stopped containers
docker container prune