Skip to content

Instantly share code, notes, and snippets.

@willnode
Last active April 10, 2024 11:38
Show Gist options
  • Save willnode/88da35d0c0542276b4631746d8fc3de1 to your computer and use it in GitHub Desktop.
Save willnode/88da35d0c0542276b4631746d8fc3de1 to your computer and use it in GitHub Desktop.
Build Redox OS in MacOS Apple Silicon

This is a way to compile Redox OS in MacOS Apple Silicon without using podman.

Clone

git clone --recurse-submodules https://gitlab.redox-os.org/redox-os/redox.git
cd redox

Additional brew installs & deps

sh ./bootstrap.sh -d -e qemu
brew install coreutils

Setup .config

Set arch target. Write this to ./.config:

ARCH=x86_64

ARCH=aarch64 is currently not compile on relibc AFAIK

Patch pkgutils

This patch has on going merge request: https://gitlab.redox-os.org/redox-os/pkgutils/-/merge_requests/40

Please patch the submodule to ./cookbook/pkgutils.

cd ./cookbook/pkgutils
git remote set-url origin https://gitlab.redox-os.org/willnode/pkgutils.git
git checkout patch-1
git pull

Then modify these files: ./cookbook/Cargo.toml, ./installer/Cargo.toml

[patch.crates-io]
redox_pkgutils = { path = "../cookbook/pkgutils"  }

Patch binutils and gcc

Currently, these modified components are using old upstream that doesn't support compiling with MacOS Apple Silicon.

I forked these repos and updated their upstream as needed in my personal forks. Let's use them.

mkdir -p prefix
cd prefix
git clone https://gitlab.redox-os.org/willnode/binutils-gdb
git clone https://gitlab.redox-os.org/willnode/gcc
mkdir -p x86_64-unknown-redox && cd $_
touch binutils.tar.bz2
touch gcc.tar.bz2
ln -s ../binutils-gdb binutils
ln -s ../gcc gcc
cd ./gcc && ./contrib/download_prerequisites
cd ../../..

If you use aarch64 please change x86_64-unknown-redox to aarch64-unknown-redox

Lastly, install GMP and put it as part of bintuils's configure. This is because a newer utils needs it.

brew install gmp
brew info gmp

Copy its directory dir and put if on binutils's configure. This is in file mk/prefix.mk around line 94-99.

"$(ROOT)/$</configure" \
		--target="$(TARGET)" \
		--program-prefix="$(TARGET)-" \
		--prefix="" \
		--disable-werror \
+		--with-libgmp-prefix=/opt/homebrew/Cellar/gmp/6.2.1_1 \
		&& \

Build Prefix

After everything done, execute the build:

time make all

It will build all prefix builds..

Unfortunately, it will stop after error[E0463]: can't find crate for `std`.. So after the build stop, comment this line in ./Makefile:

# Cross compiler recipes
-include mk/prefix.mk
+# include mk/prefix.mk

Next we need to install gnu-tar and set it as the alias for tar:

brew install gnu-tar
export PATH="/opt/homebrew/opt/gnu-tar/libexec/gnubin:$PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment