Is build rust compiler require rust compiler?

Hi everyone,

I tried to build Rust compiler. In the build process, I got errors about #[feature] not supported. I build v1.12.0 with NixOS (thus, it may be my mistake). Below specifically,

link: x86_64-unknown-linux-gnu/rt/libcompiler-rt.a
ar: `u' modifier ignored since `D' is the default (see `U')
mkdir -p x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/
cp: x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler-rt.a
rustc: x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore
src/libcore/lib.rs:67:1: 67:37 error: #[feature] may not be used on the stable release channel
src/libcore/lib.rs:67 #![feature(allow_internal_unstable)]
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/libcore/lib.rs:68:1: 68:17 error: #[feature] may not be used on the stable release channel
src/libcore/lib.rs:68 #![feature(asm)]
                      ^~~~~~~~~~~~~~~~
src/libcore/lib.rs:69:1: 69:38 error: #[feature] may not be used on the stable release channel
src/libcore/lib.rs:69 #![feature(associated_type_defaults)]
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Then I curious, is rustc need rust compiler to compile itself. And additionally, a "nightly" one should be used? Or how rustc be compiled without this requirement?

Typically the rust build system sorts all this out for you, downloading an old version of the compiler (or allowing you to use rustc you have installed locally).

Since you got this error I suspect you're not just using the rust build system, in which case it'd be useful to see the exact steps you've gone through to get to this point.

1 Like

It quite scary then without rust build system. Since NixOS is rather different and I've just learn some trick to build a package. Thank you @aidanhs , now It's better when I know exactly how rust being compiled.

I use this NixOS build script but I want to build the v1.12.0 (so I change it's version, hash, git ref).

  rustc = callPackage ./rustc.nix {
    shortVersion = "1.12.0";
    isRelease = true;
    forceBundledLLVM = false;
    configureFlags = [ "--release-channel=stable" ];
    srcRev = "3191fbae9da539442351f883bdabcad0d72efcb6";
    srcSha = "16vxy8wdw238aa0fwpl7i8sp6l3spvg5caay4z5wv7h3sf6g2pip";

    inherit targets;
    inherit targetPatches;
    inherit targetToolchains;
    inherit rustPlatform;
  };

I hope someone here is an experienced NixOS user.

https://github.com/NixOS/nixpkgs/blob/56904d7c423f2b13b37fbd29f39bbb4b52bc7824/pkgs/development/compilers/rust/rustc.nix#L57

I don't know much about nix, but if I had to guess I'd say that the path being passed here is pointing to a stable rust, which won't work - you need to find out where it's coming from.

src/stage0.txt in the rust repo tells you which compiler should be used to bootstrap (in theory), but in practice any nightly >= to the version specified in that file should work.