Cross compile target i386 architecture


#1

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

Running rust on i386 systems
#2

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?


#3

Check out

Maybe you can get by with just tweaking this line.


#4

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

edit: there is more -

http://www.cs.brandeis.edu/~cs146a/rust/doc-02-21-2015/rustc_back/target/index.html

http://doc.rust-lang.org/1.1.0/rustc_back/target/struct.Target.html


#5

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 hello.rs

I’m getting the following error:

hello.rs:1:1: 1:1 error: can't find crate for `std`
hello.rs:1 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 https://github.com/japaric/std-with-cargo/blob/master/README.md )


#6

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).


#7

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:

EDIT:
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.


#8

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 hello.rs

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 hello.rs

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.


#9