Skip to content

Commit 8767aeb

Browse files
authored
Merge pull request #19126 from lnicola/sync-from-rust
minor: Sync from downstream
2 parents a888bf3 + 5b39181 commit 8767aeb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+359
-215
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ jobs:
3535
~/.cargo/bin
3636
key: ${{ runner.os }}-${{ env.MDBOOK_VERSION }}--${{ env.MDBOOK_LINKCHECK2_VERSION }}--${{ env.MDBOOK_TOC_VERSION }}--${{ env.MDBOOK_MERMAID_VERSION }}
3737

38-
- name: Cache linkcheck
39-
uses: actions/cache@v4
38+
- name: Restore cached Linkcheck
39+
if: github.event_name == 'schedule'
40+
id: cache-linkcheck-restore
41+
uses: actions/cache/restore@v4
4042
with:
41-
path: |
42-
~/book/linkcheck
43-
key: ${{ runner.os }}-${{ hashFiles('./book/linkcheck') }}
43+
path: book/linkcheck/cache.json
44+
key: linkcheck--${{ env.MDBOOK_LINKCHECK2_VERSION }}--${{ github.run_id }}
45+
restore-keys: |
46+
linkcheck--${{ env.MDBOOK_LINKCHECK2_VERSION }}--
4447
4548
- name: Install latest nightly Rust toolchain
4649
if: steps.mdbook-cache.outputs.cache-hit != 'true'
@@ -59,6 +62,14 @@ jobs:
5962
- name: Check build
6063
run: ENABLE_LINKCHECK=1 mdbook build
6164

65+
- name: Save cached Linkcheck
66+
id: cache-linkcheck-save
67+
if: ${{ !cancelled() && github.event_name == 'schedule' }}
68+
uses: actions/cache/save@v4
69+
with:
70+
path: book/linkcheck/cache.json
71+
key: linkcheck--${{ env.MDBOOK_LINKCHECK2_VERSION }}--${{ github.run_id }}
72+
6273
- name: Deploy to gh-pages
6374
if: github.event_name == 'push'
6475
run: |

.github/workflows/rustc-pull.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: rustc-pull
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
# Run at 04:00 UTC every Monday
7+
- cron: '0 4 * * 1'
8+
9+
jobs:
10+
pull:
11+
if: github.repository == 'rust-lang/rustc-dev-guide'
12+
runs-on: ubuntu-latest
13+
outputs:
14+
pr_url: ${{ steps.update-pr.outputs.pr_url }}
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
# We need the full history for josh to work
22+
fetch-depth: '0'
23+
- name: Install stable Rust toolchain
24+
run: rustup update stable
25+
- uses: Swatinem/rust-cache@v2
26+
with:
27+
workspaces: "josh-sync"
28+
# Cache the josh directory with checked out rustc
29+
cache-directories: "/home/runner/.cache/rustc-dev-guide-josh"
30+
- name: Install josh
31+
run: RUSTFLAGS="--cap-lints warn" cargo +stable install josh-proxy --git https://github.com/josh-project/josh --tag r24.10.04
32+
- name: Setup bot git name and email
33+
run: |
34+
git config --global user.name 'The rustc-dev-guide Cronjob Bot'
35+
git config --global user.email 'github-actions@github.com'
36+
- name: Perform rustc-pull
37+
run: cargo run --manifest-path josh-sync/Cargo.toml -- rustc-pull
38+
- name: Push changes to a branch
39+
run: |
40+
# Update a sticky branch that is used only for rustc pulls
41+
BRANCH="rustc-pull"
42+
git switch -c $BRANCH
43+
git push -u origin $BRANCH --force
44+
- name: Create pull request
45+
id: update-pr
46+
run: |
47+
# Check if an open pull request for an rustc pull update already exists
48+
# If it does, the previous push has just updated it
49+
# If not, we create it now
50+
RESULT=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | length' --json title`
51+
if [[ "$RESULT" -eq 0 ]]; then
52+
echo "Creating new pull request"
53+
PR_URL=`gh pr create -B master --title 'Rustc pull update' --body 'Latest update from rustc.'`
54+
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
55+
else
56+
PR_URL=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | .[0].url' --json url,title`
57+
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
58+
fi
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
send-zulip-message:
62+
needs: [pull]
63+
if: ${{ !cancelled() }}
64+
runs-on: ubuntu-latest
65+
steps:
66+
- name: Compute message
67+
id: message
68+
run: |
69+
if [ "${{ needs.pull.result }}" == "failure" ];
70+
then
71+
WORKFLOW_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
72+
echo "message=Rustc pull sync failed. Check out the [workflow URL]($WORKFLOW_URL)." >> $GITHUB_OUTPUT
73+
else
74+
echo "message=Rustc pull sync succeeded. Check out the [PR](${{ needs.pull.outputs.pr_url }})." >> $GITHUB_OUTPUT
75+
fi
76+
- name: Send a Zulip message about updated PR
77+
uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5
78+
with:
79+
api-key: ${{ secrets.ZULIP_API_TOKEN }}
80+
email: "rustc-dev-guide-gha-notif-bot@rust-lang.zulipchat.com"
81+
organization-url: "https://rust-lang.zulipchat.com"
82+
to: 196385
83+
type: "stream"
84+
topic: "Subtree sync automation"
85+
content: ${{ steps.message.outputs.message }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ ci/date-check/target/
44

55
# Generated by check-in.sh
66
pulls.json
7+
8+
josh-sync/target

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ including the `<!-- toc -->` marker at the place where you want the TOC.
7474

7575
This repository is linked to `rust-lang/rust` as a [josh](https://josh-project.github.io/josh/intro.html) subtree. You can use the following commands to synchronize the subtree in both directions.
7676

77+
You'll need to install `josh-proxy` locally via
78+
79+
```
80+
cargo +stable install josh-proxy --git https://github.com/josh-project/josh --tag r24.10.04
81+
```
82+
Older versions of `josh-proxy` may not round trip commits losslessly so it is important to install this exact version.
83+
7784
### Pull changes from `rust-lang/rust` into this repository
7885
1) Checkout a new branch that will be used to create a PR into `rust-lang/rustc-dev-guide`
7986
2) Run the pull command

