Skip to content

Loading…

Mac OS support #55

Open
phil-opp opened this Issue · 15 comments

5 participants

@phil-opp
Owner

Some Mac OS users seem to have tool problems in the first post. So it might be a good idea to create a separate page that lists all needed extra steps (such as updating nasm).

Unfortunately, I have zero Mac experience and can only copy instructions from the post's comments. So if someone got it working, I would really appreciate a list of required commands!

@sptramer

Here's what I did to get up and running on OS X:

  • Install Xcode 7.1.1 and Command Line Tools (xcode-select --install once Xcode is installed)
  • Install rust (latest stable? Not quite at the point where features from Nightly might be getting used)
  • Install homebrew: http://brew.sh/
  • Install latest nasm: brew install nasm
  • Install GCC: brew install gcc -- this is only necessary for the binutils compilation, and if you want, you can nuke GCC afterwards.
  • Cross-compile binutils: Just follow the handy instructions provided by you -- although I used /usr/local as the prefix install point just for ease of use.
@sptramer

Note on the binutils cross-compile -- looks like it builds into /usr/local/x86_64-elf/ (a change with binutils 2.26.51?) and no longer prefixes the commands automatically. Instead it looks like --program-prefix does the name prefixing. Maybe I just missed the automation before?

Here's the "works for me" binutils config: ../binutils-2.26.51/configure --target=x86_64-elf --prefix=/usr/local --disable-nls --disable-werror --disable-gdb --disable-libdecnumber --disable-readline --disable-sim --program-prefix=x86_64-elf-

@phil-opp
Owner

Thank you very much! I hope I find some time to create a first draft soon.

@sptramer

No problem. There's still one missing piece, which is building the GRUB toolchain. For now there is an (outdated; sketchy?) homebrew tap that can be used, found by a commenter on the blog post:

http://os.phil-opp.com/multiboot-kernel.html#comment-2374018414

Others have said that the OSDev wiki grub building instructions worked:

http://wiki.osdev.org/GRUB_2#Installing_GRUB2_on_Mac_OS_X

@jcaudle

Do you think you'd prefer a list of commands or a PR with how someone could get things set up on a Mac? I was planning on adding a README to my own implementation of the OS, but if you need a writer for the page, I'd be happy to put something together when I get the chance to write out what I did to get things going on my own Mac.

@phil-opp
Owner

@jcaudle That would be really awesome!

@jcaudle

@sptramer have you been able to link the rust code into your kernel as described in the Setup Rust post? I've been running into a problem where I need to run ranlib, which then doesn't properly add the symbol for rust_main (I think...). If you've gotten past that, I'd be much more able to write something up for future OS builders! :smile:

@sptramer

@jcaudle Not yet - I'm still setting up the cross-compilers correctly. It looks like I goofed on the i386 binutils above by putting them in /usr/local -- cross-compiling GCC against these binutils, even setting CC/CXX/CPP/LD to the correct installed gcc version seems to force it to link against the clang assembler, which screws everything up.

I just installed rust from the .pkg distribution they offered. If it turns out that's not quite enough, I'll look into it when I reach that point.

@sptramer

Here's how I was able to eventually get a grub build working:

  • When cross-compiling i386 binutils, make sure that they go into a non-standard location. I used --prefix=/opt/i386-toolchain. The full command line that worked for me was: CC=gcc-5 CXX=g++-5 CPP=cpp-5 LD=gcc-5 ../binutils-2.26.51/configure --target=i386-elf --prefix=/opt/i386-toolchain --disable-nls --disable-werror --disable-gdb --disable-libdecnumber --disable-readline --disable-sim
  • In addition to cross-compiling i386 binutils, you need an i386 GCC for grub: CC=gcc-5 CXX=g++-5 CPP=cpp-5 LD=gcc-5 ../gcc-5.2.0/configure --target=i386-elf --disable-nls --enable-languages=c,c++ --without-headers --prefix=/opt/i386-toolchain.
  • Build objconv for the host architecture, meaning that you can just use gcc-5 as the compiler invoke.
  • Configure grub to use the cross-compiled tools and also the host GCC toolchain: CC=gcc-5 CXX=g++-5 CPP=gcc-5 LD=gcc-5 ../grub/configure --disable-werror TARGET_CC=i386-elf-gcc TARGET_STRIP=i386-elf-strip TARGET_NM=i386-elf-nm TARGET_RANLIB=i386-elf-ranlib --target=i386-elf --prefix=/opt/i386-toolchain
  • NOTE: You may need to upgrade flex for building grub. You want to brew install flex and then brew link --force flex so it replaces the system flex. Then brew unlink flex to clean it up when you're done.

Other brew formulas you'll probably need are qemu and xorriso. At this point I had the bootloader working and showing OK from make run.

@sptramer

Well, get ready for the bad news on cross-compiling a bare metal capable rust libcore on OS X:

rust-lang/rust#16259

Seems like the rust team doesn't have the bandwidth to resolve the issue at this time. Cross-compiler support for rust in general seems pretty back-burner, but Darwin -> i686/x86_64 seems like an especially low priority because how how screwed up Apple's linker is. Seems like you can provide your own x86_64 toolchain - but it's complicated as hell.

@phil-opp
Owner

This seems to be much more complicated than I thought… Maybe it's easier to use a virtual Linux machine. For example, see Lifepillar's comment.

Ashley Williams's x86-kernel repository contains a Vagrantfile that should make it easy to get a working virtual environment. There are some instructions in the readme, too.

@phil-opp phil-opp changed the title from Add a `Get started on Mac OS` page to Mac OS support
@jcaudle

Good call on suggesting the use of vagrant. After the find by @sptramer, I was going to switch to setting up vagrant myself.

@steveklabnik

cc @ashleygwilliams, who was mentioned upthread but not in a way that would ping her :)

@ashleygwilliams

hey @phil-opp would you be interested in a PR with the vagrantfile and the mac docs? i'd me more than happy to contribute

@phil-opp
Owner

That would be awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.