| <!DOCTYPE HTML> |
| <html lang="en" class="light sidebar-visible" dir="ltr"> |
| <head> |
| <!-- Book generated using mdBook --> |
| <meta charset="UTF-8"> |
| <title>Crater - Cargo Contributor Guide</title> |
| |
| |
| <!-- Custom HTML head --> |
| |
| <meta name="description" content=""> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <meta name="theme-color" content="#ffffff"> |
| |
| <link rel="icon" href="../favicon.svg"> |
| <link rel="shortcut icon" href="../favicon.png"> |
| <link rel="stylesheet" href="../css/variables.css"> |
| <link rel="stylesheet" href="../css/general.css"> |
| <link rel="stylesheet" href="../css/chrome.css"> |
| <link rel="stylesheet" href="../css/print.css" media="print"> |
| |
| <!-- Fonts --> |
| <link rel="stylesheet" href="../FontAwesome/css/font-awesome.css"> |
| <link rel="stylesheet" href="../fonts/fonts.css"> |
| |
| <!-- Highlight.js Stylesheets --> |
| <link rel="stylesheet" id="highlight-css" href="../highlight.css"> |
| <link rel="stylesheet" id="tomorrow-night-css" href="../tomorrow-night.css"> |
| <link rel="stylesheet" id="ayu-highlight-css" href="../ayu-highlight.css"> |
| |
| <!-- Custom theme stylesheets --> |
| |
| |
| <!-- Provide site root and default themes to javascript --> |
| <script> |
| const path_to_root = "../"; |
| const default_light_theme = "light"; |
| const default_dark_theme = "navy"; |
| window.path_to_searchindex_js = "../searchindex.js"; |
| </script> |
| <!-- Start loading toc.js asap --> |
| <script src="../toc.js"></script> |
| </head> |
| <body> |
| <div id="mdbook-help-container"> |
| <div id="mdbook-help-popup"> |
| <h2 class="mdbook-help-title">Keyboard shortcuts</h2> |
| <div> |
| <p>Press <kbd>←</kbd> or <kbd>→</kbd> to navigate between chapters</p> |
| <p>Press <kbd>S</kbd> or <kbd>/</kbd> to search in the book</p> |
| <p>Press <kbd>?</kbd> to show this help</p> |
| <p>Press <kbd>Esc</kbd> to hide this help</p> |
| </div> |
| </div> |
| </div> |
| <div id="body-container"> |
| <!-- Work around some values being stored in localStorage wrapped in quotes --> |
| <script> |
| try { |
| let theme = localStorage.getItem('mdbook-theme'); |
| let sidebar = localStorage.getItem('mdbook-sidebar'); |
| |
| if (theme.startsWith('"') && theme.endsWith('"')) { |
| localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1)); |
| } |
| |
| if (sidebar.startsWith('"') && sidebar.endsWith('"')) { |
| localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1)); |
| } |
| } catch (e) { } |
| </script> |
| |
| <!-- Set the theme before any content is loaded, prevents flash --> |
| <script> |
| const default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? default_dark_theme : default_light_theme; |
| let theme; |
| try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { } |
| if (theme === null || theme === undefined) { theme = default_theme; } |
| const html = document.documentElement; |
| html.classList.remove('light') |
| html.classList.add(theme); |
| html.classList.add("js"); |
| </script> |
| |
| <input type="checkbox" id="sidebar-toggle-anchor" class="hidden"> |
| |
| <!-- Hide / unhide sidebar before it is displayed --> |
| <script> |
| let sidebar = null; |
| const sidebar_toggle = document.getElementById("sidebar-toggle-anchor"); |
| if (document.body.clientWidth >= 1080) { |
| try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { } |
| sidebar = sidebar || 'visible'; |
| } else { |
| sidebar = 'hidden'; |
| sidebar_toggle.checked = false; |
| } |
| if (sidebar === 'visible') { |
| sidebar_toggle.checked = true; |
| } else { |
| html.classList.remove('sidebar-visible'); |
| } |
| </script> |
| |
| <nav id="sidebar" class="sidebar" aria-label="Table of contents"> |
| <!-- populated by js --> |
| <mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox> |
| <noscript> |
| <iframe class="sidebar-iframe-outer" src="../toc.html"></iframe> |
| </noscript> |
| <div id="sidebar-resize-handle" class="sidebar-resize-handle"> |
| <div class="sidebar-resize-indicator"></div> |
| </div> |
| </nav> |
| |
| <div id="page-wrapper" class="page-wrapper"> |
| |
| <div class="page"> |
| <div id="menu-bar-hover-placeholder"></div> |
| <div id="menu-bar" class="menu-bar sticky"> |
| <div class="left-buttons"> |
| <label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar"> |
| <i class="fa fa-bars"></i> |
| </label> |
| <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list"> |
| <i class="fa fa-paint-brush"></i> |
| </button> |
| <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu"> |
| <li role="none"><button role="menuitem" class="theme" id="default_theme">Auto</button></li> |
| <li role="none"><button role="menuitem" class="theme" id="light">Light</button></li> |
| <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li> |
| <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li> |
| <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li> |
| <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li> |
| </ul> |
| <button id="search-toggle" class="icon-button" type="button" title="Search (`/`)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="/ s" aria-controls="searchbar"> |
| <i class="fa fa-search"></i> |
| </button> |
| </div> |
| |
| <h1 class="menu-title">Cargo Contributor Guide</h1> |
| |
| <div class="right-buttons"> |
| <a href="../print.html" title="Print this book" aria-label="Print this book"> |
| <i id="print-button" class="fa fa-print"></i> |
| </a> |
| <a href="https://github.com/rust-lang/cargo/tree/master/src/doc/contrib/src" title="Git repository" aria-label="Git repository"> |
| <i id="git-repository-button" class="fa fa-github"></i> |
| </a> |
| <a href="https://github.com/rust-lang/cargo/edit/master/src/doc/contrib/src/tests/crater.md" title="Suggest an edit" aria-label="Suggest an edit" rel="edit"> |
| <i id="git-edit-button" class="fa fa-edit"></i> |
| </a> |
| |
| </div> |
| </div> |
| |
| <div id="search-wrapper" class="hidden"> |
| <form id="searchbar-outer" class="searchbar-outer"> |
| <div class="search-wrapper"> |
| <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header"> |
| <div class="spinner-wrapper"> |
| <i class="fa fa-spinner fa-spin"></i> |
| </div> |
| </div> |
| </form> |
| <div id="searchresults-outer" class="searchresults-outer hidden"> |
| <div id="searchresults-header" class="searchresults-header"></div> |
| <ul id="searchresults"> |
| </ul> |
| </div> |
| </div> |
| |
| <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM --> |
| <script> |
| document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible'); |
| document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible'); |
| Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) { |
| link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1); |
| }); |
| </script> |
| |
| <div id="content" class="content"> |
| <main> |
| <h1 id="crater"><a class="header" href="#crater">Crater</a></h1> |
| <p><a href="https://github.com/rust-lang/crater">Crater</a> is a tool for compiling and running tests for <em>every</em> crate on <a href="https://crates.io">crates.io</a> (and a few on GitHub). |
| It is mainly used for checking the extent of breakage when implementing potentially breaking changes and ensuring lack of breakage by running beta vs stable compiler versions.</p> |
| <p>Essentially it runs some <code>cargo</code> command on every crate twice; once against the “start” toolchain and again against the “end” toolchain. |
| For example, “start” could be the stable release, and “end” could be beta. |
| If it passes in “start” but fails with “end”, then that is reported as a regression.</p> |
| <p>There is a bot called <a href="https://github.com/rust-lang/crater/blob/master/docs/bot-usage.md">craterbot</a> which is used to run crater on hardware managed by the rust-lang organization.</p> |
| <p>Crater is run by the release team during the beta cycle. |
| If there are any regressions that look like they are caused by Cargo, they should contact the Cargo team to decide how to handle it.</p> |
| <h2 id="running-crater"><a class="header" href="#running-crater">Running crater</a></h2> |
| <p>If you have a change that you want to test before the beta release, or you want to test behavior that is not normally exercised by crater, you can do a manual run of crater. |
| Roughly the steps are:</p> |
| <ol> |
| <li> |
| <p>Create a branch with your changes.</p> |
| <p>In your clone of cargo, make the changes to incorporate whatever new thing you want to test and push it to a branch on your fork on GitHub.</p> |
| </li> |
| <li> |
| <p>Get a clone of <a href="https://github.com/rust-lang/rust">https://github.com/rust-lang/rust</a></p> |
| </li> |
| <li> |
| <p>Create a branch in your rust-lang/rust clone to add your changes.</p> |
| </li> |
| <li> |
| <p>Change the <code>src/tools/cargo</code> submodule to point to your new branch.</p> |
| <p>Modify <code>.gitmodules</code> to point to your clone and branch of cargo with the changes you want to test. |
| For example:</p> |
| <pre><code class="language-bash">git submodule set-url src/tools/cargo https://github.com/ehuss/cargo.git |
| git submodule set-branch --branch my-awesome-feature src/tools/cargo |
| git submodule update --remote src/tools/cargo |
| git add .gitmodules src/tools/cargo |
| git commit |
| </code></pre> |
| </li> |
| <li> |
| <p>Create a PR on rust-lang/rust.</p> |
| <p>Push your submodule changes to GitHub and make a PR. |
| Start the PR title with <code>[EXPERIMENT]</code> to make it clear what the PR is for and assign yourself or @ghost.</p> |
| </li> |
| <li> |
| <p>Make a “try” build.</p> |
| <p>A “try” build creates a full release of x86_64-unknown-linux-gnu and stores it on rust-lang servers. |
| This can be done with a comment <code>@bors try</code> on the PR (all Cargo team members should have permission to do this).</p> |
| </li> |
| <li> |
| <p>Run crater.</p> |
| <p>Look at the <a href="https://github.com/rust-lang/crater/blob/master/docs/bot-usage.md">craterbot</a> docs to determine the command that you want to run. |
| There are different modes like <code>check-only</code>, <code>build-and-test</code>, <code>rustdoc</code>, etc.</p> |
| <p>You can also choose how many crates to run against. |
| If you are uncertain if your cargo changes will work correctly, it might be a good idea to run against <code>top-100</code> first to check its behavior. |
| This will run much faster. |
| You can do a full run afterwards.</p> |
| <p>After the try build finishes (which should take a couple hours), ask someone to make a crater run. |
| The Cargo team does not have that permission, so just ask someone on Zulip. |
| They will need to write a comment to <code>@craterbot</code> with the command that you have specified.</p> |
| </li> |
| <li> |
| <p>Wait.</p> |
| <p>Crater can take anywhere from a few hours to a few weeks to run depending on how long the <a href="https://crater.rust-lang.org/">craterbot queue</a> is and which mode you picked and the priority of your job. |
| When the crater run finishes, craterbot will post a comment to the PR with a link to a report of the results.</p> |
| </li> |
| <li> |
| <p>Investigate the report.</p> |
| <p>Look through the report which contains links to build logs for any regressions or errors.</p> |
| </li> |
| <li> |
| <p>Close the PR.</p> |
| <p>Whenever you are done doing crater runs, close your PR.</p> |
| </li> |
| </ol> |
| <h2 id="advanced-crater-modes"><a class="header" href="#advanced-crater-modes">Advanced crater modes</a></h2> |
| <p>Crater only has a few built-in modes, such as running <code>cargo check</code> or <code>cargo test</code>. |
| You can pass extra flags with <code>+cargoflags</code>.</p> |
| <p>More complex tests can be accomplished by customizing Cargo to perform whatever actions you want. |
| Since crater essentially runs <code>cargo check</code>, you can modify the <code>check</code> command to perform whichever actions you want. |
| For example, to test <code>cargo fix --edition</code>, <a href="https://github.com/ehuss/cargo/commit/6901690a6f8d519efb4fabf48c1c2b94af0c3bd8">this commit</a> intercepted <code>cargo check</code> and modified it to instead:</p> |
| <ol> |
| <li>Only run on crates with the 2018 edition.</li> |
| <li>Run <code>cargo fix --edition</code>.</li> |
| <li>Modify the manifest to switch to the 2021 edition.</li> |
| <li>Run <code>cargo check</code> to verify.</li> |
| </ol> |
| <p>If you need to compare the before and after of a command that is not part of crater’s built-in modes, that can be more difficult. |
| Two possible options:</p> |
| <ul> |
| <li>Work with the infra team to add a new mode.</li> |
| <li>Build two custom try builds. |
| Each one should modify the <code>cargo check</code> command as described above. |
| The “start” build should perform whichever action you want with an otherwise unmodified cargo. |
| The “end” build should perform whichever action you want with your modified cargo. |
| Then, in the <code>@craterbot</code> command, specify the start and end hashes of the two try builds.</li> |
| </ul> |
| <h2 id="limitations"><a class="header" href="#limitations">Limitations</a></h2> |
| <p>There are some limitations of crater to consider when running Cargo:</p> |
| <ul> |
| <li>A crater run without regressions is not a green light to move forward. |
| <ul> |
| <li>A large portion of Rust code is not tested, such as closed-source projects or things otherwise not collected by crater.</li> |
| <li>Many crates can’t build in crater’s environment or are otherwise broken.</li> |
| <li>Some crates have flaky tests.</li> |
| </ul> |
| </li> |
| <li>Crater runs in an isolated environment. |
| <ul> |
| <li>It only runs on Linux x86-64.</li> |
| <li>It does not have network access.</li> |
| <li>The crate source is in a read-only mount.</li> |
| </ul> |
| </li> |
| <li>Crater does several steps before running the test (using its own copy of the stable toolchain): |
| <ul> |
| <li>It generates a lockfile using <code>generate-lockfile</code> and includes <code>-Zno-index-update</code> to prevent index updates (which makes it run much faster).</li> |
| <li>All dependencies are downloaded ahead-of-time with <code>cargo fetch</code>.</li> |
| </ul> |
| </li> |
| <li>The built-in modes pass several flags to cargo such as <code>--frozen</code> or <code>--message-format=json</code>. |
| It will sometimes use <code>--all-targets</code> and sometimes not. |
| Check the <a href="https://github.com/rust-lang/crater/blob/master/src/runner/test.rs">crater source</a> for more details on how it works.</li> |
| </ul> |
| |
| </main> |
| |
| <nav class="nav-wrapper" aria-label="Page navigation"> |
| <!-- Mobile navigation buttons --> |
| <a rel="prev" href="../tests/profiling.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left"> |
| <i class="fa fa-angle-left"></i> |
| </a> |
| |
| <a rel="next prefetch" href="../documentation/index.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right"> |
| <i class="fa fa-angle-right"></i> |
| </a> |
| |
| <div style="clear: both"></div> |
| </nav> |
| </div> |
| </div> |
| |
| <nav class="nav-wide-wrapper" aria-label="Page navigation"> |
| <a rel="prev" href="../tests/profiling.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left"> |
| <i class="fa fa-angle-left"></i> |
| </a> |
| |
| <a rel="next prefetch" href="../documentation/index.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right"> |
| <i class="fa fa-angle-right"></i> |
| </a> |
| </nav> |
| |
| </div> |
| |
| |
| |
| |
| <script> |
| window.playground_copyable = true; |
| </script> |
| |
| |
| <script src="../elasticlunr.min.js"></script> |
| <script src="../mark.min.js"></script> |
| <script src="../searcher.js"></script> |
| |
| <script src="../clipboard.min.js"></script> |
| <script src="../highlight.js"></script> |
| <script src="../book.js"></script> |
| |
| <!-- Custom JS scripts --> |
| |
| |
| |
| </div> |
| </body> |
| </html> |