Skip to content

Commit

Permalink
Unrolled build for rust-lang#136875
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#136875 - BoxyUwU:rdg-push, r=jieyouxu

Rustc dev guide subtree update

r? ``@ghost``
  • Loading branch information
rust-timer authored Feb 12, 2025
2 parents 021fb9c + 67ba6a6 commit 9ae6b95
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 94 deletions.
47 changes: 38 additions & 9 deletions src/doc/rustc-dev-guide/.github/workflows/rustc-pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: rustc-pull
on:
workflow_dispatch:
schedule:
# Run at 04:00 UTC every Monday
- cron: '0 4 * * 1'
# Run at 04:00 UTC every Monday and Thursday
- cron: '0 4 * * 1,4'

jobs:
pull:
Expand Down Expand Up @@ -34,15 +34,35 @@ jobs:
git config --global user.name 'The rustc-dev-guide Cronjob Bot'
git config --global user.email '[email protected]'
- name: Perform rustc-pull
run: cargo run --manifest-path josh-sync/Cargo.toml -- rustc-pull
id: rustc-pull
# Turn off -e to disable early exit
shell: bash {0}
run: |
cargo run --manifest-path josh-sync/Cargo.toml -- rustc-pull
exitcode=$?
# If no pull was performed, we want to mark this job as successful,
# but we do not want to perform the follow-up steps.
if [ $exitcode -eq 0 ]; then
echo "pull_result=pull-finished" >> $GITHUB_OUTPUT
elif [ $exitcode -eq 2 ]; then
echo "pull_result=skipped" >> $GITHUB_OUTPUT
exitcode=0
fi
exit ${exitcode}
- name: Push changes to a branch
if: ${{ steps.rustc-pull.outputs.pull_result == 'pull-finished' }}
run: |
# Update a sticky branch that is used only for rustc pulls
BRANCH="rustc-pull"
git switch -c $BRANCH
git push -u origin $BRANCH --force
- name: Create pull request
id: update-pr
if: ${{ steps.rustc-pull.outputs.pull_result == 'pull-finished' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Check if an open pull request for an rustc pull update already exists
# If it does, the previous push has just updated it
Expand All @@ -54,26 +74,35 @@ jobs:
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
else
PR_URL=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | .[0].url' --json url,title`
echo "Updating pull request ${PR_URL}"
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
send-zulip-message:
needs: [pull]
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Compute message
id: message
id: create-message
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ needs.pull.result }}" == "failure" ];
then
if [ "${{ needs.pull.result }}" == "failure" ]; then
WORKFLOW_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
echo "message=Rustc pull sync failed. Check out the [workflow URL]($WORKFLOW_URL)." >> $GITHUB_OUTPUT
else
echo "message=Rustc pull sync succeeded. Check out the [PR](${{ needs.pull.outputs.pr_url }})." >> $GITHUB_OUTPUT
CREATED_AT=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | .[0].createdAt' --json createdAt,title`
PR_URL=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | .[0].url' --json url,title`
week_ago=$(date +%F -d '7 days ago')
# If there is an open PR that is at least a week old, post a message about it
if [[ -n $DATE_GH && $DATE_GH < $week_ago ]]; then
echo "message=A PR with a Rustc pull has been opened for more a week. Check out the [PR](${PR_URL})." >> $GITHUB_OUTPUT
fi
fi
- name: Send a Zulip message about updated PR
if: ${{ steps.create-message.outputs.message != '' }}
uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5
with:
api-key: ${{ secrets.ZULIP_API_TOKEN }}
Expand Down
15 changes: 13 additions & 2 deletions src/doc/rustc-dev-guide/josh-sync/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use crate::sync::GitSync;
use crate::sync::{GitSync, RustcPullError};

mod sync;

