Skip to content
  • Eric Kidd's avatar
    Define a custom target and compile our own libcore · 7b225fbf
    Eric Kidd authored
    Up until now, we've been using the standard `x86_64-unknown-linux-gnu`
    target to build our operating system.  This builds normal Linux Rust
    binaries which assume that they're running in userspace.
    
    According the http://wiki.osdev.org/Beginner_Mistakes, we _really_ out
    to be using a cross-compiler instead:
    
    > Avoid Ignorance
    >
    > Beginners often ask "What is the easiest way to do X?" rather than
    > "What is the best, proper, correct way to do X?". This is dangerous as
    > the newcomer doesn't invest time into understanding the superior way
    > to implement something, but instead pick a conceptually simpler method
    > copied from a tutorial. Indeed, the simpler route is often too simple
    > and end up causing more problems in the long run, because the beginner
    > is ignorant of the superior alternative and doesn't know when it is
    > better to switch. What's so bad about taking the hard route instead?
    >
    > Common examples include being too lazy to use a Cross-Compiler,
    > developing in Real Mode instead of Protected Mode or Long Mode,
    > relying on BIOS calls rather than writing real hardware drivers, using
    > flat binaries instead of ELF, and so on.
    
    The Rust equivalent using a cross-compiler is to define a custom target
    file (`x86_64-unknown-none-gnu.json`, where `none` means "bare metal")
    and configure Rust correctly.  Then we need to build a custom libcore.
    
    We do this using a patch from
    https://github.com/thepowersgang/rust-barebones-kernel, which we
    download and apply to a copy of the Rust source.  From there, it's
    possible to get cargo running against `x86_64-unknown-none-gnu.json`,
    which is awesome.
    7b225fbf