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

document keep-stage1 and also try to clarify #191

Merged
merged 9 commits into from
Sep 11, 2018

Conversation

nikomatsakis
Copy link
Contributor

This documents the --keep-stage 1 workflow (thanks @Mark-Simulacrum !) and tries to clarify a bit how staging works.

cc @sunjay -- the new language is intended to clear up some of the confusion you had around why building --stage 1 src/libstd does more than build the standard library. What do you think?

@sunjay
Copy link
Member

sunjay commented Aug 31, 2018

LGTM. Thanks for adding all of this to the guide! 😁🎉

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A semi-related question: I've been confused for a long time why some tests have various stage options (like ignore-stage1). Shouldn't the stage1 compiler be functionally identical to the stage2 compiler?

src/how-to-build-and-run.md Outdated Show resolved Hide resolved
src/how-to-build-and-run.md Outdated Show resolved Hide resolved
@nikomatsakis
Copy link
Contributor Author

@ehuss I added a paragraph about that

@ehuss
Copy link
Contributor

ehuss commented Aug 31, 2018

Oh, that makes sense. TYVM!

Copy link
Member

@mark-i-m mark-i-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

Thanks! I was wondering how to use --keep-stage 1 too.

I few minor nits/typos, then r=me

we can build it again
with stage2 compiler which must be identical to itself,
unless something has broken.
internally. The result is the compiling `rustc` is done in stages:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/is the/is that/

@@ -80,6 +86,8 @@ It is, in particular, very useful when you're doing some kind of
"type-based refactoring", like renaming a method, or changing the
signature of some function.

<a name=command>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please close this tag? Sometimes leaving open tags leads to weird rendering in mdbook.

build. The **full** rustc build (what you get if you just say `./x.py
build`) has quite a few more steps:

- Build librustc rustc with the stage1 compiler.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/librustc rustc/rustc/ ?

@@ -140,6 +160,63 @@ release: 1.25.0-dev
LLVM version: 4.0
```

<a name=workflow>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

src/how-to-build-and-run.md Show resolved Hide resolved
src/how-to-build-and-run.md Outdated Show resolved Hide resolved
src/how-to-build-and-run.md Outdated Show resolved Hide resolved

- Initial test run: `./x.py test -i --stage 1 src/test/ui`
- Subsequent test run: `./x.py test -i --stage 1 src/test/ui --keep-stage 1`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's good to note that the --keep-stage flag can be passed multiple times.

Furthermore, if you want guaranteed to work and optimal build times when changing just the compiler, the workflow I would suggest is: ./x.py build -i --stage 2 --keep-stage 0; the --stage 2 is optional. The effect of this command is that when the compiler is changed, we just rebuild it and you have a compiler that is now both fully capable (i.e., proc macros, sysroot fully populated) and you did not need to rebuild std at all. If, however, you wanted to have your changes take effect on the std that compiler uses, then that won't happen with this. But that's relatively rare.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and you did not need to rebuild std at all

I don't think such a compiler can possibly be guaranteed to work. I guess what you mean is "if you want a compiler that avoids the stage1 limitations"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided not to add this text because I still don't really understand what --keep-stage 0 even means. :) Does it mean that we copy the stdlib from the beta?

I guess in that case maybe we always want to suggest it, unless you are editing the stdlib?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikomatsakis
Copy link
Contributor Author

I'm pulling out this conversation about --keep-stage 0 etc since GitHub wants to hide it. @Mark-Simulacrum can you clarify?

I decided not to add this text because I still don't really understand what --keep-stage 0 even means. :) Does it mean that we copy the stdlib from the beta? I guess in that case maybe we always want to suggest it, unless you are editing the stdlib?

@Mark-Simulacrum
Copy link
Member

I think there's a few workflows to consider:

Modifying std, with the intent of trying out some other user-space (i.e., not compiler-space) code. I believe the fastest way to do this today, when iterating, is: x.py build --stage 1 --keep-stage 0 src/libstd.

  • This will build the compiler once and only once
  • That compiler will then build a standard library and be mostly usable -- can build most code, but no proc macros currently
  • The compiler produced is build/<build triple>/stage1/bin/rustc

Modifying std, with intent to see results in the compiler. If you don't care about userspace -- which includes tests -- then x.py build --stage 1 src/libstd --keep-stage 1 will be the fastest way to start and iterate. This will rebuild std, test, and the compiler, but it won't rebuild std more than once. If you do care about userspace seeing the std changes, you'll need to either remove the --keep-stage 1 argument (and pay for two std rebuilds), or, if you're willing to invest more time upfront, then you can run x.py build --stage 2 --keep-stage 0 instead. This will build a fully working compiler, building std, test, and rustc once each time you change std, and produces a compiler capable of supporting proc macros.

Modifying the compiler:

If you need proc macros, you'll need to invest more time up-front. Use x.py build --keep-stage 0 src/librustc_codegen_llvm. This will, on each run, attempt to build std/test/rustc with the stage1/bin/rustc compiler. Since we're only changing rustc, this is quite fast.

If you don't need proc macros, and aren't changing metadata or other ABI details, you can invest less time up-front. Use x.py build --keep-stage 1 src/libstd. This will build everything as per normal but skips the std build in stage 1, just reusing "old" artifacts.


In general, any command run with --keep-stage N should have a preceding --stage N run with other arguments being the same, otherwise you will likely fail to produce a working compiler due to the artifacts being stale or nonexistent.

I'm happy to clarify further, not sure if I've properly explained or even explained in the wrong direction -- let me know what would be best.

@nikomatsakis
Copy link
Contributor Author

nikomatsakis commented Sep 11, 2018

My inclination is to merge this as is and file a follow-up issue with a link to @Mark-Simulacrum's comment. I don't think I have the time to try and write up more detailed notes here (and I also still feel sort of unclear about what anything other than --keep-stage 1 actually does)

@nikomatsakis
Copy link
Contributor Author

Filed #201

@nikomatsakis nikomatsakis merged commit 1fa5685 into rust-lang:master Sep 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants