How to cross compile a rust kernel with a default toolchain.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Layl
Posts: 4
Joined: Wed Nov 19, 2014 5:24 pm

How to cross compile a rust kernel with a default toolchain.

Post by Layl »

I'm looking to compile a rust kernel (preferably built with cargo) without any recompiling of GCC needed. Preferably this needs to work on MinGW or Cygwin out of the box. The goal with this is that I can give a really simple setup guide. I know that I can do the assembly part with nasm and the rust part with rustc/cargo without recompiling, but the linking part is a problem I don't know how to solve.
Octocontrabass
Member
Member
Posts: 5588
Joined: Mon Mar 25, 2013 7:01 pm

Re: How to cross compile a rust kernel with a default toolch

Post by Octocontrabass »

Building a GCC Cross-Compiler works with MinGW out of the box (as long as you also installed MSYS).

I know that's not what you want to hear, but abusing OS-specific GCC for OS development is generally discouraged around here.
Layl
Posts: 4
Joined: Wed Nov 19, 2014 5:24 pm

Re: How to cross compile a rust kernel with a default toolch

Post by Layl »

I am not looking at using OS-specific toolchains in such a way, rather I am looking at tools that can output binaries for a variety of platforms without recompiling the tool. Recompiling GCC unfortunately did not work for me out of the box with MinGW, so I do that on a VM with [insert linux distro here] instead when I need GCC for a specific platform.
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: How to cross compile a rust kernel with a default toolch

Post by zhiayang »

clang, at least on OS X, supports the "-target" argument, which you can use to target x86_64-elf, or some ARM platform of your choice.
Icee
Member
Member
Posts: 100
Joined: Wed Jan 08, 2014 8:41 am
Location: Moscow, Russia

Re: How to cross compile a rust kernel with a default toolch

Post by Icee »

The canonical (I guess) way to compile with Rust in this case is by passing a .json file as a --target argument. Start your journey here. For final linking, you'll still want a cross-compiled ld from binutils; although you may end up well with just objcopy'ing to your desired output format with the stock binutils depending on your setup.

EDIT: in any case, as long as you don't have any C sources in your project, you don't need GCC at all.
Post Reply