diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 30e93c42a..c9c23bf99 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,4 +87,4 @@ jobs: continue-on-error: true run: | # using split_inclusive that uses regex feature that uses an unstable feature - RUSTC_BOOTSTRAP=true cargo run --manifest-path ci/sembr/Cargo.toml src + RUSTC_BOOTSTRAP=1 cargo run --manifest-path ci/sembr/Cargo.toml src diff --git a/ci/sembr/src/main.rs b/ci/sembr/src/main.rs index 7f07d6e81..accdcb68c 100644 --- a/ci/sembr/src/main.rs +++ b/ci/sembr/src/main.rs @@ -22,6 +22,8 @@ struct Cli { static REGEX_IGNORE: LazyLock = LazyLock::new(|| Regex::new(r"^\s*(\d\.|\-|\*)\s+").unwrap()); static REGEX_IGNORE_END: LazyLock = LazyLock::new(|| Regex::new(r"(\.|\?|;|!)$").unwrap()); +static REGEX_IGNORE_LINK_TARGETS: LazyLock = + LazyLock::new(|| Regex::new(r"^\[.+\]: ").unwrap()); static REGEX_SPLIT: LazyLock = LazyLock::new(|| Regex::new(r"(\.|\?|;|!)\s+").unwrap()); fn main() -> Result<()> { @@ -94,6 +96,7 @@ fn ignore(line: &str, in_code_block: bool) -> bool { || line.starts_with('#') || line.trim().is_empty() || REGEX_IGNORE.is_match(line) + || REGEX_IGNORE_LINK_TARGETS.is_match(line) } fn comply(content: &str) -> String { @@ -221,6 +224,15 @@ fn test_prettify_prefix_spaces() { assert_eq!(expected, lengthen_lines(original, 50)); } +#[test] +fn test_prettify_ignore_link_targets() { + let original = "\ +[a target]: https://example.com +[another target]: https://example.com +"; + assert_eq!(original, lengthen_lines(original, 100)); +} + #[test] fn test_sembr_then_prettify() { let original = "\ diff --git a/src/tests/ci.md b/src/tests/ci.md index 6c0b5c2e8..c0e48b314 100644 --- a/src/tests/ci.md +++ b/src/tests/ci.md @@ -7,18 +7,18 @@ From a high-level point of view, when you open a pull request at `rust-lang/rust`, the following will happen: - A small [subset](#pull-request-builds) of tests and checks are run after each - push to the PR. This should help catch common errors. + push to the PR. + This should help catch common errors. - When the PR is approved, the [bors] bot enqueues the PR into a [merge queue]. - Once the PR gets to the front of the queue, bors will create a merge commit - and run the [full test suite](#auto-builds) on it. The merge commit either - contains only one specific PR or it can be a ["rollup"](#rollups) which + and run the [full test suite](#auto-builds) on it. + The merge commit either contains only one specific PR or it can be a ["rollup"](#rollups) which combines multiple PRs together, to reduce CI costs and merge delays. - Once the whole test suite finishes, two things can happen. Either CI fails with an error that needs to be addressed by the developer, or CI succeeds and the merge commit is then pushed to the `master` branch. -If you want to modify what gets executed on CI, see [Modifying CI -jobs](#modifying-ci-jobs). +If you want to modify what gets executed on CI, see [Modifying CI jobs](#modifying-ci-jobs). ## CI workflow @@ -26,10 +26,10 @@ jobs](#modifying-ci-jobs). Our CI is primarily executed on [GitHub Actions], with a single workflow defined in [`.github/workflows/ci.yml`], which contains a bunch of steps that are -unified for all CI jobs that we execute. When a commit is pushed to a -corresponding branch or a PR, the workflow executes the -[`src/ci/citool`] crate, which dynamically generates the specific CI -jobs that should be executed. This script uses the [`jobs.yml`] file as an +unified for all CI jobs that we execute. +When a commit is pushed to a corresponding branch or a PR, the workflow executes the +[`src/ci/citool`] crate, which dynamically generates the specific CI jobs that should be executed. +This script uses the [`jobs.yml`] file as an input, which contains a declarative configuration of all our CI jobs. > Almost all build steps shell out to separate scripts. This keeps the CI fairly @@ -38,21 +38,22 @@ input, which contains a declarative configuration of all our CI jobs. > orchestrating the scripts that drive the process. In essence, all CI jobs run `./x test`, `./x dist` or some other command with -different configurations, across various operating systems, targets, and -platforms. There are two broad categories of jobs that are executed, `dist` and -non-`dist` jobs. +different configurations, across various operating systems, targets, and platforms. +There are two broad categories of jobs that are executed, `dist` and non-`dist` jobs. - Dist jobs build a full release of the compiler for a specific platform, - including all the tools we ship through rustup. Those builds are then uploaded + including all the tools we ship through rustup. + Those builds are then uploaded to the `rust-lang-ci2` S3 bucket and are available to be locally installed - with the [rustup-toolchain-install-master] tool. The same builds are also used + with the [rustup-toolchain-install-master] tool. + The same builds are also used for actual releases: our release process basically consists of copying those artifacts from `rust-lang-ci2` to the production endpoint and signing them. - Non-dist jobs run our full test suite on the platform, and the test suite of - all the tools we ship through rustup; The amount of stuff we test depends on + all the tools we ship through rustup; + The amount of stuff we test depends on the platform (for example some tests are run only on Tier 1 platforms), and - some quicker platforms are grouped together on the same builder to avoid - wasting CI resources. + some quicker platforms are grouped together on the same builder to avoid wasting CI resources. Based on an input event (usually a push to a branch), we execute one of three kinds of builds (sets of jobs). @@ -65,13 +66,15 @@ kinds of builds (sets of jobs). ### Pull Request builds -After each push to a pull request, a set of `pr` jobs are executed. Currently, -these execute the `x86_64-gnu-llvm-X`, `x86_64-gnu-tools`, `pr-check-1`, `pr-check-2` -and `tidy` jobs, all running on Linux. These execute a relatively short -(~40 minutes) and lightweight test suite that should catch common issues. More -specifically, they run a set of lints, they try to perform a cross-compile check +After each push to a pull request, a set of `pr` jobs are executed. +Currently, these execute the `x86_64-gnu-llvm-X`, `x86_64-gnu-tools`, `pr-check-1`, `pr-check-2` +and `tidy` jobs, all running on Linux. +These execute a relatively short +(~40 minutes) and lightweight test suite that should catch common issues. +More specifically, they run a set of lints, they try to perform a cross-compile check build to Windows mingw (without producing any artifacts), and they test the -compiler using a *system* version of LLVM. Unfortunately, it would take too many +compiler using a *system* version of LLVM. +Unfortunately, it would take too many resources to run the full test suite for each commit on every PR. > **Note on doc comments** @@ -84,27 +87,28 @@ resources to run the full test suite for each commit on every PR. > Thus, it is a good idea to run `./x doc xxx` locally for any doc comment > changes to help catch these early. -PR jobs are defined in the `pr` section of [`jobs.yml`]. Their results can be observed +PR jobs are defined in the `pr` section of [`jobs.yml`]. +Their results can be observed directly on the PR, in the "CI checks" section at the bottom of the PR page. ### Auto builds -Before a commit can be merged into the `master` branch, it needs to pass our -complete test suite. We call this an `auto` build. This build runs tens of CI -jobs that exercise various tests across operating systems and targets. The full -test suite is quite slow; it can take several hours until all the `auto` CI -jobs finish. +Before a commit can be merged into the `master` branch, it needs to pass our complete test suite. +We call this an `auto` build. +This build runs tens of CI jobs that exercise various tests across operating systems and targets. +The full test suite is quite slow; +it can take several hours until all the `auto` CI jobs finish. Most platforms only run the build steps, some run a restricted set of tests; only a subset run the full suite of tests (see Rust's [platform tiers]). -Auto jobs are defined in the `auto` section of [`jobs.yml`]. They are executed -on the `auto` branch under the `rust-lang/rust` repository, +Auto jobs are defined in the `auto` section of [`jobs.yml`]. +They are executed on the `auto` branch under the `rust-lang/rust` repository, and the final result will be reported via a comment made by bors on the corresponding PR. The live results can be seen on [the GitHub Actions workflows page]. -At any given time, at most a single `auto` build is being executed. Find out -more in [Merging PRs serially with bors](#merging-prs-serially-with-bors). +At any given time, at most a single `auto` build is being executed. +Find out more in [Merging PRs serially with bors](#merging-prs-serially-with-bors). [platform tiers]: https://forge.rust-lang.org/release/platform-support.html#rust-platform-support @@ -112,7 +116,8 @@ more in [Merging PRs serially with bors](#merging-prs-serially-with-bors). Sometimes we want to run a subset of the test suite on CI for a given PR, or build a set of compiler artifacts from that PR, without attempting to merge it. -We call this a "try build". A try build is started after a user with the proper +We call this a "try build". +A try build is started after a user with the proper permissions posts a PR comment with the `@bors try` command. There are several use-cases for try builds: @@ -121,9 +126,9 @@ There are several use-cases for try builds: For this, a working compiler build is needed, which can be generated with a try build that runs the [dist-x86_64-linux] CI job, which builds an optimized version of the compiler on Linux (this job is currently executed by default - when you start a try build). To create a try build and schedule it for a - performance benchmark, you can use the `@bors try @rust-timer queue` command - combination. + when you start a try build). + To create a try build and schedule it for a + performance benchmark, you can use the `@bors try @rust-timer queue` command combination. - Check the impact of the PR across the Rust ecosystem, using a [Crater](crater.md) run. Again, a working compiler build is needed for this, which can be produced by the [dist-x86_64-linux] CI job. @@ -131,25 +136,32 @@ There are several use-cases for try builds: passes the test suite executed by that job. By default, if you send a comment with `@bors try`, the jobs defined in the `try` section of -[`jobs.yml`] will be executed. We call this mode a "fast try build". Such a try build -will not execute any tests, and it will allow compilation warnings. It is useful when you want to +[`jobs.yml`] will be executed. +We call this mode a "fast try build". +Such a try build will not execute any tests, and it will allow compilation warnings. +It is useful when you want to get an optimized toolchain as fast as possible, for a Crater run or performance benchmarks, -even if it might not be working fully correctly. If you want to do a full build for the default try job, +even if it might not be working fully correctly. +If you want to do a full build for the default try job, specify its job name in a job pattern (explained below). If you want to run custom CI jobs in a try build and make sure that they pass all tests and do not produce any compilation warnings, you can select CI jobs to be executed by specifying a *job pattern*, which can be used in one of two ways: - You can add a set of `try-job: ` directives to the PR description (described below) and then - simply run `@bors try`. CI will read these directives and run the jobs that you have specified. This is + simply run `@bors try`. + CI will read these directives and run the jobs that you have specified. + This is useful if you want to rerun the same set of try jobs multiple times, after incrementally modifying a PR. - You can specify the job pattern using the `jobs` parameter of the try command: `@bors try jobs=`. - This is useful for one-off try builds with specific jobs. Note that the `jobs` parameter has a higher priority - than the PR description directives. + This is useful for one-off try builds with specific jobs. + Note that the `jobs` parameter has a higher priority than the PR description directives. - There can also be multiple patterns specified, e.g. `@bors try jobs=job1,job2,job3`. Each job pattern can either be an exact name of a job or a glob pattern that matches multiple jobs, -for example `*msvc*` or `*-alt`. You can start at most 20 jobs in a single try build. When using +for example `*msvc*` or `*-alt`. +You can start at most 20 jobs in a single try build. +When using glob patterns in the PR description, you can optionally wrap them in backticks (`` ` ``) to avoid GitHub rendering the pattern as Markdown if it contains e.g. an asterisk. Note that this escaping will not work when using the `@bors jobs=` parameter. @@ -208,20 +220,20 @@ If you want to modify what gets executed on our CI, you can simply modify the You can also modify what gets executed temporarily, for example to test a particular platform or configuration that is challenging to test locally (for -example, if a Windows build fails, but you don't have access to a Windows -machine). Don't hesitate to use CI resources in such situations. +example, if a Windows build fails, but you don't have access to a Windows machine). +Don't hesitate to use CI resources in such situations. You can perform an arbitrary CI job in two ways: - Use the [try build](#try-builds) functionality, and specify the CI jobs that you want to be executed in try builds in your PR description. - Modify the [`pr`](#pull-request-builds) section of `jobs.yml` to specify which - CI jobs should be executed after each push to your PR. This might be faster - than repeatedly starting try builds. + CI jobs should be executed after each push to your PR. + This might be faster than repeatedly starting try builds. To modify the jobs executed after each push to a PR, you can simply copy one of -the job definitions from the `auto` section to the `pr` section. For example, -the `x86_64-msvc` job is responsible for running the 64-bit MSVC tests. You can -copy it to the `pr` section to cause it to be executed after a commit is pushed +the job definitions from the `auto` section to the `pr` section. +For example, the `x86_64-msvc` job is responsible for running the 64-bit MSVC tests. +You can copy it to the `pr` section to cause it to be executed after a commit is pushed to your PR, like this: ```yaml @@ -238,8 +250,8 @@ pr: <<: *job-windows-8c ``` -Then you can commit the file and push it to your PR branch on GitHub. GitHub -Actions should then execute this CI job after each push to your PR. +Then you can commit the file and push it to your PR branch on GitHub. +GitHub Actions should then execute this CI job after each push to your PR.
@@ -247,12 +259,12 @@ Actions should then execute this CI job after each push to your PR. you have made to `jobs.yml`, if they were supposed to be temporary!** A good practice is to prefix `[WIP]` in PR title while still running try jobs -and `[DO NOT MERGE]` in the commit that modifies the CI jobs for testing -purposes. +and `[DO NOT MERGE]` in the commit that modifies the CI jobs for testing purposes.
Although you are welcome to use CI, just be conscious that this is a shared -resource with limited concurrency. Try not to enable too many jobs at once; +resource with limited concurrency. +Try not to enable too many jobs at once; one or two should be sufficient in most cases. ## Merging PRs serially with bors @@ -265,26 +277,28 @@ after the build happened. To ensure a `master` branch that works all the time, we forbid manual merges. Instead, all PRs have to be approved through our bot, [bors] (the software -behind it is called [homu]). All the approved PRs are put in a [merge queue] -(sorted by priority and creation date) and are automatically tested one at the -time. If all the builders are green, the PR is merged, otherwise the failure is +behind it is called [homu]). +All the approved PRs are put in a [merge queue] +(sorted by priority and creation date) and are automatically tested one at the time. +If all the builders are green, the PR is merged, otherwise the failure is recorded and the PR will have to be re-approved again. Bors doesn’t interact with CI services directly, but it works by pushing the merge commit it wants to test to specific branches (like `auto` or `try`), which -are configured to execute CI checks. Bors then detects the outcome of the build -by listening for either Commit Statuses or Check Runs. Since the merge commit is +are configured to execute CI checks. +Bors then detects the outcome of the build by listening for either Commit Statuses or Check Runs. +Since the merge commit is based on the latest `master` and only one can be tested at the same time, when the results are green, `master` is fast-forwarded to that merge commit. Unfortunately, testing a single PR at a time, combined with our long CI (~2 hours for a full run), means we can’t merge a lot of PRs in a single day, and a -single failure greatly impacts our throughput. The maximum number of -PRs we can merge in a day is around ~10. +single failure greatly impacts our throughput. +The maximum number of PRs we can merge in a day is around ~10. The long CI run times, and requirement for a large builder pool, is largely due -to the fact that full release artifacts are built in the `dist-` builders. This -is worth it because these release artifacts: +to the fact that full release artifacts are built in the `dist-` builders. +This is worth it because these release artifacts: - Allow perf testing even at a later date. - Allow bisection when bugs are discovered later. @@ -295,23 +309,23 @@ is worth it because these release artifacts: Some PRs don’t need the full test suite to be executed: trivial changes like typo fixes or README improvements *shouldn’t* break the build, and testing every -single one of them for 2+ hours would be wasteful. To solve this, we -regularly create a "rollup", a PR where we merge several pending trivial PRs so -they can be tested together. Rollups are created manually by a team member using -the "create a rollup" button on the [merge queue]. The team member uses their -judgment to decide if a PR is risky or not. +single one of them for 2+ hours would be wasteful. +To solve this, we regularly create a "rollup", a PR where we merge several pending trivial PRs so +they can be tested together. +Rollups are created manually by a team member using +the "create a rollup" button on the [merge queue]. +The team member uses their judgment to decide if a PR is risky or not. ## Docker All CI jobs, except those on macOS and Windows, are executed inside that -platform’s custom [Docker container]. This has a lot of advantages for us: +platform’s custom [Docker container]. +This has a lot of advantages for us: - The build environment is consistent regardless of the changes of the - underlying image (switching from the trusty image to xenial was painless for - us). + underlying image (switching from the trusty image to xenial was painless for us). - We can use ancient build environments to ensure maximum binary compatibility, - for example [using older CentOS releases][dist-x86_64-linux] on our Linux - builders. + for example [using older CentOS releases][dist-x86_64-linux] on our Linux builders. - We can avoid reinstalling tools (like QEMU or the Android emulator) every time, thanks to Docker image caching. - Users can run the same tests in the same environment locally by just running this command: @@ -325,13 +339,11 @@ platform’s custom [Docker container]. This has a lot of advantages for us: The Docker images prefixed with `dist-` are used for building artifacts while those without that prefix run tests and checks. -We also run tests for less common architectures (mainly Tier 2 and Tier 3 -platforms) in CI. Since those platforms are not x86, we either run everything -inside QEMU, or we just cross-compile if we don’t want to run the tests for that -platform. +We also run tests for less common architectures (mainly Tier 2 and Tier 3 platforms) in CI. +Since those platforms are not x86, we either run everything +inside QEMU, or we just cross-compile if we don’t want to run the tests for that platform. -These builders are running on a special pool of builders set up and maintained -for us by GitHub. +These builders are running on a special pool of builders set up and maintained for us by GitHub. [Docker container]: https://github.com/rust-lang/rust/tree/master/src/ci/docker @@ -341,16 +353,16 @@ Our CI workflow uses various caching mechanisms, mainly for two things: ### Docker images caching -The Docker images we use to run most of the Linux-based builders take a *long* -time to fully build. To speed up the build, we cache them using [Docker registry -caching], with the intermediate artifacts being stored on [ghcr.io]. We also -push the built Docker images to ghcr, so that they can be reused by other tools -(rustup) or by developers running the Docker build locally (to speed up their -build). +The Docker images we use to run most of the Linux-based builders take a *long* time to fully build. +To speed up the build, we cache them using [Docker registry +caching], with the intermediate artifacts being stored on [ghcr.io]. +We also push the built Docker images to ghcr, so that they can be reused by other tools +(rustup) or by developers running the Docker build locally (to speed up their build). Since we test multiple, diverged branches (`master`, `beta` and `stable`), we can’t rely on a single cache for the images, otherwise builds on a branch would -override the cache for the others. Instead, we store the images under different +override the cache for the others. +Instead, we store the images under different tags, identifying them with a custom hash made from the contents of all the Dockerfiles and related scripts. @@ -367,17 +379,17 @@ invalidated if one of the following changes: ### LLVM caching with Sccache We build some C/C++ stuff in various CI jobs, and we rely on [Sccache] to cache -the intermediate LLVM artifacts. Sccache is a distributed ccache developed by +the intermediate LLVM artifacts. +Sccache is a distributed ccache developed by Mozilla, which can use an object storage bucket as the storage backend. -With Sccache there's no need to calculate the hash key ourselves. Sccache -invalidates the cache automatically when it detects changes to relevant inputs, -such as the source code, the version of the compiler, and important environment -variables. +With Sccache there's no need to calculate the hash key ourselves. +Sccache invalidates the cache automatically when it detects changes to relevant inputs, +such as the source code, the version of the compiler, and important environment variables. So we just pass the Sccache wrapper on top of Cargo and Sccache does the rest. -We store the persistent artifacts on the S3 bucket, `rust-lang-ci-sccache2`. So -when the CI runs, if Sccache sees that LLVM is being compiled with the same C/C++ +We store the persistent artifacts on the S3 bucket, `rust-lang-ci-sccache2`. +So when the CI runs, if Sccache sees that LLVM is being compiled with the same C/C++ compiler and the LLVM source code is the same, Sccache retrieves the individual compiled translation units from S3. @@ -396,26 +408,28 @@ receives the build logs on failure, and extracts the error message automatically posting it on the PR thread. The bot is not hardcoded to look for error strings, but was trained with a bunch -of build failures to recognize which lines are common between builds and which -are not. While the generated snippets can be weird sometimes, the bot is pretty -good at identifying the relevant lines, even if it’s an error we've never seen -before. +of build failures to recognize which lines are common between builds and which are not. +While the generated snippets can be weird sometimes, the bot is pretty +good at identifying the relevant lines, even if it’s an error we've never seen before. [rla]: https://github.com/rust-lang/rust-log-analyzer ### Toolstate to support allowed failures The `rust-lang/rust` repo doesn’t only test the compiler on its CI, but also a -variety of tools and documentation. Some documentation is pulled in via git -submodules. If we blocked merging rustc PRs on the documentation being fixed, we +variety of tools and documentation. +Some documentation is pulled in via git submodules. +If we blocked merging rustc PRs on the documentation being fixed, we would be stuck in a chicken-and-egg problem, because the documentation's CI would not pass since updating it would need the not-yet-merged version of rustc to test against (and we usually require CI to be passing). To avoid the problem, submodules are allowed to fail, and their status is -recorded in [rust-toolstate]. When a submodule breaks, a bot automatically pings +recorded in [rust-toolstate]. +When a submodule breaks, a bot automatically pings the maintainers so they know about the breakage, and it records the failure on -the toolstate repository. The release process will then ignore broken tools on +the toolstate repository. +The release process will then ignore broken tools on nightly, removing them from the shipped nightlies. While tool failures are allowed most of the time, they’re automatically @@ -448,8 +462,8 @@ To learn more about the dashboard, see the [Datadog CI docs]. ## Determining the CI configuration If you want to determine which `bootstrap.toml` settings are used in CI for a -particular job, it is probably easiest to just look at the build log. To do -this: +particular job, it is probably easiest to just look at the build log. +To do this: 1. Go to