Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootstrap: artifacts are not moved to build/:target/stage1 on x.py build --stage 0 #73519

Closed
jyn514 opened this issue Jun 19, 2020 · 7 comments · Fixed by #89759
Closed

bootstrap: artifacts are not moved to build/:target/stage1 on x.py build --stage 0 #73519

jyn514 opened this issue Jun 19, 2020 · 7 comments · Fixed by #89759
Labels
C-bug Category: This is a bug. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@jyn514
Copy link
Member

jyn514 commented Jun 19, 2020

I've lost so much of my life to this.

$ xpy build --stage 0
Updating only changed submodules
Submodules updated in 0.01 seconds
    Finished dev [unoptimized] target(s) in 0.09s
Building stage0 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized + debuginfo] target(s) in 0.11s
Copying stage0 std from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage0 compiler artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized + debuginfo] target(s) in 0.12s
Copying stage0 rustc from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Build completed successfully in 0:00:01
$ rustc +stage1 -Z unpretty=everybody_loops priv-in-pub.rs 
error: 'rustc' is not installed for the toolchain 'stage1'
To install, run `rustup component add rustc --toolchain stage1`
$ xpy build --stage 1
Updating only changed submodules
Submodules updated in 0.01 seconds
    Finished dev [unoptimized] target(s) in 0.09s
Building stage0 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized + debuginfo] target(s) in 0.11s
Copying stage0 std from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage0 compiler artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized + debuginfo] target(s) in 0.12s
Copying stage0 rustc from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Assembling stage1 compiler (x86_64-unknown-linux-gnu)
Building stage1 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
   Compiling cc v1.0.54
   Compiling core v0.0.0 (/home/joshua/src/rust/src/libcore)
   Compiling libc v0.2.71
   Compiling autocfg v0.1.7
   Compiling std v0.0.0 (/home/joshua/src/rust/src/libstd)
   Compiling hashbrown v0.6.2
^C  Building [=====>                                                    ] 4/35: ...
Build completed unsuccessfully in 0:00:02
$ rustc +stage1 -Z unpretty=everybody_loops priv-in-pub.rs 
#![no_std]
// ... expected output follows ...
$ rustup toolchain list -v
stage1	/home/joshua/src/rust/build/x86_64-unknown-linux-gnu/stage1

It looks like the critical missing line is Assembling stage1 compiler (x86_64-unknown-linux-gnu). I would expect this to happen whenever I pass build --stage 0.

@jyn514 jyn514 added the C-bug Category: This is a bug. label Jun 19, 2020
@jonas-schievink jonas-schievink added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Jun 19, 2020
@jyn514
Copy link
Member Author

jyn514 commented Jun 19, 2020

The part of bootstrap emitting Assembling ... is Assemble, which is called by bootstrap/builder.rs:compiler_for. The bit emitting 'Copy ...' is RustcLink. Notably, RustcLink does not call Assemble.

@jyn514
Copy link
Member Author

jyn514 commented Jun 19, 2020

This does not fix the issue and I'm not sure why:

$ git diff src/bootstrap/
diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs
index c09b73b0420..630f9ecbe25 100644
--- a/src/bootstrap/compile.rs
+++ b/src/bootstrap/compile.rs
@@ -589,6 +589,7 @@ impl Step for RustcLink {
             &builder.sysroot_libdir(target_compiler, compiler.host),
             &librustc_stamp(builder, compiler, target),
         );
+        builder.ensure(Assemble { target_compiler });
     }
 }

@jyn514
Copy link
Member Author

jyn514 commented Jun 19, 2020

It looks like bootstrap mistakenly thinks that the compiler has been linked and is cached.

c Assemble { target_compiler: Compiler { stage: 0, host: "x86_64-unknown-linux-gnu" } }

@jyn514
Copy link
Member Author

jyn514 commented Jun 19, 2020

So this is still a bug, but it turns out it wouldn't do what I want anyway because it doesn't build libcore. So it would only be able to build crates with #![no_core] (basically nothing).

@Mark-Simulacrum
Copy link
Member

Yeah you want something like build --stage 1 src/libcore (though we don't support separate crate builds currently, but we could).

I think it's not possible today to get bootstrap to copy the compiler but not build anything with it - the compiler itself isn't considered an artifact in some sense.

@jyn514
Copy link
Member Author

jyn514 commented Jun 19, 2020

I think it's not possible today to get bootstrap to copy the compiler but not build anything with it - the compiler itself isn't considered an artifact in some sense.

Right, this issue is asking that to change. I think this would still be useful for what I'm doing now which is only printing the AST and not even doing name resolution (-Z unpretty=everybody_loops).

jyn514 added a commit to jyn514/rust that referenced this issue Jul 28, 2020
- Set rustc to build only when explicitly asked for

This allows building the stage2 rustc artifacts, which nothing depends
on.

Previously the behavior was as follows (where stageN <-> stage(N-1) artifacts, except for stage0 libstd):

- `x.py build --stage 0`:
  - stage0 libstd
  - stage1 rustc (but without putting rustc in stage0/)

This leaves you without any rustc at all except for the beta compiler
(rust-lang#73519). This is never what you want.

- `x.py build --stage 1`:
  - stage0 libstd
  - stage1 rustc
  - stage1 libstd
  - stage1 rustdoc
  - stage2 rustc

This leaves you with a broken stage2 rustc which doesn't even have
libcore and is effectively useless. Additionally, it compiles rustc
twice, which is not normally what you want.

- `x.py build --stage 2`:
  - stage0 libstd
  - stage1 rustc
  - stage1 libstd
  - stage2 rustc
  - stage2 rustdoc and tools

This builds all tools in release mode. This is the correct usage for CI,
but takes far to long for development.

Now the behavior is as follows:

- `x.py build --stage 0`:
  - stage0 libstd

This is suitable for contributors only working on the standard library,
as it means rustc never has to be compiled.

- `x.py build --stage 1`:
  - stage0 libstd
  - stage1 rustc
  - stage1 libstd
  - stage1 rustdoc

This is suitable for contributors working on the compiler. It ensures
that you have a working rustc and libstd without having to pass
`src/libstd` in addition.

- `x.py build --stage 2`:
  - stage0 libstd
  - stage1 rustc
  - stage1 libstd
  - stage2 rustc
  - stage2 libstd
  - stage2 rustdoc

This is suitable for debugging errors which only appear with the stage2
compiler.

- `x.py build --stage 2 src/libstd src/rustc`
  - stage0 libstd
  - stage1 rustc
  - stage1 libstd
  - stage2 rustc
  - stage2 libstd
  - stage2 rustdoc, tools, etc.
  - stage2 rustc artifacts ('stage3')

This is suitable for CI, which wants all tools in release mode.
However, most of the use cases for this should use `x.py dist` instead,
which builds all the tools without each having to be named individually.
@jyn514
Copy link
Member Author

jyn514 commented Oct 4, 2020

Once this is fixed, the docs for Assemble in rustc-dev-guide (rust-lang/rustc-dev-guide#912) should be moved to src/bootstrap/README.md.

@jyn514 jyn514 added the E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. label Dec 21, 2020
the8472 added a commit to the8472/rust that referenced this issue Oct 13, 2021
…ulacrum

Assemble the compiler when running `x.py build`

Previously, there was no way to actually get binaries in
`build/$TARGET/stage1/bin` without building the standard library. This
makes it possible to build just the compiler. This can be useful when
the standard library isn't actually necessary for trying out your tests
(e.g. a bug that can be reproduced with only a `no_core` crate).

Closes rust-lang#73519.
@bors bors closed this as completed in 204bd6e Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants