User:Immolo/rust i686

From Gentoo Wiki
Jump to:navigation Jump to:search
Warning
This guide is a work in progress and is only to be used as a starting point!

Environment

  • Figure out LLVM target name corresponding to our destination platform (look at e.g. emerge -pvO sys-devel/llvm for hints).
    • We'll refer to this as LLVM_TARGET just for the purposes of this page.
    • For sparc, it's Sparc.
  • Figure out the Rust target name for our destination platform.
    • Hint: try rustc --print target-list | grep ${ARCH}
    • For sparc, it's sparc64-unknown-linux-gnu.
  • Figure out CHOST for use with both crossdev and later, Rust as CTARGET.
    • We'll call this CTARGET.
    • Hint: look at /var/db/repos/gentoo/profiles/arch/${ARCH}/make.defaults.
    • For sparc, it's sparc64-unknown-linux-gnu as we're not going to worry about 32-bit (at least for now!)


32bit chroot

Create a 32bit chroot on a machine with sse2 using the correct tarball for your needs (I used stage3-i686-openrc).

You will need to install the following in your chroot:

chroot #emerge -va clang
chroot #emerge -va dev-vcs/git

Rust

Grab repo

The git repo is used because the tag tarballs lack the needed submodules.

amd64 #cd rust
amd64 #git checkout 1.62.1
amd64 #git submodule update --init --recursive

Build it

Configure:

FILE config.toml
# Includes one of the default files in src/bootstrap/defaults
profile = "user"
changelog-seen = 2

[rust]
channel = "stable"

Run the mono x.py build script:

chroot #./x.py build --dist i686-unknown-linux-gnu --host i686-pc-linux-gnu --target i686-pc-linux-gnu

All going well, when it terminates, there should be a fresh rustc binary:

chroot #file build/i686-unknown-linux-gnu/stage2/bin/rustc
build/i686-unknown-linux-gnu/stage2/bin/rustc: ELF 32-bit LSB pie executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 3.2.0, not stripped

On the other side

Install built Rust temporarily

Warning
Use a path like /usr/local where it's easy to delete the files afterwards and be sure nothing is lingering contaminating later builds. In fact, this whole procedure should be done in a clean chroot.

Copy the files over to the destination box (i686 in this case):

  • Copy over:
    • build/dist/cargo-1.63.0-i686-unknown-linux-gnu.tar.xz
    • build/dist/rust-std-1.63.0-i686-unknown-linux-gnu.tar.xz
    • build/dist/rustc-1.63.0-i686-unknown-linux-gnu.tar.xz
  • For each: on the other side, untar it to a temporary location, and run inside ./install.sh --prefix=/usr/local/lib/rust/1.63.0/

Ebuild mangling

Some changes are needed to /etc/portage:

FILE /etc/portage/package.unmask
app-eselect/eselect-rust
dev-lang/rust
virtual/rust
FILE /etc/portage/package.accept_keywords
app-eselect/eselect-rust * ~*
dev-lang/rust * ~*
virtual/rust * ~*
FILE /etc/portage/package.use
# This is our LLVM_TARGET from earlier.
dev-lang/rust RUST_TARGETS: Sparc

Copy the Rust ebuilds to a temporary location:

x86 #mkdir -p /tmp/dev-lang/rust && cd /tmp/dev-lang/rust
x86 #cp -rv /var/db/repos/gentoo/dev-lang/rust/* .

Modify the relevant Rust ebuild corresponding to the current latest Rust release (must match the version built from git):

  1. Add 'return' to the top of pkg_setup (re eselect-rust checks)
  2. Replace the rustc call in src_configure by just setting rust_stage0_root=/usr/local/lib/rust/1.61.0/
  3. May need to comment out the [[ -d ${rust_stage0_root} ]] check (?)

Then try to emerge using it:

sparc #USE=system-bootstrap ebuild rust-1.61.0.ebuild clean merge

Once done, some manual fiddling may be needed to get LDPATH right initially and make eselect rust happy.

Run eselect rust update and placate any complaints it has if there's stale stuff left over from the /usr/local bits. Try env-update && . /etc/profile.

Remember to clean up /usr/local/{bin,lib/*}.

Now do it all again using a vanilla ebuild:

sparc #USE=system-bootstrap ebuild /var/db/repos/gentoo/dev-lang/rust/rust-1.61.0.ebuild clean merge

Distribution tarball

Note
See bug #671736 and bug #842246 which will make it easier to add non-upstream bootstrap tarballs into dev-lang/rust-bin.

We need to now re-emerge dev-lang/rust with USE=dist:

sparc #USE="dist system-bootstrap" ebuild rust-1.61.0.ebuild clean merge

Once done, the binaries should be at $(rustc --print sysroot)/dist (in this case, that's /usr/lib/rust/1.61.0/dist):

sparc #ls -al $(rustc --print sysroot)/dist
total 61732
drwxr-xr-x 2 root root     4096 Jun 22 19:19 .
drwxr-xr-x 7 root root     4096 Jun 22 19:19 ..
-rw-r--r-- 1 root root  4134536 Jun 22 19:18 cargo-1.61.0-sparc64-unknown-linux-gnu.tar.xz
-rw-r--r-- 1 root root 20586916 Jun 22 19:18 rust-std-1.61.0-sparc64-unknown-linux-gnu.tar.xz
-rw-r--r-- 1 root root 38477600 Jun 22 19:18 rustc-1.61.0-sparc64-unknown-linux-gnu.tar.xz

See Also