Expand All @@ -22,7 +22,18 @@ fn main() -> anyhow::Result<()> {
let sync = GitSync::from_current_dir()?;
match args {
Args::RustcPull => {
sync.rustc_pull(None)?;
if let Err(error) = sync.rustc_pull(None) {
match error {
RustcPullError::NothingToPull => {
eprintln!("Nothing to pull");
std::process::exit(2);
}
RustcPullError::PullFailed(error) => {
eprintln!("Pull failure: {error:?}");
std::process::exit(1);
}
}
}
}
Args::RustcPush { github_username, branch } => {
sync.rustc_push(github_username, branch)?;
Expand Down
24 changes: 19 additions & 5 deletions src/doc/rustc-dev-guide/josh-sync/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ const JOSH_FILTER: &str = ":/src/doc/rustc-dev-guide";
const JOSH_PORT: u16 = 42042;
const UPSTREAM_REPO: &str = "rust-lang/rust";

pub enum RustcPullError {
/// No changes are available to be pulled.
NothingToPull,
/// A rustc-pull has failed, probably a git operation error has occurred.
PullFailed(anyhow::Error)
}

impl<E> From<E> for RustcPullError where E: Into<anyhow::Error> {
fn from(error: E) -> Self {
Self::PullFailed(error.into())
}
}

pub struct GitSync {
dir: PathBuf,
}
Expand All @@ -24,7 +37,7 @@ impl GitSync {
})
}

pub fn rustc_pull(&self, commit: Option<String>) -> anyhow::Result<()> {
pub fn rustc_pull(&self, commit: Option<String>) -> Result<(), RustcPullError> {
let sh = Shell::new()?;
sh.change_dir(&self.dir);
let commit = commit.map(Ok).unwrap_or_else(|| {
Expand All @@ -38,7 +51,7 @@ impl GitSync {
})?;
// Make sure the repo is clean.
if cmd!(sh, "git status --untracked-files=no --porcelain").read()?.is_empty().not() {
bail!("working directory must be clean before performing rustc pull");
return Err(anyhow::anyhow!("working directory must be clean before performing rustc pull").into());
}
// Make sure josh is running.
let josh = Self::start_josh()?;
Expand All @@ -47,7 +60,7 @@ impl GitSync {

let previous_base_commit = sh.read_file("rust-version")?.trim().to_string();
if previous_base_commit == commit {
return Err(anyhow::anyhow!("No changes since last pull"));
return Err(RustcPullError::NothingToPull);
}

// Update rust-version file. As a separate commit, since making it part of
Expand Down Expand Up @@ -94,12 +107,13 @@ impl GitSync {
cmd!(sh, "git reset --hard HEAD^")
.run()
.expect("FAILED to clean up after creating the preparation commit");
return Err(anyhow::anyhow!("No merge was performed, nothing to pull. Rolled back the preparation commit."));
eprintln!("No merge was performed, no changes to pull were found. Rolled back the preparation commit.");
return Err(RustcPullError::NothingToPull);
}

// Check that the number of roots did not increase.
if num_roots()? != num_roots_before {
bail!("Josh created a new root commit. This is probably not the history you want.");
return Err(anyhow::anyhow!("Josh created a new root commit. This is probably not the history you want.").into());
}

drop(josh);
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc-dev-guide/rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
66d6064f9eb888018775e08f84747ee6f39ba28e
124cc92199ffa924f6b4c7cc819a85b65e0c3984
2 changes: 1 addition & 1 deletion src/doc/rustc-dev-guide/src/appendix/bibliography.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Rust, as well as publications about Rust.
* [Ownership is Theft: Experiences Building an Embedded OS in Rust - Amit Levy, et. al.](https://amitlevy.com/papers/tock-plos2015.pdf)
* [You can't spell trust without Rust](https://faultlore.com/blah/papers/thesis.pdf). Aria Beingessner's master's thesis.
* [Rust-Bio: a fast and safe bioinformatics library](https://rust-bio.github.io/). Johannes Köster
* [Safe, Correct, and Fast Low-Level Networking](https://octarineparrot.com/assets/msci_paper.pdf). Robert Clipsham's master's thesis.
* [Safe, Correct, and Fast Low-Level Networking](https://csperkins.org/research/thesis-msci-clipsham.pdf). Robert Clipsham's master's thesis.
* [Formalizing Rust traits](https://open.library.ubc.ca/cIRcle/collections/ubctheses/24/items/1.0220521). Jonatan Milewski's master's thesis.
* [Rust as a Language for High Performance GC Implementation](https://dl.acm.org/doi/pdf/10.1145/3241624.2926707)
* [Simple Verification of Rust Programs via Functional Purification](https://github.com/Kha/electrolysis). Sebastian Ullrich's master's thesis.
Expand Down
45 changes: 19 additions & 26 deletions src/doc/rustc-dev-guide/src/building/suggested.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,24 @@ and follow the same instructions as above.
### Emacs

Emacs provides support for rust-analyzer with project-local configuration
through [Eglot](https://www.gnu.org/software/emacs/manual/html_node/eglot/).
through [Eglot](https://www.gnu.org/software/emacs/manual/html_node/eglot/).
Steps for setting up Eglot with rust-analyzer can be [found
here](https://rust-analyzer.github.io/manual.html#eglot).
here](https://rust-analyzer.github.io/manual.html#eglot).
Having set up Emacs & Eglot for Rust development in general, you can run
`./x setup editor` and select `emacs`, which will prompt you to create
`.dir-locals.el` with the recommended configuration for Eglot.
The recommended settings live at [`src/etc/rust_analyzer_eglot.el`].
The recommended settings live at [`src/etc/rust_analyzer_eglot.el`].
For more information on project-specific Eglot configuration, consult [the
manual](https://www.gnu.org/software/emacs/manual/html_node/eglot/Project_002dspecific-configuration.html).

### Helix

Helix comes with built-in LSP and rust-analyzer support.
Helix comes with built-in LSP and rust-analyzer support.
It can be configured through `languages.toml`, as described
[here](https://docs.helix-editor.com/languages.html).
[here](https://docs.helix-editor.com/languages.html).
You can run `./x setup editor` and select `helix`, which will prompt you to
create `languages.toml` with the recommended configuration for Helix. The
recommended settings live at [`src/etc/rust_analyzer_helix.toml`].
recommended settings live at [`src/etc/rust_analyzer_helix.toml`].

## Check, check, and check again

Expand Down Expand Up @@ -181,7 +181,7 @@ example, running `tidy` and `linkchecker` is useful when editing Markdown files,
whereas UI tests are much less likely to be helpful. While `x suggest` is a
useful tool, it does not guarantee perfect coverage (just as PR CI isn't a
substitute for bors). See the [dedicated chapter](../tests/suggest-tests.md) for
more information and contribution instructions.
more information and contribution instructions.

Please note that `x suggest` is in a beta state currently and the tests that it
will suggest are limited.
Expand Down Expand Up @@ -332,29 +332,22 @@ git worktree add -b my-feature ../rust2 master
You can then use that rust2 folder as a separate workspace for modifying and
building `rustc`!

## Using nix-shell
## Working with nix

If you're using nix, you can use the following nix-shell to work on Rust:
Several nix configurations are defined in `src/tools/nix-dev-shell`.

```nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
name = "rustc";
nativeBuildInputs = with pkgs; [
binutils cmake ninja pkg-config python3 git curl cacert patchelf nix
];
buildInputs = with pkgs; [
openssl glibc.out glibc.static
];
# Avoid creating text files for ICEs.
RUSTC_ICE = "0";
# Provide `libstdc++.so.6` for the self-contained lld.
LD_LIBRARY_PATH = "${with pkgs; lib.makeLibraryPath [
stdenv.cc.cc.lib
]}";
}
If you're using direnv, you can create a symbol link to `src/tools/nix-dev-shell/envrc-flake` or `src/tools/nix-dev-shell/envrc-shell`

```bash
ln -s ./src/tools/nix-dev-shell/envrc-flake ./.envrc # Use flake
```
or
```bash
ln -s ./src/tools/nix-dev-shell/envrc-shell ./.envrc # Use nix-shell
```

### Note

Note that when using nix on a not-NixOS distribution, it may be necessary to set
**`patch-binaries-for-nix = true` in `config.toml`**. Bootstrap tries to detect
whether it's running in nix and enable patching automatically, but this
Expand Down
6 changes: 4 additions & 2 deletions src/doc/rustc-dev-guide/src/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,8 @@ The trait implementation allows you to check certain syntactic constructs
as the linter walks the AST. You can then choose to emit lints in a
very similar way to compile errors.

You also declare the metadata of a particular lint via the `declare_lint!`
macro. [This macro](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/macro.declare_lint.html) includes the name, the default level, a short description, and some
You also declare the metadata of a particular lint via the [`declare_lint!`]
macro. This macro includes the name, the default level, a short description, and some
more details.

Note that the lint and the lint pass must be registered with the compiler.
Expand Down Expand Up @@ -671,6 +671,8 @@ example-use-loop = denote infinite loops with `loop {"{"} ... {"}"}`
.suggestion = use `loop`
```

[`declare_lint!`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/macro.declare_lint.html

### Edition-gated lints

Sometimes we want to change the behavior of a lint in a new edition. To do this,
Expand Down
1 change: 0 additions & 1 deletion src/doc/rustc-dev-guide/src/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ it's easy to pick up work without a large time commitment:
- [Rustdoc Askama Migration](https://github.com/rust-lang/rust/issues/108868)
- [Diagnostic Translation](https://github.com/rust-lang/rust/issues/100717)
- [Move UI tests to subdirectories](https://github.com/rust-lang/rust/issues/73494)
- [Port run-make tests from Make to Rust](https://github.com/rust-lang/rust/issues/121876)

If you find more recurring work, please feel free to add it here!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Creating an env from an arbitrary set of where clauses is usually unnecessary an

Creating an empty environment via `ParamEnv::empty` is almost always wrong. There are very few places where we actually know that the environment should be empty. One of the only places where we do actually know this is after monomorphization, however the `ParamEnv` there should be constructed via `ParamEnv::reveal_all` instead as at this point we should be able to determine the hidden type of opaque types. Codegen/Post-mono is one of the only places that should be using `ParamEnv::reveal_all`.

An additional piece of complexity here is specifying the [`Reveal`][reveal] (see linked docs for explanation of what reveal does) used for the `ParamEnv`. When constructing a param env using the `param_env` query it will have `Reveal::UserFacing`, if `Reveal::All` is desired then the [`tcx.param_env_reveal_all_normalized`][env_reveal_all_normalized] query can be used instead.
An additional piece of complexity here is specifying the `Reveal` (see linked docs for explanation of what reveal does) used for the `ParamEnv`. When constructing a param env using the `param_env` query it will have `Reveal::UserFacing`, if `Reveal::All` is desired then the [`tcx.param_env_reveal_all_normalized`][env_reveal_all_normalized] query can be used instead.

The `ParamEnv` type has a method [`ParamEnv::with_reveal_all_normalized`][with_reveal_all] which converts an existing `ParamEnv` into one with `Reveal::All` specified. Where possible the previously mentioned query should be preferred as it is more efficient.

Expand All @@ -38,7 +38,6 @@ The `ParamEnv` type has a method [`ParamEnv::with_reveal_all_normalized`][with_r
[with_reveal_all]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.ParamEnv.html#method.with_reveal_all_normalized
[env_reveal_all]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.ParamEnv.html#method.reveal_all
[env_empty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.ParamEnv.html#method.empty
[reveal]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/traits/enum.Reveal.html
[pe]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.ParamEnv.html
[param_env_query]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/fn_ctxt/struct.FnCtxt.html#structfield.param_env
[method_pred_entailment]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/check/compare_impl_item/fn.compare_method_predicate_entailment.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

The type system relies on information in the environment in order for it to function correctly. This information is stored in the [`ParamEnv`][pe] type and it is important to use the correct `ParamEnv` when interacting with the type system.

The information represented by `ParamEnv` is a list of in-scope where-clauses, and a [`Reveal`][reveal] (see linked docs for more information). A `ParamEnv` typically corresponds to a specific item's where clauses, some clauses are not explicitly written bounds and instead are implicitly added in [`predicates_of`][predicates_of] such as `ConstArgHasType` or some implied bounds.
The information represented by `ParamEnv` is a list of in-scope where-clauses, and a `Reveal` (see linked docs for more information). A `ParamEnv` typically corresponds to a specific item's where clauses, some clauses are not explicitly written bounds and instead are implicitly added in [`predicates_of`][predicates_of] such as `ConstArgHasType` or some implied bounds.

A `ParamEnv` can also be created with arbitrary data that is not derived from a specific item such as in [`compare_method_predicate_entailment`][method_pred_entailment] which creates a hybrid `ParamEnv` consisting of the impl's where clauses and the trait definition's function's where clauses. In most cases `ParamEnv`s are initially created via the [`param_env` query][query] which returns a `ParamEnv` derived from the provided item's where clauses.

Expand Down Expand Up @@ -57,4 +57,3 @@ It's very important to use the correct `ParamEnv` when interacting with the type
[method_pred_entailment]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/check/compare_impl_item/fn.compare_method_predicate_entailment.html
[pe]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.ParamEnv.html
[query]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.param_env
[reveal]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/traits/enum.Reveal.html
8 changes: 4 additions & 4 deletions src/doc/rustc-dev-guide/src/rustdoc-internals/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ For space savings, it's also written without newlines or spaces.
]
```

[`src/librustdoc/html/static/js/externs.js`]
defines an actual schema in a Closure `@typedef`.
[`src/librustdoc/html/static/js/rustdoc.d.ts`]
defines an actual schema in a TypeScript `type`.

| Key | Name | Description |
| --- | -------------------- | ------------ |
Expand All @@ -68,7 +68,7 @@ with a free function called `function_name` and a struct called `Data`,
with the type signature `Data, i32 -> str`,
and an alias, `get_name`, that equivalently refers to `function_name`.

[`src/librustdoc/html/static/js/externs.js`]: https://github.com/rust-lang/rust/blob/79b710c13968a1a48d94431d024d2b1677940866/src/librustdoc/html/static/js/externs.js#L204-L258
[`src/librustdoc/html/static/js/rustdoc.d.ts`]: https://github.com/rust-lang/rust/blob/2f92f050e83bf3312ce4ba73c31fe843ad3cbc60/src/librustdoc/html/static/js/rustdoc.d.ts#L344-L390

The search index needs to fit the needs of the `rustdoc` compiler,
the `search.js` frontend,
Expand Down Expand Up @@ -469,7 +469,7 @@ want the libs team to be able to add new items without causing unrelated
tests to fail, but standalone tests will use it more often.

The `ResultsTable` and `ParsedQuery` types are specified in
[`externs.js`](https://github.com/rust-lang/rust/blob/master/src/librustdoc/html/static/js/externs.js).
[`rustdoc.d.ts`](https://github.com/rust-lang/rust/blob/master/src/librustdoc/html/static/js/rustdoc.d.ts).

For example, imagine we needed to fix a bug where a function named
`constructor` couldn't be found. To do this, write two files:
Expand Down
Loading

0 comments on commit 9ae6b95

Please sign in to comment.