book.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ exclude = [
5252
# 500 is returned for HEAD request
5353
"code\\.visualstudio\\.com/docs/editor/tasks",
5454
]
55-
cache-timeout = 86400
55+
# The scheduled CI runs every day and so we need to reuse a part of the cache
56+
# in order to face "Server returned 429 Too Many Requests" errors for github.com.
57+
cache-timeout = 90000
5658
warning-policy = "error"
5759

5860
[output.html.redirect]

examples/rustc-driver-example.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ extern crate rustc_span;
1515

1616
use std::io;
1717
use std::path::Path;
18+
use std::sync::Arc;
1819

1920
use rustc_ast_pretty::pprust::item_to_string;
20-
use rustc_data_structures::sync::Lrc;
21-
use rustc_driver::{Compilation, RunCompiler};
22-
use rustc_interface::interface::Compiler;
21+
use rustc_driver::{Compilation, run_compiler};
22+
use rustc_interface::interface::{Compiler, Config};
2323
use rustc_middle::ty::TyCtxt;
2424

2525
struct MyFileLoader;
@@ -43,18 +43,22 @@ fn main() {
4343
}
4444
}
4545

46-
fn read_binary_file(&self, _path: &Path) -> io::Result<Lrc<[u8]>> {
46+
fn read_binary_file(&self, _path: &Path) -> io::Result<Arc<[u8]>> {
4747
Err(io::Error::other("oops"))
4848
}
4949
}
5050

5151
struct MyCallbacks;
5252

5353
impl rustc_driver::Callbacks for MyCallbacks {
54+
fn config(&mut self, config: &mut Config) {
55+
config.file_loader = Some(Box::new(MyFileLoader));
56+
}
57+
5458
fn after_crate_root_parsing(
5559
&mut self,
5660
_compiler: &Compiler,
57-
krate: &rustc_ast::Crate,
61+
krate: &mut rustc_ast::Crate,
5862
) -> Compilation {
5963
for item in &krate.items {
6064
println!("{}", item_to_string(&item));
@@ -83,10 +87,5 @@ impl rustc_driver::Callbacks for MyCallbacks {
8387
}
8488

8589
fn main() {
86-
match RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks) {
87-
mut compiler => {
88-
compiler.set_file_loader(Some(Box::new(MyFileLoader)));
89-
compiler.run();
90-
}
91-
}
90+
run_compiler(&["main.rs".to_string()], &mut MyCallbacks);
9291
}

examples/rustc-driver-interacting-with-the-ast.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ extern crate rustc_span;
1515

1616
use std::io;
1717
use std::path::Path;
18+
use std::sync::Arc;
1819

1920
use rustc_ast_pretty::pprust::item_to_string;
20-
use rustc_data_structures::sync::Lrc;
21-
use rustc_driver::{Compilation, RunCompiler};
22-
use rustc_interface::interface::Compiler;
21+
use rustc_driver::{Compilation, run_compiler};
22+
use rustc_interface::interface::{Compiler, Config};
2323
use rustc_middle::ty::TyCtxt;
2424

2525
struct MyFileLoader;
@@ -43,18 +43,22 @@ fn main() {
4343
}
4444
}
4545

46-
fn read_binary_file(&self, _path: &Path) -> io::Result<Lrc<[u8]>> {
46+
fn read_binary_file(&self, _path: &Path) -> io::Result<Arc<[u8]>> {
4747
Err(io::Error::other("oops"))
4848
}
4949
}
5050

5151
struct MyCallbacks;
5252

5353
impl rustc_driver::Callbacks for MyCallbacks {
54+
fn config(&mut self, config: &mut Config) {
55+
config.file_loader = Some(Box::new(MyFileLoader));
56+
}
57+
5458
fn after_crate_root_parsing(
5559
&mut self,
5660
_compiler: &Compiler,
57-
krate: &rustc_ast::Crate,
61+
krate: &mut rustc_ast::Crate,
5862
) -> Compilation {
5963
for item in &krate.items {
6064
println!("{}", item_to_string(&item));
@@ -90,10 +94,5 @@ impl rustc_driver::Callbacks for MyCallbacks {
9094
}
9195

9296
fn main() {
93-
match RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks) {
94-
mut compiler => {
95-
compiler.set_file_loader(Some(Box::new(MyFileLoader)));
96-
compiler.run();
97-
}
98-
}
97+
run_compiler(&["main.rs".to_string()], &mut MyCallbacks);
9998
}

examples/rustc-interface-getting-diagnostics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ extern crate rustc_interface;
1010
extern crate rustc_session;
1111
extern crate rustc_span;
1212

13+
use std::sync::{Arc, Mutex};
14+
1315
use rustc_errors::emitter::Emitter;
1416
use rustc_errors::registry::{self, Registry};
1517
use rustc_errors::translation::Translate;
1618
use rustc_errors::{DiagCtxt, DiagInner, FluentBundle};
1719
use rustc_session::config;
1820
use rustc_span::source_map::SourceMap;
1921

20-
use std::sync::{Arc, Mutex};
21-
2222
struct DebugEmitter {
2323
source_map: Arc<SourceMap>,
2424
diagnostics: Arc<Mutex<Vec<DiagInner>>>,
@@ -67,10 +67,10 @@ fn main() {
6767
locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES.to_owned(),
6868
lint_caps: rustc_hash::FxHashMap::default(),
6969
psess_created: Some(Box::new(|parse_sess| {
70-
parse_sess.set_dcx(DiagCtxt::new(Box::new(DebugEmitter {
70+
parse_sess.dcx().set_emitter(Box::new(DebugEmitter {
7171
source_map: parse_sess.clone_source_map(),
7272
diagnostics,
73-
})));
73+
}));
7474
})),
7575
register_lints: None,
7676
override_queries: None,

josh-sync/src/sync.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ impl GitSync {
4545
let josh_url =
4646
format!("http://localhost:{JOSH_PORT}/{UPSTREAM_REPO}.git@{commit}{JOSH_FILTER}.git");
4747

48+
let previous_base_commit = sh.read_file("rust-version")?.trim().to_string();
49+
if previous_base_commit == commit {
50+
return Err(anyhow::anyhow!("No changes since last pull"));
51+
}
52+
4853
// Update rust-version file. As a separate commit, since making it part of
4954
// the merge has confused the heck out of josh in the past.
5055
// We pass `--no-verify` to avoid running git hooks.
@@ -76,12 +81,22 @@ impl GitSync {
7681
};
7782
let num_roots_before = num_roots()?;
7883

84+
let sha = cmd!(sh, "git rev-parse HEAD").output().context("FAILED to get current commit")?.stdout;
85+
7986
// Merge the fetched commit.
8087
const MERGE_COMMIT_MESSAGE: &str = "Merge from rustc";
8188
cmd!(sh, "git merge FETCH_HEAD --no-verify --no-ff -m {MERGE_COMMIT_MESSAGE}")
8289
.run()
8390
.context("FAILED to merge new commits, something went wrong")?;
8491

92+
let current_sha = cmd!(sh, "git rev-parse HEAD").output().context("FAILED to get current commit")?.stdout;
93+
if current_sha == sha {
94+
cmd!(sh, "git reset --hard HEAD^")
95+
.run()
96+
.expect("FAILED to clean up after creating the preparation commit");
97+
return Err(anyhow::anyhow!("No merge was performed, nothing to pull. Rolled back the preparation commit."));
98+
}
99+
85100
// Check that the number of roots did not increase.
86101
if num_roots()? != num_roots_before {
87102
bail!("Josh created a new root commit. This is probably not the history you want.");

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dcfa38fe234de9304169afc6638e81d0dd222c06
1+
66d6064f9eb888018775e08f84747ee6f39ba28e

0 commit comments

Comments
 (0)