Cross compile target i386 architecture

Hello everyone, total Rust noob here. I'm mucking about with Rust on an old i586 300mhz Pentium MMX running a bare bones Debian 8.1 upgraded to Debian Sid.

I'd been hesistant to upgrade to the unstable release of Debian but I shouldn't have been. It was completely painless and now I've got the Rust goodies.

I'm wondering how to cross compile for i386 on an amd64 machine. Perhaps its' as simple as running the Rust compiler like this:

rustc --target=i386-linux-gnu
1 Like

Wasn't so simple, I get the following error:

error: Error loading target specification: Could not find specification for target "i386-linux-gnu"

I've tried various different targets such as i386-linux-unknown, i386-pc-linux. Not found one that works yet but I am stabbing in the dark. Is it possible to get a list of available ones?

Check out

Maybe you can get by with just tweaking this line.

Wonderful, thanks for the links! Looks like essential reading for this kind of thing.

edit: there is more -

So the "target specification" should be json format. I've created one:

    "data-layout": "",
    "llvm-target": "i386-linux-gnu",
    "target-endian": "little",
    "target-pointer-width": "32",
    "os": "linux",
    "target-env": "gnu",
    "arch": "x86",
    "options": "base"

Compile the hello world example like:

rustc --target=i386.json

I'm getting the following error: 1:1 error: can't find crate for `std` fn main() {
error: aborting due to previous error

Without setting a target I can compile fine. Do I need to get the rust std library compiled for i386?

edit: (yes, it seems I do , I'll be trying this later - Cross compiling std (quickly) with cargo )

1 Like

So were you successful? I'd like to build a non-SSE version of rust tools to play on my first windows computer from 98' (P2).

Between the three of us we've already solved virtually all pertinent issues in those other threads - it would be nice if you guys could finish this off (next stable?) so we could score a hat-trick :smile:

The 64-bit windows laptop that I'd been using is no longer at my disposal so I won't be able to help directly. :sob:

A cross-compiled custom target like e.g. atom-unknown-linux-gnu should prove to be more interesting (and useful) if anyone decides to attempt it.

I was looking into this problem recently and the answer is more or less this (if you meant cross-bootstrapping) :

Had you simply meant cross-compiling for i686 on x86_64, the problem becomes trivial.

All you need is a gcc for your cross architecture for linking (x86_64 linker is already compatible with i686 so you'll just need the multilib part) and all the rust static rlibs which you can copy from the official i686 distribution (rustc commit hashes must be identical). They need to be put in lib/rustlib in a separate target triple directory, next to the native one.

It should work like this on x86_64:

rustc --target=i686-unknown-linux-gnu

whereas for a truly incompatible architecture the linker needs to be specified explicitly:

rustc -C linker=arm-linux-gnueabihf-gcc-5.2 --target=arm-unknown-linux-gnueabihf

What if you wanted to actually cross-compile for Pentium Pro and not Pentium4? You'd have to use rlibs built for a compatible CPU architecture and pass an additional -C target-cpu= flag to rustc.

For a quick test that doesn't require gcc/multilib, after copying over the crates (rlibs) for the cross architecture you could do:

cargo build --target=i686-unknown-linux-gnu

inside some project directory on your x86_64 machine.