fork/rules_rust

git clone https://git.julia.blue/fork/rules_rust

P1n3appl3Deploying to gh-pages from @ P1n3appl3/rules_rust@c3d71edd99fe764bf831a95ba2a9c486fc0b9e9c 🚀482a21cf

gh-pages
17.1 KiB314 linesraw
1<!DOCTYPE HTML>
2<html lang="en" class="light sidebar-visible" dir="ltr">
3    <head>
4        <!-- Book generated using mdBook -->
5        <meta charset="UTF-8">
6        <title>rust_analyzer - rules_rust</title>
7
8
9        <!-- Custom HTML head -->
10
11        <meta name="description" content="">
12        <meta name="viewport" content="width=device-width, initial-scale=1">
13        <meta name="theme-color" content="#ffffff">
14
15        <link rel="icon" href="favicon.svg">
16        <link rel="shortcut icon" href="favicon.png">
17        <link rel="stylesheet" href="css/variables.css">
18        <link rel="stylesheet" href="css/general.css">
19        <link rel="stylesheet" href="css/chrome.css">
20        <link rel="stylesheet" href="css/print.css" media="print">
21
22        <!-- Fonts -->
23        <link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
24        <link rel="stylesheet" href="fonts/fonts.css">
25
26        <!-- Highlight.js Stylesheets -->
27        <link rel="stylesheet" href="highlight.css">
28        <link rel="stylesheet" href="tomorrow-night.css">
29        <link rel="stylesheet" href="ayu-highlight.css">
30
31        <!-- Custom theme stylesheets -->
32
33
34        <!-- Provide site root to javascript -->
35        <script>
36            var path_to_root = "";
37            var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
38        </script>
39        <!-- Start loading toc.js asap -->
40        <script src="toc.js"></script>
41    </head>
42    <body>
43    <div id="body-container">
44        <!-- Work around some values being stored in localStorage wrapped in quotes -->
45        <script>
46            try {
47                var theme = localStorage.getItem('mdbook-theme');
48                var sidebar = localStorage.getItem('mdbook-sidebar');
49
50                if (theme.startsWith('"') && theme.endsWith('"')) {
51                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
52                }
53
54                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
55                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
56                }
57            } catch (e) { }
58        </script>
59
60        <!-- Set the theme before any content is loaded, prevents flash -->
61        <script>
62            var theme;
63            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
64            if (theme === null || theme === undefined) { theme = default_theme; }
65            const html = document.documentElement;
66            html.classList.remove('light')
67            html.classList.add(theme);
68            html.classList.add("js");
69        </script>
70
71        <input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
72
73        <!-- Hide / unhide sidebar before it is displayed -->
74        <script>
75            var sidebar = null;
76            var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
77            if (document.body.clientWidth >= 1080) {
78                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
79                sidebar = sidebar || 'visible';
80            } else {
81                sidebar = 'hidden';
82            }
83            sidebar_toggle.checked = sidebar === 'visible';
84            html.classList.remove('sidebar-visible');
85            html.classList.add("sidebar-" + sidebar);
86        </script>
87
88        <nav id="sidebar" class="sidebar" aria-label="Table of contents">
89            <!-- populated by js -->
90            <mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
91            <noscript>
92                <iframe class="sidebar-iframe-outer" src="toc.html"></iframe>
93            </noscript>
94            <div id="sidebar-resize-handle" class="sidebar-resize-handle">
95                <div class="sidebar-resize-indicator"></div>
96            </div>
97        </nav>
98
99        <div id="page-wrapper" class="page-wrapper">
100
101            <div class="page">
102                <div id="menu-bar-hover-placeholder"></div>
103                <div id="menu-bar" class="menu-bar sticky">
104                    <div class="left-buttons">
105                        <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">
106                            <i class="fa fa-bars"></i>
107                        </label>
108                        <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">
109                            <i class="fa fa-paint-brush"></i>
110                        </button>
111                        <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
112                            <li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
113                            <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
114                            <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
115                            <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
116                            <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
117                        </ul>
118                        <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
119                            <i class="fa fa-search"></i>
120                        </button>
121                    </div>
122
123                    <h1 class="menu-title">rules_rust</h1>
124
125                    <div class="right-buttons">
126                        <a href="print.html" title="Print this book" aria-label="Print this book">
127                            <i id="print-button" class="fa fa-print"></i>
128                        </a>
129                        <a href="https://github.com/bazelbuild/rules_rust" title="Git repository" aria-label="Git repository">
130                            <i id="git-repository-button" class="fa fa-github"></i>
131                        </a>
132
133                    </div>
134                </div>
135
136                <div id="search-wrapper" class="hidden">
137                    <form id="searchbar-outer" class="searchbar-outer">
138                        <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
139                    </form>
140                    <div id="searchresults-outer" class="searchresults-outer hidden">
141                        <div id="searchresults-header" class="searchresults-header"></div>
142                        <ul id="searchresults">
143                        </ul>
144                    </div>
145                </div>
146
147                <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
148                <script>
149                    document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
150                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
151                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
152                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
153                    });
154                </script>
155
156                <div id="content" class="content">
157                    <main>
158                        <!-- Generated with Stardoc: http://skydoc.bazel.build -->
159<h1 id="rust-analyzer"><a class="header" href="#rust-analyzer">Rust Analyzer</a></h1>
160<ul>
161<li><a href="#rust_analyzer_aspect">rust_analyzer_aspect</a></li>
162<li><a href="#rust_analyzer_toolchain">rust_analyzer_toolchain</a></li>
163</ul>
164<h2 id="overview"><a class="header" href="#overview">Overview</a></h2>
165<p>For <a href="https://rust-analyzer.github.io/manual.html#non-cargo-based-projects">non-Cargo projects</a>,
166<a href="https://rust-analyzer.github.io/">rust-analyzer</a> depends on a <code>rust-project.json</code> file at the
167root of the project that describes its structure. The <code>rust_analyzer</code> rule facilitates generating
168such a file.</p>
169<h3 id="setup"><a class="header" href="#setup">Setup</a></h3>
170<p>First, ensure <code>rules_rust</code> is setup in your workspace. By default, <code>rust_register_toolchains</code> will
171ensure a <a href="#rust_analyzer_toolchain">rust_analyzer_toolchain</a> is registered within the WORKSPACE.</p>
172<p>Next, load the dependencies for the <code>rust-project.json</code> generator tool:</p>
173<pre><code class="language-python">load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")
174
175rust_analyzer_dependencies()
176</code></pre>
177<p>Finally, run <code>bazel run @rules_rust//tools/rust_analyzer:gen_rust_project</code>
178whenever dependencies change to regenerate the <code>rust-project.json</code> file. It
179should be added to <code>.gitignore</code> because it is effectively a build artifact.
180Once the <code>rust-project.json</code> has been generated in the project root,
181rust-analyzer can pick it up upon restart.</p>
182<p>For users who do not use <code>rust_register_toolchains</code> to register toolchains, the following can be added
183to their WORKSPACE to register a <code>rust_analyzer_toolchain</code>. Please make sure the Rust version used in
184this toolchain matches the version used by the currently registered toolchain or the sources/documentation
185will not match what's being compiled with and can lead to confusing results.</p>
186<pre><code class="language-python">load("@rules_rust//rust:repositories.bzl", "rust_analyzer_toolchain_repository")
187
188register_toolchains(rust_analyzer_toolchain_repository(
189    name = "rust_analyzer_toolchain",
190    # This should match the currently registered toolchain.
191    version = "1.63.0",
192))
193</code></pre>
194<h4 id="vscode"><a class="header" href="#vscode">VSCode</a></h4>
195<p>To set this up using <a href="https://code.visualstudio.com/">VSCode</a>, users should first install the
196<a href="https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer">rust_analyzer plugin</a>.
197With that in place, the following task can be added to the <code>.vscode/tasks.json</code> file of the workspace
198to ensure a <code>rust-project.json</code> file is created and up to date when the editor is opened.</p>
199<pre><code class="language-json">{
200    "version": "2.0.0",
201    "tasks": [
202        {
203            "label": "Generate rust-project.json",
204            "command": "bazel",
205            "args": [
206                "run",
207                "//tools/rust_analyzer:gen_rust_project"
208            ],
209            "options": {
210                "cwd": "${workspaceFolder}"
211            },
212            "group": "build",
213            "problemMatcher": [],
214            "presentation": {
215                "reveal": "never",
216                "panel": "dedicated",
217            },
218            "runOptions": {
219                "runOn": "folderOpen"
220            }
221        },
222    ]
223}
224</code></pre>
225<h4 id="alternative-vscode-option-prototype"><a class="header" href="#alternative-vscode-option-prototype">Alternative vscode option (prototype)</a></h4>
226<p>Add the following to your bazelrc:</p>
227<pre><code>build --@rules_rust//rust/settings:rustc_output_diagnostics=true --output_groups=+rust_lib_rustc_output,+rust_metadata_rustc_output
228</code></pre>
229<p>Then you can use a prototype <a href="https://marketplace.visualstudio.com/items?itemName=MattStark.bazel-rust-analyzer">rust-analyzer plugin</a> that automatically collects the outputs whenever you recompile.</p>
230<p><a id="rust_analyzer_toolchain"></a></p>
231<h2 id="rust_analyzer_toolchain"><a class="header" href="#rust_analyzer_toolchain">rust_analyzer_toolchain</a></h2>
232<pre>
233rust_analyzer_toolchain(<a href="#rust_analyzer_toolchain-name">name</a>, <a href="#rust_analyzer_toolchain-proc_macro_srv">proc_macro_srv</a>, <a href="#rust_analyzer_toolchain-rustc">rustc</a>, <a href="#rust_analyzer_toolchain-rustc_srcs">rustc_srcs</a>)
234</pre>
235<p>A toolchain for <a href="https://rust-analyzer.github.io/">rust-analyzer</a>.</p>
236<p><strong>ATTRIBUTES</strong></p>
237<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
238<tr><td style="text-align: left"><a id="rust_analyzer_toolchain-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
239<tr><td style="text-align: left"><a id="rust_analyzer_toolchain-proc_macro_srv"></a>proc_macro_srv</td><td style="text-align: left">The path to a <code>rust_analyzer_proc_macro_srv</code> binary.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
240<tr><td style="text-align: left"><a id="rust_analyzer_toolchain-rustc"></a>rustc</td><td style="text-align: left">The path to a <code>rustc</code> binary.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
241<tr><td style="text-align: left"><a id="rust_analyzer_toolchain-rustc_srcs"></a>rustc_srcs</td><td style="text-align: left">The source code of rustc.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
242</tbody></table>
243</div>
244<p><a id="rust_analyzer_aspect"></a></p>
245<h2 id="rust_analyzer_aspect"><a class="header" href="#rust_analyzer_aspect">rust_analyzer_aspect</a></h2>
246<pre>
247rust_analyzer_aspect(<a href="#rust_analyzer_aspect-name">name</a>)
248</pre>
249<p>Annotates rust rules with RustAnalyzerInfo later used to build a rust-project.json</p>
250<p><strong>ASPECT ATTRIBUTES</strong></p>
251<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Type</th></tr></thead><tbody>
252<tr><td style="text-align: left">deps</td><td style="text-align: left">String</td></tr>
253<tr><td style="text-align: left">proc_macro_deps</td><td style="text-align: left">String</td></tr>
254<tr><td style="text-align: left">crate</td><td style="text-align: left">String</td></tr>
255<tr><td style="text-align: left">actual</td><td style="text-align: left">String</td></tr>
256<tr><td style="text-align: left">proto</td><td style="text-align: left">String</td></tr>
257</tbody></table>
258</div>
259<p><strong>ATTRIBUTES</strong></p>
260<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
261<tr><td style="text-align: left"><a id="rust_analyzer_aspect-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
262</tbody></table>
263</div>
264                    </main>
265
266                    <nav class="nav-wrapper" aria-label="Page navigation">
267                        <!-- Mobile navigation buttons -->
268                            <a rel="prev" href="cargo.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
269                                <i class="fa fa-angle-left"></i>
270                            </a>
271
272                            <a rel="next prefetch" href="flatten.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
273                                <i class="fa fa-angle-right"></i>
274                            </a>
275
276                        <div style="clear: both"></div>
277                    </nav>
278                </div>
279            </div>
280
281            <nav class="nav-wide-wrapper" aria-label="Page navigation">
282                    <a rel="prev" href="cargo.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
283                        <i class="fa fa-angle-left"></i>
284                    </a>
285
286                    <a rel="next prefetch" href="flatten.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
287                        <i class="fa fa-angle-right"></i>
288                    </a>
289            </nav>
290
291        </div>
292
293
294
295
296        <script>
297            window.playground_copyable = true;
298        </script>
299
300
301        <script src="elasticlunr.min.js"></script>
302        <script src="mark.min.js"></script>
303        <script src="searcher.js"></script>
304
305        <script src="clipboard.min.js"></script>
306        <script src="highlight.js"></script>
307        <script src="book.js"></script>
308
309        <!-- Custom JS scripts -->
310
311
312    </div>
313    </body>
314</html>