Skip to content

Instantly share code, notes, and snippets.

@edwardw
Created November 21, 2013 19:20
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save edwardw/7587876 to your computer and use it in GitHub Desktop.
Boot to Rust in OS X

Booting to Rust by Eric Holk! It is just mind-bogglingly cool. What else can I say? His enhancement to Rust has been landed so it is time for me to try that out, in OS X. The setup of the toolchain could be a little bit challenging.

First and foremost, check out the latest Rust with win64 calling convention contributed by Eric Holk and build it.

Then prepare the cross linker.

$ wget http://ftpmirror.gnu.org/binutils/binutils-2.23.2.tar.gz
$ tar xvzf binutils-2.23.2.tar.gz
$ cd binutils-2.23.2
$ mkdir dist
$ ./configure --target=x86_64-efi-pe --disable-werror --prefix=./dist
$ make && make install

If all goes well, there will be dist/bin/x86_64-efi-pe-ld.

Grab the boot.rs, compile it and link it.

$ path/to/latest/rustc -c -O --target x86_64-pc-linux-gnu --lib boot.rs
$ path/to/x86_64-efi-pe-ld --oformat pei-x86-64 --subsystem 10 -pie -e efi_main boot.o -o boot.efi

Now create the iso file in correct format, which will be used to boot the VM.

$ mkdir -p rustos/efi/boot
$ cp boot.efi rustos/efi/boot/bootx64.efi
$ hdiutil create -format UDTO -srcfolder rustos rustos
$ hdiutil makehybrid -iso -joliet -o rustos.iso rustos.cdr

Finally, go ahead create a new VM in virtualbox for other/unknown 64-bit OS and enable the EFI option. Point the VM to the ISO file just created and it should be able to boot to the "Hello World"!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment