Bug 216143 - lang/rust, devel/cargo: generate bootstraps for Tier2 architectures via cross-compilation
Summary: lang/rust, devel/cargo: generate bootstraps for Tier2 architectures via cross...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Jean-Sébastien Pédron
Keywords: dogfood, needs-patch
Depends on:
Blocks: 225279
  Show dependency treegraph
Reported: 2017-01-16 15:04 UTC by Jan Beich
Modified: 2019-03-02 22:21 UTC (History)
8 users (show)

See Also:
dumbbell: maintainer-feedback+


Note You need to log in before you can comment on or make changes to this bug.
Description Jan Beich freebsd_committer 2017-01-16 15:04:45 UTC
Firefox >= 51 requires Cargo to build with Rust support. The option to disable it will[1] go away sometime this year. If we leave things as is www/firefox may become amd64-only, even losing recently gained aarch64 support.

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1284816
Comment 1 Jean-Sébastien Pédron freebsd_committer 2017-01-21 00:09:26 UTC

I started to look into this.

== Updating lang/rust-nightly ==

I'm updating lang/rust-nightly to a recent snapshot and add support for i386 at the same time. This is not directly related to this issue but will help to make sure we don't have regression. I'm currently testing the port in Poudriere for HEAD/amd64 and 11.0/i386.

== Cargo on i386 ==

I'm updating devel/cargo to 0.15.0 and add i386 support at the same time. There cargo prebuilt binaries available for FreeBSD/i386 since last October, I missed that. I'm currently testing the port in Poudriere for HEAD/amd64. Unfortunately, I can't test 11.0/i386 because cargo(1) for i386 segfaults on amd64. The executable runs successfully in ref11-i386. I will try to build the port there.

== Rust and Cargo on !x86 ==

Finally, I started to look for guides to bootstrap Rust and Cargo on unsupported hosts. I'm going to take aarch64 as the first victim.

I found the following article from someone who did several ports of Rust:

The following article might be useful too; I'm not sure yet:

I will keep you posted.
Comment 2 Jean-Sébastien Pédron freebsd_committer 2017-01-21 13:09:45 UTC
The patch to update Cargo to 0.15.0 and enable it on i386 is up for review:
Comment 3 Jean-Sébastien Pédron freebsd_committer 2017-01-21 13:11:29 UTC
Sorry, wrong copy/paste...

The review is this one:
Comment 4 commit-hook freebsd_committer 2017-01-22 10:45:48 UTC
A commit references this bug:

Author: dumbbell
Date: Sun Jan 22 10:45:30 UTC 2017
New revision: 432111
URL: https://svnweb.freebsd.org/changeset/ports/432111

  devel/cargo: Update to 0.15.0, enable on i386

  The new version requires cargo(1) to be available. Therefore, we let the
  Ports system to extract the bootstrap cargo (it was done by the Cargo
  build system before) and set a configure flag to point to it.

  We need to set OPENSSL_DIR as a Make environment variable because the
  openssl-sys crate's build.rs doesn't know about FreeBSD.

  Finally, enable devel/cargo on i386. A bootstrap cargo executable is
  available for FreeBSD/i386 since last October but I missed it. We can
  now use it to build a port/package for i386.

  PR:		216143
  Approved by:	bapt (mentor)
  Differential Revision:	https://reviews.freebsd.org/D9273

Comment 5 commit-hook freebsd_committer 2017-01-23 21:56:12 UTC
A commit references this bug:

Author: dumbbell
Date: Mon Jan 23 21:55:49 UTC 2017
New revision: 432293
URL: https://svnweb.freebsd.org/changeset/ports/432293

  devel/cargo: Fix bootstrap checksum + use ${OPENSSLBASE}

  Because devel/cargo and lang/rust-nightly use a different DISTFILE with
  the same name, the wrong checksum and size was selected in devel/cargo.
  To fix this, keep the parent directory (a date) in the DISTFILE name.

  Also, depending on the value of DEFAULT_VERSION=ssl= and whether OpenSSL
  from ports is installed, the openssl-sys crate could fail to build.
  Passing OpenSSL location to make was way too complicated anyway. So
  simplify it and use ${OPENSSLBASE}. This was reported in PR 216385.


  PR:		216143, 216385
  Reported by:	gja822@narod.ru (216385, SSL build failure)
  Approved by:	antoine (mentor), jbeich
  Differential Revision:	https://reviews.freebsd.org/D9295

Comment 6 commit-hook freebsd_committer 2017-01-23 22:06:25 UTC
A commit references this bug:

Author: jbeich
Date: Mon Jan 23 22:05:31 UTC 2017
New revision: 432294
URL: https://svnweb.freebsd.org/changeset/ports/432294

  www/firefox: re-enable RUST on i386 after r432111

  PR:		216143

Comment 7 Jean-Sébastien Pédron freebsd_committer 2017-01-26 08:59:54 UTC
Quick status update on boostrapping on aarch64.

I'm following japaric's guide [1]. Step 1 (manually cross-compiling the `core` crate) and step 2 (teaching `rustc` about aarch64-unknown-freebsd) are done. I'm at step 3 (cross-compiling `std`). I made the required changes to the `libc` crate and `std` builds but doesn't link:

The `panic_unwind` crate builds fine, but it is not picked by `std`. I asked for help on IRC.

I submitted no pull request so far: I want to be sure the existing patches are fine.

[1] https://www.reddit.com/r/rust/comments/5ag60z/how_do_i_bootstrap_rust_to_crosscompile_for_a_new/
Comment 8 Jean-Sébastien Pédron freebsd_committer 2017-01-31 23:52:16 UTC
Another quick update: I could cross-compile rust-std for aarch64, using `x.py`, Clang 3.7 and a cross-compiled buildworld. So far, it was much simpler than the guide I linked before.

However, `x.py` doesn't even try to compile rustc. I need to firgure out why.
Comment 9 Jean-Sébastien Pédron freebsd_committer 2017-02-02 08:59:24 UTC
Status update:

I could finally cross-compile a working rustc for aarch64:

    dumbbell@ref12-aarch64:~/rust % uname -a
    FreeBSD ref12-aarch64.freebsd.org 12.0-CURRENT FreeBSD 12.0-CURRENT #0
    r306376: Tue Sep 27 20:33:16 UTC 2016

    dumbbell@ref12-aarch64:~/rust % ./nightly/bin/rustc -V
    rustc 1.16.0-nightly (3f4718c82 2017-01-26)

    dumbbell@ref12-aarch64:~/rust % ./nightly/bin/rustc -o hello hello.rs

    dumbbell@ref12-aarch64:~/rust % ./hello
    Hello from Rust on FreeBSD/arm64!

The next steps are:
- bootstrapping Cargo;
- testing a native build of Rust using the cross-compiled compiler and Cargo;
- submitting pull requests;
- asking upstream to enable automated buildd of nightlies.
Comment 10 Jean-Sébastien Pédron freebsd_committer 2017-02-02 17:23:40 UTC
Status update:

Cargo is bootstrapped! That was easy compared to Rust.

    dumbbell@ref12-aarch64:~/rust % ./nightly/bin/cargo --version
    cargo-0.17.0-nightly (38f52ea8 2017-02-02)

    dumbbell@ref12-aarch64:~/rust % cargo new hello_world --bin
         Created binary (application) `hello_world` project

    dumbbell@ref12-aarch64:~/rust % cd hello_world/

    dumbbell@ref12-aarch64:~/rust/hello_world % cargo build
       Compiling hello_world v0.1.0 (file:///home/dumbbell/rust/hello_world)
        Finished dev [unoptimized + debuginfo] target(s) in 3.50 secs

    dumbbell@ref12-aarch64:~/rust/hello_world % ./target/debug/hello_world
    Hello, world!

    dumbbell@ref12-aarch64:~/rust/hello_world % cargo run
        Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
         Running `target/debug/hello_world`
    Hello, world!
Comment 11 Jean-Sébastien Pédron freebsd_committer 2017-02-03 11:50:22 UTC
I could cross-compile Rust for aarch64 again from scratch, just to verify my notes, scripts and patches. I put the results here (including Cargo), in case people want to play with them:

There is an install script in the three archives.

Patches are in those two Git branches:

I installed them on ref12-arm64.freebsd.org and now, I'm building Rust there to see if it can self-host. Once this is done, I can finally submit patches :)
Comment 12 Jean-Sébastien Pédron freebsd_committer 2017-02-03 13:57:43 UTC
Rust can self-host on FreeBSD/aarch64:

    Copying stage2 compiler (aarch64-unknown-freebsd)
    Copying stage2 std from stage1 (... -> aarch64-unknown-freebsd)
    Copying stage2 test from stage1 (... -> aarch64-unknown-freebsd)
    Copying stage2 rustc from stage1 (... -> aarch64-unknown-freebsd)
    Build completed in 2:04:16
    dumbbell@ref12-aarch64:~/rust/rust %
Comment 13 Jean-Sébastien Pédron freebsd_committer 2017-02-03 17:06:50 UTC
I submitted two pull requests:
Comment 14 Jean-Sébastien Pédron freebsd_committer 2017-02-03 21:41:32 UTC
I put my notes in a gist:

The `libc` pull request was approved, tested and merged! The `rust` pull request was approved and is being tested.
Comment 15 Jean-Sébastien Pédron freebsd_committer 2017-02-06 09:25:18 UTC
The pull request to rust-lang/rust was merged too. I'm going to ask about when/how the libc Git submodule is updated and how to enable official FreeBSD/aarch64 bootstraps.
Comment 16 Jean-Sébastien Pédron freebsd_committer 2017-02-09 17:31:13 UTC
The pull request to update the libc Git submodule in Rust was just merged:

Thus all patches are in to build for and run on FreeBSD/aarch64.

The next step is asking upstream how to enable automatic creation of official FreeBSD/aarch64 bootstraps.

In the meantime, it's probably possible we produce our own use it to build packages of lang/rust-nightly, perhaps lang/rust too. For Cargo, I'm wondering if we would need a devel/cargo-nightly. I'll play around that as soon as I can.

For sparc64, the patches are ready, but I can't get a working C++ cross-compiler: either I get compilation/link failures or the produced executable segfaults. To be exact, I could obtain a working hello world with base's libstdc++, but LLVM (built as part of the Rust build) requires libstdc++ 4.7+.
Comment 17 Jean-Sébastien Pédron freebsd_committer 2017-02-13 22:40:36 UTC
I'm waiting for the following review to be approved (updating rust-nightly to a recent snapshot):

Then I will modify the port to build on FreeBSD/aarch64.
Comment 18 Jean-Sébastien Pédron freebsd_committer 2017-02-13 22:47:53 UTC
About sparc64, I'm building lang/gcc6 on the target because the cross-compiler (sparc64-gcc) is 6.3.0 and it doesn't want libstdc++ from gcc 4.9. Unfortunately, I'm having some troubles: comparison of stage2 and stage3 fails. I'm now rebuilding the port with the `BOOTSTRAP` option.

About armv6, Mikaël Urankar could bootstrap Rust and Cargo. However, Cargo segfaults while verifying if Rust can self-host.
Comment 19 Jean-Sébastien Pédron freebsd_committer 2017-02-16 13:28:34 UTC
Status update for sparc64

I could finally build lang/gcc6 natively and use its libstdc++ with sparc64-gcc cross-compiler. Building the bootstrap of Rust and Cargo was straightforward after that. I uploaded the bootstrap on freefall:

I could build and run a Hello World with Cargo. Note that the bootstrapped rustc requires libstdc++ from lang/gcc6.

I'm going to test Rust self-hosting now.
Comment 20 commit-hook freebsd_committer 2017-02-22 19:04:46 UTC
A commit references this bug:

Author: dumbbell
Date: Wed Feb 22 19:04:05 UTC 2017
New revision: 434631
URL: https://svnweb.freebsd.org/changeset/ports/434631

  lang/rust, lang/rust-nightly: Update to 1.15.1 and 1.17.0 respectively

  Both versions of Rust seen changes to their build system. Now they
  require a bootstrap of Cargo and thus, a snapshot of Cargo's registry.

  Each library has its own suffix instead of a common suffix for a given
  version of Rust. Thus all future updates of the ports will include
  changes to their plist.

  $DISTFILES are now all under the `rust` directory in `$DISTDIR`. A
  similar change will be committed to devel/cargo later.

  lang/rust-nightly is enabled on i386 (bugzilla 216143). The source
  snapshot also contains everything to build it on aarch64, but enabling
  it will be committed later.

  PR:		216143
  Approved by:	riggs, bapt (mentor), antoine (mentor)
  Differential Revision:	https://reviews.freebsd.org/D9286

Comment 21 Jean-Sébastien Pédron freebsd_committer 2017-03-04 13:26:40 UTC
I still have change waiting for approval before I can start with lang/rust* on aarch64. Sorry it takes so long.
Comment 22 Jean-Sébastien Pédron freebsd_committer 2017-03-04 13:28:18 UTC
About sparc64, I made little progress. Rust is having issues with kqueue(2) there. Also gcc segfaults quite often.
Comment 23 Jan Beich freebsd_committer 2017-05-21 00:38:39 UTC
Any news on aarch64 in lang/rust (1.17+) + devel/cargo (0.18+)? I can probably keep --disable-rust availability for a while longer (ideally until ESR59) as Mozilla doesn't plan to remove non-oxidated codepaths just yet. Here's how FF55 version currently looks like: https://github.com/jbeich/gecko-dev/commit/5528caa9d548
Comment 24 Jean-Sébastien Pédron freebsd_committer 2017-05-21 08:44:38 UTC
I resumed the work on aarch64 last week and this week-end.

I have some patches almost ready for the port, but the bootstrap compiler I created previously is too old and can't compile Rust anymore. I'm now creating a new bootstrap compiler based on Rust 1.17.0.
Comment 25 Jean-Sébastien Pédron freebsd_committer 2017-05-21 08:51:24 UTC
Note that Rust 1.17.0 has the commits for FreeBSD/aarch64 so it should not require any additional patches. The patches I was talking about are the changes to lang/rust and lang/rust-nightly themselves.
Comment 26 Jean-Sébastien Pédron freebsd_committer 2017-05-22 15:31:44 UTC
Here is the patch on Phabricator to enable lang/rust on FreeBSD/aarch64:
Comment 27 Jean-Sébastien Pédron freebsd_committer 2017-05-23 07:38:02 UTC
And here is the patch on Phabricator to enable devel/cargo on FreeBSD/aarch64:

This patch is *UNTESTED* for now.
Comment 28 commit-hook freebsd_committer 2017-06-17 14:44:54 UTC
A commit references this bug:

Author: dumbbell
Date: Sat Jun 17 14:44:30 UTC 2017
New revision: 443777
URL: https://svnweb.freebsd.org/changeset/ports/443777

  lang/rust: Enable on FreeBSD/aarch64 + various fixes

  This port now uses an unofficial bootstrap of Rust 1.17.0 and Cargo
  0.18.0 for FreeBSD/aarch64. Here are my notes to create this boostrap:

  The port's Makefile was changed to:
      - allow to override the versions and directories of the bootstrap
      - patch the bootstrap script and manifest with those

  Beside changes to support FreeBSD/aarch64, the port received the
  following fixes:
      - Pass python path to the configure script.
      - Fix and simplify the extraction of rust-std bootstrap by re-using
        existing variables.
      - Make sure tar(1) doesn't produce sparse file entries when it
        recreates the rust-std bootstrap because Python 2's tarfile module
        doesn't support them (PR 219842).

  PR:		216143, 219842
  Differential Revision:	https://reviews.freebsd.org/D10857

Comment 29 Jean-Sébastien Pédron freebsd_committer 2017-06-17 14:55:33 UTC
Support for FreeBSD/aarch64 was just enabled in lang/rust. Next step is to do the same in devel/cargo. No ETA :)
Comment 30 commit-hook freebsd_committer 2017-06-17 15:37:39 UTC
A commit references this bug:

Author: dumbbell
Date: Sat Jun 17 15:37:26 UTC 2017
New revision: 443780
URL: https://svnweb.freebsd.org/changeset/ports/443780

  devel/cargo: Update to 0.19.0 + enable on FreeBSD/aarch64

  See r443777 for details on the FreeBSD/aarch64 bootstrap.

  PR:		216143
  Differential Revision:	https://reviews.freebsd.org/D10867

Comment 31 commit-hook freebsd_committer 2017-06-22 01:19:36 UTC
A commit references this bug:

Author: jbeich
Date: Thu Jun 22 01:19:17 UTC 2017
New revision: 444090
URL: https://svnweb.freebsd.org/changeset/ports/444090

  www/firefox: enable RUST on aarch64 after r443777 and r443780

  PR:		216143

Comment 32 Jan Beich freebsd_committer 2017-06-27 10:25:27 UTC
www/firefox wasn't ready: https://bugzilla.mozilla.org/show_bug.cgi?id=1376411
Comment 33 Jan Beich freebsd_committer 2017-07-10 14:07:31 UTC
Any news on armv6?

(In reply to Jan Beich from comment #23)
> I can probably keep --disable-rust availability for a while longer
> (ideally until ESR59) as Mozilla doesn't plan to remove non-oxidated
> codepaths just yet.

https://bugzilla.mozilla.org/show_bug.cgi?id=1261841 made it non-trivial, so FF56 (circa 2017-09-26) will probably be the end. powerpc* and sparc64 are already out of hope due Skia not supporting big-endian archs since FF53.
Comment 34 Mikael Urankar freebsd_committer 2017-07-10 14:27:34 UTC
(In reply to Jan Beich from comment #33)
I gave it a shot to not avail.
I was able to bootstrap rust and cargo, unfortunately cargo segfault at startup and rust wasn't able to compile itself.
I'll try again in august.

FWIW firefox doesn't build on armv6.
Comment 35 Jan Beich freebsd_committer 2017-07-14 03:28:37 UTC
(In reply to mikael.urankar from comment #34)
> FWIW firefox doesn't build on armv6.

www/firefox hasn't appeared on pkg-fallout@ since 51.0 when it was blocked by a Clang crash. Now it's blocked by math/fftw3 and maybe more ports. I can't really begin on a fix without prebuilt packages as my build of devel/llvm40 is killed as runaway after ~20 hours spent on trying to link bin/clang-check.
Comment 36 Jan Beich freebsd_committer 2017-11-30 09:17:32 UTC
Mikael, have you tried to bootstrap Rust on armv7? For one, FreeBSD armv7 appears to assume NEON.

$ cc -v
FreeBSD clang version 5.0.0 (tags/RELEASE_500/final 312559) (based on LLVM 5.0.0svn)
Target: armv7-unknown-freebsd12.0-gnueabihf
Thread model: posix
InstalledDir: /nxb-bin/usr/bin

$ cc -dM -E -</dev/null 2>&1 | fgrep -i -e vfp -e neon
#define __ARM_NEON 1
#define __ARM_NEON_FP 0x4
#define __ARM_NEON__ 1
#define __ARM_PCS_VFP 1
#define __ARM_VFPV3__ 1
#define __VFP_FP__ 1
Comment 37 Michal Meloun freebsd_committer 2017-11-30 13:40:34 UTC
I have rust bootstrapped for armv6 and armv7. The problem is that bootstrap is built on head/12. The bootstrap on stable/11 fails in final phase (when making dist packages, with strange linker error) and I haven't access to 
releng/11.0 machine.

But I'm current trapped by fixing jemalloc / libc TLS bugs in head, so rustc  is on hold now :(
Comment 38 vali gholami 2017-12-17 07:14:49 UTC
Comment 39 commit-hook freebsd_committer 2019-02-18 15:31:26 UTC
A commit references this bug:

Author: tobik
Date: Mon Feb 18 15:30:45 UTC 2019
New revision: 493268
URL: https://svnweb.freebsd.org/changeset/ports/493268

  lang/rust: Add aarch64, armv{6,7}, and powerpc64 bootstraps

  PR:		216143, 228892
  Submitted by:	Mika?l Urankar <mikael.urankar@gmail.com>
  Differential Revision:	https://reviews.freebsd.org/D18367

Comment 40 Jan Beich freebsd_committer 2019-03-02 22:21:41 UTC
Many Tier2 are supported after ports r493268. The rest is mostly Tier3, not represented on the package cluster.