| <!DOCTYPE HTML> |
| <html lang="en" class="light sidebar-visible" dir="ltr"> |
| <head> |
| <!-- Book generated using mdBook --> |
| <meta charset="UTF-8"> |
| <title>rules_rust</title> |
| <meta name="robots" content="noindex"> |
| |
| |
| <!-- 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" href="highlight.css"> |
| <link rel="stylesheet" href="tomorrow-night.css"> |
| <link rel="stylesheet" href="ayu-highlight.css"> |
| |
| <!-- Custom theme stylesheets --> |
| |
| |
| <!-- Provide site root to javascript --> |
| <script> |
| var path_to_root = ""; |
| var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light"; |
| </script> |
| <!-- Start loading toc.js asap --> |
| <script src="toc.js"></script> |
| </head> |
| <body> |
| <div id="body-container"> |
| <!-- Work around some values being stored in localStorage wrapped in quotes --> |
| <script> |
| try { |
| var theme = localStorage.getItem('mdbook-theme'); |
| var 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> |
| var 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> |
| var sidebar = null; |
| var 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 = sidebar === 'visible'; |
| html.classList.remove('sidebar-visible'); |
| html.classList.add("sidebar-" + sidebar); |
| </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="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. (Shortkey: s)" 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">rules_rust</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/bazelbuild/rules_rust" title="Git repository" aria-label="Git repository"> |
| <i id="git-repository-button" class="fa fa-github"></i> |
| </a> |
| |
| </div> |
| </div> |
| |
| <div id="search-wrapper" class="hidden"> |
| <form id="searchbar-outer" class="searchbar-outer"> |
| <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header"> |
| </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="rules-rust"><a class="header" href="#rules-rust">Rules Rust</a></h1> |
| <p>This repository provides rules for building <a href="http://www.rust-lang.org/">Rust</a> projects with <a href="https://bazel.build/">Bazel</a>.</p> |
| <!-- TODO: Render generated docs on the github pages site again, https://bazelbuild.github.io/rules_rust/ --> |
| <p><a name="setup"></a></p> |
| <h2 id="setup"><a class="header" href="#setup">Setup</a></h2> |
| <p>The rules are released, and releases can be found on <a href="https://github.com/bazelbuild/rules_rust/releases">the GitHub Releases page</a>. We recommend using the latest release from that page.</p> |
| <p>To use <code>rules_rust</code> in a project, add the following to your <code>MODULE.bazel</code> file:</p> |
| <pre><code class="language-python">bazel_dep(name = "rules_rust", version = "0.70.0") |
| </code></pre> |
| <p>Don't forget to substitute in your desired release's version number.</p> |
| <h2 id="specifying-rust-version"><a class="header" href="#specifying-rust-version">Specifying Rust version</a></h2> |
| <p>To use a particular version of the Rust compiler, pass that version to the <code>toolchain</code> method of the <code>rust</code> extension, like this:</p> |
| <pre><code class="language-python">rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") |
| rust.toolchain( |
| edition = "2024", |
| versions = [ "1.85.0" ], |
| ) |
| </code></pre> |
| <p>As well as an exact version, <code>versions</code> can accept <code>nightly/{iso_date}</code> and <code>beta/{iso_date}</code> strings for toolchains from different release channels, as in</p> |
| <pre><code class="language-python">rust.toolchain( |
| edition = "2021", |
| versions = [ "nightly/1.85.0" ], |
| ) |
| </code></pre> |
| <p>By default, a <code>stable</code> and <code>nightly</code> toolchain will be registered if no <code>toolchain</code> method is called (and thus no specific versions are registered). However, if only 1 version is passed and it is from the <code>nightly</code> or <code>beta</code> release channels (i.e. <strong>not</strong> <code>stable</code>), then the following build setting flag must be present, either on the command line or set in the project's <code>.bazelrc</code> file:</p> |
| <pre><code class="language-text">build --@rules_rust//rust/toolchain/channel=nightly |
| </code></pre> |
| <p>Failure to do so will result in rules attempting to match a <code>stable</code> toolchain when one was not registered, thus raising an error.</p> |
| <h2 id="supported-bazel-versions"><a class="header" href="#supported-bazel-versions">Supported bazel versions</a></h2> |
| <p>The oldest version of Bazel the <code>main</code> branch is tested against is <code>7.4.1</code>. Previous versions may still be functional in certain environments, but this is the minimum version we strive to fully support.</p> |
| <p>We test these rules against the latest rolling releases of Bazel, and aim for compatibility with them, but prioritise stable releases over rolling releases where necessary.</p> |
| <h2 id="supported-platforms"><a class="header" href="#supported-platforms">Supported platforms</a></h2> |
| <p>We aim to support Linux and macOS.</p> |
| <p>We do not have sufficient maintainer expertise to support Windows. Most things probably work, but we have had to disable many tests in CI because we lack the expertise to fix them. We welcome contributions to help improve its support.</p> |
| <div style="break-before: page; page-break-before: always;"></div><h1 id="rules"><a class="header" href="#rules">Rules</a></h1> |
| <ul> |
| <li><a href="defs.html">defs</a>: standard rust rules for building and testing libraries and binaries.</li> |
| <li><a href="rust_doc.html">rustdoc</a>: rules for generating and testing rust documentation.</li> |
| <li><a href="rust_clippy.html">clippy</a>: rules for running <a href="https://github.com/rust-lang/rust-clippy#readme">clippy</a>.</li> |
| <li><a href="rust_fmt.html">rustfmt</a>: rules for running <a href="https://github.com/rust-lang/rustfmt#readme">rustfmt</a>.</li> |
| <li><a href="cargo.html">cargo</a>: Rules dedicated to Cargo compatibility. ie: <a href="https://doc.rust-lang.org/cargo/reference/build-scripts.html"><code>build.rs</code> scripts</a>.</li> |
| <li><a href="external_crates.html">crate_universe</a>: Rules for generating Bazel targets for external crate dependencies.</li> |
| </ul> |
| <h2 id="experimental-rules"><a class="header" href="#experimental-rules">Experimental rules</a></h2> |
| <ul> |
| <li><a href="rust_analyzer.html">rust_analyzer</a>: rules for generating <code>rust-project.json</code> files for <a href="https://rust-analyzer.github.io/">rust-analyzer</a></li> |
| </ul> |
| <h2 id="3rd-party-rules"><a class="header" href="#3rd-party-rules">3rd party rules</a></h2> |
| <ul> |
| <li><a href="rust_bindgen.html">rust_bindgen</a>: rules for generating C++ bindings.</li> |
| <li><a href="rust_prost.html">rust_prost</a>: rules for generating <a href="https://developers.google.com/protocol-buffers">protobuf</a> and <a href="https://grpc.io">gRPC</a> stubs using <a href="https://github.com/tokio-rs/prost">prost</a>.</li> |
| <li><a href="rust_pyo3.html">rust_pyo3</a>: Bazel rules for <a href="https://pyo3.rs/v0.23.4/">PyO3</a>.</li> |
| <li><a href="rust_wasm_bindgen.html">rust_wasm_bindgen</a>: rules for generating <a href="https://www.rust-lang.org/what/wasm">WebAssembly</a> bindings.</li> |
| </ul> |
| <div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build --> |
| <p>Public entry point to all Rust rules and supported APIs.</p> |
| <h2 id="rules-1"><a class="header" href="#rules-1">Rules</a></h2> |
| <ul> |
| <li><a href="rust.html#rust_binary">rust_binary</a></li> |
| <li><a href="rust.html#rust_library">rust_library</a></li> |
| <li><a href="rust.html#rust_library_group">rust_library_group</a></li> |
| <li><a href="rust.html#rust_lint_config">rust_lint_config</a></li> |
| <li><a href="rust.html#rust_proc_macro">rust_proc_macro</a></li> |
| <li><a href="rust.html#rust_shared_library">rust_shared_library</a></li> |
| <li><a href="rust.html#rust_static_library">rust_static_library</a></li> |
| <li><a href="rust.html#rust_test">rust_test</a></li> |
| <li><a href="rust.html#rust_unpretty">rust_unpretty</a></li> |
| </ul> |
| <h2 id="functions"><a class="header" href="#functions">Functions</a></h2> |
| <ul> |
| <li><a href="rust.html#rust_test_suite">rust_test_suite</a></li> |
| </ul> |
| <h2 id="aspects"><a class="header" href="#aspects">Aspects</a></h2> |
| <ul> |
| <li><a href="rust.html#rust_unpretty_aspect">rust_unpretty_aspect</a></li> |
| </ul> |
| <p><a id="rust_binary"></a></p> |
| <h2 id="rust_binary"><a class="header" href="#rust_binary">rust_binary</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_binary") |
| |
| rust_binary(<a href="rust.html#rust_binary-name">name</a>, <a href="rust.html#rust_binary-deps">deps</a>, <a href="rust.html#rust_binary-srcs">srcs</a>, <a href="rust.html#rust_binary-data">data</a>, <a href="rust.html#rust_binary-aliases">aliases</a>, <a href="rust.html#rust_binary-allocator_libraries">allocator_libraries</a>, <a href="rust.html#rust_binary-alwayslink">alwayslink</a>, <a href="rust.html#rust_binary-binary_name">binary_name</a>, |
| <a href="rust.html#rust_binary-compile_data">compile_data</a>, <a href="rust.html#rust_binary-crate_features">crate_features</a>, <a href="rust.html#rust_binary-crate_name">crate_name</a>, <a href="rust.html#rust_binary-crate_root">crate_root</a>, <a href="rust.html#rust_binary-crate_type">crate_type</a>, <a href="rust.html#rust_binary-edition">edition</a>, <a href="rust.html#rust_binary-env">env</a>, |
| <a href="rust.html#rust_binary-experimental_use_cc_common_link">experimental_use_cc_common_link</a>, <a href="rust.html#rust_binary-linker_script">linker_script</a>, <a href="rust.html#rust_binary-lint_config">lint_config</a>, <a href="rust.html#rust_binary-malloc">malloc</a>, <a href="rust.html#rust_binary-platform">platform</a>, |
| <a href="rust.html#rust_binary-proc_macro_deps">proc_macro_deps</a>, <a href="rust.html#rust_binary-require_explicit_unstable_features">require_explicit_unstable_features</a>, <a href="rust.html#rust_binary-rustc_env">rustc_env</a>, <a href="rust.html#rust_binary-rustc_env_files">rustc_env_files</a>, |
| <a href="rust.html#rust_binary-rustc_flags">rustc_flags</a>, <a href="rust.html#rust_binary-stamp">stamp</a>, <a href="rust.html#rust_binary-unstable_rust_features_config">unstable_rust_features_config</a>, <a href="rust.html#rust_binary-version">version</a>) |
| </pre> |
| <p>Builds a Rust binary crate.</p> |
| <p>Example:</p> |
| <p>Suppose you have the following directory structure for a Rust project with a |
| library crate, <code>hello_lib</code>, and a binary crate, <code>hello_world</code> that uses the |
| <code>hello_lib</code> library:</p> |
| <pre><code class="language-output">[workspace]/ |
| WORKSPACE |
| hello_lib/ |
| BUILD |
| src/ |
| lib.rs |
| hello_world/ |
| BUILD |
| src/ |
| main.rs |
| </code></pre> |
| <p><code>hello_lib/src/lib.rs</code>:</p> |
| <pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)] |
| </span><span class="boring">fn main() { |
| </span>pub struct Greeter { |
| greeting: String, |
| } |
| |
| impl Greeter { |
| pub fn new(greeting: &str) -> Greeter { |
| Greeter { greeting: greeting.to_string(), } |
| } |
| |
| pub fn greet(&self, thing: &str) { |
| println!("{} {}", &self.greeting, thing); |
| } |
| } |
| <span class="boring">}</span></code></pre></pre> |
| <p><code>hello_lib/BUILD</code>:</p> |
| <pre><code class="language-python">package(default_visibility = ["//visibility:public"]) |
| |
| load("@rules_rust//rust:defs.bzl", "rust_library") |
| |
| rust_library( |
| name = "hello_lib", |
| srcs = ["src/lib.rs"], |
| ) |
| </code></pre> |
| <p><code>hello_world/src/main.rs</code>:</p> |
| <pre><pre class="playground"><code class="language-rust">extern crate hello_lib; |
| |
| fn main() { |
| let hello = hello_lib::Greeter::new("Hello"); |
| hello.greet("world"); |
| }</code></pre></pre> |
| <p><code>hello_world/BUILD</code>:</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_binary") |
| |
| rust_binary( |
| name = "hello_world", |
| srcs = ["src/main.rs"], |
| deps = ["//hello_lib"], |
| ) |
| </code></pre> |
| <p>Build and run <code>hello_world</code>:</p> |
| <pre><code>$ bazel run //hello_world |
| INFO: Found 1 target... |
| Target //examples/rust/hello_world:hello_world up-to-date: |
| bazel-bin/examples/rust/hello_world/hello_world |
| INFO: Elapsed time: 1.308s, Critical Path: 1.22s |
| |
| INFO: Running command line: bazel-bin/examples/rust/hello_world/hello_world |
| Hello world |
| </code></pre> |
| <p>On Windows, a PDB file containing debugging information is available under |
| the key <code>pdb_file</code> in <code>OutputGroupInfo</code>. Similarly on macOS, a dSYM folder |
| is available under the key <code>dsym_folder</code> in <code>OutputGroupInfo</code>.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_binary-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> |
| <tr><td style="text-align: left"><a id="rust_binary-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-allocator_libraries"></a>allocator_libraries</td><td style="text-align: left">-</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>"@rules_rust//ffi/rs:default_allocator_libraries"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-binary_name"></a>binary_name</td><td style="text-align: left">Override the resulting binary file name. By default, the binary file will be named using the <code>name</code> attribute on this rule, however sometimes that is not deseriable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</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> |
| <tr><td style="text-align: left"><a id="rust_binary-crate_type"></a>crate_type</td><td style="text-align: left">Crate type that will be passed to <code>rustc</code> to be used for building this crate.<br><br>This option is a temporary workaround and should be used only when building for WebAssembly targets (//rust/platform:wasi and //rust/platform:wasm).</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"bin"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-env"></a>env</td><td style="text-align: left">Specifies additional environment variables to set when the target is executed by bazel run. Values are subject to <code>$(rootpath)</code>, <code>$(execpath)</code>, location, and <a href="https://docs.bazel.build/versions/master/be/make-variables.html">"Make variable"</a> substitution.<br><br>Execpath returns absolute path, and in order to be able to construct the absolute path we need to wrap the test binary in a launcher. Using a launcher comes with complications, such as more complicated debugger attachment.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-experimental_use_cc_common_link"></a>experimental_use_cc_common_link</td><td style="text-align: left">Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-linker_script"></a>linker_script</td><td style="text-align: left">Link script to forward into linker via rustc options.</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> |
| <tr><td style="text-align: left"><a id="rust_binary-lint_config"></a>lint_config</td><td style="text-align: left">Set of lints to apply when building this crate.</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> |
| <tr><td style="text-align: left"><a id="rust_binary-malloc"></a>malloc</td><td style="text-align: left">Override the default dependency on <code>malloc</code>.<br><br>By default, Rust binaries linked with <a href="https://bazel.build/rules/lib/toplevel/cc_common#link"><code>cc_common.link</code></a> are linked against <code>@rules_rust//rust/private/cc:malloc</code>, which is an empty library and the resulting binary will use libc's <code>malloc</code>. This label must refer to a <code>cc_library</code> rule.</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>"@rules_rust//rust/private/cc:malloc"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-platform"></a>platform</td><td style="text-align: left">Optional platform to transition the static library to.</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> |
| <tr><td style="text-align: left"><a id="rust_binary-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-require_explicit_unstable_features"></a>require_explicit_unstable_features</td><td style="text-align: left">Whether to require all unstable features to be explicitly opted in to using <code>-Zallow-features=...</code>. Possible values: [-1, 0, 1]. -1 means delegate to the toolchain.require_explicit_unstable_features boolean build setting; 0 means False; 1 means True.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-unstable_rust_features_config"></a>unstable_rust_features_config</td><td style="text-align: left">Controls which unstable features are allowed to be used by this target. Setting this to anything other than None requires a nightly toolchain.</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> |
| <tr><td style="text-align: left"><a id="rust_binary-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_library"></a></p> |
| <h2 id="rust_library"><a class="header" href="#rust_library">rust_library</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_library") |
| |
| rust_library(<a href="rust.html#rust_library-name">name</a>, <a href="rust.html#rust_library-deps">deps</a>, <a href="rust.html#rust_library-srcs">srcs</a>, <a href="rust.html#rust_library-data">data</a>, <a href="rust.html#rust_library-aliases">aliases</a>, <a href="rust.html#rust_library-allocator_libraries">allocator_libraries</a>, <a href="rust.html#rust_library-alwayslink">alwayslink</a>, <a href="rust.html#rust_library-compile_data">compile_data</a>, |
| <a href="rust.html#rust_library-crate_features">crate_features</a>, <a href="rust.html#rust_library-crate_name">crate_name</a>, <a href="rust.html#rust_library-crate_root">crate_root</a>, <a href="rust.html#rust_library-disable_pipelining">disable_pipelining</a>, <a href="rust.html#rust_library-edition">edition</a>, <a href="rust.html#rust_library-lint_config">lint_config</a>, |
| <a href="rust.html#rust_library-proc_macro_deps">proc_macro_deps</a>, <a href="rust.html#rust_library-require_explicit_unstable_features">require_explicit_unstable_features</a>, <a href="rust.html#rust_library-rustc_env">rustc_env</a>, <a href="rust.html#rust_library-rustc_env_files">rustc_env_files</a>, |
| <a href="rust.html#rust_library-rustc_flags">rustc_flags</a>, <a href="rust.html#rust_library-stamp">stamp</a>, <a href="rust.html#rust_library-unstable_rust_features_config">unstable_rust_features_config</a>, <a href="rust.html#rust_library-version">version</a>) |
| </pre> |
| <p>Builds a Rust library crate.</p> |
| <p>Example:</p> |
| <p>Suppose you have the following directory structure for a simple Rust library crate:</p> |
| <pre><code class="language-output">[workspace]/ |
| WORKSPACE |
| hello_lib/ |
| BUILD |
| src/ |
| greeter.rs |
| lib.rs |
| </code></pre> |
| <p><code>hello_lib/src/greeter.rs</code>:</p> |
| <pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)] |
| </span><span class="boring">fn main() { |
| </span>pub struct Greeter { |
| greeting: String, |
| } |
| |
| impl Greeter { |
| pub fn new(greeting: &str) -> Greeter { |
| Greeter { greeting: greeting.to_string(), } |
| } |
| |
| pub fn greet(&self, thing: &str) { |
| println!("{} {}", &self.greeting, thing); |
| } |
| } |
| <span class="boring">}</span></code></pre></pre> |
| <p><code>hello_lib/src/lib.rs</code>:</p> |
| <pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)] |
| </span><span class="boring">fn main() { |
| </span>pub mod greeter; |
| <span class="boring">}</span></code></pre></pre> |
| <p><code>hello_lib/BUILD</code>:</p> |
| <pre><code class="language-python">package(default_visibility = ["//visibility:public"]) |
| |
| load("@rules_rust//rust:defs.bzl", "rust_library") |
| |
| rust_library( |
| name = "hello_lib", |
| srcs = [ |
| "src/greeter.rs", |
| "src/lib.rs", |
| ], |
| ) |
| </code></pre> |
| <p>Build the library:</p> |
| <pre><code class="language-output">$ bazel build //hello_lib |
| INFO: Found 1 target... |
| Target //examples/rust/hello_lib:hello_lib up-to-date: |
| bazel-bin/examples/rust/hello_lib/libhello_lib.rlib |
| INFO: Elapsed time: 1.245s, Critical Path: 1.01s |
| </code></pre> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_library-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> |
| <tr><td style="text-align: left"><a id="rust_library-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-allocator_libraries"></a>allocator_libraries</td><td style="text-align: left">-</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>"@rules_rust//ffi/rs:default_allocator_libraries"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</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> |
| <tr><td style="text-align: left"><a id="rust_library-disable_pipelining"></a>disable_pipelining</td><td style="text-align: left">Disables pipelining for this rule if it is globally enabled. This will cause this rule to not produce a <code>.rmeta</code> file and all the dependent crates will instead use the <code>.rlib</code> file.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-lint_config"></a>lint_config</td><td style="text-align: left">Set of lints to apply when building this crate.</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> |
| <tr><td style="text-align: left"><a id="rust_library-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-require_explicit_unstable_features"></a>require_explicit_unstable_features</td><td style="text-align: left">Whether to require all unstable features to be explicitly opted in to using <code>-Zallow-features=...</code>. Possible values: [-1, 0, 1]. -1 means delegate to the toolchain.require_explicit_unstable_features boolean build setting; 0 means False; 1 means True.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>0</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_library-unstable_rust_features_config"></a>unstable_rust_features_config</td><td style="text-align: left">Controls which unstable features are allowed to be used by this target. Setting this to anything other than None requires a nightly toolchain.</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> |
| <tr><td style="text-align: left"><a id="rust_library-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_library_group"></a></p> |
| <h2 id="rust_library_group"><a class="header" href="#rust_library_group">rust_library_group</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_library_group") |
| |
| rust_library_group(<a href="rust.html#rust_library_group-name">name</a>, <a href="rust.html#rust_library_group-deps">deps</a>) |
| </pre> |
| <p>Functions as an alias for a set of dependencies.</p> |
| <p>Specifically, the following are equivalent:</p> |
| <pre><code class="language-starlark">rust_library_group( |
| name = "crate_group", |
| deps = [ |
| ":crate1", |
| ":crate2", |
| ], |
| ) |
| |
| rust_library( |
| name = "foobar", |
| deps = [":crate_group"], |
| ... |
| ) |
| </code></pre> |
| <p>and</p> |
| <pre><code class="language-starlark">rust_library( |
| name = "foobar", |
| deps = [ |
| ":crate1", |
| ":crate2", |
| ], |
| ... |
| ) |
| </code></pre> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_library_group-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> |
| <tr><td style="text-align: left"><a id="rust_library_group-deps"></a>deps</td><td style="text-align: left">Other dependencies to forward through this crate group.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_lint_config"></a></p> |
| <h2 id="rust_lint_config"><a class="header" href="#rust_lint_config">rust_lint_config</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_lint_config") |
| |
| rust_lint_config(<a href="rust.html#rust_lint_config-name">name</a>, <a href="rust.html#rust_lint_config-clippy">clippy</a>, <a href="rust.html#rust_lint_config-rustc">rustc</a>, <a href="rust.html#rust_lint_config-rustc_check_cfg">rustc_check_cfg</a>, <a href="rust.html#rust_lint_config-rustdoc">rustdoc</a>) |
| </pre> |
| <p>Defines a group of lints that can be applied when building Rust targets.</p> |
| <p>For example, you can define a single group of lints:</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_lint_config") |
| |
| rust_lint_config( |
| name = "workspace_lints", |
| rustc = { |
| "unknown_lints": "allow", |
| "unexpected_cfgs": "warn", |
| }, |
| rustc_check_cfg = { |
| "bazel": [], |
| "fuzzing": [], |
| "mz_featutres": ["laser", "rocket"], |
| }, |
| clippy = { |
| "box_default": "allow", |
| "todo": "warn", |
| "unused_async": "warn", |
| }, |
| rustdoc = { |
| "unportable_markdown": "allow", |
| }, |
| ) |
| </code></pre> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_lint_config-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> |
| <tr><td style="text-align: left"><a id="rust_lint_config-clippy"></a>clippy</td><td style="text-align: left">Set of 'clippy' lints to 'allow', 'expect', 'warn', 'force-warn', 'deny', or 'forbid'.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_lint_config-rustc"></a>rustc</td><td style="text-align: left">Set of 'rustc' lints to 'allow', 'expect', 'warn', 'force-warn', 'deny', or 'forbid'.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_lint_config-rustc_check_cfg"></a>rustc_check_cfg</td><td style="text-align: left">Set of 'cfg' names and list of values to expect.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> List of strings</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_lint_config-rustdoc"></a>rustdoc</td><td style="text-align: left">Set of 'rustdoc' lints to 'allow', 'expect', 'warn', 'force-warn', 'deny', or 'forbid'.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_proc_macro"></a></p> |
| <h2 id="rust_proc_macro"><a class="header" href="#rust_proc_macro">rust_proc_macro</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_proc_macro") |
| |
| rust_proc_macro(<a href="rust.html#rust_proc_macro-name">name</a>, <a href="rust.html#rust_proc_macro-deps">deps</a>, <a href="rust.html#rust_proc_macro-srcs">srcs</a>, <a href="rust.html#rust_proc_macro-data">data</a>, <a href="rust.html#rust_proc_macro-aliases">aliases</a>, <a href="rust.html#rust_proc_macro-allocator_libraries">allocator_libraries</a>, <a href="rust.html#rust_proc_macro-alwayslink">alwayslink</a>, <a href="rust.html#rust_proc_macro-compile_data">compile_data</a>, |
| <a href="rust.html#rust_proc_macro-crate_features">crate_features</a>, <a href="rust.html#rust_proc_macro-crate_name">crate_name</a>, <a href="rust.html#rust_proc_macro-crate_root">crate_root</a>, <a href="rust.html#rust_proc_macro-edition">edition</a>, <a href="rust.html#rust_proc_macro-lint_config">lint_config</a>, <a href="rust.html#rust_proc_macro-proc_macro_deps">proc_macro_deps</a>, |
| <a href="rust.html#rust_proc_macro-require_explicit_unstable_features">require_explicit_unstable_features</a>, <a href="rust.html#rust_proc_macro-rustc_env">rustc_env</a>, <a href="rust.html#rust_proc_macro-rustc_env_files">rustc_env_files</a>, <a href="rust.html#rust_proc_macro-rustc_flags">rustc_flags</a>, <a href="rust.html#rust_proc_macro-stamp">stamp</a>, |
| <a href="rust.html#rust_proc_macro-unstable_rust_features_config">unstable_rust_features_config</a>, <a href="rust.html#rust_proc_macro-version">version</a>) |
| </pre> |
| <p>Builds a Rust proc-macro crate.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-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> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-allocator_libraries"></a>allocator_libraries</td><td style="text-align: left">-</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>"@rules_rust//ffi/rs:default_allocator_libraries"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</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> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-lint_config"></a>lint_config</td><td style="text-align: left">Set of lints to apply when building this crate.</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> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-require_explicit_unstable_features"></a>require_explicit_unstable_features</td><td style="text-align: left">Whether to require all unstable features to be explicitly opted in to using <code>-Zallow-features=...</code>. Possible values: [-1, 0, 1]. -1 means delegate to the toolchain.require_explicit_unstable_features boolean build setting; 0 means False; 1 means True.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>0</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-unstable_rust_features_config"></a>unstable_rust_features_config</td><td style="text-align: left">Controls which unstable features are allowed to be used by this target. Setting this to anything other than None requires a nightly toolchain.</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> |
| <tr><td style="text-align: left"><a id="rust_proc_macro-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_shared_library"></a></p> |
| <h2 id="rust_shared_library"><a class="header" href="#rust_shared_library">rust_shared_library</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_shared_library") |
| |
| rust_shared_library(<a href="rust.html#rust_shared_library-name">name</a>, <a href="rust.html#rust_shared_library-deps">deps</a>, <a href="rust.html#rust_shared_library-srcs">srcs</a>, <a href="rust.html#rust_shared_library-data">data</a>, <a href="rust.html#rust_shared_library-aliases">aliases</a>, <a href="rust.html#rust_shared_library-allocator_libraries">allocator_libraries</a>, <a href="rust.html#rust_shared_library-alwayslink">alwayslink</a>, <a href="rust.html#rust_shared_library-compile_data">compile_data</a>, |
| <a href="rust.html#rust_shared_library-crate_features">crate_features</a>, <a href="rust.html#rust_shared_library-crate_name">crate_name</a>, <a href="rust.html#rust_shared_library-crate_root">crate_root</a>, <a href="rust.html#rust_shared_library-edition">edition</a>, <a href="rust.html#rust_shared_library-experimental_use_cc_common_link">experimental_use_cc_common_link</a>, |
| <a href="rust.html#rust_shared_library-lint_config">lint_config</a>, <a href="rust.html#rust_shared_library-malloc">malloc</a>, <a href="rust.html#rust_shared_library-platform">platform</a>, <a href="rust.html#rust_shared_library-proc_macro_deps">proc_macro_deps</a>, |
| <a href="rust.html#rust_shared_library-require_explicit_unstable_features">require_explicit_unstable_features</a>, <a href="rust.html#rust_shared_library-rustc_env">rustc_env</a>, <a href="rust.html#rust_shared_library-rustc_env_files">rustc_env_files</a>, <a href="rust.html#rust_shared_library-rustc_flags">rustc_flags</a>, |
| <a href="rust.html#rust_shared_library-stamp">stamp</a>, <a href="rust.html#rust_shared_library-unstable_rust_features_config">unstable_rust_features_config</a>, <a href="rust.html#rust_shared_library-version">version</a>) |
| </pre> |
| <p>Builds a Rust shared library.</p> |
| <p>This shared library will contain all transitively reachable crates and native objects. |
| It is meant to be used when producing an artifact that is then consumed by some other build system |
| (for example to produce a shared library that Python program links against).</p> |
| <p>This rule provides CcInfo, so it can be used everywhere Bazel expects <code>rules_cc</code>.</p> |
| <p>When building the whole binary in Bazel, use <code>rust_library</code> instead.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_shared_library-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> |
| <tr><td style="text-align: left"><a id="rust_shared_library-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-allocator_libraries"></a>allocator_libraries</td><td style="text-align: left">-</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>"@rules_rust//ffi/rs:default_allocator_libraries"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</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> |
| <tr><td style="text-align: left"><a id="rust_shared_library-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-experimental_use_cc_common_link"></a>experimental_use_cc_common_link</td><td style="text-align: left">Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-lint_config"></a>lint_config</td><td style="text-align: left">Set of lints to apply when building this crate.</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> |
| <tr><td style="text-align: left"><a id="rust_shared_library-malloc"></a>malloc</td><td style="text-align: left">Override the default dependency on <code>malloc</code>.<br><br>By default, Rust binaries linked with <a href="https://bazel.build/rules/lib/toplevel/cc_common#link"><code>cc_common.link</code></a> are linked against <code>@rules_rust//rust/private/cc:malloc</code>, which is an empty library and the resulting binary will use libc's <code>malloc</code>. This label must refer to a <code>cc_library</code> rule.</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>"@rules_rust//rust/private/cc:malloc"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-platform"></a>platform</td><td style="text-align: left">Optional platform to transition the static library to.</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> |
| <tr><td style="text-align: left"><a id="rust_shared_library-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-require_explicit_unstable_features"></a>require_explicit_unstable_features</td><td style="text-align: left">Whether to require all unstable features to be explicitly opted in to using <code>-Zallow-features=...</code>. Possible values: [-1, 0, 1]. -1 means delegate to the toolchain.require_explicit_unstable_features boolean build setting; 0 means False; 1 means True.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>0</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_shared_library-unstable_rust_features_config"></a>unstable_rust_features_config</td><td style="text-align: left">Controls which unstable features are allowed to be used by this target. Setting this to anything other than None requires a nightly toolchain.</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> |
| <tr><td style="text-align: left"><a id="rust_shared_library-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_static_library"></a></p> |
| <h2 id="rust_static_library"><a class="header" href="#rust_static_library">rust_static_library</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_static_library") |
| |
| rust_static_library(<a href="rust.html#rust_static_library-name">name</a>, <a href="rust.html#rust_static_library-deps">deps</a>, <a href="rust.html#rust_static_library-srcs">srcs</a>, <a href="rust.html#rust_static_library-data">data</a>, <a href="rust.html#rust_static_library-aliases">aliases</a>, <a href="rust.html#rust_static_library-allocator_libraries">allocator_libraries</a>, <a href="rust.html#rust_static_library-alwayslink">alwayslink</a>, <a href="rust.html#rust_static_library-compile_data">compile_data</a>, |
| <a href="rust.html#rust_static_library-crate_features">crate_features</a>, <a href="rust.html#rust_static_library-crate_name">crate_name</a>, <a href="rust.html#rust_static_library-crate_root">crate_root</a>, <a href="rust.html#rust_static_library-edition">edition</a>, <a href="rust.html#rust_static_library-lint_config">lint_config</a>, <a href="rust.html#rust_static_library-platform">platform</a>, |
| <a href="rust.html#rust_static_library-proc_macro_deps">proc_macro_deps</a>, <a href="rust.html#rust_static_library-require_explicit_unstable_features">require_explicit_unstable_features</a>, <a href="rust.html#rust_static_library-rustc_env">rustc_env</a>, <a href="rust.html#rust_static_library-rustc_env_files">rustc_env_files</a>, |
| <a href="rust.html#rust_static_library-rustc_flags">rustc_flags</a>, <a href="rust.html#rust_static_library-stamp">stamp</a>, <a href="rust.html#rust_static_library-unstable_rust_features_config">unstable_rust_features_config</a>, <a href="rust.html#rust_static_library-version">version</a>) |
| </pre> |
| <p>Builds a Rust static library.</p> |
| <p>This static library will contain all transitively reachable crates and native objects. |
| It is meant to be used when producing an artifact that is then consumed by some other build system |
| (for example to produce an archive that Python program links against).</p> |
| <p>This rule provides CcInfo, so it can be used everywhere Bazel expects <code>rules_cc</code>.</p> |
| <p>When building the whole binary in Bazel, use <code>rust_library</code> instead.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_static_library-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> |
| <tr><td style="text-align: left"><a id="rust_static_library-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-allocator_libraries"></a>allocator_libraries</td><td style="text-align: left">-</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>"@rules_rust//ffi/rs:default_allocator_libraries"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</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> |
| <tr><td style="text-align: left"><a id="rust_static_library-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-lint_config"></a>lint_config</td><td style="text-align: left">Set of lints to apply when building this crate.</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> |
| <tr><td style="text-align: left"><a id="rust_static_library-platform"></a>platform</td><td style="text-align: left">Optional platform to transition the static library to.</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> |
| <tr><td style="text-align: left"><a id="rust_static_library-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-require_explicit_unstable_features"></a>require_explicit_unstable_features</td><td style="text-align: left">Whether to require all unstable features to be explicitly opted in to using <code>-Zallow-features=...</code>. Possible values: [-1, 0, 1]. -1 means delegate to the toolchain.require_explicit_unstable_features boolean build setting; 0 means False; 1 means True.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>0</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_static_library-unstable_rust_features_config"></a>unstable_rust_features_config</td><td style="text-align: left">Controls which unstable features are allowed to be used by this target. Setting this to anything other than None requires a nightly toolchain.</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> |
| <tr><td style="text-align: left"><a id="rust_static_library-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_test"></a></p> |
| <h2 id="rust_test"><a class="header" href="#rust_test">rust_test</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_test") |
| |
| rust_test(<a href="rust.html#rust_test-name">name</a>, <a href="rust.html#rust_test-deps">deps</a>, <a href="rust.html#rust_test-srcs">srcs</a>, <a href="rust.html#rust_test-data">data</a>, <a href="rust.html#rust_test-aliases">aliases</a>, <a href="rust.html#rust_test-allocator_libraries">allocator_libraries</a>, <a href="rust.html#rust_test-alwayslink">alwayslink</a>, <a href="rust.html#rust_test-compile_data">compile_data</a>, <a href="rust.html#rust_test-crate">crate</a>, |
| <a href="rust.html#rust_test-crate_features">crate_features</a>, <a href="rust.html#rust_test-crate_name">crate_name</a>, <a href="rust.html#rust_test-crate_root">crate_root</a>, <a href="rust.html#rust_test-edition">edition</a>, <a href="rust.html#rust_test-env">env</a>, <a href="rust.html#rust_test-env_inherit">env_inherit</a>, |
| <a href="rust.html#rust_test-experimental_use_cc_common_link">experimental_use_cc_common_link</a>, <a href="rust.html#rust_test-lint_config">lint_config</a>, <a href="rust.html#rust_test-malloc">malloc</a>, <a href="rust.html#rust_test-platform">platform</a>, <a href="rust.html#rust_test-proc_macro_deps">proc_macro_deps</a>, |
| <a href="rust.html#rust_test-require_explicit_unstable_features">require_explicit_unstable_features</a>, <a href="rust.html#rust_test-rustc_env">rustc_env</a>, <a href="rust.html#rust_test-rustc_env_files">rustc_env_files</a>, <a href="rust.html#rust_test-rustc_flags">rustc_flags</a>, <a href="rust.html#rust_test-stamp">stamp</a>, |
| <a href="rust.html#rust_test-unstable_rust_features_config">unstable_rust_features_config</a>, <a href="rust.html#rust_test-use_libtest_harness">use_libtest_harness</a>, <a href="rust.html#rust_test-version">version</a>) |
| </pre> |
| <p>Builds a Rust test crate.</p> |
| <p>Examples:</p> |
| <p>Suppose you have the following directory structure for a Rust library crate with unit test code in the library sources:</p> |
| <pre><code class="language-output">[workspace]/ |
| WORKSPACE |
| hello_lib/ |
| BUILD |
| src/ |
| lib.rs |
| </code></pre> |
| <p><code>hello_lib/src/lib.rs</code>:</p> |
| <pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)] |
| </span><span class="boring">fn main() { |
| </span>pub struct Greeter { |
| greeting: String, |
| } |
| |
| impl Greeter { |
| pub fn new(greeting: &str) -> Greeter { |
| Greeter { greeting: greeting.to_string(), } |
| } |
| |
| pub fn greet(&self, thing: &str) -> String { |
| format!("{} {}", &self.greeting, thing) |
| } |
| } |
| |
| #[cfg(test)] |
| mod test { |
| use super::Greeter; |
| |
| #[test] |
| fn test_greeting() { |
| let hello = Greeter::new("Hi"); |
| assert_eq!("Hi Rust", hello.greet("Rust")); |
| } |
| } |
| <span class="boring">}</span></code></pre></pre> |
| <p>To build and run the tests, simply add a <code>rust_test</code> rule with no <code>srcs</code> |
| and only depends on the <code>hello_lib</code> <code>rust_library</code> target via the |
| <code>crate</code> attribute:</p> |
| <p><code>hello_lib/BUILD</code>:</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") |
| |
| rust_library( |
| name = "hello_lib", |
| srcs = ["src/lib.rs"], |
| ) |
| |
| rust_test( |
| name = "hello_lib_test", |
| crate = ":hello_lib", |
| # You may add other deps that are specific to the test configuration |
| deps = ["//some/dev/dep"], |
| ) |
| </code></pre> |
| <p>Run the test with <code>bazel test //hello_lib:hello_lib_test</code>.</p> |
| <h3 id="example-test-directory"><a class="header" href="#example-test-directory">Example: <code>test</code> directory</a></h3> |
| <p>Integration tests that live in the <a href="http://doc.rust-lang.org/book/testing.html#the-tests-directory"><code>tests</code> directory</a>, they are essentially built as separate crates. Suppose you have the following directory structure where <code>greeting.rs</code> is an integration test for the <code>hello_lib</code> library crate:</p> |
| <pre><code class="language-output">[workspace]/ |
| WORKSPACE |
| hello_lib/ |
| BUILD |
| src/ |
| lib.rs |
| tests/ |
| greeting.rs |
| </code></pre> |
| <p><code>hello_lib/tests/greeting.rs</code>:</p> |
| <pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)] |
| </span><span class="boring">fn main() { |
| </span>extern crate hello_lib; |
| |
| use hello_lib; |
| |
| #[test] |
| fn test_greeting() { |
| let hello = greeter::Greeter::new("Hello"); |
| assert_eq!("Hello world", hello.greeting("world")); |
| } |
| <span class="boring">}</span></code></pre></pre> |
| <p>To build the <code>greeting.rs</code> integration test, simply add a <code>rust_test</code> target |
| with <code>greeting.rs</code> in <code>srcs</code> and a dependency on the <code>hello_lib</code> target:</p> |
| <p><code>hello_lib/BUILD</code>:</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") |
| |
| rust_library( |
| name = "hello_lib", |
| srcs = ["src/lib.rs"], |
| ) |
| |
| rust_test( |
| name = "greeting_test", |
| srcs = ["tests/greeting.rs"], |
| deps = [":hello_lib"], |
| ) |
| </code></pre> |
| <p>Run the test with <code>bazel test //hello_lib:greeting_test</code>.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_test-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> |
| <tr><td style="text-align: left"><a id="rust_test-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-allocator_libraries"></a>allocator_libraries</td><td style="text-align: left">-</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>"@rules_rust//ffi/rs:default_allocator_libraries"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-crate"></a>crate</td><td style="text-align: left">Target inline tests declared in the given crate<br><br>These tests are typically those that would be held out under <code>#[cfg(test)]</code> declarations.</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> |
| <tr><td style="text-align: left"><a id="rust_test-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</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> |
| <tr><td style="text-align: left"><a id="rust_test-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-env"></a>env</td><td style="text-align: left">Specifies additional environment variables to set when the test is executed by bazel test. Values are subject to <code>$(rootpath)</code>, <code>$(execpath)</code>, location, and <a href="https://docs.bazel.build/versions/master/be/make-variables.html">"Make variable"</a> substitution.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-env_inherit"></a>env_inherit</td><td style="text-align: left">Specifies additional environment variables to inherit from the external environment when the test is executed by bazel test.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-experimental_use_cc_common_link"></a>experimental_use_cc_common_link</td><td style="text-align: left">Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-lint_config"></a>lint_config</td><td style="text-align: left">Set of lints to apply when building this crate.</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> |
| <tr><td style="text-align: left"><a id="rust_test-malloc"></a>malloc</td><td style="text-align: left">Override the default dependency on <code>malloc</code>.<br><br>By default, Rust binaries linked with <a href="https://bazel.build/rules/lib/toplevel/cc_common#link"><code>cc_common.link</code></a> are linked against <code>@rules_rust//rust/private/cc:malloc</code>, which is an empty library and the resulting binary will use libc's <code>malloc</code>. This label must refer to a <code>cc_library</code> rule.</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>"@rules_rust//rust/private/cc:malloc"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-platform"></a>platform</td><td style="text-align: left">Optional platform to transition the static library to.</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> |
| <tr><td style="text-align: left"><a id="rust_test-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-require_explicit_unstable_features"></a>require_explicit_unstable_features</td><td style="text-align: left">Whether to require all unstable features to be explicitly opted in to using <code>-Zallow-features=...</code>. Possible values: [-1, 0, 1]. -1 means delegate to the toolchain.require_explicit_unstable_features boolean build setting; 0 means False; 1 means True.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>0</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-unstable_rust_features_config"></a>unstable_rust_features_config</td><td style="text-align: left">Controls which unstable features are allowed to be used by this target. Setting this to anything other than None requires a nightly toolchain.</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> |
| <tr><td style="text-align: left"><a id="rust_test-use_libtest_harness"></a>use_libtest_harness</td><td style="text-align: left">Whether to use <code>libtest</code>. For targets using this flag, individual tests can be run by using the <a href="https://docs.bazel.build/versions/4.0.0/command-line-reference.html#flag--test_arg">--test_arg</a> flag. E.g. <code>bazel test //src:rust_test --test_arg=foo::test::test_fn</code>.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_unpretty"></a></p> |
| <h2 id="rust_unpretty"><a class="header" href="#rust_unpretty">rust_unpretty</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_unpretty") |
| |
| rust_unpretty(<a href="rust.html#rust_unpretty-name">name</a>, <a href="rust.html#rust_unpretty-deps">deps</a>, <a href="rust.html#rust_unpretty-mode">mode</a>) |
| </pre> |
| <p>Executes rust unpretty on a specific target.</p> |
| <p>Similar to <code>rust_unpretty_aspect</code>, but allows specifying a list of dependencies within the build system.</p> |
| <p>For example, given the following example targets:</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") |
| |
| rust_library( |
| name = "hello_lib", |
| srcs = ["src/lib.rs"], |
| ) |
| |
| rust_test( |
| name = "greeting_test", |
| srcs = ["tests/greeting.rs"], |
| deps = [":hello_lib"], |
| ) |
| </code></pre> |
| <p>Rust expand can be set as a build target with the following:</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_unpretty") |
| |
| rust_unpretty( |
| name = "hello_library_expand", |
| testonly = True, |
| deps = [ |
| ":hello_lib", |
| ":greeting_test", |
| ], |
| mode = "expand", |
| ) |
| </code></pre> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_unpretty-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> |
| <tr><td style="text-align: left"><a id="rust_unpretty-deps"></a>deps</td><td style="text-align: left">Rust targets to run unpretty on.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_unpretty-mode"></a>mode</td><td style="text-align: left">The value to pass to <code>--unpretty</code></td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"expanded"</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_test_suite"></a></p> |
| <h2 id="rust_test_suite"><a class="header" href="#rust_test_suite">rust_test_suite</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_test_suite") |
| |
| rust_test_suite(<a href="rust.html#rust_test_suite-name">name</a>, <a href="rust.html#rust_test_suite-srcs">srcs</a>, <a href="rust.html#rust_test_suite-shared_srcs">shared_srcs</a>, <a href="rust.html#rust_test_suite-kwargs">**kwargs</a>) |
| </pre> |
| <p>A rule for creating a test suite for a set of <code>rust_test</code> targets.</p> |
| <p>This rule can be used for setting up typical rust <a href="https://doc.rust-lang.org/rust-by-example/testing/integration_testing.html">integration tests</a>. Given the following |
| directory structure:</p> |
| <pre><code class="language-text">[crate]/ |
| BUILD.bazel |
| src/ |
| lib.rs |
| main.rs |
| tests/ |
| integrated_test_a.rs |
| integrated_test_b.rs |
| integrated_test_c.rs |
| patterns/ |
| fibonacci_test.rs |
| helpers/ |
| mod.rs |
| </code></pre> |
| <p>The rule can be used to generate <a href="rust.html#rust_test">rust_test</a> targets for each source file under <code>tests</code> |
| and a <a href="https://docs.bazel.build/versions/master/be/general.html#test_suite">test_suite</a> which encapsulates all tests.</p> |
| <pre><code class="language-python">load("//rust:defs.bzl", "rust_binary", "rust_library", "rust_test_suite") |
| |
| rust_library( |
| name = "math_lib", |
| srcs = ["src/lib.rs"], |
| ) |
| |
| rust_binary( |
| name = "math_bin", |
| srcs = ["src/main.rs"], |
| ) |
| |
| rust_test_suite( |
| name = "integrated_tests_suite", |
| srcs = glob(["tests/**"]), |
| shared_srcs=glob(["tests/helpers/**"]), |
| deps = [":math_lib"], |
| ) |
| </code></pre> |
| <p><strong>PARAMETERS</strong></p> |
| <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">Default Value</th></tr></thead><tbody> |
| <tr><td style="text-align: left"><a id="rust_test_suite-name"></a>name</td><td style="text-align: left">The name of the <code>test_suite</code>.</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="rust_test_suite-srcs"></a>srcs</td><td style="text-align: left">All test sources, typically <code>glob(["tests/**/*.rs"])</code>.</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="rust_test_suite-shared_srcs"></a>shared_srcs</td><td style="text-align: left">Optional argument for sources shared among tests, typically helper functions.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_test_suite-kwargs"></a>kwargs</td><td style="text-align: left">Additional keyword arguments for the underlying <a href="rust.html#rust_test">rust_test</a> targets. The <code>tags</code> argument is also passed to the generated <code>test_suite</code> target.</td><td style="text-align: left">none</td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_unpretty_aspect"></a></p> |
| <h2 id="rust_unpretty_aspect"><a class="header" href="#rust_unpretty_aspect">rust_unpretty_aspect</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_unpretty_aspect") |
| |
| rust_unpretty_aspect() |
| </pre> |
| <p>Executes Rust expand on specified targets.</p> |
| <p>This aspect applies to existing rust_library, rust_test, and rust_binary rules.</p> |
| <p>As an example, if the following is defined in <code>examples/hello_lib/BUILD.bazel</code>:</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") |
| |
| rust_library( |
| name = "hello_lib", |
| srcs = ["src/lib.rs"], |
| ) |
| |
| rust_test( |
| name = "greeting_test", |
| srcs = ["tests/greeting.rs"], |
| deps = [":hello_lib"], |
| ) |
| </code></pre> |
| <p>Then the targets can be expanded with the following command:</p> |
| <pre><code class="language-output">$ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_unpretty_aspect \ |
| --output_groups=rust_unpretty_expanded \ |
| //hello_lib:all |
| </code></pre> |
| <p><strong>ASPECT ATTRIBUTES</strong></p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <div style="break-before: page; page-break-before: always;"></div><h2 id="overview"><a class="header" href="#overview">Overview</a></h2> |
| <p><a href="https://github.com/rust-lang/rust-clippy#readme">Clippy</a> is a tool for catching common mistakes in Rust code and improving it. An |
| expansive list of lints and the justification can be found in their <a href="https://rust-lang.github.io/rust-clippy/">documentation</a>.</p> |
| <h3 id="setup-1"><a class="header" href="#setup-1">Setup</a></h3> |
| <p>Simply add the following to the <code>.bazelrc</code> file in the root of your workspace:</p> |
| <pre><code class="language-text">build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect |
| build --output_groups=+clippy_checks |
| </code></pre> |
| <p>This will enable clippy on all <a href="./defs.html">Rust targets</a>.</p> |
| <p>Note that targets tagged with <code>no-clippy</code> will not perform clippy checks</p> |
| <p>To use a local clippy.toml, add the following flag to your <code>.bazelrc</code>. Note that due to |
| the upstream implementation of clippy, this file must be named either <code>.clippy.toml</code> or |
| <code>clippy.toml</code>. Using a custom config file requires Rust 1.34.0 or newer.</p> |
| <pre><code class="language-text">build --@rules_rust//rust/settings:clippy.toml=//:clippy.toml |
| </code></pre> |
| <h2 id="rules-2"><a class="header" href="#rules-2">Rules</a></h2> |
| <ul> |
| <li><a href="rust_clippy.html#rust_clippy">rust_clippy</a></li> |
| </ul> |
| <h2 id="aspects-1"><a class="header" href="#aspects-1">Aspects</a></h2> |
| <ul> |
| <li><a href="rust_clippy.html#rust_clippy_aspect">rust_clippy_aspect</a></li> |
| </ul> |
| <p><a id="rust_clippy"></a></p> |
| <h2 id="rust_clippy"><a class="header" href="#rust_clippy">rust_clippy</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_clippy") |
| |
| rust_clippy(<a href="rust_clippy.html#rust_clippy-name">name</a>, <a href="rust_clippy.html#rust_clippy-deps">deps</a>) |
| </pre> |
| <p>Executes the clippy checker on a specific target.</p> |
| <p>Similar to <code>rust_clippy_aspect</code>, but allows specifying a list of dependencies within the build system.</p> |
| <p>For example, given the following example targets:</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") |
| |
| rust_library( |
| name = "hello_lib", |
| srcs = ["src/lib.rs"], |
| ) |
| |
| rust_test( |
| name = "greeting_test", |
| srcs = ["tests/greeting.rs"], |
| deps = [":hello_lib"], |
| ) |
| </code></pre> |
| <p>Rust clippy can be set as a build target with the following:</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_clippy") |
| |
| rust_clippy( |
| name = "hello_library_clippy", |
| testonly = True, |
| deps = [ |
| ":hello_lib", |
| ":greeting_test", |
| ], |
| ) |
| </code></pre> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_clippy-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> |
| <tr><td style="text-align: left"><a id="rust_clippy-deps"></a>deps</td><td style="text-align: left">Rust targets to run clippy on.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_clippy_aspect"></a></p> |
| <h2 id="rust_clippy_aspect"><a class="header" href="#rust_clippy_aspect">rust_clippy_aspect</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_clippy_aspect") |
| |
| rust_clippy_aspect() |
| </pre> |
| <p>Executes the clippy checker on specified targets.</p> |
| <p>This aspect applies to existing rust_library, rust_test, and rust_binary rules.</p> |
| <p>As an example, if the following is defined in <code>examples/hello_lib/BUILD.bazel</code>:</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") |
| |
| rust_library( |
| name = "hello_lib", |
| srcs = ["src/lib.rs"], |
| ) |
| |
| rust_test( |
| name = "greeting_test", |
| srcs = ["tests/greeting.rs"], |
| deps = [":hello_lib"], |
| ) |
| </code></pre> |
| <p>Then the targets can be analyzed with clippy using the following command:</p> |
| <pre><code class="language-output">$ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect --output_groups=clippy_checks //hello_lib:all |
| </code></pre> |
| <p><strong>ASPECT ATTRIBUTES</strong></p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <div style="break-before: page; page-break-before: always;"></div><h2 id="overview-1"><a class="header" href="#overview-1">Overview</a></h2> |
| <p><a href="https://github.com/rust-lang/rustfmt#readme">Rustfmt</a> is a tool for formatting Rust code according to style guidelines. |
| By default, Rustfmt uses a style which conforms to the <a href="https://github.com/rust-lang-nursery/fmt-rfcs/blob/master/guide/guide.md">Rust style guide</a> that |
| has been formalized through the <a href="https://github.com/rust-lang-nursery/fmt-rfcs">style RFC process</a>. A complete list of all |
| configuration options can be found in the <a href="https://rust-lang.github.io/rustfmt/">Rustfmt GitHub Pages</a>.</p> |
| <h3 id="setup-2"><a class="header" href="#setup-2">Setup</a></h3> |
| <p>Formatting your Rust targets' source code requires no setup outside of loading <code>rules_rust</code> |
| in your workspace. Simply run <code>bazel run @rules_rust//:rustfmt</code> to format source code.</p> |
| <p>In addition to this formatter, a simple check can be performed using the <a href="rust_fmt.html#rustfmt-aspect">rustfmt_aspect</a> aspect by running</p> |
| <pre><code class="language-text">bazel build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect --output_groups=rustfmt_checks |
| </code></pre> |
| <p>Add the following to a <code>.bazelrc</code> file to enable this check during the build phase.</p> |
| <pre><code class="language-text">build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect |
| build --output_groups=+rustfmt_checks |
| </code></pre> |
| <p>It's recommended to only enable this aspect in your CI environment so formatting issues do not |
| impact user's ability to rapidly iterate on changes.</p> |
| <p>The <code>rustfmt_aspect</code> also uses a <code>--@rules_rust//rust/settings:rustfmt.toml</code> setting which determines the |
| <a href="https://rust-lang.github.io/rustfmt/">configuration file</a> used by the formatter (<code>@rules_rust//tools/rustfmt</code>) and the aspect |
| (<code>rustfmt_aspect</code>). This flag can be added to your <code>.bazelrc</code> file to ensure a consistent config |
| file is used whenever <code>rustfmt</code> is run:</p> |
| <pre><code class="language-text">build --@rules_rust//rust/settings:rustfmt.toml=//:rustfmt.toml |
| </code></pre> |
| <h3 id="tips"><a class="header" href="#tips">Tips</a></h3> |
| <p>Any target which uses Bazel generated sources will cause the <code>@rules_rust//tools/rustfmt</code> tool to fail with |
| <code>failed to resolve mod `MOD` </code>. To avoid failures, <a href="https://rust-lang.github.io/rustfmt/?version=v1.6.0&search=skip_chil#skip_children"><code>skip_children = true</code></a> |
| is recommended to be set in the workspace's <code>rustfmt.toml</code> file which allows rustfmt to run on these targets |
| without failing.</p> |
| <h2 id="rules-3"><a class="header" href="#rules-3">Rules</a></h2> |
| <ul> |
| <li><a href="rust_fmt.html#rustfmt_test">rustfmt_test</a></li> |
| </ul> |
| <h2 id="aspects-2"><a class="header" href="#aspects-2">Aspects</a></h2> |
| <ul> |
| <li><a href="rust_fmt.html#rustfmt_aspect">rustfmt_aspect</a></li> |
| </ul> |
| <p><a id="rustfmt_test"></a></p> |
| <h2 id="rustfmt_test"><a class="header" href="#rustfmt_test">rustfmt_test</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rustfmt_test") |
| |
| rustfmt_test(<a href="rust_fmt.html#rustfmt_test-name">name</a>, <a href="rust_fmt.html#rustfmt_test-targets">targets</a>) |
| </pre> |
| <p>A test rule for performing <code>rustfmt --check</code> on a set of targets</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rustfmt_test-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> |
| <tr><td style="text-align: left"><a id="rustfmt_test-targets"></a>targets</td><td style="text-align: left">Rust targets to run <code>rustfmt --check</code> on.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rustfmt_aspect"></a></p> |
| <h2 id="rustfmt_aspect"><a class="header" href="#rustfmt_aspect">rustfmt_aspect</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rustfmt_aspect") |
| |
| rustfmt_aspect() |
| </pre> |
| <p>This aspect is used to gather information about a crate for use in rustfmt and perform rustfmt checks</p> |
| <p>Output Groups:</p> |
| <ul> |
| <li><code>rustfmt_checks</code>: Executes <code>rustfmt --check</code> on the specified target.</li> |
| </ul> |
| <p>The build setting <code>@rules_rust//rust/settings:rustfmt.toml</code> is used to control the Rustfmt <a href="https://rust-lang.github.io/rustfmt/">configuration settings</a> |
| used at runtime.</p> |
| <p>This aspect is executed on any target which provides the <code>CrateInfo</code> provider. However |
| users may tag a target with <code>no-rustfmt</code> or <code>no-format</code> to have it skipped. Additionally, |
| generated source files are also ignored by this aspect.</p> |
| <p><strong>ASPECT ATTRIBUTES</strong></p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build --> |
| <p>Public entry point to all Rust rules and supported APIs.</p> |
| <h2 id="rules-4"><a class="header" href="#rules-4">Rules</a></h2> |
| <ul> |
| <li><a href="rust_doc.html#rust_doc">rust_doc</a></li> |
| <li><a href="rust_doc.html#rust_doc_test">rust_doc_test</a></li> |
| </ul> |
| <p><a id="rust_doc"></a></p> |
| <h2 id="rust_doc"><a class="header" href="#rust_doc">rust_doc</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_doc") |
| |
| rust_doc(<a href="rust_doc.html#rust_doc-name">name</a>, <a href="rust_doc.html#rust_doc-crate">crate</a>, <a href="rust_doc.html#rust_doc-crate_features">crate_features</a>, <a href="rust_doc.html#rust_doc-html_after_content">html_after_content</a>, <a href="rust_doc.html#rust_doc-html_before_content">html_before_content</a>, <a href="rust_doc.html#rust_doc-html_in_header">html_in_header</a>, |
| <a href="rust_doc.html#rust_doc-markdown_css">markdown_css</a>, <a href="rust_doc.html#rust_doc-rustc_flags">rustc_flags</a>, <a href="rust_doc.html#rust_doc-rustdoc_flags">rustdoc_flags</a>) |
| </pre> |
| <p>Generates code documentation.</p> |
| <p>Example: |
| Suppose you have the following directory structure for a Rust library crate:</p> |
| <pre><code>[workspace]/ |
| WORKSPACE |
| hello_lib/ |
| BUILD |
| src/ |
| lib.rs |
| </code></pre> |
| <p>To build <a href="https://doc.rust-lang.org/book/documentation.html"><code>rustdoc</code></a> documentation for the <code>hello_lib</code> crate, define a <code>rust_doc</code> rule that depends on the the <code>hello_lib</code> <code>rust_library</code> target:</p> |
| <pre><code class="language-python">package(default_visibility = ["//visibility:public"]) |
| |
| load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc") |
| |
| rust_library( |
| name = "hello_lib", |
| srcs = ["src/lib.rs"], |
| ) |
| |
| rust_doc( |
| name = "hello_lib_doc", |
| crate = ":hello_lib", |
| ) |
| </code></pre> |
| <p>Running <code>bazel build //hello_lib:hello_lib_doc</code> will build a zip file containing the documentation for the <code>hello_lib</code> library crate generated by <code>rustdoc</code>.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_doc-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> |
| <tr><td style="text-align: left"><a id="rust_doc-crate"></a>crate</td><td style="text-align: left">The label of the target to generate code documentation for.<br><br><code>rust_doc</code> can generate HTML code documentation for the source files of <code>rust_library</code> or <code>rust_binary</code> targets.</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> |
| <tr><td style="text-align: left"><a id="rust_doc-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for the crate being documented.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_doc-html_after_content"></a>html_after_content</td><td style="text-align: left">File to add in <code><body></code>, after content.</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> |
| <tr><td style="text-align: left"><a id="rust_doc-html_before_content"></a>html_before_content</td><td style="text-align: left">File to add in <code><body></code>, before content.</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> |
| <tr><td style="text-align: left"><a id="rust_doc-html_in_header"></a>html_in_header</td><td style="text-align: left">File to add to <code><head></code>.</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> |
| <tr><td style="text-align: left"><a id="rust_doc-markdown_css"></a>markdown_css</td><td style="text-align: left">CSS files to include via <code><link></code> in a rendered Markdown file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_doc-rustc_flags"></a>rustc_flags</td><td style="text-align: left"><strong>Deprecated</strong>: use <code>rustdoc_flags</code> instead</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_doc-rustdoc_flags"></a>rustdoc_flags</td><td style="text-align: left">List of flags passed to <code>rustdoc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_doc_test"></a></p> |
| <h2 id="rust_doc_test"><a class="header" href="#rust_doc_test">rust_doc_test</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_doc_test") |
| |
| rust_doc_test(<a href="rust_doc.html#rust_doc_test-name">name</a>, <a href="rust_doc.html#rust_doc_test-deps">deps</a>, <a href="rust_doc.html#rust_doc_test-crate">crate</a>, <a href="rust_doc.html#rust_doc_test-crate_features">crate_features</a>, <a href="rust_doc.html#rust_doc_test-proc_macro_deps">proc_macro_deps</a>, <a href="rust_doc.html#rust_doc_test-rustdoc_flags">rustdoc_flags</a>) |
| </pre> |
| <p>Runs Rust documentation tests.</p> |
| <p>Example:</p> |
| <p>Suppose you have the following directory structure for a Rust library crate:</p> |
| <pre><code class="language-output">[workspace]/ |
| WORKSPACE |
| hello_lib/ |
| BUILD |
| src/ |
| lib.rs |
| </code></pre> |
| <p>To run <a href="https://doc.rust-lang.org/book/documentation.html#documentation-as-tests">documentation tests</a> for the <code>hello_lib</code> crate, define a <code>rust_doc_test</code> target that depends on the <code>hello_lib</code> <code>rust_library</code> target:</p> |
| <pre><code class="language-python">package(default_visibility = ["//visibility:public"]) |
| |
| load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc_test") |
| |
| rust_library( |
| name = "hello_lib", |
| srcs = ["src/lib.rs"], |
| ) |
| |
| rust_doc_test( |
| name = "hello_lib_doc_test", |
| crate = ":hello_lib", |
| ) |
| </code></pre> |
| <p>Running <code>bazel test //hello_lib:hello_lib_doc_test</code> will run all documentation tests for the <code>hello_lib</code> library crate.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_doc_test-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> |
| <tr><td style="text-align: left"><a id="rust_doc_test-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_doc_test-crate"></a>crate</td><td style="text-align: left">The label of the target to generate code documentation for. <code>rust_doc_test</code> can generate HTML code documentation for the source files of <code>rust_library</code> or <code>rust_binary</code> targets.</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> |
| <tr><td style="text-align: left"><a id="rust_doc_test-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for the crate being documented.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_doc_test-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_doc_test-rustdoc_flags"></a>rustdoc_flags</td><td style="text-align: left">List of flags passed to <code>rustdoc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| </tbody></table> |
| </div><div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build --> |
| <h1 id="cargo"><a class="header" href="#cargo">Cargo</a></h1> |
| <p>Common definitions for the <code>@rules_rust//cargo</code> package</p> |
| <h2 id="rules-5"><a class="header" href="#rules-5">Rules</a></h2> |
| <ul> |
| <li><a href="cargo.html#cargo_dep_env">cargo_dep_env</a></li> |
| <li><a href="cargo.html#extract_cargo_lints">extract_cargo_lints</a></li> |
| </ul> |
| <h2 id="functions-1"><a class="header" href="#functions-1">Functions</a></h2> |
| <ul> |
| <li><a href="cargo.html#cargo_build_script">cargo_build_script</a></li> |
| <li><a href="cargo.html#cargo_env">cargo_env</a></li> |
| </ul> |
| <h2 id="repository-rules"><a class="header" href="#repository-rules">Repository Rules</a></h2> |
| <ul> |
| <li><a href="cargo.html#cargo_bootstrap_repository">cargo_bootstrap_repository</a></li> |
| </ul> |
| <p><a id="cargo_dep_env"></a></p> |
| <h2 id="cargo_dep_env"><a class="header" href="#cargo_dep_env">cargo_dep_env</a></h2> |
| <pre> |
| load("@rules_rust//cargo:defs.bzl", "cargo_dep_env") |
| |
| cargo_dep_env(<a href="cargo.html#cargo_dep_env-name">name</a>, <a href="cargo.html#cargo_dep_env-src">src</a>, <a href="cargo.html#cargo_dep_env-out_dir">out_dir</a>) |
| </pre> |
| <p>A rule for generating variables for dependent <code>cargo_build_script</code>s without a build script. This is useful for using Bazel rules instead of a build script, while also generating configuration information for build scripts which depend on this crate.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="cargo_dep_env-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> |
| <tr><td style="text-align: left"><a id="cargo_dep_env-src"></a>src</td><td style="text-align: left">File containing additional environment variables to set for build scripts of direct dependencies.<br><br>This has the same effect as a <code>cargo_build_script</code> which prints <code>cargo:VAR=VALUE</code> lines, but without requiring a build script.<br><br>This files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).</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> |
| <tr><td style="text-align: left"><a id="cargo_dep_env-out_dir"></a>out_dir</td><td style="text-align: left">Folder containing additional inputs when building all direct dependencies.<br><br>This has the same effect as a <code>cargo_build_script</code> which prints puts files into <code>$OUT_DIR</code>, but without requiring a build script.</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> |
| </tbody></table> |
| </div> |
| <p><a id="extract_cargo_lints"></a></p> |
| <h2 id="extract_cargo_lints"><a class="header" href="#extract_cargo_lints">extract_cargo_lints</a></h2> |
| <pre> |
| load("@rules_rust//cargo:defs.bzl", "extract_cargo_lints") |
| |
| extract_cargo_lints(<a href="cargo.html#extract_cargo_lints-name">name</a>, <a href="cargo.html#extract_cargo_lints-manifest">manifest</a>, <a href="cargo.html#extract_cargo_lints-workspace">workspace</a>) |
| </pre> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="extract_cargo_lints-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> |
| <tr><td style="text-align: left"><a id="extract_cargo_lints-manifest"></a>manifest</td><td style="text-align: left">Cargo.toml to read lints from.</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> |
| <tr><td style="text-align: left"><a id="extract_cargo_lints-workspace"></a>workspace</td><td style="text-align: left">Workspace Cargo.toml that the manifest Cargo.toml inherits from.</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> |
| </tbody></table> |
| </div> |
| <p><a id="cargo_build_script"></a></p> |
| <h2 id="cargo_build_script"><a class="header" href="#cargo_build_script">cargo_build_script</a></h2> |
| <pre> |
| load("@rules_rust//cargo:defs.bzl", "cargo_build_script") |
| |
| cargo_build_script(*, <a href="cargo.html#cargo_build_script-name">name</a>, <a href="cargo.html#cargo_build_script-edition">edition</a>, <a href="cargo.html#cargo_build_script-crate_name">crate_name</a>, <a href="cargo.html#cargo_build_script-crate_root">crate_root</a>, <a href="cargo.html#cargo_build_script-srcs">srcs</a>, <a href="cargo.html#cargo_build_script-crate_features">crate_features</a>, <a href="cargo.html#cargo_build_script-version">version</a>, <a href="cargo.html#cargo_build_script-deps">deps</a>, |
| <a href="cargo.html#cargo_build_script-link_deps">link_deps</a>, <a href="cargo.html#cargo_build_script-proc_macro_deps">proc_macro_deps</a>, <a href="cargo.html#cargo_build_script-build_script_env">build_script_env</a>, <a href="cargo.html#cargo_build_script-build_script_env_files">build_script_env_files</a>, |
| <a href="cargo.html#cargo_build_script-use_default_shell_env">use_default_shell_env</a>, <a href="cargo.html#cargo_build_script-data">data</a>, <a href="cargo.html#cargo_build_script-compile_data">compile_data</a>, <a href="cargo.html#cargo_build_script-tools">tools</a>, <a href="cargo.html#cargo_build_script-links">links</a>, <a href="cargo.html#cargo_build_script-rundir">rundir</a>, <a href="cargo.html#cargo_build_script-rustc_env">rustc_env</a>, |
| <a href="cargo.html#cargo_build_script-rustc_env_files">rustc_env_files</a>, <a href="cargo.html#cargo_build_script-rustc_flags">rustc_flags</a>, <a href="cargo.html#cargo_build_script-visibility">visibility</a>, <a href="cargo.html#cargo_build_script-tags">tags</a>, <a href="cargo.html#cargo_build_script-aliases">aliases</a>, <a href="cargo.html#cargo_build_script-pkg_name">pkg_name</a>, <a href="cargo.html#cargo_build_script-kwargs">**kwargs</a>) |
| </pre> |
| <p>Compile and execute a rust build script to generate build attributes</p> |
| <p>This rules take the same arguments as rust_binary.</p> |
| <p>Example:</p> |
| <p>Suppose you have a crate with a cargo build script <code>build.rs</code>:</p> |
| <pre><code class="language-output">[workspace]/ |
| hello_lib/ |
| BUILD |
| build.rs |
| src/ |
| lib.rs |
| </code></pre> |
| <p>Then you want to use the build script in the following:</p> |
| <p><code>hello_lib/BUILD</code>:</p> |
| <pre><code class="language-python">package(default_visibility = ["//visibility:public"]) |
| |
| load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library") |
| load("@rules_rust//cargo:defs.bzl", "cargo_build_script") |
| |
| # This will run the build script from the root of the workspace, and |
| # collect the outputs. |
| cargo_build_script( |
| name = "build_script", |
| srcs = ["build.rs"], |
| # Optional environment variables passed during build.rs compilation |
| rustc_env = { |
| "CARGO_PKG_VERSION": "0.1.2", |
| }, |
| # Optional environment variables passed during build.rs execution. |
| # Note that as the build script's working directory is not execroot, |
| # execpath/location will return an absolute path, instead of a relative |
| # one. |
| build_script_env = { |
| "SOME_TOOL_OR_FILE": "$(execpath @tool//:binary)" |
| }, |
| # Optional data/tool dependencies |
| data = ["@tool//:binary"], |
| ) |
| |
| rust_library( |
| name = "hello_lib", |
| srcs = [ |
| "src/lib.rs", |
| ], |
| deps = [":build_script"], |
| ) |
| </code></pre> |
| <p>The <code>hello_lib</code> target will be build with the flags and the environment variables declared by the build script in addition to the file generated by it.</p> |
| <p><strong>PARAMETERS</strong></p> |
| <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">Default Value</th></tr></thead><tbody> |
| <tr><td style="text-align: left"><a id="cargo_build_script-name"></a>name</td><td style="text-align: left">The name for the underlying rule. This should be the name of the package being compiled, optionally with a suffix of <code>_bs</code>. Otherwise, you can set the package name via <code>pkg_name</code>.</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-edition"></a>edition</td><td style="text-align: left">The rust edition to use for the internal binary crate.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for build script.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to rustc to be used for building this crate.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-srcs"></a>srcs</td><td style="text-align: left">Source files of the crate to build. Passing source files here can be used to trigger rebuilds when changes are made.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-crate_features"></a>crate_features</td><td style="text-align: left">A list of features to enable for the build script.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-version"></a>version</td><td style="text-align: left">The semantic version (semver) of the crate.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-deps"></a>deps</td><td style="text-align: left">The build-dependencies of the crate.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-link_deps"></a>link_deps</td><td style="text-align: left">The subset of the (normal) dependencies of the crate that have the links attribute and therefore provide environment variables to this build script.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of rust_proc_macro targets used to build the script.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-build_script_env"></a>build_script_env</td><td style="text-align: left">Environment variables for build scripts.</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-build_script_env_files"></a>build_script_env_files</td><td style="text-align: left">Files containing additional environment variables to set when running the build script.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-use_default_shell_env"></a>use_default_shell_env</td><td style="text-align: left">Whether or not to include the default shell environment for the build script action. If unset the global setting <code>@rules_rust//cargo/settings:use_default_shell_env</code> will be used to determine this value.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-data"></a>data</td><td style="text-align: left">Files needed by the build script.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-compile_data"></a>compile_data</td><td style="text-align: left">Files needed for the compilation of the build script.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-tools"></a>tools</td><td style="text-align: left">Tools (executables) needed by the build script.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-links"></a>links</td><td style="text-align: left">Name of the native library this crate links against.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-rundir"></a>rundir</td><td style="text-align: left">A directory to <code>cd</code> to before the cargo_build_script is run. This should be a path relative to the exec root.<br><br>The default behaviour (and the behaviour if rundir is set to the empty string) is to change to the relative path corresponding to the cargo manifest directory, which replicates the normal behaviour of cargo so it is easy to write compatible build scripts.<br><br>If set to <code>.</code>, the cargo build script will run in the exec root.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-rustc_env"></a>rustc_env</td><td style="text-align: left">Environment variables to set in rustc when compiling the build script.</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc when building the build script.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-visibility"></a>visibility</td><td style="text-align: left">Visibility to apply to the generated build script output.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-tags"></a>tags</td><td style="text-align: left">(list of str, optional): Tags to apply to the generated build script output.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target. These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-pkg_name"></a>pkg_name</td><td style="text-align: left">Override the package name used for the build script. This is useful if the build target name gets too long otherwise.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_build_script-kwargs"></a>kwargs</td><td style="text-align: left">Forwards to the underlying <code>rust_binary</code> rule. An exception is the <code>compatible_with</code> attribute, which shouldn't be forwarded to the <code>rust_binary</code>, as the <code>rust_binary</code> is only built and used in <code>exec</code> mode. We propagate the <code>compatible_with</code> attribute to the <code>_build_script_run</code> target.</td><td style="text-align: left">none</td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="cargo_env"></a></p> |
| <h2 id="cargo_env"><a class="header" href="#cargo_env">cargo_env</a></h2> |
| <pre> |
| load("@rules_rust//cargo:defs.bzl", "cargo_env") |
| |
| cargo_env(<a href="cargo.html#cargo_env-env">env</a>) |
| </pre> |
| <p>A helper for generating platform specific environment variables</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_common") |
| load("@rules_rust//cargo:defs.bzl", "cargo_bootstrap_repository", "cargo_env") |
| |
| cargo_bootstrap_repository( |
| name = "bootstrapped_bin", |
| cargo_lockfile = "//:Cargo.lock", |
| cargo_toml = "//:Cargo.toml", |
| srcs = ["//:resolver_srcs"], |
| version = rust_common.default_version, |
| binary = "my-crate-binary", |
| env = { |
| "x86_64-unknown-linux-gnu": cargo_env({ |
| "FOO": "BAR", |
| }), |
| }, |
| env_label = { |
| "aarch64-unknown-linux-musl": cargo_env({ |
| "DOC": "//:README.md", |
| }), |
| } |
| ) |
| </code></pre> |
| <p><strong>PARAMETERS</strong></p> |
| <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">Default Value</th></tr></thead><tbody> |
| <tr><td style="text-align: left"><a id="cargo_env-env"></a>env</td><td style="text-align: left">A map of environment variables</td><td style="text-align: left">none</td></tr> |
| </tbody></table> |
| </div> |
| <p><strong>RETURNS</strong></p> |
| <p>str: A json encoded string of the environment variables</p> |
| <p><a id="cargo_bootstrap_repository"></a></p> |
| <h2 id="cargo_bootstrap_repository"><a class="header" href="#cargo_bootstrap_repository">cargo_bootstrap_repository</a></h2> |
| <pre> |
| load("@rules_rust//cargo:defs.bzl", "cargo_bootstrap_repository") |
| |
| cargo_bootstrap_repository(<a href="cargo.html#cargo_bootstrap_repository-name">name</a>, <a href="cargo.html#cargo_bootstrap_repository-srcs">srcs</a>, <a href="cargo.html#cargo_bootstrap_repository-binary">binary</a>, <a href="cargo.html#cargo_bootstrap_repository-build_mode">build_mode</a>, <a href="cargo.html#cargo_bootstrap_repository-cargo_config">cargo_config</a>, <a href="cargo.html#cargo_bootstrap_repository-cargo_lockfile">cargo_lockfile</a>, <a href="cargo.html#cargo_bootstrap_repository-cargo_toml">cargo_toml</a>, |
| <a href="cargo.html#cargo_bootstrap_repository-compressed_windows_toolchain_names">compressed_windows_toolchain_names</a>, <a href="cargo.html#cargo_bootstrap_repository-env">env</a>, <a href="cargo.html#cargo_bootstrap_repository-env_label">env_label</a>, |
| <a href="cargo.html#cargo_bootstrap_repository-rust_toolchain_cargo_template">rust_toolchain_cargo_template</a>, <a href="cargo.html#cargo_bootstrap_repository-rust_toolchain_rustc_template">rust_toolchain_rustc_template</a>, <a href="cargo.html#cargo_bootstrap_repository-timeout">timeout</a>, |
| <a href="cargo.html#cargo_bootstrap_repository-version">version</a>) |
| </pre> |
| <p>A rule for bootstrapping a Rust binary using <a href="https://doc.rust-lang.org/cargo/">Cargo</a></p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="cargo_bootstrap_repository-name"></a>name</td><td style="text-align: left">A unique name for this repository.</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> |
| <tr><td style="text-align: left"><a id="cargo_bootstrap_repository-srcs"></a>srcs</td><td style="text-align: left">Source files of the crate to build. Passing source files here can be used to trigger rebuilds when changes are made</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_bootstrap_repository-binary"></a>binary</td><td style="text-align: left">The binary to build (the <code>--bin</code> parameter for Cargo). If left empty, the repository name will be used.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_bootstrap_repository-build_mode"></a>build_mode</td><td style="text-align: left">The build mode the binary should be built with</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"release"</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_bootstrap_repository-cargo_config"></a>cargo_config</td><td style="text-align: left">The path of the Cargo configuration (<code>Config.toml</code>) file.</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> |
| <tr><td style="text-align: left"><a id="cargo_bootstrap_repository-cargo_lockfile"></a>cargo_lockfile</td><td style="text-align: left">The lockfile of the crate_universe resolver</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> |
| <tr><td style="text-align: left"><a id="cargo_bootstrap_repository-cargo_toml"></a>cargo_toml</td><td style="text-align: left">The path of the <code>Cargo.toml</code> file.</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> |
| <tr><td style="text-align: left"><a id="cargo_bootstrap_repository-compressed_windows_toolchain_names"></a>compressed_windows_toolchain_names</td><td style="text-align: left">Whether or not the toolchain names of windows toolchains are expected to be in a <code>compressed</code> format.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_bootstrap_repository-env"></a>env</td><td style="text-align: left">A mapping of platform triple to a set of environment variables. See <a href="cargo.html#cargo_env">cargo_env</a> for usage details. Additionally, the platform triple <code>*</code> applies to all platforms.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_bootstrap_repository-env_label"></a>env_label</td><td style="text-align: left">A mapping of platform triple to a set of environment variables. This attribute differs from <code>env</code> in that all variables passed here must be fully qualified labels of files. See <a href="cargo.html#cargo_env">cargo_env</a> for usage details. Additionally, the platform triple <code>*</code> applies to all platforms.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_bootstrap_repository-rust_toolchain_cargo_template"></a>rust_toolchain_cargo_template</td><td style="text-align: left">The template to use for finding the host <code>cargo</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), <code>{channel}</code> (eg. 'stable'), and <code>{tool}</code> (eg. 'rustc.exe') will be replaced in the string if present.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}"</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_bootstrap_repository-rust_toolchain_rustc_template"></a>rust_toolchain_rustc_template</td><td style="text-align: left">The template to use for finding the host <code>rustc</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), <code>{channel}</code> (eg. 'stable'), and <code>{tool}</code> (eg. 'rustc.exe') will be replaced in the string if present.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}"</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_bootstrap_repository-timeout"></a>timeout</td><td style="text-align: left">Maximum duration of the Cargo build command in seconds</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>600</code></td></tr> |
| <tr><td style="text-align: left"><a id="cargo_bootstrap_repository-version"></a>version</td><td style="text-align: left">The version of Rust the currently registered toolchain is using. Eg. <code>1.56.0</code>, or <code>nightly/2021-09-08</code></td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"1.95.0"</code></td></tr> |
| </tbody></table> |
| </div><div style="break-before: page; page-break-before: always;"></div><h1 id="rust-analyzer"><a class="header" href="#rust-analyzer">Rust Analyzer</a></h1> |
| <p>For <a href="https://rust-analyzer.github.io/manual.html#non-cargo-based-projects">non-Cargo projects</a>, |
| <a href="https://rust-analyzer.github.io/">rust-analyzer</a> depends on either a <code>rust-project.json</code> file |
| at the root of the project that describes its structure or on build system specific |
| <a href="https://rust-analyzer.github.io/manual.html#rust-analyzer.workspace.discoverConfig">project auto-discovery</a>. |
| The <code>rust_analyzer</code> rules facilitate both approaches.</p> |
| <h2 id="rust-projectjson-approach"><a class="header" href="#rust-projectjson-approach">rust-project.json approach</a></h2> |
| <h3 id="setup-3"><a class="header" href="#setup-3">Setup</a></h3> |
| <p>First, ensure <code>rules_rust</code> is setup in your <code>MODULE.bazel</code>:</p> |
| <pre><code class="language-python"># MODULE.bazel |
| |
| # See releases page for available versions: |
| # https://github.com/bazelbuild/rules_rust/releases |
| bazel_dep(name = "rules_rust", version = "{SEE_RELEASES}") |
| </code></pre> |
| <p>Bazel will create the target <code>@rules_rust//tools/rust_analyzer:gen_rust_project</code>, which you can build |
| with</p> |
| <pre><code>bazel run @rules_rust//tools/rust_analyzer:gen_rust_project |
| </code></pre> |
| <p>whenever dependencies change to regenerate the <code>rust-project.json</code> file. It |
| should be added to <code>.gitignore</code> because it is effectively a build artifact. |
| Once the <code>rust-project.json</code> has been generated in the project root, |
| rust-analyzer can pick it up upon restart.</p> |
| <h4 id="vscode"><a class="header" href="#vscode">VSCode</a></h4> |
| <p>To set this up using <a href="https://code.visualstudio.com/">VSCode</a>, users should first install the |
| <a href="https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer">rust_analyzer plugin</a>. |
| With that in place, the following task can be added to the <code>.vscode/tasks.json</code> file of the workspace |
| to ensure a <code>rust-project.json</code> file is created and up to date when the editor is opened.</p> |
| <pre><code class="language-json">{ |
| "version": "2.0.0", |
| "tasks": [ |
| { |
| "label": "Generate rust-project.json", |
| "command": "bazel", |
| "args": [ |
| "run", |
| "@rules_rust//tools/rust_analyzer:gen_rust_project" |
| ], |
| "options": { |
| "cwd": "${workspaceFolder}" |
| }, |
| "group": "build", |
| "problemMatcher": [], |
| "presentation": { |
| "reveal": "never", |
| "panel": "dedicated" |
| }, |
| "runOptions": { |
| "runOn": "folderOpen" |
| } |
| } |
| ] |
| } |
| </code></pre> |
| <h4 id="alternative-vscode-option-prototype"><a class="header" href="#alternative-vscode-option-prototype">Alternative vscode option (prototype)</a></h4> |
| <p>Add the following to your bazelrc:</p> |
| <pre><code>build --@rules_rust//rust/settings:rustc_output_diagnostics=true --output_groups=+rust_lib_rustc_output,+rust_metadata_rustc_output |
| </code></pre> |
| <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> |
| <h2 id="project-auto-discovery"><a class="header" href="#project-auto-discovery">Project auto-discovery</a></h2> |
| <h3 id="setup-4"><a class="header" href="#setup-4">Setup</a></h3> |
| <p>Auto-discovery makes <code>rust-analyzer</code> behave in a Bazel project in a similar fashion to how it does |
| in a Cargo project. This is achieved by generating a structure similar to what <code>rust-project.json</code> |
| contains but, instead of writing that to a file, the data gets piped to <code>rust-analyzer</code> directly |
| through <code>stdout</code>. To use auto-discovery the <code>rust-analyzer</code> IDE settings must be configured similar to:</p> |
| <pre><code class="language-json">"rust-analyzer": { |
| "workspace": { |
| "discoverConfig": { |
| "command": ["discover_bazel_rust_project.sh"], |
| "progressLabel": "rust_analyzer", |
| "filesToWatch": ["BUILD", "BUILD.bazel", "MODULE.bazel"] |
| } |
| } |
| } |
| </code></pre> |
| <p>The shell script passed to <code>discoverConfig.command</code> is typically meant to wrap the bazel rule invocation, |
| primarily for muting <code>stderr</code> (because <code>rust-analyzer</code> will consider that an error has occurred if anything |
| is passed through <code>stderr</code>) and, additionally, for specifying rule arguments. E.g:</p> |
| <pre><code class="language-shell">#!/usr/bin/bash |
| |
| bazel \ |
| run \ |
| @rules_rust//tools/rust_analyzer:discover_bazel_rust_project -- \ |
| --bazel_startup_option=--output_base=~/ide_bazel \ |
| --bazel_arg=--watchfs \ |
| ${1:+"$1"} 2>/dev/null |
| </code></pre> |
| <p>The script above also handles an optional CLI argument which gets passed when workspace splitting is |
| enabled. The script path should be either absolute or relative to the project root.</p> |
| <h3 id="workspace-splitting"><a class="header" href="#workspace-splitting">Workspace splitting</a></h3> |
| <p>The above configuration treats the entire project as a single workspace. However, large codebases might be |
| too much to handle for <code>rust-analyzer</code> all at once. This can be addressed by splitting the codebase in |
| multiple workspaces by extending the <code>discoverConfig.command</code> setting:</p> |
| <pre><code class="language-json">"rust-analyzer": { |
| "workspace": { |
| "discoverConfig": { |
| "command": ["discover_bazel_rust_project.sh", "{arg}"], |
| "progressLabel": "rust_analyzer", |
| "filesToWatch": ["BUILD", "BUILD.bazel", "MODULE.bazel"] |
| } |
| } |
| } |
| </code></pre> |
| <p><code>{arg}</code> acts as a placeholder that <code>rust-analyzer</code> replaces with the path of the source / build file |
| that gets opened.</p> |
| <p>The root of the workspace will, in this configuration, be the package the crate currently being worked on |
| belongs to. This means that only that package and its dependencies get built and indexed by <code>rust-analyzer</code>, |
| thus allowing for a smaller footprint.</p> |
| <p><code>rust-analyzer</code> will switch workspaces whenever an out-of-tree file gets opened, essentially indexing that |
| crate and its dependencies separately. A caveat of this is that <em>dependents</em> of the crate currently being |
| worked on are not indexed and won't be tracked by <code>rust-analyzer</code>.</p> |
| <div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build --> |
| <p>Public entry point to all Rust rules and supported APIs.</p> |
| <h2 id="rules-6"><a class="header" href="#rules-6">Rules</a></h2> |
| <ul> |
| <li><a href="rust_unpretty.html#rust_unpretty">rust_unpretty</a></li> |
| </ul> |
| <h2 id="aspects-3"><a class="header" href="#aspects-3">Aspects</a></h2> |
| <ul> |
| <li><a href="rust_unpretty.html#rust_unpretty_aspect">rust_unpretty_aspect</a></li> |
| </ul> |
| <p><a id="rust_unpretty"></a></p> |
| <h2 id="rust_unpretty-1"><a class="header" href="#rust_unpretty-1">rust_unpretty</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_unpretty") |
| |
| rust_unpretty(<a href="rust_unpretty.html#rust_unpretty-name">name</a>, <a href="rust_unpretty.html#rust_unpretty-deps">deps</a>, <a href="rust_unpretty.html#rust_unpretty-mode">mode</a>) |
| </pre> |
| <p>Executes rust unpretty on a specific target.</p> |
| <p>Similar to <code>rust_unpretty_aspect</code>, but allows specifying a list of dependencies within the build system.</p> |
| <p>For example, given the following example targets:</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") |
| |
| rust_library( |
| name = "hello_lib", |
| srcs = ["src/lib.rs"], |
| ) |
| |
| rust_test( |
| name = "greeting_test", |
| srcs = ["tests/greeting.rs"], |
| deps = [":hello_lib"], |
| ) |
| </code></pre> |
| <p>Rust expand can be set as a build target with the following:</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_unpretty") |
| |
| rust_unpretty( |
| name = "hello_library_expand", |
| testonly = True, |
| deps = [ |
| ":hello_lib", |
| ":greeting_test", |
| ], |
| mode = "expand", |
| ) |
| </code></pre> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_unpretty-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> |
| <tr><td style="text-align: left"><a id="rust_unpretty-deps"></a>deps</td><td style="text-align: left">Rust targets to run unpretty on.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_unpretty-mode"></a>mode</td><td style="text-align: left">The value to pass to <code>--unpretty</code></td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"expanded"</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_unpretty_aspect"></a></p> |
| <h2 id="rust_unpretty_aspect-1"><a class="header" href="#rust_unpretty_aspect-1">rust_unpretty_aspect</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_unpretty_aspect") |
| |
| rust_unpretty_aspect() |
| </pre> |
| <p>Executes Rust expand on specified targets.</p> |
| <p>This aspect applies to existing rust_library, rust_test, and rust_binary rules.</p> |
| <p>As an example, if the following is defined in <code>examples/hello_lib/BUILD.bazel</code>:</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") |
| |
| rust_library( |
| name = "hello_lib", |
| srcs = ["src/lib.rs"], |
| ) |
| |
| rust_test( |
| name = "greeting_test", |
| srcs = ["tests/greeting.rs"], |
| deps = [":hello_lib"], |
| ) |
| </code></pre> |
| <p>Then the targets can be expanded with the following command:</p> |
| <pre><code class="language-output">$ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_unpretty_aspect \ |
| --output_groups=rust_unpretty_expanded \ |
| //hello_lib:all |
| </code></pre> |
| <p><strong>ASPECT ATTRIBUTES</strong></p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <div style="break-before: page; page-break-before: always;"></div><h1 id="settings"><a class="header" href="#settings">Settings</a></h1> |
| <p>Flags which control granular behavior of various Rust rules.</p> |
| <div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build --> |
| <h1 id="rust-settings"><a class="header" href="#rust-settings">Rust settings</a></h1> |
| <p>Definitions for all <code>@rules_rust//rust</code> settings</p> |
| <p><a id="always_enable_metadata_output_groups"></a></p> |
| <h2 id="always_enable_metadata_output_groups"><a class="header" href="#always_enable_metadata_output_groups">always_enable_metadata_output_groups</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:always_enable_metadata_output_groups |
| </pre> |
| <p>A flag to enable the <code>always_enable_metadata_output_groups</code> setting.</p> |
| <p>If this flag is true, all rules will support the <code>metadata</code> and |
| <code>rustc_rmeta_output</code> output groups.</p> |
| <p><a id="capture_clippy_output"></a></p> |
| <h2 id="capture_clippy_output"><a class="header" href="#capture_clippy_output">capture_clippy_output</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:capture_clippy_output |
| </pre> |
| <p>Control whether to print clippy output or store it to a file, using the configured error_format.</p> |
| <p><a id="clippy_error_format"></a></p> |
| <h2 id="clippy_error_format"><a class="header" href="#clippy_error_format">clippy_error_format</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:clippy_error_format |
| </pre> |
| <p>This setting may be changed from the command line to generate machine readable errors.</p> |
| <p><a id="clippy_flag"></a></p> |
| <h2 id="clippy_flag"><a class="header" href="#clippy_flag">clippy_flag</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:clippy_flag |
| </pre> |
| <p>Add a custom clippy flag from the command line with <code>--@rules_rust//rust/settings:clippy_flag</code>.</p> |
| <p>Multiple uses are accumulated and appended after the <code>extra_rustc_flags</code>.</p> |
| <p><a id="clippy_flags"></a></p> |
| <h2 id="clippy_flags"><a class="header" href="#clippy_flags">clippy_flags</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:clippy_flags |
| </pre> |
| <p>This setting may be used to pass extra options to clippy from the command line.</p> |
| <p>It applies across all targets.</p> |
| <p><a id="clippy_output_diagnostics"></a></p> |
| <h2 id="clippy_output_diagnostics"><a class="header" href="#clippy_output_diagnostics">clippy_output_diagnostics</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:clippy_output_diagnostics |
| </pre> |
| <p>A flag to enable the <code>clippy_output_diagnostics</code> setting.</p> |
| <p>If this flag is true, rules_rust will save clippy json output (suitable for consumption |
| by rust-analyzer) in a file, available from the <code>clippy_output</code> output group. This is the |
| clippy equivalent of <code>rustc_output_diagnostics</code>.</p> |
| <p><a id="clippy_toml"></a></p> |
| <h2 id="clippy_toml"><a class="header" href="#clippy_toml">clippy_toml</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:clippy_toml |
| </pre> |
| <p>This setting is used by the clippy rules. See https://bazelbuild.github.io/rules_rust/rust_clippy.html</p> |
| <p>Note that this setting is actually called <code>clippy.toml</code>.</p> |
| <p><a id="codegen_units"></a></p> |
| <h2 id="codegen_units"><a class="header" href="#codegen_units">codegen_units</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:codegen_units |
| </pre> |
| <p>The default value for <code>--codegen-units</code> which also affects resource allocation for rustc actions.</p> |
| <p>Note that any value 0 or less will prevent this flag from being passed by Bazel and allow rustc to |
| perform it's default behavior.</p> |
| <p>https://doc.rust-lang.org/rustc/codegen-options/index.html#codegen-units</p> |
| <p><a id="collect_cfgs"></a></p> |
| <h2 id="collect_cfgs"><a class="header" href="#collect_cfgs">collect_cfgs</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:collect_cfgs |
| </pre> |
| <p>Enable collection of cfg flags with results stored in CrateInfo.cfgs.</p> |
| <p><a id="default_allocator_library"></a></p> |
| <h2 id="default_allocator_library"><a class="header" href="#default_allocator_library">default_allocator_library</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:default_allocator_library |
| </pre> |
| <p>A flag that determines the default allocator library for <code>rust_toolchain</code> targets.</p> |
| <p><a id="error_format"></a></p> |
| <h2 id="error_format"><a class="header" href="#error_format">error_format</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:error_format |
| </pre> |
| <p>This setting may be changed from the command line to generate machine readable errors.</p> |
| <p><a id="experimental_link_std_dylib"></a></p> |
| <h2 id="experimental_link_std_dylib"><a class="header" href="#experimental_link_std_dylib">experimental_link_std_dylib</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:experimental_link_std_dylib |
| </pre> |
| <p>A flag to control whether to link libstd dynamically.</p> |
| <p><a id="experimental_per_crate_rustc_flag"></a></p> |
| <h2 id="experimental_per_crate_rustc_flag"><a class="header" href="#experimental_per_crate_rustc_flag">experimental_per_crate_rustc_flag</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:experimental_per_crate_rustc_flag |
| </pre> |
| <p>Add additional rustc_flag to matching crates from the command line with <code>--@rules_rust//rust/settings:experimental_per_crate_rustc_flag</code>.</p> |
| <p>The expected flag format is prefix_filter@flag, where any crate with a label or execution path starting |
| with the prefix filter will be built with the given flag. The label matching uses the canonical form of |
| the label (i.e <code>//package:label_name</code>). The execution path is the relative path to your workspace directory |
| including the base name (including extension) of the crate root. This flag is not applied to the exec |
| configuration (proc-macros, cargo_build_script, etc). Multiple uses are accumulated.</p> |
| <p><a id="experimental_use_allocator_libraries_with_mangled_symbols"></a></p> |
| <h2 id="experimental_use_allocator_libraries_with_mangled_symbols"><a class="header" href="#experimental_use_allocator_libraries_with_mangled_symbols">experimental_use_allocator_libraries_with_mangled_symbols</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:experimental_use_allocator_libraries_with_mangled_symbols |
| </pre> |
| <p>A flag used to select allocator libraries implemented in rust that are compatible with the rustc allocator symbol mangling.</p> |
| <p>The symbol mangling mechanism relies on unstable language features and requires a nightly rustc from 2025-04-05 or later.</p> |
| <p>Rustc generates references to internal allocator symbols when building rust |
| libraries. At link time, rustc generates the definitions of these symbols. |
| When rustc is not used as the final linker, we need to generate the |
| definitions ourselves. This happens for example when a rust_library is |
| used as a dependency of a rust_binary, or when the |
| experimental_use_cc_common_link setting is used.</p> |
| <p>For older versions of rustc, the allocator symbol definitions can be provided |
| via the <code>rust_toolchain</code>'s <code>allocator_library</code> or <code>global_allocator_library</code> |
| attributes, with sample targets like <code>@rules_rust//ffi/cc/allocator_library</code> |
| and <code>@rules_rust//ffi/cc/global_allocator_library</code>.</p> |
| <p>Recent versions of rustc started mangling these allocator symbols (https://github.com/rust-lang/rust/pull/127173). |
| The mangling uses a scheme that is specific to the exact version of the compiler. |
| This makes the cc allocator library definitions ineffective. When rustc builds a |
| staticlib it provides the mapping definitions. We rely on this and build an empty |
| staticlib as a basis for the allocator definitions.</p> |
| <p>Since the new symbol definitions are written in rust, we cannot just attach |
| them as attributes on the <code>rust_toolchain</code> as the old cc versions, as that |
| would create a build graph cycle (we need a <code>rust_toolchain</code> to build a |
| <code>rust_library</code>, so the allocator library cannot be a rust_library directly).</p> |
| <p>The bootstrapping cycle can be avoided by defining a separate internal |
| "initial" rust toolchain specifically for building the rust allocator libraries, |
| and use a transition to attach the generated libraries to the "main" rust |
| toolchain. But that duplicates the whole sub-graph of the build around the |
| rust toolchains, repository and supporting tools used for them.</p> |
| <p>Instead, we define a new custom <code>rust_allocator_library</code> rule, which exposes |
| the result of building the rust allocator libraries via a provider, which |
| can be consumed by the rust build actions. We attach an instance of this |
| as a common attribute to the rust rule set.</p> |
| <p><strong>PARAMETERS</strong></p> |
| <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">Options</th></tr></thead><tbody> |
| <tr><td style="text-align: left"><a id="experimental_use_allocator_libraries_with_mangled_symbols-name"></a>name</td><td style="text-align: left"><p align="center"> - </p></td><td style="text-align: left"><code>"experimental_use_allocator_libraries_with_mangled_symbols"</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="experimental_use_cc_common_link"></a></p> |
| <h2 id="experimental_use_cc_common_link"><a class="header" href="#experimental_use_cc_common_link">experimental_use_cc_common_link</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:experimental_use_cc_common_link |
| </pre> |
| <p>A flag to control whether to link rust_binary and rust_test targets using cc_common.link instead of rustc.</p> |
| <p><a id="experimental_use_coverage_metadata_files"></a></p> |
| <h2 id="experimental_use_coverage_metadata_files"><a class="header" href="#experimental_use_coverage_metadata_files">experimental_use_coverage_metadata_files</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:experimental_use_coverage_metadata_files |
| </pre> |
| <p>A flag to have coverage tooling added as <code>coverage_common.instrumented_files_info.metadata_files</code> instead of reporting tools like <code>llvm-cov</code> and <code>llvm-profdata</code> as runfiles to each test.</p> |
| <p><a id="experimental_use_global_allocator"></a></p> |
| <h2 id="experimental_use_global_allocator"><a class="header" href="#experimental_use_global_allocator">experimental_use_global_allocator</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:experimental_use_global_allocator |
| </pre> |
| <p>A flag to indicate that a global allocator is in use when using <code>--@rules_rust//rust/settings:experimental_use_cc_common_link</code></p> |
| <p>Users need to specify this flag because rustc generates different set of symbols at link time when a global allocator is in use. |
| When the linking is not done by rustc, the <code>rust_toolchain</code> itself provides the appropriate set of symbols.</p> |
| <p><a id="experimental_use_sh_toolchain_for_bootstrap_process_wrapper"></a></p> |
| <h2 id="experimental_use_sh_toolchain_for_bootstrap_process_wrapper"><a class="header" href="#experimental_use_sh_toolchain_for_bootstrap_process_wrapper">experimental_use_sh_toolchain_for_bootstrap_process_wrapper</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:experimental_use_sh_toolchain_for_bootstrap_process_wrapper |
| </pre> |
| <p>A flag to control whether the shell path from a shell toolchain (<code>@bazel_tools//tools/sh:toolchain_type</code>) is embedded into the bootstrap process wrapper for the <code>.sh</code> file.</p> |
| <p><a id="extra_exec_rustc_env"></a></p> |
| <h2 id="extra_exec_rustc_env"><a class="header" href="#extra_exec_rustc_env">extra_exec_rustc_env</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:extra_exec_rustc_env |
| </pre> |
| <p>This setting may be used to pass extra environment variables to rustc from the command line in exec configuration.</p> |
| <p>It applies to tools built and run during the build process, such as proc-macros and build scripts. |
| This can be useful for enabling features that are needed during tool compilation.</p> |
| <p><a id="extra_exec_rustc_flag"></a></p> |
| <h2 id="extra_exec_rustc_flag"><a class="header" href="#extra_exec_rustc_flag">extra_exec_rustc_flag</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:extra_exec_rustc_flag |
| </pre> |
| <p>Add additional rustc_flags in the exec configuration from the command line with <code>--@rules_rust//rust/settings:extra_exec_rustc_flag</code>.</p> |
| <p>Multiple uses are accumulated and appended after the extra_exec_rustc_flags.</p> |
| <p><a id="extra_exec_rustc_flags"></a></p> |
| <h2 id="extra_exec_rustc_flags"><a class="header" href="#extra_exec_rustc_flags">extra_exec_rustc_flags</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:extra_exec_rustc_flags |
| </pre> |
| <p>This setting may be used to pass extra options to rustc from the command line in exec configuration.</p> |
| <p>It applies across all targets whereas the rustc_flags option on targets applies only |
| to that target. This can be useful for passing build-wide options such as LTO.</p> |
| <p><a id="extra_rustc_env"></a></p> |
| <h2 id="extra_rustc_env"><a class="header" href="#extra_rustc_env">extra_rustc_env</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:extra_rustc_env |
| </pre> |
| <p>This setting may be used to pass extra environment variables to rustc from the command line in non-exec configuration.</p> |
| <p>It applies across all targets whereas environment variables set in a specific rule apply only to that target. |
| This can be useful for setting build-wide env flags such as <code>RUSTC_BOOTSTRAP=1</code>.</p> |
| <p><a id="extra_rustc_flag"></a></p> |
| <h2 id="extra_rustc_flag"><a class="header" href="#extra_rustc_flag">extra_rustc_flag</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:extra_rustc_flag |
| </pre> |
| <p>Add additional rustc_flag from the command line with <code>--@rules_rust//rust/settings:extra_rustc_flag</code>.</p> |
| <p>Multiple uses are accumulated and appended after the <code>extra_rustc_flags</code>.</p> |
| <p><a id="extra_rustc_flags"></a></p> |
| <h2 id="extra_rustc_flags"><a class="header" href="#extra_rustc_flags">extra_rustc_flags</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:extra_rustc_flags |
| </pre> |
| <p>This setting may be used to pass extra options to rustc from the command line in non-exec configuration.</p> |
| <p>It applies across all targets whereas the rustc_flags option on targets applies only |
| to that target. This can be useful for passing build-wide options such as LTO.</p> |
| <p><a id="incompatible_change_clippy_error_format"></a></p> |
| <h2 id="incompatible_change_clippy_error_format"><a class="header" href="#incompatible_change_clippy_error_format">incompatible_change_clippy_error_format</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:incompatible_change_clippy_error_format |
| </pre> |
| <p>A flag to enable the <code>clippy_error_format</code> setting.</p> |
| <p>If this flag is true, Clippy uses the format set in <code>clippy_error_format</code> to |
| format its diagnostics; otherwise, it uses the format set in <code>error_format</code>.</p> |
| <p><a id="incompatible_do_not_include_data_in_compile_data"></a></p> |
| <h2 id="incompatible_do_not_include_data_in_compile_data"><a class="header" href="#incompatible_do_not_include_data_in_compile_data">incompatible_do_not_include_data_in_compile_data</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:incompatible_do_not_include_data_in_compile_data |
| </pre> |
| <p>A flag to control whether to include data files in compile_data.</p> |
| <p><a id="incompatible_do_not_include_transitive_data_in_compile_inputs"></a></p> |
| <h2 id="incompatible_do_not_include_transitive_data_in_compile_inputs"><a class="header" href="#incompatible_do_not_include_transitive_data_in_compile_inputs">incompatible_do_not_include_transitive_data_in_compile_inputs</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:incompatible_do_not_include_transitive_data_in_compile_inputs |
| </pre> |
| <p>A flag to control whether transitive data dependencies are included in compile inputs.</p> |
| <p><a id="lto"></a></p> |
| <h2 id="lto"><a class="header" href="#lto">lto</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:lto |
| </pre> |
| <p>A build setting which specifies the link time optimization mode used when building Rust code.</p> |
| <p><a id="no_std"></a></p> |
| <h2 id="no_std"><a class="header" href="#no_std">no_std</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:no_std |
| </pre> |
| <p>This setting may be used to enable builds without the standard library.</p> |
| <p>Currently only no_std + alloc is supported, which can be enabled with setting the value to "alloc". |
| In the future we could add support for additional modes, e.g "core", "alloc,collections".</p> |
| <p><a id="pipelined_compilation"></a></p> |
| <h2 id="pipelined_compilation"><a class="header" href="#pipelined_compilation">pipelined_compilation</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:pipelined_compilation |
| </pre> |
| <p>When set, this flag causes rustc to emit <code>*.rmeta</code> files and use them for <code>rlib -> rlib</code> dependencies.</p> |
| <p>While this involves one extra (short) rustc invocation to build the rmeta file, |
| it allows library dependencies to be unlocked much sooner, increasing parallelism during compilation.</p> |
| <p><a id="rename_first_party_crates"></a></p> |
| <h2 id="rename_first_party_crates"><a class="header" href="#rename_first_party_crates">rename_first_party_crates</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:rename_first_party_crates |
| </pre> |
| <p>A flag controlling whether to rename first-party crates such that their names encode the Bazel package and target name, instead of just the target name.</p> |
| <p>First-party vs. third-party crates are identified using the value of |
| <code>@rules_rust//settings:third_party_dir</code>.</p> |
| <p><a id="require_explicit_unstable_features"></a></p> |
| <h2 id="require_explicit_unstable_features"><a class="header" href="#require_explicit_unstable_features">require_explicit_unstable_features</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:require_explicit_unstable_features |
| </pre> |
| <p>A flag controlling whether unstable features should be disallowed by default</p> |
| <p>If true, an empty <code>-Zallow-features=</code> will be added to the rustc command line whenever no other |
| <code>-Zallow-features=</code> is present in the rustc flags. The effect is to disallow all unstable |
| features by default, with the possibility to explicitly re-enable them selectively using |
| <code>-Zallow-features=...</code>.</p> |
| <p><a id="rustc_output_diagnostics"></a></p> |
| <h2 id="rustc_output_diagnostics"><a class="header" href="#rustc_output_diagnostics">rustc_output_diagnostics</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:rustc_output_diagnostics |
| </pre> |
| <p>This setting may be changed from the command line to generate rustc diagnostics.</p> |
| <p><a id="rustfmt_toml"></a></p> |
| <h2 id="rustfmt_toml"><a class="header" href="#rustfmt_toml">rustfmt_toml</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:rustfmt_toml |
| </pre> |
| <p>This setting is used by the rustfmt rules. See https://bazelbuild.github.io/rules_rust/rust_fmt.html</p> |
| <p>Note that this setting is actually called <code>rustfmt.toml</code>.</p> |
| <p><a id="third_party_dir"></a></p> |
| <h2 id="third_party_dir"><a class="header" href="#third_party_dir">third_party_dir</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:third_party_dir |
| </pre> |
| <p>A flag specifying the location of vendored third-party rust crates within this repository that must not be renamed when <code>rename_first_party_crates</code> is enabled.</p> |
| <p>Must be specified as a Bazel package, e.g. "//some/location/in/repo".</p> |
| <p><a id="toolchain_generated_sysroot"></a></p> |
| <h2 id="toolchain_generated_sysroot"><a class="header" href="#toolchain_generated_sysroot">toolchain_generated_sysroot</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:toolchain_generated_sysroot |
| </pre> |
| <p>A flag to set rustc --sysroot flag to the sysroot generated by rust_toolchain.</p> |
| <p><a id="toolchain_linker_preference"></a></p> |
| <h2 id="toolchain_linker_preference"><a class="header" href="#toolchain_linker_preference">toolchain_linker_preference</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:toolchain_linker_preference |
| </pre> |
| <p>A flag to control which linker is preferred for linking Rust binaries.</p> |
| <p>Accepts three values:</p> |
| <ul> |
| <li>"rust": Use <code>rust_toolchain.linker</code> always (e.g., <code>rust-lld</code>). This uses rustc to invoke |
| the linker directly.</li> |
| <li>"cc": Use the linker provided by the configured <code>cc_toolchain</code>. This uses rustc to invoke |
| the C++ toolchain's linker (e.g., <code>clang</code>, <code>gcc</code>, <code>link.exe</code>).</li> |
| <li>"none": Default to <code>cc</code> being the preference and falling back to <code>rust</code> if no <code>cc_toolchain</code> |
| is available.</li> |
| </ul> |
| <p><a id="unpretty"></a></p> |
| <h2 id="unpretty"><a class="header" href="#unpretty">unpretty</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:unpretty |
| </pre> |
| <p>A build setting to control the output of <code>RustUnpretty*</code> actions</p> |
| <p>Supported values are:</p> |
| <ul> |
| <li><code>ast-tree,expanded</code></li> |
| <li><code>ast-tree</code></li> |
| <li><code>expanded,hygiene</code></li> |
| <li><code>expanded,identified</code></li> |
| <li><code>expanded</code></li> |
| <li><code>hir-tree</code></li> |
| <li><code>hir,identified</code></li> |
| <li><code>hir,typed</code></li> |
| <li><code>hir</code></li> |
| <li><code>identified</code></li> |
| <li><code>mir-cfg</code></li> |
| <li><code>mir</code></li> |
| <li><code>normal</code></li> |
| </ul> |
| <p><a id="use_real_import_macro"></a></p> |
| <h2 id="use_real_import_macro"><a class="header" href="#use_real_import_macro">use_real_import_macro</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:use_real_import_macro |
| </pre> |
| <p>A flag to control whether rust_library and rust_binary targets should implicitly depend on the <em>real</em> import macro, or on a no-op target.</p> |
| <div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build --> |
| <h1 id="cargo-settings"><a class="header" href="#cargo-settings">Cargo settings</a></h1> |
| <p>Definitions for all <code>@rules_rust//cargo</code> settings</p> |
| <p><a id="cargo_manifest_dir_filename_suffixes_to_retain"></a></p> |
| <h2 id="cargo_manifest_dir_filename_suffixes_to_retain"><a class="header" href="#cargo_manifest_dir_filename_suffixes_to_retain">cargo_manifest_dir_filename_suffixes_to_retain</a></h2> |
| <pre> |
| --@rules_rust//cargo/settings:cargo_manifest_dir_filename_suffixes_to_retain |
| </pre> |
| <p>A flag which determines what files are retained in <code>CARGO_MANIFEST_DIR</code> directories that are created in <code>CargoBuildScriptRun</code> actions.</p> |
| <p><a id="debug_std_streams_output_group"></a></p> |
| <h2 id="debug_std_streams_output_group"><a class="header" href="#debug_std_streams_output_group">debug_std_streams_output_group</a></h2> |
| <pre> |
| --@rules_rust//cargo/settings:debug_std_streams_output_group |
| </pre> |
| <p>A flag which adds a <code>streams</code> output group to <code>cargo_build_script</code> targets that contain the raw <code>stderr</code> and <code>stdout</code> streams from the build script.</p> |
| <p><a id="experimental_symlink_execroot"></a></p> |
| <h2 id="experimental_symlink_execroot"><a class="header" href="#experimental_symlink_execroot">experimental_symlink_execroot</a></h2> |
| <pre> |
| --@rules_rust//cargo/settings:experimental_symlink_execroot |
| </pre> |
| <p>A flag for which causes <code>cargo_build_script</code> to symlink the execroot of the action to the <code>CARGO_MANIFEST_DIR</code> where the scripts are run.</p> |
| <p><a id="out_dir_volatile_file_basenames"></a></p> |
| <h2 id="out_dir_volatile_file_basenames"><a class="header" href="#out_dir_volatile_file_basenames">out_dir_volatile_file_basenames</a></h2> |
| <pre> |
| --@rules_rust//cargo/settings:out_dir_volatile_file_basenames |
| </pre> |
| <p>A flag which determines what file basenames are removed from <code>OUT_DIR</code> by <code>cargo_build_script</code> actions to make the <code>_bs.out_dir</code> TreeArtifact deterministic.</p> |
| <p>Files whose names appear in this list, as well as files with a <code>.d</code> or <code>.pc</code> |
| extension, are deleted from <code>OUT_DIR</code> after the build script runs and before Bazel |
| captures the directory. Files like <code>config.log</code> and <code>Makefile</code> embed the Bazel |
| sandbox path, so their content changes on every action invocation, causing cache |
| misses for all downstream <code>rustc</code> compilations.</p> |
| <p><a id="use_default_shell_env"></a></p> |
| <h2 id="use_default_shell_env"><a class="header" href="#use_default_shell_env">use_default_shell_env</a></h2> |
| <pre> |
| --@rules_rust//cargo/settings:use_default_shell_env |
| </pre> |
| <p>A flag which controls the global default of <code>ctx.actions.run.use_default_shell_env</code> for <code>cargo_build_script</code> targets.</p> |
| <div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build --> |
| <h1 id="rust-toolchains"><a class="header" href="#rust-toolchains">Rust Toolchains</a></h1> |
| <p>Toolchain rules for Rust.</p> |
| <h2 id="rules-7"><a class="header" href="#rules-7">Rules</a></h2> |
| <ul> |
| <li><a href="rust_toolchains.html#rust_analyzer_toolchain">rust_analyzer_toolchain</a></li> |
| <li><a href="rust_toolchains.html#rust_toolchain">rust_toolchain</a></li> |
| <li><a href="rust_toolchains.html#rustfmt_toolchain">rustfmt_toolchain</a></li> |
| </ul> |
| <p><a id="rust_analyzer_toolchain"></a></p> |
| <h2 id="rust_analyzer_toolchain"><a class="header" href="#rust_analyzer_toolchain">rust_analyzer_toolchain</a></h2> |
| <pre> |
| load("@rules_rust//rust:toolchain.bzl", "rust_analyzer_toolchain") |
| |
| rust_analyzer_toolchain(<a href="rust_toolchains.html#rust_analyzer_toolchain-name">name</a>, <a href="rust_toolchains.html#rust_analyzer_toolchain-proc_macro_srv">proc_macro_srv</a>, <a href="rust_toolchains.html#rust_analyzer_toolchain-rust_analyzer">rust_analyzer</a>, <a href="rust_toolchains.html#rust_analyzer_toolchain-rustc">rustc</a>, <a href="rust_toolchains.html#rust_analyzer_toolchain-rustc_srcs">rustc_srcs</a>, <a href="rust_toolchains.html#rust_analyzer_toolchain-rustc_srcs_path">rustc_srcs_path</a>) |
| </pre> |
| <p>A toolchain for <a href="https://rust-analyzer.github.io/">rust-analyzer</a>.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <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> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_analyzer_toolchain-rust_analyzer"></a>rust_analyzer</td><td style="text-align: left">The path to a <code>rust-analyzer</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> |
| <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> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_analyzer_toolchain-rustc_srcs_path"></a>rustc_srcs_path</td><td style="text-align: left">The direct path to rustc srcs relative to rustc_srcs package root.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"library"</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_toolchain"></a></p> |
| <h2 id="rust_toolchain"><a class="header" href="#rust_toolchain">rust_toolchain</a></h2> |
| <pre> |
| load("@rules_rust//rust:toolchain.bzl", "rust_toolchain") |
| |
| rust_toolchain(<a href="rust_toolchains.html#rust_toolchain-name">name</a>, <a href="rust_toolchains.html#rust_toolchain-allocator_library">allocator_library</a>, <a href="rust_toolchains.html#rust_toolchain-binary_ext">binary_ext</a>, <a href="rust_toolchains.html#rust_toolchain-cargo">cargo</a>, <a href="rust_toolchains.html#rust_toolchain-cargo_clippy">cargo_clippy</a>, <a href="rust_toolchains.html#rust_toolchain-channel">channel</a>, <a href="rust_toolchains.html#rust_toolchain-clippy_driver">clippy_driver</a>, |
| <a href="rust_toolchains.html#rust_toolchain-debug_info">debug_info</a>, <a href="rust_toolchains.html#rust_toolchain-default_edition">default_edition</a>, <a href="rust_toolchains.html#rust_toolchain-dylib_ext">dylib_ext</a>, <a href="rust_toolchains.html#rust_toolchain-env">env</a>, <a href="rust_toolchains.html#rust_toolchain-exec_triple">exec_triple</a>, <a href="rust_toolchains.html#rust_toolchain-experimental_link_std_dylib">experimental_link_std_dylib</a>, |
| <a href="rust_toolchains.html#rust_toolchain-experimental_use_allocator_libraries_with_mangled_symbols">experimental_use_allocator_libraries_with_mangled_symbols</a>, |
| <a href="rust_toolchains.html#rust_toolchain-experimental_use_cc_common_link">experimental_use_cc_common_link</a>, <a href="rust_toolchains.html#rust_toolchain-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="rust_toolchains.html#rust_toolchain-extra_rustc_flags">extra_rustc_flags</a>, |
| <a href="rust_toolchains.html#rust_toolchain-extra_rustc_flags_for_crate_types">extra_rustc_flags_for_crate_types</a>, <a href="rust_toolchains.html#rust_toolchain-global_allocator_library">global_allocator_library</a>, <a href="rust_toolchains.html#rust_toolchain-iso_date">iso_date</a>, <a href="rust_toolchains.html#rust_toolchain-linker">linker</a>, |
| <a href="rust_toolchains.html#rust_toolchain-linker_preference">linker_preference</a>, <a href="rust_toolchains.html#rust_toolchain-linker_type">linker_type</a>, <a href="rust_toolchains.html#rust_toolchain-llvm_cov">llvm_cov</a>, <a href="rust_toolchains.html#rust_toolchain-llvm_lib">llvm_lib</a>, <a href="rust_toolchains.html#rust_toolchain-llvm_profdata">llvm_profdata</a>, <a href="rust_toolchains.html#rust_toolchain-llvm_tools">llvm_tools</a>, <a href="rust_toolchains.html#rust_toolchain-lto">lto</a>, |
| <a href="rust_toolchains.html#rust_toolchain-opt_level">opt_level</a>, <a href="rust_toolchains.html#rust_toolchain-per_crate_rustc_flags">per_crate_rustc_flags</a>, <a href="rust_toolchains.html#rust_toolchain-require_explicit_unstable_features">require_explicit_unstable_features</a>, <a href="rust_toolchains.html#rust_toolchain-rust_doc">rust_doc</a>, |
| <a href="rust_toolchains.html#rust_toolchain-rust_objcopy">rust_objcopy</a>, <a href="rust_toolchains.html#rust_toolchain-rust_std">rust_std</a>, <a href="rust_toolchains.html#rust_toolchain-rustc">rustc</a>, <a href="rust_toolchains.html#rust_toolchain-rustc_lib">rustc_lib</a>, <a href="rust_toolchains.html#rust_toolchain-rustfmt">rustfmt</a>, <a href="rust_toolchains.html#rust_toolchain-staticlib_ext">staticlib_ext</a>, <a href="rust_toolchains.html#rust_toolchain-stdlib_linkflags">stdlib_linkflags</a>, |
| <a href="rust_toolchains.html#rust_toolchain-strip_level">strip_level</a>, <a href="rust_toolchains.html#rust_toolchain-target_json">target_json</a>, <a href="rust_toolchains.html#rust_toolchain-target_triple">target_triple</a>, <a href="rust_toolchains.html#rust_toolchain-version">version</a>) |
| </pre> |
| <p>Declares a Rust toolchain for use.</p> |
| <p>This is for declaring a custom toolchain, eg. for configuring a particular version of rust or supporting a new platform.</p> |
| <p>Example:</p> |
| <p>Suppose the core rust team has ported the compiler to a new target CPU, called <code>cpuX</code>. This support can be used in Bazel by defining a new toolchain definition and declaration:</p> |
| <pre><code class="language-python">load('@rules_rust//rust:toolchain.bzl', 'rust_toolchain') |
| |
| rust_toolchain( |
| name = "rust_cpuX_impl", |
| binary_ext = "", |
| dylib_ext = ".so", |
| exec_triple = "cpuX-unknown-linux-gnu", |
| rust_doc = "@rust_cpuX//:rustdoc", |
| rust_std = "@rust_cpuX//:rust_std", |
| rustc = "@rust_cpuX//:rustc", |
| rustc_lib = "@rust_cpuX//:rustc_lib", |
| staticlib_ext = ".a", |
| stdlib_linkflags = ["-lpthread", "-ldl"], |
| target_triple = "cpuX-unknown-linux-gnu", |
| ) |
| |
| toolchain( |
| name = "rust_cpuX", |
| exec_compatible_with = [ |
| "@platforms//cpu:cpuX", |
| "@platforms//os:linux", |
| ], |
| target_compatible_with = [ |
| "@platforms//cpu:cpuX", |
| "@platforms//os:linux", |
| ], |
| toolchain = ":rust_cpuX_impl", |
| ) |
| </code></pre> |
| <p>Then, either add the label of the toolchain rule to <code>register_toolchains</code> in the WORKSPACE, or pass it to the <code>"--extra_toolchains"</code> flag for Bazel, and it will be used.</p> |
| <p>To use a platform-specific linker, you can use a <code>select()</code> in the <code>linker</code> attribute:</p> |
| <pre><code class="language-python">rust_toolchain( |
| name = "rust_toolchain_impl", |
| # ... other attributes ... |
| linker = select({ |
| "@platforms//os:linux": "//tools:rust-lld-linux", |
| "@platforms//os:windows": "//tools:rust-lld-windows", |
| "//conditions:default": "//tools:rust-lld", |
| }), |
| ) |
| </code></pre> |
| <p>The <code>select()</code> is evaluated against the target platform before the exec transition is applied, allowing platform-specific linker selection while ensuring the selected linker is built for the exec platform.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_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> |
| <tr><td style="text-align: left"><a id="rust_toolchain-allocator_library"></a>allocator_library</td><td style="text-align: left">Target that provides allocator functions when <code>rust_library</code> targets are embedded in a <code>cc_binary</code>.</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>"@rules_rust//rust/settings:default_allocator_library"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-binary_ext"></a>binary_ext</td><td style="text-align: left">The extension for binaries created from rustc.</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-cargo"></a>cargo</td><td style="text-align: left">The location of the <code>cargo</code> binary. Can be a direct source or a filegroup containing one item.</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> |
| <tr><td style="text-align: left"><a id="rust_toolchain-cargo_clippy"></a>cargo_clippy</td><td style="text-align: left">The location of the <code>cargo_clippy</code> binary. Can be a direct source or a filegroup containing one item.</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> |
| <tr><td style="text-align: left"><a id="rust_toolchain-channel"></a>channel</td><td style="text-align: left">The Rust release channel (<code>stable</code>, <code>nightly</code>, or <code>beta</code>).</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-clippy_driver"></a>clippy_driver</td><td style="text-align: left">The location of the <code>clippy-driver</code> binary. Can be a direct source or a filegroup containing one item.</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> |
| <tr><td style="text-align: left"><a id="rust_toolchain-debug_info"></a>debug_info</td><td style="text-align: left">Rustc debug info levels per opt level</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{"dbg": "2", "fastbuild": "0", "opt": "0"}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-default_edition"></a>default_edition</td><td style="text-align: left">The edition to use for rust_* rules that don't specify an edition. If absent, every rule is required to specify its <code>edition</code> attribute.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-dylib_ext"></a>dylib_ext</td><td style="text-align: left">The extension for dynamic libraries created from rustc.</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-env"></a>env</td><td style="text-align: left">Environment variables to set in actions.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-exec_triple"></a>exec_triple</td><td style="text-align: left">The platform triple for the toolchains execution environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-experimental_link_std_dylib"></a>experimental_link_std_dylib</td><td style="text-align: left">Label to a boolean build setting that controls whether whether to link libstd dynamically.</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>"@rules_rust//rust/settings:experimental_link_std_dylib"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-experimental_use_allocator_libraries_with_mangled_symbols"></a>experimental_use_allocator_libraries_with_mangled_symbols</td><td style="text-align: left">Whether to use rust-based allocator libraries with mangled symbols. Possible values: [-1, 0, 1]. -1 means to use the value of the build setting //rust/settings:experimental_use_allocator_libraries_with_mangled_symbols. 0 means do not use. In that case, rules_rust will try to use the c-based allocator libraries that don't support symbol mangling. 1 means use the rust-based allocator libraries.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-experimental_use_cc_common_link"></a>experimental_use_cc_common_link</td><td style="text-align: left">Label to a boolean build setting that controls whether cc_common.link is used to link rust binaries.</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>"@rules_rust//rust/settings:experimental_use_cc_common_link"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-extra_exec_rustc_flags"></a>extra_exec_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in exec configuration. Subject to location expansion with respect to the srcs of the <code>rust_std</code> attribute. Subject to Make variable expansion with respect to RUST_SYSROOT, RUST_SYSROOT_SHORT, RUSTC, etc.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-extra_rustc_flags"></a>extra_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in non-exec configuration. Subject to location expansion with respect to the srcs of the <code>rust_std</code> attribute. Subject to Make variable expansion with respect to RUST_SYSROOT, RUST_SYSROOT_SHORT, RUSTC, etc.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-extra_rustc_flags_for_crate_types"></a>extra_rustc_flags_for_crate_types</td><td style="text-align: left">Extra flags to pass to rustc based on crate type</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> List of strings</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-global_allocator_library"></a>global_allocator_library</td><td style="text-align: left">Target that provides allocator functions for when a global allocator is present.</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>"@rules_rust//rust/private/cc:global_allocator_library"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-iso_date"></a>iso_date</td><td style="text-align: left">The ISO date of the nightly or beta release (e.g. <code>2026-03-26</code>). Empty for stable releases.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-linker"></a>linker</td><td style="text-align: left">The label to an explicit linker to use (e.g. rust-lld, ld, link-ld.exe, etc.). Linker binaries must be runnable in the exec configuration, so cfg = "exec" is used. To choose a linker based on the target platform, use a select() when providing this attribute. The select() will be evaluated against the target platform before the exec transition is applied, allowing platform-specific linker selection while ensuring the selected linker is built for the exec platform.</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> |
| <tr><td style="text-align: left"><a id="rust_toolchain-linker_preference"></a>linker_preference</td><td style="text-align: left">The preferred linker to use. If unspecified, <code>cc</code> is preferred and <code>rust</code> is used as a fallback whenever <code>linker</code> is provided.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-linker_type"></a>linker_type</td><td style="text-align: left">The type of linker invocation: 'direct' (ld, rust-lld) or 'indirect' (via compiler like clang/gcc). If unset, defaults based on linker_preference.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-llvm_cov"></a>llvm_cov</td><td style="text-align: left">The location of the <code>llvm-cov</code> binary. Can be a direct source or a filegroup containing one item. If None, rust code is not instrumented for coverage.</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> |
| <tr><td style="text-align: left"><a id="rust_toolchain-llvm_lib"></a>llvm_lib</td><td style="text-align: left">The location of the <code>libLLVM</code> shared object files. If <code>llvm_cov</code> is None, this can be None as well and rust code is not instrumented for coverage.</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> |
| <tr><td style="text-align: left"><a id="rust_toolchain-llvm_profdata"></a>llvm_profdata</td><td style="text-align: left">The location of the <code>llvm-profdata</code> binary. Can be a direct source or a filegroup containing one item. If <code>llvm_cov</code> is None, this can be None as well and rust code is not instrumented for coverage.</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> |
| <tr><td style="text-align: left"><a id="rust_toolchain-llvm_tools"></a>llvm_tools</td><td style="text-align: left">LLVM tools that are shipped with the Rust toolchain.</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> |
| <tr><td style="text-align: left"><a id="rust_toolchain-lto"></a>lto</td><td style="text-align: left">Label to an LTO setting whether which can enable custom LTO settings</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>"@rules_rust//rust/settings:lto"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-opt_level"></a>opt_level</td><td style="text-align: left">Rustc optimization levels.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{"dbg": "0", "fastbuild": "0", "opt": "3"}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-per_crate_rustc_flags"></a>per_crate_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in non-exec configuration</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-require_explicit_unstable_features"></a>require_explicit_unstable_features</td><td style="text-align: left">Label to a boolean build setting that controls whether all uses of unstable Rust features must be explicitly opted in to using <code>-Zallow-features=...</code>.</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>"@rules_rust//rust/settings:require_explicit_unstable_features"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-rust_doc"></a>rust_doc</td><td style="text-align: left">The location of the <code>rustdoc</code> binary. Can be a direct source or a filegroup containing one item.</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> |
| <tr><td style="text-align: left"><a id="rust_toolchain-rust_objcopy"></a>rust_objcopy</td><td style="text-align: left">The location of the <code>rust-objcopy</code> binary. Can be a direct source or a filegroup containing one item.</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> |
| <tr><td style="text-align: left"><a id="rust_toolchain-rust_std"></a>rust_std</td><td style="text-align: left">The Rust standard library.</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> |
| <tr><td style="text-align: left"><a id="rust_toolchain-rustc"></a>rustc</td><td style="text-align: left">The location of the <code>rustc</code> binary. Can be a direct source or a filegroup containing one item.</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> |
| <tr><td style="text-align: left"><a id="rust_toolchain-rustc_lib"></a>rustc_lib</td><td style="text-align: left">The libraries used by rustc during compilation.</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> |
| <tr><td style="text-align: left"><a id="rust_toolchain-rustfmt"></a>rustfmt</td><td style="text-align: left"><strong>Deprecated</strong>: Instead see <a href="rust_toolchains.html#rustfmt_toolchain">rustfmt_toolchain</a></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> |
| <tr><td style="text-align: left"><a id="rust_toolchain-staticlib_ext"></a>staticlib_ext</td><td style="text-align: left">The extension for static libraries created from rustc.</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-stdlib_linkflags"></a>stdlib_linkflags</td><td style="text-align: left">Additional linker flags to use when Rust standard library is linked by a C++ linker (rustc will deal with these automatically). Subject to location expansion with respect to the srcs of the <code>rust_std</code> attribute. Subject to Make variable expansion with respect to RUST_SYSROOT, RUST_SYSROOT_SHORT, RUSTC, etc.</td><td style="text-align: left">List of strings</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-strip_level"></a>strip_level</td><td style="text-align: left">Rustc strip levels. For all potential options, see https://doc.rust-lang.org/rustc/codegen-options/index.html#strip</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{"dbg": "none", "fastbuild": "none", "opt": "debuginfo"}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-target_json"></a>target_json</td><td style="text-align: left">Override the target_triple with a custom target specification. For more details see: https://doc.rust-lang.org/rustc/targets/custom.html</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-target_triple"></a>target_triple</td><td style="text-align: left">The platform triple for the toolchains target environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain-version"></a>version</td><td style="text-align: left">The version of the Rust compiler (e.g. <code>1.94.1</code>).</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rustfmt_toolchain"></a></p> |
| <h2 id="rustfmt_toolchain"><a class="header" href="#rustfmt_toolchain">rustfmt_toolchain</a></h2> |
| <pre> |
| load("@rules_rust//rust:toolchain.bzl", "rustfmt_toolchain") |
| |
| rustfmt_toolchain(<a href="rust_toolchains.html#rustfmt_toolchain-name">name</a>, <a href="rust_toolchains.html#rustfmt_toolchain-rustc">rustc</a>, <a href="rust_toolchains.html#rustfmt_toolchain-rustc_lib">rustc_lib</a>, <a href="rust_toolchains.html#rustfmt_toolchain-rustfmt">rustfmt</a>) |
| </pre> |
| <p>A toolchain for <a href="https://rust-lang.github.io/rustfmt/">rustfmt</a></p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rustfmt_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> |
| <tr><td style="text-align: left"><a id="rustfmt_toolchain-rustc"></a>rustc</td><td style="text-align: left">The location of the <code>rustc</code> binary. Can be a direct source or a filegroup containing one item.</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> |
| <tr><td style="text-align: left"><a id="rustfmt_toolchain-rustc_lib"></a>rustc_lib</td><td style="text-align: left">The libraries used by rustc during compilation.</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> |
| <tr><td style="text-align: left"><a id="rustfmt_toolchain-rustfmt"></a>rustfmt</td><td style="text-align: left">The location of the <code>rustfmt</code> binary. Can be a direct source or a filegroup containing one item.</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> |
| </tbody></table> |
| </div><div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build --> |
| <p>Module extensions for using rules_rust with bzlmod</p> |
| <h2 id="module-extensions"><a class="header" href="#module-extensions">Module Extensions</a></h2> |
| <ul> |
| <li><a href="rust_bzlmod.html#rust">rust</a></li> |
| <li><a href="rust_bzlmod.html#rust_host_tools">rust_host_tools</a></li> |
| </ul> |
| <p><a id="rust"></a></p> |
| <h2 id="rust"><a class="header" href="#rust">rust</a></h2> |
| <pre> |
| rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") |
| rust.repository_set(<a href="rust_bzlmod.html#rust.repository_set-name">name</a>, <a href="rust_bzlmod.html#rust.repository_set-allocator_library">allocator_library</a>, <a href="rust_bzlmod.html#rust.repository_set-auth">auth</a>, <a href="rust_bzlmod.html#rust.repository_set-auth_patterns">auth_patterns</a>, <a href="rust_bzlmod.html#rust.repository_set-dev_components">dev_components</a>, <a href="rust_bzlmod.html#rust.repository_set-edition">edition</a>, |
| <a href="rust_bzlmod.html#rust.repository_set-exec_compatible_with">exec_compatible_with</a>, <a href="rust_bzlmod.html#rust.repository_set-exec_triple">exec_triple</a>, <a href="rust_bzlmod.html#rust.repository_set-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="rust_bzlmod.html#rust.repository_set-extra_rustc_flags">extra_rustc_flags</a>, |
| <a href="rust_bzlmod.html#rust.repository_set-global_allocator_library">global_allocator_library</a>, <a href="rust_bzlmod.html#rust.repository_set-netrc">netrc</a>, <a href="rust_bzlmod.html#rust.repository_set-opt_level">opt_level</a>, <a href="rust_bzlmod.html#rust.repository_set-rustfmt_version">rustfmt_version</a>, <a href="rust_bzlmod.html#rust.repository_set-sha256s">sha256s</a>, <a href="rust_bzlmod.html#rust.repository_set-strip_level">strip_level</a>, |
| <a href="rust_bzlmod.html#rust.repository_set-target_compatible_with">target_compatible_with</a>, <a href="rust_bzlmod.html#rust.repository_set-target_settings">target_settings</a>, <a href="rust_bzlmod.html#rust.repository_set-target_triple">target_triple</a>, <a href="rust_bzlmod.html#rust.repository_set-urls">urls</a>, <a href="rust_bzlmod.html#rust.repository_set-versions">versions</a>) |
| rust.toolchain(<a href="rust_bzlmod.html#rust.toolchain-aliases">aliases</a>, <a href="rust_bzlmod.html#rust.toolchain-allocator_library">allocator_library</a>, <a href="rust_bzlmod.html#rust.toolchain-dev_components">dev_components</a>, <a href="rust_bzlmod.html#rust.toolchain-edition">edition</a>, <a href="rust_bzlmod.html#rust.toolchain-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, |
| <a href="rust_bzlmod.html#rust.toolchain-extra_exec_rustc_flags_triples">extra_exec_rustc_flags_triples</a>, <a href="rust_bzlmod.html#rust.toolchain-extra_rustc_flags">extra_rustc_flags</a>, <a href="rust_bzlmod.html#rust.toolchain-extra_rustc_flags_triples">extra_rustc_flags_triples</a>, |
| <a href="rust_bzlmod.html#rust.toolchain-extra_target_triples">extra_target_triples</a>, <a href="rust_bzlmod.html#rust.toolchain-global_allocator_library">global_allocator_library</a>, <a href="rust_bzlmod.html#rust.toolchain-rust_analyzer_version">rust_analyzer_version</a>, |
| <a href="rust_bzlmod.html#rust.toolchain-rustfmt_toolchain_triples">rustfmt_toolchain_triples</a>, <a href="rust_bzlmod.html#rust.toolchain-rustfmt_version">rustfmt_version</a>, <a href="rust_bzlmod.html#rust.toolchain-sha256s">sha256s</a>, <a href="rust_bzlmod.html#rust.toolchain-strip_level">strip_level</a>, <a href="rust_bzlmod.html#rust.toolchain-target_settings">target_settings</a>, |
| <a href="rust_bzlmod.html#rust.toolchain-urls">urls</a>, <a href="rust_bzlmod.html#rust.toolchain-versions">versions</a>) |
| </pre> |
| <p>Rust toolchain extension.</p> |
| <p><strong>TAG CLASSES</strong></p> |
| <p><a id="rust.repository_set"></a></p> |
| <h3 id="repository_set"><a class="header" href="#repository_set">repository_set</a></h3> |
| <p>Tags for defining rust repository sets (where toolchains are defined).</p> |
| <p><strong>Attributes</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust.repository_set-name"></a>name</td><td style="text-align: left">Name of the repository_set - if you're looking to replace default toolchains you must use the exact name you're replacing.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-allocator_library"></a>allocator_library</td><td style="text-align: left">Target that provides allocator functions when rust_library targets are embedded in a cc_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> |
| <tr><td style="text-align: left"><a id="rust.repository_set-auth"></a>auth</td><td style="text-align: left">Auth object compatible with repository_ctx.download to use when downloading files.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-auth_patterns"></a>auth_patterns</td><td style="text-align: left">Override mapping of hostnames to authorization patterns; mirrors the eponymous attribute from http_archive.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-dev_components"></a>dev_components</td><td style="text-align: left">Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly".</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-edition"></a>edition</td><td style="text-align: left">The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its <code>edition</code> attribute.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-exec_compatible_with"></a>exec_compatible_with</td><td style="text-align: left">A list of constraints for the execution platform for this toolchain.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-exec_triple"></a>exec_triple</td><td style="text-align: left">Exec triple for this repository_set.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-extra_exec_rustc_flags"></a>extra_exec_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in exec configuration.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-extra_rustc_flags"></a>extra_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in non-exec configuration.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-global_allocator_library"></a>global_allocator_library</td><td style="text-align: left">Target that provides allocator functions when global allocator is used with cc_common.link.</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> |
| <tr><td style="text-align: left"><a id="rust.repository_set-netrc"></a>netrc</td><td style="text-align: left">.netrc file to use for authentication; mirrors the eponymous attribute from http_archive.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-opt_level"></a>opt_level</td><td style="text-align: left">Rustc optimization levels. For more details see the documentation for <code>rust_toolchain.opt_level</code>.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-rustfmt_version"></a>rustfmt_version</td><td style="text-align: left">The version of the tool among "nightly", "beta", or an exact version.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"nightly/2026-04-16"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-sha256s"></a>sha256s</td><td style="text-align: left">A dict associating tool subdirectories to sha256 hashes.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-strip_level"></a>strip_level</td><td style="text-align: left">Rustc strip levels. For more details see the documentation for <code>rust_toolchain.strip_level</code>.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-target_compatible_with"></a>target_compatible_with</td><td style="text-align: left">List of platform constraints this toolchain produces, for the particular target_triple this call is for.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-target_settings"></a>target_settings</td><td style="text-align: left">A list of <code>config_settings</code> that must be satisfied by the target configuration in order for this toolchain to be selected during toolchain resolution.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-target_triple"></a>target_triple</td><td style="text-align: left">target_triple to configure.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-urls"></a>urls</td><td style="text-align: left">A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format).</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>["https://static.rust-lang.org/dist/{}.tar.xz"]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.repository_set-versions"></a>versions</td><td style="text-align: left">A list of toolchain versions to download. This parameter only accepts one version per channel. E.g. <code>["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]</code>. May be set to an empty list (<code>[]</code>) to inhibit <code>rules_rust</code> from registering toolchains.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust.toolchain"></a></p> |
| <h3 id="toolchain"><a class="header" href="#toolchain">toolchain</a></h3> |
| <p>Tags for defining rust toolchains (where toolchain tools are fetched).</p> |
| <p><strong>Attributes</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust.toolchain-aliases"></a>aliases</td><td style="text-align: left">Map of full toolchain repository name to an alias. If any repository is created by this extension matches a key in this dictionary, the name of the created repository will be remapped to the value instead. This may be required to work around path length limits on Windows.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.toolchain-allocator_library"></a>allocator_library</td><td style="text-align: left">Target that provides allocator functions when rust_library targets are embedded in a cc_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> |
| <tr><td style="text-align: left"><a id="rust.toolchain-dev_components"></a>dev_components</td><td style="text-align: left">Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly".</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.toolchain-edition"></a>edition</td><td style="text-align: left">The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its <code>edition</code> attribute.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.toolchain-extra_exec_rustc_flags"></a>extra_exec_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in exec configuration</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.toolchain-extra_exec_rustc_flags_triples"></a>extra_exec_rustc_flags_triples</td><td style="text-align: left">Extra flags to pass to rustc in exec configuration. Key is the triple, value is the flag.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> List of strings</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.toolchain-extra_rustc_flags"></a>extra_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in non-exec configuration</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.toolchain-extra_rustc_flags_triples"></a>extra_rustc_flags_triples</td><td style="text-align: left">Extra flags to pass to rustc in non-exec configuration. Key is the triple, value is the flag.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> List of strings</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.toolchain-extra_target_triples"></a>extra_target_triples</td><td style="text-align: left">-</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>["aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "wasm32-unknown-unknown", "wasm32-wasip1", "wasm32-wasip2"]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.toolchain-global_allocator_library"></a>global_allocator_library</td><td style="text-align: left">Target that provides allocator functions when global allocator is used with cc_common.link.</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> |
| <tr><td style="text-align: left"><a id="rust.toolchain-rust_analyzer_version"></a>rust_analyzer_version</td><td style="text-align: left">The version of Rustc to pair with rust-analyzer.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.toolchain-rustfmt_toolchain_triples"></a>rustfmt_toolchain_triples</td><td style="text-align: left">Like toolchain_triples, but for rustfmt toolchains. Mapping of rust target triple to repository name.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.toolchain-rustfmt_version"></a>rustfmt_version</td><td style="text-align: left">The version of the tool among "nightly", "beta", or an exact version.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"nightly/2026-04-16"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.toolchain-sha256s"></a>sha256s</td><td style="text-align: left">A dict associating tool subdirectories to sha256 hashes.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.toolchain-strip_level"></a>strip_level</td><td style="text-align: left">Rustc strip levels. For more details see the documentation for <code>rust_toolchain.strip_level</code>.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.toolchain-target_settings"></a>target_settings</td><td style="text-align: left">A list of <code>config_settings</code> that must be satisfied by the target configuration in order for this toolchain to be selected during toolchain resolution.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.toolchain-urls"></a>urls</td><td style="text-align: left">A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format).</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>["https://static.rust-lang.org/dist/{}.tar.xz"]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust.toolchain-versions"></a>versions</td><td style="text-align: left">A list of toolchain versions to download. This parameter only accepts one version per channel. E.g. <code>["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]</code>. May be set to an empty list (<code>[]</code>) to inhibit <code>rules_rust</code> from registering toolchains.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>["1.95.0", "nightly/2026-04-16"]</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_host_tools"></a></p> |
| <h2 id="rust_host_tools"><a class="header" href="#rust_host_tools">rust_host_tools</a></h2> |
| <pre> |
| rust_host_tools = use_extension("@rules_rust//rust:extensions.bzl", "rust_host_tools") |
| rust_host_tools.host_tools(<a href="rust_bzlmod.html#rust_host_tools.host_tools-name">name</a>, <a href="rust_bzlmod.html#rust_host_tools.host_tools-allocator_library">allocator_library</a>, <a href="rust_bzlmod.html#rust_host_tools.host_tools-dev_components">dev_components</a>, <a href="rust_bzlmod.html#rust_host_tools.host_tools-edition">edition</a>, |
| <a href="rust_bzlmod.html#rust_host_tools.host_tools-global_allocator_library">global_allocator_library</a>, <a href="rust_bzlmod.html#rust_host_tools.host_tools-rustfmt_version">rustfmt_version</a>, <a href="rust_bzlmod.html#rust_host_tools.host_tools-sha256s">sha256s</a>, <a href="rust_bzlmod.html#rust_host_tools.host_tools-urls">urls</a>, <a href="rust_bzlmod.html#rust_host_tools.host_tools-version">version</a>) |
| </pre> |
| <p>An extension which exposes Rust tools compatible with the current host platform.</p> |
| <p><strong>TAG CLASSES</strong></p> |
| <p><a id="rust_host_tools.host_tools"></a></p> |
| <h3 id="host_tools"><a class="header" href="#host_tools">host_tools</a></h3> |
| <p><strong>Attributes</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_host_tools.host_tools-name"></a>name</td><td style="text-align: left">The name of the module to create</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"rust_host_tools"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_host_tools.host_tools-allocator_library"></a>allocator_library</td><td style="text-align: left">Target that provides allocator functions when rust_library targets are embedded in a cc_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> |
| <tr><td style="text-align: left"><a id="rust_host_tools.host_tools-dev_components"></a>dev_components</td><td style="text-align: left">Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly".</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_host_tools.host_tools-edition"></a>edition</td><td style="text-align: left">The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its <code>edition</code> attribute.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_host_tools.host_tools-global_allocator_library"></a>global_allocator_library</td><td style="text-align: left">Target that provides allocator functions when global allocator is used with cc_common.link.</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> |
| <tr><td style="text-align: left"><a id="rust_host_tools.host_tools-rustfmt_version"></a>rustfmt_version</td><td style="text-align: left">The version of the tool among "nightly", "beta", or an exact version.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"nightly/2026-04-16"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_host_tools.host_tools-sha256s"></a>sha256s</td><td style="text-align: left">A dict associating tool subdirectories to sha256 hashes.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_host_tools.host_tools-urls"></a>urls</td><td style="text-align: left">A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format).</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>["https://static.rust-lang.org/dist/{}.tar.xz"]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_host_tools.host_tools-version"></a>version</td><td style="text-align: left">The version of Rust to use for tools executed on the Bazel host.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"1.95.0"</code></td></tr> |
| </tbody></table> |
| </div><div style="break-before: page; page-break-before: always;"></div><h1 id="external-dependencies"><a class="header" href="#external-dependencies">External Dependencies</a></h1> |
| <p><a href="crate_universe_workspace.html">crate_universe workspace</a> (<a href="crate_universe_bzlmod.html">crate_universe bzlmod</a>) is a tool built into <code>rules_rust</code> that can be used to fetch dependencies.</p> |
| <div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build --> |
| <h1 id="crate-universe"><a class="header" href="#crate-universe">Crate Universe</a></h1> |
| <p>Crate Universe is a set of Bazel rule for generating Rust targets using Cargo.</p> |
| <p>This doc describes using crate_universe with bzlmod.</p> |
| <p>If you're using a WORKSPACE file, please see <a href="crate_universe_workspace.html">the WORKSPACE equivalent of this doc</a>.</p> |
| <p>There are some examples of using crate_universe with bzlmod in the <a href="https://github.com/bazelbuild/rules_rust/tree/main/examples">example folder</a>.</p> |
| <h1 id="table-of-contents"><a class="header" href="#table-of-contents">Table of Contents</a></h1> |
| <ol> |
| <li><a href="crate_universe_bzlmod.html#Setup">Setup</a></li> |
| <li><a href="crate_universe_bzlmod.html#dependencies">Dependencies</a> |
| <ul> |
| <li><a href="crate_universe_bzlmod.html#cargo-workspaces">Cargo Workspace</a></li> |
| <li><a href="crate_universe_bzlmod.html#direct-dependencies">Direct Packages</a></li> |
| <li><a href="crate_universe_bzlmod.html#binary-dependencies">Binary Dependencies</a></li> |
| <li><a href="crate_universe_bzlmod.html#vendored-dependencies">Vendored Dependencies</a></li> |
| </ul> |
| </li> |
| <li><a href="crate_universe_bzlmod.html#crate">Crate reference</a> |
| <ul> |
| <li><a href="crate_universe_bzlmod.html#from_cargo">from_cargo</a></li> |
| <li><a href="crate_universe_bzlmod.html#from_specs">from_specs</a></li> |
| </ul> |
| </li> |
| </ol> |
| <h2 id="setup-5"><a class="header" href="#setup-5">Setup</a></h2> |
| <p>To use rules_rust in a project using bzlmod, add the following to your MODULE.bazel file:</p> |
| <pre><code class="language-python">bazel_dep(name = "rules_rust", version = "0.70.0") |
| </code></pre> |
| <p>You find the latest version on the <a href="https://github.com/bazelbuild/rules_rust/releases">release page</a>.</p> |
| <p>After adding <code>rules_rust</code> in your <code>MODULE.bazel</code>, set the following to begin using <code>crate_universe</code>:</p> |
| <pre><code class="language-python">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate") |
| // # ... Dependencies |
| use_repo(crate, "crates") |
| </code></pre> |
| <h2 id="dependencies"><a class="header" href="#dependencies">Dependencies</a></h2> |
| <p>There are three different ways to declare dependencies in your MODULE.</p> |
| <ol> |
| <li>Cargo workspace</li> |
| <li>Direct Dependencies</li> |
| <li>Binary Dependencies</li> |
| <li>Vendored Dependencies</li> |
| </ol> |
| <h3 id="cargo-workspaces"><a class="header" href="#cargo-workspaces">Cargo Workspaces</a></h3> |
| <p>One of the simpler ways to wire up dependencies would be to first structure your project into a Cargo workspace. |
| The crates_repository rule can ingest a root Cargo.toml file and generate Bazel dependencies from there. |
| You find a complete example in the in the <a href="https://github.com/bazelbuild/rules_rust/tree/main/examples/all_crate_deps">example folder</a>.</p> |
| <pre><code class="language-python">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate") |
| |
| crate.from_cargo( |
| name = "crates", |
| cargo_lockfile = "//:Cargo.lock", |
| manifests = ["//:Cargo.toml"], |
| ) |
| use_repo(crate, "crates") |
| </code></pre> |
| <h4 id="note-if-using-private-crate-registries"><a class="header" href="#note-if-using-private-crate-registries">Note if using Private Crate Registries</a></h4> |
| <p>If you are using from_cargo and are pulling dependencies from a private crate registry such as Artifactory, |
| make sure you set the <code>CARGO_BAZEL_ISOLATED=false bazel build //...</code> environmental. If not <code>crates_universe</code> |
| will not be able to pull from your private registry.</p> |
| <p>The generated crates_repository contains helper macros which make collecting dependencies for Bazel targets simpler. |
| Notably, the all_crate_deps, aliases, and crate_edition macros ( |
| see <a href="https://bazelbuild.github.io/rules_rust/crate_universe_workspace.html#dependencies-api">Dependencies API</a>) commonly allow the |
| Cargo.toml files to be the single source of truth for dependencies. |
| Since these macros come from the generated repository, the dependency labels, |
| alias definitions, and editions they return will automatically update BUILD targets. In your BUILD files, |
| you use these macros for a Rust library as shown below:</p> |
| <pre><code class="language-python">load("@crates//:defs.bzl", "aliases", "all_crate_deps", "crate_edition") |
| load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") |
| |
| rust_library( |
| name = "lib", |
| aliases = aliases(), |
| edition = crate_edition(), |
| deps = all_crate_deps( |
| normal = True, |
| ), |
| proc_macro_deps = all_crate_deps( |
| proc_macro = True, |
| ), |
| ) |
| |
| rust_test( |
| name = "unit_test", |
| crate = ":lib", |
| aliases = aliases( |
| normal_dev = True, |
| proc_macro_dev = True, |
| ), |
| edition = crate_edition(), |
| deps = all_crate_deps( |
| normal_dev = True, |
| ), |
| proc_macro_deps = all_crate_deps( |
| proc_macro_dev = True, |
| ), |
| ) |
| </code></pre> |
| <p>For a Rust binary that does not depend on any macro, use the following configuration |
| in your build file:</p> |
| <pre><code class="language-python">rust_binary( |
| name = "bin", |
| srcs = ["src/main.rs"], |
| edition = crate_edition(), |
| deps = all_crate_deps(normal = True), |
| ) |
| </code></pre> |
| <p>You have to repin before your first build to ensure all Bazel targets for the macros |
| are generated.</p> |
| <p>Dependency syncing and updating is done in the repository rule which means it's done during the |
| analysis phase of builds. As mentioned in the environments variable table above, the <code>CARGO_BAZEL_REPIN</code> |
| (or <code>REPIN</code>) environment variables can be used to force the rule to update dependencies and potentially |
| render a new lockfile. Given an instance of this repository rule named <code>crates</code>, the easiest way to |
| repin dependencies is to run:</p> |
| <pre><code class="language-shell">CARGO_BAZEL_REPIN=1 bazel sync --only=crates |
| </code></pre> |
| <p>This will result in all dependencies being updated for a project. The <code>CARGO_BAZEL_REPIN</code> |
| environment variable can also be used to customize how dependencies are updated. |
| For more details about repin, <a href="https://bazelbuild.github.io/rules_rust/crate_universe_workspace.html#crates_vendor">please refer to the documentation</a>.</p> |
| <h3 id="direct-dependencies"><a class="header" href="#direct-dependencies">Direct Dependencies</a></h3> |
| <p>In cases where Rust targets have heavy interactions with other Bazel targets (<a href="https://docs.bazel.build/versions/main/be/c-cpp.html">Cc</a>, <a href="https://rules-proto-grpc.com/en/4.5.0/lang/rust.html">Proto</a>, |
| etc.), maintaining Cargo.toml files may have diminishing returns as things like rust-analyzer |
| begin to be confused about missing targets or environment variables defined only in Bazel. |
| In situations like this, it may be desirable to have a "Cargo free" setup. You find an example in the in the <a href="https://github.com/bazelbuild/rules_rust/tree/main/examples/hello_world_no_cargo">example folder</a>.</p> |
| <p>crates_repository supports this through the packages attribute, |
| as shown below.</p> |
| <pre><code class="language-python">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate") |
| |
| crate.spec(package = "serde", features = ["derive"], version = "1.0") |
| crate.spec(package = "serde_json", version = "1.0") |
| crate.spec(package = "tokio", default_features = False, features = ["macros", "net", "rt-multi-thread"], version = "1.38") |
| |
| crate.from_specs() |
| use_repo(crate, "crates") |
| </code></pre> |
| <p>Consuming dependencies may be more ergonomic in this case through the aliases defined in the new repository. |
| In your BUILD files, you use direct dependencies as shown below:</p> |
| <pre><code class="language-python">rust_binary( |
| name = "bin", |
| crate_root = "src/main.rs", |
| srcs = glob([ |
| "src/*.rs", |
| ]), |
| deps = [ |
| # External crates |
| "@crates//:serde", |
| "@crates//:serde_json", |
| "@crates//:tokio", |
| ], |
| visibility = ["//visibility:public"], |
| ) |
| </code></pre> |
| <p>Notice, direct dependencies do not need repining. |
| Only a cargo workspace needs updating whenever the underlying Cargo.toml file changed.</p> |
| <h3 id="binary-dependencies"><a class="header" href="#binary-dependencies">Binary Dependencies</a></h3> |
| <p>With cargo you <code>can install</code> binary dependencies (bindeps) as well with <code>cargo install</code> command.</p> |
| <p>We don't have such easy facilities available in bazel besides specifying it as a dependency. |
| To mimic cargo's bindeps feature we use the unstable feature called <a href="https://doc.rust-lang.org/nightly/cargo/reference/unstable.html?highlight=feature#artifact-dependencies">artifact-dependencies</a> |
| which integrates well with bazel concepts.</p> |
| <p>You could use the syntax specified in the above document to place it in <code>Cargo.toml</code>. For that you can consult the following <a href="https://github.com/bazelbuild/rules_rust/blob/main/crate_universe/tests/integration/cargo_bindeps/MODULE.bazel">example</a>.</p> |
| <p>This method has the following consequences:</p> |
| <ul> |
| <li>if you use shared dependency tree with your project these binary dependencies will interfere with yours (may conflict)</li> |
| <li>you have to use nightly <code>host_tools</code> to generate dependencies because</li> |
| </ul> |
| <p>Alternatively you can specify this in a separate <code>repo</code> with <code>cargo.from_specs</code> syntax:</p> |
| <pre><code class="language-python">bindeps = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate") |
| |
| bindeps.spec(package = "cargo-machete", version = "=0.7.0", artifact = "bin") |
| bindeps.annotation(crate = "cargo-machete", gen_all_binaries = True) |
| |
| bindeps.from_specs( |
| name = "bindeps", |
| host_tools = "@rust_host_tools_nightly", |
| ) |
| |
| use_repo(bindeps, "bindeps") |
| </code></pre> |
| <p>You can run the specified binary dependency with the following command or create additional more complex rules on top of it.</p> |
| <pre><code class="language-bash">bazel run @bindeps//:cargo-machete__cargo-machete |
| </code></pre> |
| <p>Notice, direct dependencies do not need repining. |
| Only a cargo workspace needs updating whenever the underlying Cargo.toml file changed.</p> |
| <h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">Vendored Dependencies</a></h3> |
| <p>In some cases, it is require that all external dependencies are vendored, meaning downloaded |
| and stored in the workspace. This helps, for example, to conduct licence scans, apply custom patches, |
| or to ensure full build reproducibility since no download error could possibly occur. |
| You find a complete example in the in the <a href="https://github.com/bazelbuild/rules_rust/tree/main/examples/all_deps_vendor">example folder</a>.</p> |
| <p>For the setup, you need to add the skylib in addition to the rust rules to your <code>MODULE.bazel</code>.</p> |
| <pre><code class="language-python">module( |
| name = "deps_vendored", |
| version = "0.0.0" |
| ) |
| ############################################################################### |
| # B A Z E L C E N T R A L R E G I S T R Y # https://registry.bazel.build/ |
| ############################################################################### |
| # https://github.com/bazelbuild/bazel-skylib/releases/ |
| bazel_dep(name = "bazel_skylib", version = "1.8.2") |
| |
| # https://github.com/bazelbuild/rules_rust/releases |
| bazel_dep(name = "rules_rust", version = "0.70.0") |
| |
| ############################################################################### |
| # T O O L C H A I N S |
| ############################################################################### |
| |
| # Rust toolchain |
| RUST_EDITION = "2021" |
| RUST_VERSION = "1.80.1" |
| |
| rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") |
| rust.toolchain( |
| edition = RUST_EDITION, |
| versions = [RUST_VERSION], |
| ) |
| use_repo(rust, "rust_toolchains") |
| register_toolchains("@rust_toolchains//:all") |
| |
| ############################################################################### |
| # R U S T C R A T E S |
| ############################################################################### |
| crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate") |
| </code></pre> |
| <p>Note, it is important to load the crate_universe rules otherwise you will get an error |
| as the rule set is needed in the vendored target.</p> |
| <p>Assuming you have a package called <code>basic</code> in which you want to vendor dependencies, |
| then you create a folder <code>basic/3rdparty</code>. The folder name can be arbitrary, |
| but by convention, its either thirdparty or 3rdparty to indicate vendored dependencies. |
| In the 3rdparty folder, you add a target crates_vendor to declare your dependencies to vendor. |
| In the example, we vendor a specific version of bzip2.</p> |
| <pre><code class="language-python">load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor") |
| |
| crates_vendor( |
| name = "crates_vendor", |
| annotations = { |
| "bzip2-sys": [crate.annotation( |
| gen_build_script = True, |
| )], |
| }, |
| cargo_lockfile = "Cargo.Bazel.lock", |
| generate_build_scripts = False, |
| mode = "remote", |
| packages = { |
| "bzip2": crate.spec( |
| version = "=0.3.3", |
| ), |
| }, |
| repository_name = "basic", |
| tags = ["manual"], |
| ) |
| </code></pre> |
| <p>Next, you have to run <code>Cargo build</code> to generate a Cargo.lock file with all resolved dependencies. |
| Then, you rename Cargo.lock to Cargo.Bazel.lock and place it inside the <code>basic/3rdparty</code> folder.</p> |
| <p>At this point, you have the following folder and files:</p> |
| <pre><code>basic |
| |-- 3rdparty |
| | |-- BUILD.bazel |
| | |-- Cargo.Bazel.lock |
| </code></pre> |
| <p>Now you can run the <code>crates_vendor</code> target:</p> |
| <p><code>bazel run //basic/3rdparty:crates_vendor</code></p> |
| <p>This generates a crate folders with all configurations for the vendored dependencies.</p> |
| <pre><code>basic |
| |-- 3rdparty |
| | |-- cratea |
| | |-- BUILD.bazel |
| | |-- Cargo.Bazel.lock |
| </code></pre> |
| <p>Suppose you have an application in <code>basic/src</code> that is defined in <code>basic/BUILD.bazel</code> and |
| that depends on a vendored dependency. You find a list of all available vendored dependencies |
| in the BUILD file of the generated folder: <code>basic/3rdparty/crates/BUILD.bazel</code> |
| You declare a vendored dependency in you target as following:</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_binary") |
| |
| rust_binary( |
| name = "hello_sys", |
| srcs = ["src/main.rs"], |
| deps = ["//basic/3rdparty/crates:bzip2"], |
| visibility = ["//visibility:public"], |
| ) |
| </code></pre> |
| <p>Note, the vendored dependency is not yet accessible because you have to define first |
| how to load the vendored dependencies. For that, you first create a file <code>sys_deps.bzl</code> |
| and add the following content:</p> |
| <pre><code class="language-python"># rename the default name "crate_repositories" in case you import multiple vendored folders. |
| load("//basic/3rdparty/crates:defs.bzl", basic_crate_repositories = "crate_repositories") |
| |
| def sys_deps(): |
| # Load the vendored dependencies |
| basic_crate_repositories() |
| </code></pre> |
| <p>This is straightforward, you import the generated crate_repositories from the crates folder, |
| rename it to avoid name clashes in case you import from multiple vendored folders, and then |
| just load the vendored dependencies.</p> |
| <p>In a WORKSPACE configuration, you would just load and call sys_deps(), but in a MODULE configuration, you cannot do that. |
| Instead, you create a new file <code>WORKSPACE.bzlmod</code> and add the following content.</p> |
| <pre><code class="language-python">load("//:sys_deps.bzl", "sys_deps") |
| sys_deps() |
| </code></pre> |
| <p>Now, you can build the project as usual.</p> |
| <p>There are some more examples of using crate_universe with bzlmod in the <a href="https://github.com/bazelbuild/rules_rust/blob/main/examples/">example folder</a>.</p> |
| <p><a id="crate"></a></p> |
| <h2 id="crate"><a class="header" href="#crate">crate</a></h2> |
| <pre> |
| crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate") |
| crate.annotation(<a href="crate_universe_bzlmod.html#crate.annotation-deps">deps</a>, <a href="crate_universe_bzlmod.html#crate.annotation-data">data</a>, <a href="crate_universe_bzlmod.html#crate.annotation-additive_build_file">additive_build_file</a>, <a href="crate_universe_bzlmod.html#crate.annotation-additive_build_file_content">additive_build_file_content</a>, <a href="crate_universe_bzlmod.html#crate.annotation-alias_rule">alias_rule</a>, |
| <a href="crate_universe_bzlmod.html#crate.annotation-build_script_compile_data">build_script_compile_data</a>, <a href="crate_universe_bzlmod.html#crate.annotation-build_script_data">build_script_data</a>, <a href="crate_universe_bzlmod.html#crate.annotation-build_script_data_glob">build_script_data_glob</a>, |
| <a href="crate_universe_bzlmod.html#crate.annotation-build_script_deps">build_script_deps</a>, <a href="crate_universe_bzlmod.html#crate.annotation-build_script_env">build_script_env</a>, <a href="crate_universe_bzlmod.html#crate.annotation-build_script_exec_properties">build_script_exec_properties</a>, |
| <a href="crate_universe_bzlmod.html#crate.annotation-build_script_link_deps">build_script_link_deps</a>, <a href="crate_universe_bzlmod.html#crate.annotation-build_script_proc_macro_deps">build_script_proc_macro_deps</a>, <a href="crate_universe_bzlmod.html#crate.annotation-build_script_rundir">build_script_rundir</a>, |
| <a href="crate_universe_bzlmod.html#crate.annotation-build_script_rustc_env">build_script_rustc_env</a>, <a href="crate_universe_bzlmod.html#crate.annotation-build_script_toolchains">build_script_toolchains</a>, <a href="crate_universe_bzlmod.html#crate.annotation-build_script_tools">build_script_tools</a>, <a href="crate_universe_bzlmod.html#crate.annotation-compile_data">compile_data</a>, |
| <a href="crate_universe_bzlmod.html#crate.annotation-compile_data_glob">compile_data_glob</a>, <a href="crate_universe_bzlmod.html#crate.annotation-compile_data_glob_excludes">compile_data_glob_excludes</a>, <a href="crate_universe_bzlmod.html#crate.annotation-crate">crate</a>, <a href="crate_universe_bzlmod.html#crate.annotation-crate_features">crate_features</a>, <a href="crate_universe_bzlmod.html#crate.annotation-data_glob">data_glob</a>, |
| <a href="crate_universe_bzlmod.html#crate.annotation-disable_pipelining">disable_pipelining</a>, <a href="crate_universe_bzlmod.html#crate.annotation-extra_aliased_targets">extra_aliased_targets</a>, <a href="crate_universe_bzlmod.html#crate.annotation-gen_all_binaries">gen_all_binaries</a>, <a href="crate_universe_bzlmod.html#crate.annotation-gen_binaries">gen_binaries</a>, |
| <a href="crate_universe_bzlmod.html#crate.annotation-gen_build_script">gen_build_script</a>, <a href="crate_universe_bzlmod.html#crate.annotation-override_target_bin">override_target_bin</a>, <a href="crate_universe_bzlmod.html#crate.annotation-override_target_build_script">override_target_build_script</a>, |
| <a href="crate_universe_bzlmod.html#crate.annotation-override_target_lib">override_target_lib</a>, <a href="crate_universe_bzlmod.html#crate.annotation-override_target_proc_macro">override_target_proc_macro</a>, <a href="crate_universe_bzlmod.html#crate.annotation-patch_args">patch_args</a>, <a href="crate_universe_bzlmod.html#crate.annotation-patch_tool">patch_tool</a>, <a href="crate_universe_bzlmod.html#crate.annotation-patches">patches</a>, |
| <a href="crate_universe_bzlmod.html#crate.annotation-proc_macro_deps">proc_macro_deps</a>, <a href="crate_universe_bzlmod.html#crate.annotation-repositories">repositories</a>, <a href="crate_universe_bzlmod.html#crate.annotation-rustc_env">rustc_env</a>, <a href="crate_universe_bzlmod.html#crate.annotation-rustc_env_files">rustc_env_files</a>, <a href="crate_universe_bzlmod.html#crate.annotation-rustc_flags">rustc_flags</a>, |
| <a href="crate_universe_bzlmod.html#crate.annotation-shallow_since">shallow_since</a>, <a href="crate_universe_bzlmod.html#crate.annotation-version">version</a>) |
| crate.annotation_select(<a href="crate_universe_bzlmod.html#crate.annotation_select-deps">deps</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-data">data</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-build_script_compile_data">build_script_compile_data</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-build_script_data">build_script_data</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-build_script_deps">build_script_deps</a>, |
| <a href="crate_universe_bzlmod.html#crate.annotation_select-build_script_env">build_script_env</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-build_script_exec_properties">build_script_exec_properties</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-build_script_link_deps">build_script_link_deps</a>, |
| <a href="crate_universe_bzlmod.html#crate.annotation_select-build_script_proc_macro_deps">build_script_proc_macro_deps</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-build_script_rundir">build_script_rundir</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-build_script_rustc_env">build_script_rustc_env</a>, |
| <a href="crate_universe_bzlmod.html#crate.annotation_select-build_script_tools">build_script_tools</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-compile_data">compile_data</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-crate">crate</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-crate_features">crate_features</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-proc_macro_deps">proc_macro_deps</a>, |
| <a href="crate_universe_bzlmod.html#crate.annotation_select-repositories">repositories</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-rustc_env">rustc_env</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-rustc_env_files">rustc_env_files</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-rustc_flags">rustc_flags</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-triples">triples</a>, <a href="crate_universe_bzlmod.html#crate.annotation_select-version">version</a>) |
| crate.from_cargo(<a href="crate_universe_bzlmod.html#crate.from_cargo-name">name</a>, <a href="crate_universe_bzlmod.html#crate.from_cargo-cargo_config">cargo_config</a>, <a href="crate_universe_bzlmod.html#crate.from_cargo-cargo_lockfile">cargo_lockfile</a>, <a href="crate_universe_bzlmod.html#crate.from_cargo-generate_binaries">generate_binaries</a>, <a href="crate_universe_bzlmod.html#crate.from_cargo-generate_build_scripts">generate_build_scripts</a>, |
| <a href="crate_universe_bzlmod.html#crate.from_cargo-host_tools">host_tools</a>, <a href="crate_universe_bzlmod.html#crate.from_cargo-isolated">isolated</a>, <a href="crate_universe_bzlmod.html#crate.from_cargo-lockfile">lockfile</a>, <a href="crate_universe_bzlmod.html#crate.from_cargo-manifests">manifests</a>, <a href="crate_universe_bzlmod.html#crate.from_cargo-skip_cargo_lockfile_overwrite">skip_cargo_lockfile_overwrite</a>, |
| <a href="crate_universe_bzlmod.html#crate.from_cargo-strip_internal_dependencies_from_cargo_lockfile">strip_internal_dependencies_from_cargo_lockfile</a>, <a href="crate_universe_bzlmod.html#crate.from_cargo-supported_platform_triples">supported_platform_triples</a>) |
| crate.from_specs(<a href="crate_universe_bzlmod.html#crate.from_specs-name">name</a>, <a href="crate_universe_bzlmod.html#crate.from_specs-cargo_config">cargo_config</a>, <a href="crate_universe_bzlmod.html#crate.from_specs-cargo_lockfile">cargo_lockfile</a>, <a href="crate_universe_bzlmod.html#crate.from_specs-generate_binaries">generate_binaries</a>, <a href="crate_universe_bzlmod.html#crate.from_specs-generate_build_scripts">generate_build_scripts</a>, |
| <a href="crate_universe_bzlmod.html#crate.from_specs-host_tools">host_tools</a>, <a href="crate_universe_bzlmod.html#crate.from_specs-isolated">isolated</a>, <a href="crate_universe_bzlmod.html#crate.from_specs-lockfile">lockfile</a>, <a href="crate_universe_bzlmod.html#crate.from_specs-skip_cargo_lockfile_overwrite">skip_cargo_lockfile_overwrite</a>, |
| <a href="crate_universe_bzlmod.html#crate.from_specs-strip_internal_dependencies_from_cargo_lockfile">strip_internal_dependencies_from_cargo_lockfile</a>, <a href="crate_universe_bzlmod.html#crate.from_specs-supported_platform_triples">supported_platform_triples</a>) |
| crate.render_config(<a href="crate_universe_bzlmod.html#crate.render_config-build_file_template">build_file_template</a>, <a href="crate_universe_bzlmod.html#crate.render_config-crate_alias_template">crate_alias_template</a>, <a href="crate_universe_bzlmod.html#crate.render_config-crate_label_template">crate_label_template</a>, |
| <a href="crate_universe_bzlmod.html#crate.render_config-crate_repository_template">crate_repository_template</a>, <a href="crate_universe_bzlmod.html#crate.render_config-crates_module_template">crates_module_template</a>, <a href="crate_universe_bzlmod.html#crate.render_config-default_alias_rule_bzl">default_alias_rule_bzl</a>, |
| <a href="crate_universe_bzlmod.html#crate.render_config-default_alias_rule_name">default_alias_rule_name</a>, <a href="crate_universe_bzlmod.html#crate.render_config-default_package_name">default_package_name</a>, <a href="crate_universe_bzlmod.html#crate.render_config-generate_cargo_toml_env_vars">generate_cargo_toml_env_vars</a>, |
| <a href="crate_universe_bzlmod.html#crate.render_config-generate_rules_license_metadata">generate_rules_license_metadata</a>, <a href="crate_universe_bzlmod.html#crate.render_config-generate_target_compatible_with">generate_target_compatible_with</a>, |
| <a href="crate_universe_bzlmod.html#crate.render_config-platforms_template">platforms_template</a>, <a href="crate_universe_bzlmod.html#crate.render_config-regen_command">regen_command</a>, <a href="crate_universe_bzlmod.html#crate.render_config-repositories">repositories</a>, <a href="crate_universe_bzlmod.html#crate.render_config-vendor_mode">vendor_mode</a>) |
| crate.spec(<a href="crate_universe_bzlmod.html#crate.spec-artifact">artifact</a>, <a href="crate_universe_bzlmod.html#crate.spec-branch">branch</a>, <a href="crate_universe_bzlmod.html#crate.spec-default_features">default_features</a>, <a href="crate_universe_bzlmod.html#crate.spec-features">features</a>, <a href="crate_universe_bzlmod.html#crate.spec-git">git</a>, <a href="crate_universe_bzlmod.html#crate.spec-lib">lib</a>, <a href="crate_universe_bzlmod.html#crate.spec-package">package</a>, <a href="crate_universe_bzlmod.html#crate.spec-package_alias">package_alias</a>, <a href="crate_universe_bzlmod.html#crate.spec-path">path</a>, |
| <a href="crate_universe_bzlmod.html#crate.spec-repositories">repositories</a>, <a href="crate_universe_bzlmod.html#crate.spec-rev">rev</a>, <a href="crate_universe_bzlmod.html#crate.spec-tag">tag</a>, <a href="crate_universe_bzlmod.html#crate.spec-version">version</a>) |
| crate.splicing_config(<a href="crate_universe_bzlmod.html#crate.splicing_config-repositories">repositories</a>, <a href="crate_universe_bzlmod.html#crate.splicing_config-resolver_version">resolver_version</a>) |
| </pre> |
| <p>Crate universe module extensions.</p> |
| <p>Environment Variables:</p> |
| <div class="table-wrapper"><table><thead><tr><th>variable</th><th>usage</th></tr></thead><tbody> |
| <tr><td><code>CARGO_BAZEL_GENERATOR_SHA256</code></td><td>The sha256 checksum of the file located at <code>CARGO_BAZEL_GENERATOR_URL</code></td></tr> |
| <tr><td><code>CARGO_BAZEL_GENERATOR_URL</code></td><td>The URL of a cargo-bazel binary. This variable takes precedence over attributes and can use <code>file://</code> for local paths</td></tr> |
| <tr><td><code>CARGO_BAZEL_ISOLATED</code></td><td>An authoritative flag as to whether or not the <code>CARGO_HOME</code> environment variable should be isolated from the host configuration</td></tr> |
| <tr><td><code>CARGO_BAZEL_REPIN</code></td><td>An indicator that the dependencies represented by the rule should be regenerated. <code>REPIN</code> may also be used. See <a href="crate_universe_workspace.html#repinning--updating-dependencies">Repinning / Updating Dependencies</a> for more details.</td></tr> |
| <tr><td><code>CARGO_BAZEL_REPIN_ONLY</code></td><td>A comma-delimited allowlist for rules to execute repinning. Can be useful if multiple instances of the repository rule are used in a Bazel workspace, but repinning should be limited to one of them.</td></tr> |
| <tr><td><code>CARGO_BAZEL_TIMEOUT</code></td><td>An integer value to override the default timeout setting when running the cargo-bazel binary. This value must be in seconds.</td></tr> |
| </tbody></table> |
| </div> |
| <p><strong>TAG CLASSES</strong></p> |
| <p><a id="crate.annotation"></a></p> |
| <h3 id="annotation"><a class="header" href="#annotation">annotation</a></h3> |
| <p>A collection of extra attributes and settings for a particular crate.</p> |
| <p><strong>Attributes</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="crate.annotation-deps"></a>deps</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::deps</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-data"></a>data</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-additive_build_file"></a>additive_build_file</td><td style="text-align: left">A file containing extra contents to write to the bottom of generated BUILD files.</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> |
| <tr><td style="text-align: left"><a id="crate.annotation-additive_build_file_content"></a>additive_build_file_content</td><td style="text-align: left">Extra contents to write to the bottom of generated BUILD files.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-alias_rule"></a>alias_rule</td><td style="text-align: left">Alias rule to use instead of <code>native.alias()</code>. Overrides <a href="crate_universe_bzlmod.html#render_config">render_config</a>'s 'default_alias_rule'.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-build_script_compile_data"></a>build_script_compile_data</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::compile_data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-build_script_data"></a>build_script_data</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-build_script_data_glob"></a>build_script_data_glob</td><td style="text-align: left">A list of glob patterns to add to a crate's <code>cargo_build_script::data</code> attribute</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-build_script_deps"></a>build_script_deps</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::deps</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-build_script_env"></a>build_script_env</td><td style="text-align: left">Additional environment variables to set on a crate's <code>cargo_build_script::env</code> attribute.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-build_script_exec_properties"></a>build_script_exec_properties</td><td style="text-align: left">Execution properties to set on a crate's <code>cargo_build_script::exec_properties</code> attribute.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-build_script_link_deps"></a>build_script_link_deps</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::link_deps</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-build_script_proc_macro_deps"></a>build_script_proc_macro_deps</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::proc_macro_deps</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-build_script_rundir"></a>build_script_rundir</td><td style="text-align: left">An override for the build script's rundir attribute.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-build_script_rustc_env"></a>build_script_rustc_env</td><td style="text-align: left">Additional environment variables to set on a crate's <code>cargo_build_script::env</code> attribute.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-build_script_toolchains"></a>build_script_toolchains</td><td style="text-align: left">A list of labels to set on a crates's <code>cargo_build_script::toolchains</code> attribute.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-build_script_tools"></a>build_script_tools</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::tools</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-compile_data"></a>compile_data</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::compile_data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-compile_data_glob"></a>compile_data_glob</td><td style="text-align: left">A list of glob patterns to add to a crate's <code>rust_library::compile_data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-compile_data_glob_excludes"></a>compile_data_glob_excludes</td><td style="text-align: left">A list of glob patterns to be excllued from a crate's <code>rust_library::compile_data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-crate"></a>crate</td><td style="text-align: left">The name of the crate the annotation is applied to</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-crate_features"></a>crate_features</td><td style="text-align: left">A list of strings to add to a crate's <code>rust_library::crate_features</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-data_glob"></a>data_glob</td><td style="text-align: left">A list of glob patterns to add to a crate's <code>rust_library::data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-disable_pipelining"></a>disable_pipelining</td><td style="text-align: left">If True, disables pipelining for library targets for this crate.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-extra_aliased_targets"></a>extra_aliased_targets</td><td style="text-align: left">A list of targets to add to the generated aliases in the root crate_universe repository.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-gen_all_binaries"></a>gen_all_binaries</td><td style="text-align: left">If true, generates <code>rust_binary</code> targets for all of the crates bins</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-gen_binaries"></a>gen_binaries</td><td style="text-align: left">As a list, the subset of the crate's bins that should get <code>rust_binary</code> targets produced.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-gen_build_script"></a>gen_build_script</td><td style="text-align: left">An authoritative flag to determine whether or not to produce <code>cargo_build_script</code> targets for the current crate. Supported values are 'on', 'off', and 'auto'.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"auto"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-override_target_bin"></a>override_target_bin</td><td style="text-align: left">An optional alternate target to use when something depends on this crate to allow the parent repo to provide its own version of this dependency.</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> |
| <tr><td style="text-align: left"><a id="crate.annotation-override_target_build_script"></a>override_target_build_script</td><td style="text-align: left">An optional alternate target to use when something depends on this crate to allow the parent repo to provide its own version of this dependency.</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> |
| <tr><td style="text-align: left"><a id="crate.annotation-override_target_lib"></a>override_target_lib</td><td style="text-align: left">An optional alternate target to use when something depends on this crate to allow the parent repo to provide its own version of this dependency.</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> |
| <tr><td style="text-align: left"><a id="crate.annotation-override_target_proc_macro"></a>override_target_proc_macro</td><td style="text-align: left">An optional alternate target to use when something depends on this crate to allow the parent repo to provide its own version of this dependency.</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> |
| <tr><td style="text-align: left"><a id="crate.annotation-patch_args"></a>patch_args</td><td style="text-align: left">The <code>patch_args</code> attribute of a Bazel repository rule. See <a href="https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_args">http_archive.patch_args</a></td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-patch_tool"></a>patch_tool</td><td style="text-align: left">The <code>patch_tool</code> attribute of a Bazel repository rule. See <a href="https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_tool">http_archive.patch_tool</a></td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-patches"></a>patches</td><td style="text-align: left">The <code>patches</code> attribute of a Bazel repository rule. See <a href="https://docs.bazel.build/versions/main/repo/http.html#http_archive-patches">http_archive.patches</a></td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::proc_macro_deps</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-repositories"></a>repositories</td><td style="text-align: left">A list of repository names specified from <code>crate.from_cargo(name=...)</code> that this annotation is applied to. Defaults to all repositories.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-rustc_env"></a>rustc_env</td><td style="text-align: left">Additional variables to set on a crate's <code>rust_library::rustc_env</code> attribute.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">A list of labels to set on a crate's <code>rust_library::rustc_env_files</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-rustc_flags"></a>rustc_flags</td><td style="text-align: left">A list of strings to set on a crate's <code>rust_library::rustc_flags</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-shallow_since"></a>shallow_since</td><td style="text-align: left">An optional timestamp used for crates originating from a git repository instead of a crate registry. This flag optimizes fetching the source code.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-version"></a>version</td><td style="text-align: left">The versions of the crate the annotation is applied to. Defaults to all versions.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"*"</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="crate.annotation_select"></a></p> |
| <h3 id="annotation_select"><a class="header" href="#annotation_select">annotation_select</a></h3> |
| <p>A constructor for a crate dependency with selectable attributes.</p> |
| <p><strong>Attributes</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-deps"></a>deps</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::deps</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-data"></a>data</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-build_script_compile_data"></a>build_script_compile_data</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::compile_data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-build_script_data"></a>build_script_data</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-build_script_deps"></a>build_script_deps</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::deps</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-build_script_env"></a>build_script_env</td><td style="text-align: left">Additional environment variables to set on a crate's <code>cargo_build_script::env</code> attribute.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-build_script_exec_properties"></a>build_script_exec_properties</td><td style="text-align: left">Execution properties to set on a crate's <code>cargo_build_script::exec_properties</code> attribute.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-build_script_link_deps"></a>build_script_link_deps</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::link_deps</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-build_script_proc_macro_deps"></a>build_script_proc_macro_deps</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::proc_macro_deps</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-build_script_rundir"></a>build_script_rundir</td><td style="text-align: left">An override for the build script's rundir attribute.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-build_script_rustc_env"></a>build_script_rustc_env</td><td style="text-align: left">Additional environment variables to set on a crate's <code>cargo_build_script::env</code> attribute.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-build_script_tools"></a>build_script_tools</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::tools</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-compile_data"></a>compile_data</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::compile_data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-crate"></a>crate</td><td style="text-align: left">The name of the crate the annotation is applied to</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-crate_features"></a>crate_features</td><td style="text-align: left">A list of strings to add to a crate's <code>rust_library::crate_features</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::proc_macro_deps</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-repositories"></a>repositories</td><td style="text-align: left">A list of repository names specified from <code>crate.from_cargo(name=...)</code> that this annotation is applied to. Defaults to all repositories.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-rustc_env"></a>rustc_env</td><td style="text-align: left">Additional variables to set on a crate's <code>rust_library::rustc_env</code> attribute.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">A list of labels to set on a crate's <code>rust_library::rustc_env_files</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-rustc_flags"></a>rustc_flags</td><td style="text-align: left">A list of strings to set on a crate's <code>rust_library::rustc_flags</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-triples"></a>triples</td><td style="text-align: left">A list of triples to apply the annotation to.</td><td style="text-align: left">List of strings</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation_select-version"></a>version</td><td style="text-align: left">The versions of the crate the annotation is applied to. Defaults to all versions.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"*"</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="crate.from_cargo"></a></p> |
| <h3 id="from_cargo"><a class="header" href="#from_cargo">from_cargo</a></h3> |
| <p>Generates a repo @crates from a Cargo.toml / Cargo.lock pair.</p> |
| <p><strong>Attributes</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="crate.from_cargo-name"></a>name</td><td style="text-align: left">The name of the repo to generate</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"crates"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.from_cargo-cargo_config"></a>cargo_config</td><td style="text-align: left">A <a href="https://doc.rust-lang.org/cargo/reference/config.html">Cargo configuration</a> file.</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> |
| <tr><td style="text-align: left"><a id="crate.from_cargo-cargo_lockfile"></a>cargo_lockfile</td><td style="text-align: left">The path to an existing <code>Cargo.lock</code> file</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> |
| <tr><td style="text-align: left"><a id="crate.from_cargo-generate_binaries"></a>generate_binaries</td><td style="text-align: left">Whether to generate <code>rust_binary</code> targets for all the binary crates in every package. By default only the <code>rust_library</code> targets are generated.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.from_cargo-generate_build_scripts"></a>generate_build_scripts</td><td style="text-align: left">Whether or not to generate <a href="https://doc.rust-lang.org/cargo/reference/build-scripts.html">cargo build scripts</a> by default.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.from_cargo-host_tools"></a>host_tools</td><td style="text-align: left">The <code>rust_host_tools</code> repository to use.</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>"@@rules_rust++rust_host_tools+rust_host_tools//:rust_host_tools"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.from_cargo-isolated"></a>isolated</td><td style="text-align: left">If true, <code>CARGO_HOME</code> will be overwritten to a directory within the generated repository in order to prevent other uses of Cargo from impacting having any effect on the generated targets produced by this rule. For users who either have multiple <code>crate_repository</code> definitions in a WORKSPACE or rapidly re-pin dependencies, setting this to false may improve build times. This variable is also controlled by <code>CARGO_BAZEL_ISOLATED</code> environment variable.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.from_cargo-lockfile"></a>lockfile</td><td style="text-align: left">The path to a file to use for reproducible renderings. If set, this file must exist within the workspace (but can be empty) before this rule will work.</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> |
| <tr><td style="text-align: left"><a id="crate.from_cargo-manifests"></a>manifests</td><td style="text-align: left">A list of Cargo manifests (<code>Cargo.toml</code> files).</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.from_cargo-skip_cargo_lockfile_overwrite"></a>skip_cargo_lockfile_overwrite</td><td style="text-align: left">Whether to skip writing the cargo lockfile back after resolving. You may want to set this if your dependency versions are maintained externally through a non-trivial set-up. But you probably don't want to set this.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.from_cargo-strip_internal_dependencies_from_cargo_lockfile"></a>strip_internal_dependencies_from_cargo_lockfile</td><td style="text-align: left">Whether to strip internal dependencies from the cargo lockfile. You may want to use this if you want to maintain a cargo lockfile for bazel only. Bazel only requires external dependencies to be present in the lockfile. By removing internal dependencies, the lockfile changes less frequently which reduces merge conflicts in other lockfiles where the cargo lockfile's sha is stored.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.from_cargo-supported_platform_triples"></a>supported_platform_triples</td><td style="text-align: left">A set of all platform triples to consider when generating dependencies.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>["aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "wasm32-unknown-unknown", "wasm32-wasip1", "x86_64-pc-windows-msvc", "x86_64-unknown-linux-gnu", "x86_64-unknown-nixos-gnu"]</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="crate.from_specs"></a></p> |
| <h3 id="from_specs"><a class="header" href="#from_specs">from_specs</a></h3> |
| <p>Generates a repo @crates from the defined <code>spec</code> tags.</p> |
| <p><strong>Attributes</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="crate.from_specs-name"></a>name</td><td style="text-align: left">The name of the repo to generate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"crates"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.from_specs-cargo_config"></a>cargo_config</td><td style="text-align: left">A <a href="https://doc.rust-lang.org/cargo/reference/config.html">Cargo configuration</a> file.</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> |
| <tr><td style="text-align: left"><a id="crate.from_specs-cargo_lockfile"></a>cargo_lockfile</td><td style="text-align: left">The path to an existing <code>Cargo.lock</code> file</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> |
| <tr><td style="text-align: left"><a id="crate.from_specs-generate_binaries"></a>generate_binaries</td><td style="text-align: left">Whether to generate <code>rust_binary</code> targets for all the binary crates in every package. By default only the <code>rust_library</code> targets are generated.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.from_specs-generate_build_scripts"></a>generate_build_scripts</td><td style="text-align: left">Whether or not to generate <a href="https://doc.rust-lang.org/cargo/reference/build-scripts.html">cargo build scripts</a> by default.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.from_specs-host_tools"></a>host_tools</td><td style="text-align: left">The <code>rust_host_tools</code> repository to use.</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>"@@rules_rust++rust_host_tools+rust_host_tools//:rust_host_tools"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.from_specs-isolated"></a>isolated</td><td style="text-align: left">If true, <code>CARGO_HOME</code> will be overwritten to a directory within the generated repository in order to prevent other uses of Cargo from impacting having any effect on the generated targets produced by this rule. For users who either have multiple <code>crate_repository</code> definitions in a WORKSPACE or rapidly re-pin dependencies, setting this to false may improve build times. This variable is also controlled by <code>CARGO_BAZEL_ISOLATED</code> environment variable.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.from_specs-lockfile"></a>lockfile</td><td style="text-align: left">The path to a file to use for reproducible renderings. If set, this file must exist within the workspace (but can be empty) before this rule will work.</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> |
| <tr><td style="text-align: left"><a id="crate.from_specs-skip_cargo_lockfile_overwrite"></a>skip_cargo_lockfile_overwrite</td><td style="text-align: left">Whether to skip writing the cargo lockfile back after resolving. You may want to set this if your dependency versions are maintained externally through a non-trivial set-up. But you probably don't want to set this.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.from_specs-strip_internal_dependencies_from_cargo_lockfile"></a>strip_internal_dependencies_from_cargo_lockfile</td><td style="text-align: left">Whether to strip internal dependencies from the cargo lockfile. You may want to use this if you want to maintain a cargo lockfile for bazel only. Bazel only requires external dependencies to be present in the lockfile. By removing internal dependencies, the lockfile changes less frequently which reduces merge conflicts in other lockfiles where the cargo lockfile's sha is stored.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.from_specs-supported_platform_triples"></a>supported_platform_triples</td><td style="text-align: left">A set of all platform triples to consider when generating dependencies.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>["aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "wasm32-unknown-unknown", "wasm32-wasip1", "x86_64-pc-windows-msvc", "x86_64-unknown-linux-gnu", "x86_64-unknown-nixos-gnu"]</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="crate.render_config"></a></p> |
| <h3 id="render_config"><a class="header" href="#render_config">render_config</a></h3> |
| <p>Various settings used to configure rendered outputs.</p> |
| <p>The template parameters each support a select number of format keys. A description of each key |
| can be found below where the supported keys for each template can be found in the parameter docs</p> |
| <div class="table-wrapper"><table><thead><tr><th>key</th><th>definition</th></tr></thead><tbody> |
| <tr><td><code>name</code></td><td>The name of the crate. Eg <code>tokio</code></td></tr> |
| <tr><td><code>repository</code></td><td>The rendered repository name for the crate. Directly relates to <code>crate_repository_template</code>.</td></tr> |
| <tr><td><code>triple</code></td><td>A platform triple. Eg <code>x86_64-unknown-linux-gnu</code></td></tr> |
| <tr><td><code>version</code></td><td>The crate version. Eg <code>1.2.3</code></td></tr> |
| <tr><td><code>target</code></td><td>The library or binary target of the crate</td></tr> |
| <tr><td><code>file</code></td><td>The basename of a file</td></tr> |
| </tbody></table> |
| </div> |
| <p><strong>Attributes</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="crate.render_config-build_file_template"></a>build_file_template</td><td style="text-align: left">The base template to use for BUILD file names. The available format keys are [<code>{name}</code>, {version}`].</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"//:BUILD.{name}-{version}.bazel"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.render_config-crate_alias_template"></a>crate_alias_template</td><td style="text-align: left">The base template to use for crate labels. The available format keys are [<code>{repository}</code>, <code>{name}</code>, <code>{version}</code>, <code>{target}</code>].</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@{repository}//:{name}-{version}-{target}"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.render_config-crate_label_template"></a>crate_label_template</td><td style="text-align: left">The base template to use for crate labels. The available format keys are [<code>{repository}</code>, <code>{name}</code>, <code>{version}</code>, <code>{target}</code>].</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@{repository}__{name}-{version}//:{target}"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.render_config-crate_repository_template"></a>crate_repository_template</td><td style="text-align: left">The base template to use for Crate label repository names. The available format keys are [<code>{repository}</code>, <code>{name}</code>, <code>{version}</code>].</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"{repository}__{name}-{version}"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.render_config-crates_module_template"></a>crates_module_template</td><td style="text-align: left">The pattern to use for the <code>defs.bzl</code> and <code>BUILD.bazel</code> file names used for the crates module. The available format keys are [<code>{file}</code>].</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"//:{file}"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.render_config-default_alias_rule_bzl"></a>default_alias_rule_bzl</td><td style="text-align: left">Alias rule to use when generating aliases for all crates. Acceptable values are 'alias', 'dbg'/'fastbuild'/'opt' (transitions each crate's <code>compilation_mode</code>) or a string representing a rule in the form '<label to .bzl>:<rule>' that takes a single label parameter 'actual'. See '@crate_index//:alias_rules.bzl' for an example.</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> |
| <tr><td style="text-align: left"><a id="crate.render_config-default_alias_rule_name"></a>default_alias_rule_name</td><td style="text-align: left">Alias rule to use when generating aliases for all crates. Acceptable values are 'alias', 'dbg'/'fastbuild'/'opt' (transitions each crate's <code>compilation_mode</code>) or a string representing a rule in the form '<label to .bzl>:<rule>' that takes a single label parameter 'actual'. See '@crate_index//:alias_rules.bzl' for an example.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"alias"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.render_config-default_package_name"></a>default_package_name</td><td style="text-align: left">The default package name to use in the rendered macros. This affects the auto package detection of things like <code>all_crate_deps</code>.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.render_config-generate_cargo_toml_env_vars"></a>generate_cargo_toml_env_vars</td><td style="text-align: left">Whether to generate cargo_toml_env_vars targets.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.render_config-generate_rules_license_metadata"></a>generate_rules_license_metadata</td><td style="text-align: left">Whether to generate rules license metadata.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.render_config-generate_target_compatible_with"></a>generate_target_compatible_with</td><td style="text-align: left">Whether to generate <code>target_compatible_with</code> annotations on the generated BUILD files. This catches a <code>target_triple</code> being targeted that isn't declared in <code>supported_platform_triples</code>.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.render_config-platforms_template"></a>platforms_template</td><td style="text-align: left">The base template to use for platform names. See <a href="https://docs.bazel.build/versions/main/platforms.html">platforms documentation</a>. The available format keys are [<code>{triple}</code>].</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rules_rust//rust/platform:{triple}"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.render_config-regen_command"></a>regen_command</td><td style="text-align: left">An optional command to demonstrate how generated files should be regenerated.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.render_config-repositories"></a>repositories</td><td style="text-align: left">A list of repository names specified from <code>crate.from_cargo(name=...)</code> that this annotation is applied to. Defaults to all repositories.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.render_config-vendor_mode"></a>vendor_mode</td><td style="text-align: left">An optional configuration for rendering content to be rendered into repositories.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="crate.spec"></a></p> |
| <h3 id="spec"><a class="header" href="#spec">spec</a></h3> |
| <p>A constructor for a crate dependency.</p> |
| <p><strong>Attributes</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="crate.spec-artifact"></a>artifact</td><td style="text-align: left">Set to 'bin' to pull in a binary crate as an artifact dependency. Requires a nightly Cargo.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.spec-branch"></a>branch</td><td style="text-align: left">The git branch of the remote crate. Tied with the <code>git</code> param. Only one of branch, tag or rev may be specified. Specifying <code>rev</code> is recommended for fully-reproducible builds.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.spec-default_features"></a>default_features</td><td style="text-align: left">Maps to the <code>default-features</code> flag.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.spec-features"></a>features</td><td style="text-align: left">A list of features to use for the crate.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.spec-git"></a>git</td><td style="text-align: left">The Git url to use for the crate. Cannot be used with <code>version</code> or <code>path</code>.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.spec-lib"></a>lib</td><td style="text-align: left">If using <code>artifact = 'bin'</code>, additionally setting <code>lib = True</code> declares a dependency on both the package's library and binary, as opposed to just the binary.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.spec-package"></a>package</td><td style="text-align: left">The explicit name of the package.</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr> |
| <tr><td style="text-align: left"><a id="crate.spec-package_alias"></a>package_alias</td><td style="text-align: left">Alias for the package.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.spec-path"></a>path</td><td style="text-align: left">The local path of the remote crate. Cannot be used with <code>version</code> or <code>git</code>.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.spec-repositories"></a>repositories</td><td style="text-align: left">A list of repository names specified from <code>crate.from_cargo(name=...)</code> that this spec is applied to. Defaults to all repositories.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.spec-rev"></a>rev</td><td style="text-align: left">The git revision of the remote crate. Tied with the <code>git</code> param. Only one of branch, tag or rev may be specified.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.spec-tag"></a>tag</td><td style="text-align: left">The git tag of the remote crate. Tied with the <code>git</code> param. Only one of branch, tag or rev may be specified. Specifying <code>rev</code> is recommended for fully-reproducible builds.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.spec-version"></a>version</td><td style="text-align: left">The exact version of the crate. Cannot be used with <code>git</code> or <code>path</code>.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="crate.splicing_config"></a></p> |
| <h3 id="splicing_config"><a class="header" href="#splicing_config">splicing_config</a></h3> |
| <p>Various settings used to configure Cargo manifest splicing behavior.</p> |
| <p><strong>Attributes</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="crate.splicing_config-repositories"></a>repositories</td><td style="text-align: left">A list of repository names specified from <code>crate.from_cargo(name=...)</code> that this annotation is applied to. Defaults to all repositories.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.splicing_config-resolver_version"></a>resolver_version</td><td style="text-align: left">The <a href="https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions">resolver version</a> to use in generated Cargo manifests. This flag is <strong>only</strong> used when splicing a manifest from direct package definitions. See <code>crates_repository::packages</code></td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"2"</code></td></tr> |
| </tbody></table> |
| </div><div style="break-before: page; page-break-before: always;"></div><h1 id="upstream-tooling"><a class="header" href="#upstream-tooling">Upstream Tooling</a></h1> |
| <p>rules_rust manages versions of things like rustc. If you want to manually run upstream tooling configured at the versions, plugins and such that rules_rust has configured, rules_rust exposes these as targets in <code>@rules_rust//tools/upstream_wrapper</code>:</p> |
| <pre><code class="language-console">% bazel query @rules_rust//tools/upstream_wrapper |
| @rules_rust//tools/upstream_wrapper:cargo |
| @rules_rust//tools/upstream_wrapper:cargo_clippy |
| @rules_rust//tools/upstream_wrapper:rustc |
| @rules_rust//tools/upstream_wrapper:rustfmt |
| </code></pre> |
| <p>You can run them via <code>bazel run</code>, e.g. <code>bazel run @rules_rust//tools/upstream_wrapper:cargo -- check</code>.</p> |
| <div style="break-before: page; page-break-before: always;"></div><h1 id="ide-integrations"><a class="header" href="#ide-integrations">IDE Integrations</a></h1> |
| <h2 id="vscode-1"><a class="header" href="#vscode-1">VSCode</a></h2> |
| <h3 id="intellisense"><a class="header" href="#intellisense">Intellisense</a></h3> |
| <p>The best intellisense integrations to date are documented for <a href="./rust_analyzer.html">rust-analyzer</a>. Please refer to this documentation for setup instructions.</p> |
| <h3 id="debugging"><a class="header" href="#debugging">Debugging</a></h3> |
| <p><code>rules_rust</code> offers tooling to generate VSCode targets for running <code>rust_binary</code> and <code>rust_test</code> targets with a debugger in VSCode.</p> |
| <h4 id="prerequisites"><a class="header" href="#prerequisites">Prerequisites</a></h4> |
| <p>Install <a href="https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb">CodeLLDB</a> extension in VSCode.</p> |
| <h4 id="generate-launch-configurations"><a class="header" href="#generate-launch-configurations">Generate Launch Configurations</a></h4> |
| <p>Generate VSCode <code>launch.json</code> for debugging all Rust targets in the current workspace:</p> |
| <pre><code class="language-bash">bazel run @rules_rust//tools/vscode:gen_launch_json |
| </code></pre> |
| <p>To scope debug generated <code>launch.json</code> targets, query patterns can be passed:</p> |
| <pre><code class="language-bash">bazel run @rules_rust//tools/vscode:gen_launch_json -- //path/to/... |
| </code></pre> |
| <p>Bazel targets should now be available for debugging via the "Run and Debug" menu.</p> |
| <div style="break-before: page; page-break-before: always;"></div><h1 id="extensions"><a class="header" href="#extensions">Extensions</a></h1> |
| <div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build --> |
| <h1 id="rules_rust_bindgen"><a class="header" href="#rules_rust_bindgen">rules_rust_bindgen</a></h1> |
| <p>These rules are for using <a href="https://github.com/rust-lang/rust-bindgen">Bindgen</a> to generate <a href="http://www.rust-lang.org/">Rust</a> bindings to C (and some C++) libraries.</p> |
| <h2 id="rules-8"><a class="header" href="#rules-8">Rules</a></h2> |
| <ul> |
| <li><a href="rust_bindgen.html#rust_bindgen">rust_bindgen</a></li> |
| <li><a href="rust_bindgen.html#rust_bindgen_library">rust_bindgen_library</a></li> |
| <li><a href="rust_bindgen.html#rust_bindgen_toolchain">rust_bindgen_toolchain</a></li> |
| </ul> |
| <h2 id="setup-6"><a class="header" href="#setup-6">Setup</a></h2> |
| <p>To use the Rust bindgen rules, add the following to your <code>MODULE.bazel</code> file:</p> |
| <pre><code class="language-python">bazel_dep(name = "rules_rust_bindgen", version = "{SEE_RELEASE_NOTES}") |
| </code></pre> |
| <p>rules_rust_bindgen does not automatically register a bindgen toolchain. |
| You need to register either your own or the default toolchain by adding the following to your <code>MODULE.bazel</code> file:</p> |
| <pre><code class="language-python">register_toolchains("@rules_rust_bindgen//:default_bindgen_toolchain") |
| </code></pre> |
| <p>The default toolchain builds libclang from source via the <a href="https://registry.bazel.build/modules/llvm-project">llvm-project</a> bazel_dep. |
| <a href="https://github.com/bazelbuild/rules_rust/tree/main/examples/bindgen_toolchain">examples/bindgen_toolchain</a> shows how to use a prebuilt libclang.</p> |
| <p>Bindgen aims to be as hermetic as possible so will end up building <code>libclang</code> from <a href="https://github.com/llvm/llvm-project">llvm-project</a> from |
| source. If this is found to be undesirable, users should define their own repositories using something akin to |
| <a href="https://bazelbuild.github.io/rules_rust/crate_universe_bzlmod.html">crate_universe</a> and define their own toolchains following the instructions for |
| <a href="rust_bindgen.html#rust_bindgen_toolchain">rust_bindgen_toolchain</a>.</p> |
| <hr /> |
| <hr /> |
| <p><a id="rust_bindgen"></a></p> |
| <h2 id="rust_bindgen"><a class="header" href="#rust_bindgen">rust_bindgen</a></h2> |
| <pre> |
| load("@rules_rust_bindgen//:defs.bzl", "rust_bindgen") |
| |
| rust_bindgen(<a href="rust_bindgen.html#rust_bindgen-name">name</a>, <a href="rust_bindgen.html#rust_bindgen-bindgen_flags">bindgen_flags</a>, <a href="rust_bindgen.html#rust_bindgen-cc_lib">cc_lib</a>, <a href="rust_bindgen.html#rust_bindgen-clang_flags">clang_flags</a>, <a href="rust_bindgen.html#rust_bindgen-header">header</a>, <a href="rust_bindgen.html#rust_bindgen-merge_cc_lib_objects_into_rlib">merge_cc_lib_objects_into_rlib</a>, |
| <a href="rust_bindgen.html#rust_bindgen-wrap_static_fns">wrap_static_fns</a>) |
| </pre> |
| <p>Generates a rust source file from a cc_library and a header.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_bindgen-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> |
| <tr><td style="text-align: left"><a id="rust_bindgen-bindgen_flags"></a>bindgen_flags</td><td style="text-align: left">Flags to pass directly to the bindgen executable. See https://rust-lang.github.io/rust-bindgen/ for details.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_bindgen-cc_lib"></a>cc_lib</td><td style="text-align: left">The cc_library that contains the <code>.h</code> file. This is used to find the transitive includes.</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> |
| <tr><td style="text-align: left"><a id="rust_bindgen-clang_flags"></a>clang_flags</td><td style="text-align: left">Flags to pass directly to the clang executable.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_bindgen-header"></a>header</td><td style="text-align: left">The <code>.h</code> file to generate bindings for.</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> |
| <tr><td style="text-align: left"><a id="rust_bindgen-merge_cc_lib_objects_into_rlib"></a>merge_cc_lib_objects_into_rlib</td><td style="text-align: left">When True, objects from <code>cc_lib</code> will be copied into the <code>rlib</code> archive produced by the rust_library that depends on this <code>rust_bindgen</code> rule (using <code>BuildInfo</code> provider)</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_bindgen-wrap_static_fns"></a>wrap_static_fns</td><td style="text-align: left">Whether to create a separate .c file for static fns. Requires nightly toolchain, and a header that actually needs this feature (otherwise bindgen won't generate the file and Bazel complains).</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_bindgen_toolchain"></a></p> |
| <h2 id="rust_bindgen_toolchain"><a class="header" href="#rust_bindgen_toolchain">rust_bindgen_toolchain</a></h2> |
| <pre> |
| load("@rules_rust_bindgen//:defs.bzl", "rust_bindgen_toolchain") |
| |
| rust_bindgen_toolchain(<a href="rust_bindgen.html#rust_bindgen_toolchain-name">name</a>, <a href="rust_bindgen.html#rust_bindgen_toolchain-bindgen">bindgen</a>, <a href="rust_bindgen.html#rust_bindgen_toolchain-clang">clang</a>, <a href="rust_bindgen.html#rust_bindgen_toolchain-default_rustfmt">default_rustfmt</a>, <a href="rust_bindgen.html#rust_bindgen_toolchain-libclang">libclang</a>, <a href="rust_bindgen.html#rust_bindgen_toolchain-libstdcxx">libstdcxx</a>) |
| </pre> |
| <p>The tools required for the <code>rust_bindgen</code> rule.</p> |
| <p>This rule depends on the <a href="https://crates.io/crates/bindgen"><code>bindgen</code></a> binary crate, and it |
| in turn depends on both a clang binary and the clang library. To obtain these dependencies, |
| <code>rust_bindgen_dependencies</code> imports bindgen and its dependencies.</p> |
| <pre><code class="language-python">load("@rules_rust_bindgen//:defs.bzl", "rust_bindgen_toolchain") |
| |
| rust_bindgen_toolchain( |
| name = "bindgen_toolchain_impl", |
| bindgen = "//my/rust:bindgen", |
| clang = "//my/clang:clang", |
| libclang = "//my/clang:libclang.so", |
| libstdcxx = "//my/cpp:libstdc++", |
| ) |
| |
| toolchain( |
| name = "bindgen_toolchain", |
| toolchain = "bindgen_toolchain_impl", |
| toolchain_type = "@rules_rust_bindgen//:toolchain_type", |
| ) |
| </code></pre> |
| <p>This toolchain will then need to be registered in the current <code>WORKSPACE</code>. |
| For additional information, see the <a href="https://docs.bazel.build/versions/master/toolchains.html">Bazel toolchains documentation</a>.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_bindgen_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> |
| <tr><td style="text-align: left"><a id="rust_bindgen_toolchain-bindgen"></a>bindgen</td><td style="text-align: left">The label of a <code>bindgen</code> executable.</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> |
| <tr><td style="text-align: left"><a id="rust_bindgen_toolchain-clang"></a>clang</td><td style="text-align: left">The label of a <code>clang</code> executable.</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> |
| <tr><td style="text-align: left"><a id="rust_bindgen_toolchain-default_rustfmt"></a>default_rustfmt</td><td style="text-align: left">If set, <code>rust_bindgen</code> targets will always format generated sources with <code>rustfmt</code>.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_bindgen_toolchain-libclang"></a>libclang</td><td style="text-align: left">A cc_library providing bindgen's runtime dependency on libclang. This attribute is required for hermeticity when bindgen is dynamically linked. If None, bindgen must be statically linked; else, system libraries will be used instead.</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> |
| <tr><td style="text-align: left"><a id="rust_bindgen_toolchain-libstdcxx"></a>libstdcxx</td><td style="text-align: left">A cc_library that satisfies libclang's libstdc++ dependency. This is used to make the execution of clang hermetic. If None, system libraries will be used instead.</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> |
| </tbody></table> |
| </div> |
| <p><a id="rust_bindgen_library"></a></p> |
| <h2 id="rust_bindgen_library"><a class="header" href="#rust_bindgen_library">rust_bindgen_library</a></h2> |
| <pre> |
| load("@rules_rust_bindgen//:defs.bzl", "rust_bindgen_library") |
| |
| rust_bindgen_library(<a href="rust_bindgen.html#rust_bindgen_library-name">name</a>, <a href="rust_bindgen.html#rust_bindgen_library-header">header</a>, <a href="rust_bindgen.html#rust_bindgen_library-cc_lib">cc_lib</a>, <a href="rust_bindgen.html#rust_bindgen_library-bindgen_flags">bindgen_flags</a>, <a href="rust_bindgen.html#rust_bindgen_library-bindgen_features">bindgen_features</a>, <a href="rust_bindgen.html#rust_bindgen_library-clang_flags">clang_flags</a>, |
| <a href="rust_bindgen.html#rust_bindgen_library-wrap_static_fns">wrap_static_fns</a>, <a href="rust_bindgen.html#rust_bindgen_library-kwargs">**kwargs</a>) |
| </pre> |
| <p>Generates a rust source file for <code>header</code>, and builds a rust_library.</p> |
| <p>Arguments are the same as <code>rust_bindgen</code>, and <code>kwargs</code> are passed directly to rust_library.</p> |
| <p><strong>PARAMETERS</strong></p> |
| <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">Default Value</th></tr></thead><tbody> |
| <tr><td style="text-align: left"><a id="rust_bindgen_library-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="rust_bindgen_library-header"></a>header</td><td style="text-align: left">The label of the .h file to generate bindings for.</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="rust_bindgen_library-cc_lib"></a>cc_lib</td><td style="text-align: left">The label of the cc_library that contains the .h file. This is used to find the transitive includes.</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="rust_bindgen_library-bindgen_flags"></a>bindgen_flags</td><td style="text-align: left">Flags to pass directly to the bindgen executable. See https://rust-lang.github.io/rust-bindgen/ for details.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_bindgen_library-bindgen_features"></a>bindgen_features</td><td style="text-align: left">The <code>features</code> attribute for the <code>rust_bindgen</code> target.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_bindgen_library-clang_flags"></a>clang_flags</td><td style="text-align: left">Flags to pass directly to the clang executable.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_bindgen_library-wrap_static_fns"></a>wrap_static_fns</td><td style="text-align: left">Whether to create a separate .c file for static fns. Requires nightly toolchain, and a header that actually needs this feature (otherwise bindgen won't generate the file and Bazel complains",</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_bindgen_library-kwargs"></a>kwargs</td><td style="text-align: left">Arguments to forward to the underlying <code>rust_library</code> rule.</td><td style="text-align: left">none</td></tr> |
| </tbody></table> |
| </div><div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build --> |
| <h1 id="rules_rust_mdbook"><a class="header" href="#rules_rust_mdbook">rules_rust_mdbook</a></h1> |
| <p>Bazel rules for <a href="https://github.com/rust-lang/mdBook">mdBook</a>.</p> |
| <h2 id="rules-9"><a class="header" href="#rules-9">Rules</a></h2> |
| <ul> |
| <li><a href="rust_mdbook.html#mdbook">mdbook</a></li> |
| <li><a href="rust_mdbook.html#mdbook_server">mdbook_server</a></li> |
| <li><a href="rust_mdbook.html#mdbook_toolchain">mdbook_toolchain</a></li> |
| </ul> |
| <h2 id="setup-7"><a class="header" href="#setup-7">Setup</a></h2> |
| <pre><code class="language-python">bazel_dep(name = "rules_rust_mdbook", version = "{SEE_RELEASE_NOTES}") |
| </code></pre> |
| <hr /> |
| <hr /> |
| <p><a id="mdbook"></a></p> |
| <h2 id="mdbook"><a class="header" href="#mdbook">mdbook</a></h2> |
| <pre> |
| load("@rules_rust_mdbook//:defs.bzl", "mdbook") |
| |
| mdbook(<a href="rust_mdbook.html#mdbook-name">name</a>, <a href="rust_mdbook.html#mdbook-srcs">srcs</a>, <a href="rust_mdbook.html#mdbook-book">book</a>, <a href="rust_mdbook.html#mdbook-plugins">plugins</a>) |
| </pre> |
| <p>Rules to create book from markdown files using <code>mdBook</code>.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="mdbook-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> |
| <tr><td style="text-align: left"><a id="mdbook-srcs"></a>srcs</td><td style="text-align: left">All inputs to the book.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="mdbook-book"></a>book</td><td style="text-align: left">The <code>book.toml</code> file.</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> |
| <tr><td style="text-align: left"><a id="mdbook-plugins"></a>plugins</td><td style="text-align: left">Executables to inject into <code>PATH</code> for use in <a href="https://rust-lang.github.io/mdBook/format/configuration/preprocessors.html#provide-your-own-command">preprocessor commands</a>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="mdbook_server"></a></p> |
| <h2 id="mdbook_server"><a class="header" href="#mdbook_server">mdbook_server</a></h2> |
| <pre> |
| load("@rules_rust_mdbook//:defs.bzl", "mdbook_server") |
| |
| mdbook_server(<a href="rust_mdbook.html#mdbook_server-name">name</a>, <a href="rust_mdbook.html#mdbook_server-book">book</a>, <a href="rust_mdbook.html#mdbook_server-hostname">hostname</a>, <a href="rust_mdbook.html#mdbook_server-port">port</a>) |
| </pre> |
| <p>Spawn an mdbook server for a given <code>mdbook</code> target.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="mdbook_server-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> |
| <tr><td style="text-align: left"><a id="mdbook_server-book"></a>book</td><td style="text-align: left">The <code>mdbook</code> target to serve.</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> |
| <tr><td style="text-align: left"><a id="mdbook_server-hostname"></a>hostname</td><td style="text-align: left">The default hostname to use (Can be overridden on the command line).</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"localhost"</code></td></tr> |
| <tr><td style="text-align: left"><a id="mdbook_server-port"></a>port</td><td style="text-align: left">The default port to use (Can be overridden on the command line).</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"3000"</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="mdbook_toolchain"></a></p> |
| <h2 id="mdbook_toolchain"><a class="header" href="#mdbook_toolchain">mdbook_toolchain</a></h2> |
| <pre> |
| load("@rules_rust_mdbook//:defs.bzl", "mdbook_toolchain") |
| |
| mdbook_toolchain(<a href="rust_mdbook.html#mdbook_toolchain-name">name</a>, <a href="rust_mdbook.html#mdbook_toolchain-mdbook">mdbook</a>, <a href="rust_mdbook.html#mdbook_toolchain-plugins">plugins</a>) |
| </pre> |
| <p>A <a href="https://rust-lang.github.io/mdBook/">mdBook</a> toolchain.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="mdbook_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> |
| <tr><td style="text-align: left"><a id="mdbook_toolchain-mdbook"></a>mdbook</td><td style="text-align: left">A <code>mdBook</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> |
| <tr><td style="text-align: left"><a id="mdbook_toolchain-plugins"></a>plugins</td><td style="text-align: left">Executables to inject into <code>PATH</code> for use in <a href="https://rust-lang.github.io/mdBook/format/configuration/preprocessors.html#provide-your-own-command">preprocessor commands</a>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| </tbody></table> |
| </div><div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build --> |
| <h1 id="rules_rust_prost"><a class="header" href="#rules_rust_prost">rules_rust_prost</a></h1> |
| <p>These build rules are used for building <a href="https://developers.google.com/protocol-buffers/">protobufs</a>/<a href="https://grpc.io">gRPC</a> in <a href="http://www.rust-lang.org/">Rust</a> with Bazel |
| using <a href="https://github.com/tokio-rs/prost">Prost</a> and <a href="https://github.com/tokio-rs/tonic">Tonic</a></p> |
| <h2 id="rules-10"><a class="header" href="#rules-10">Rules</a></h2> |
| <ul> |
| <li><a href="rust_prost.html#rust_prost_library">rust_prost_library</a></li> |
| <li><a href="rust_prost.html#rust_prost_toolchain">rust_prost_toolchain</a></li> |
| </ul> |
| <h2 id="setup-8"><a class="header" href="#setup-8">Setup</a></h2> |
| <pre><code class="language-python">bazel_dep(name = "rules_rust_prost", version = "{SEE_RELEASE_NOTES}") |
| </code></pre> |
| <p>The <code>prost</code> and <code>tonic</code> rules do not specify a default toolchain in order to avoid mismatched |
| dependency issues. To setup the <code>prost</code> and <code>tonic</code> toolchain, please see the section |
| <a href="rust_prost.html#custom-prost-deps">Customizing <code>prost</code> and <code>tonic</code> Dependencies</a>.</p> |
| <p>For additional information about Bazel toolchains, see <a href="https://docs.bazel.build/versions/master/toolchains.html">here</a>.</p> |
| <h4 id="customizing-prost-and-tonic-dependencies"><a class="header" href="#customizing-prost-and-tonic-dependencies"><a name="custom-prost-deps">Customizing <code>prost</code> and <code>tonic</code> Dependencies</a></h4> |
| <p>These rules depend on the <a href="https://crates.io/crates/prost"><code>prost</code></a> and <a href="https://crates.io/crates/tonic"><code>tonic</code></a> dependencies. To setup the necessary toolchain |
| for these rules, you must define a toolchain with the <a href="https://crates.io/crates/prost"><code>prost</code></a>, <a href="https://crates.io/crates/prost-types"><code>prost-types</code></a>, <a href="https://crates.io/crates/tonic"><code>tonic</code></a>, <a href="https://crates.io/crates/protoc-gen-prost"><code>protoc-gen-prost</code></a>, and <a href="https://crates.io/crates/protoc-gen-tonic"><code>protoc-gen-tonic</code></a> crates as well as the <a href="https://github.com/protocolbuffers/protobuf"><code>protoc</code></a> binary.</p> |
| <p>To get access to these crates, you can use the <a href="./crate_universe.html">crate_universe</a> repository |
| rules. For example:</p> |
| <pre><code class="language-python">load("//crate_universe:defs.bzl", "crate", "crates_repository") |
| |
| crates_repository( |
| name = "crates_io", |
| annotations = { |
| "protoc-gen-prost": [crate.annotation( |
| gen_binaries = ["protoc-gen-prost"], |
| patch_args = [ |
| "-p1", |
| ], |
| patches = [ |
| # Note: You will need to use this patch until a version greater than `0.2.2` of |
| # `protoc-gen-prost` is released. |
| "@rules_rust//proto/prost/private/3rdparty/patches:protoc-gen-prost.patch", |
| ], |
| )], |
| "protoc-gen-tonic": [crate.annotation( |
| gen_binaries = ["protoc-gen-tonic"], |
| )], |
| }, |
| cargo_lockfile = "Cargo.Bazel.lock", |
| mode = "remote", |
| packages = { |
| "prost": crate.spec( |
| version = "0", |
| ), |
| "prost-types": crate.spec( |
| version = "0", |
| ), |
| "protoc-gen-prost": crate.spec( |
| version = "0", |
| ), |
| "protoc-gen-tonic": crate.spec( |
| version = "0", |
| ), |
| "tonic": crate.spec( |
| version = "0", |
| ), |
| }, |
| repository_name = "rules_rust_prost", |
| tags = ["manual"], |
| ) |
| </code></pre> |
| <p>You can then define a toolchain with the <code>rust_prost_toolchain</code> rule which uses the crates |
| defined above. For example:</p> |
| <pre><code class="language-python">load("@rules_rust//proto/prost:defs.bzl", "rust_prost_toolchain") |
| load("@rules_rust//rust:defs.bzl", "rust_library_group") |
| |
| rust_library_group( |
| name = "prost_runtime", |
| deps = [ |
| "@crates_io//:prost", |
| ], |
| ) |
| |
| rust_library_group( |
| name = "tonic_runtime", |
| deps = [ |
| ":prost_runtime", |
| "@crates_io//:tonic", |
| ], |
| ) |
| |
| rust_prost_toolchain( |
| name = "prost_toolchain_impl", |
| prost_plugin = "@crates_io//:protoc-gen-prost__protoc-gen-prost", |
| prost_runtime = ":prost_runtime", |
| prost_types = "@crates_io//:prost-types", |
| proto_compiler = "@com_google_protobuf//:protoc", |
| tonic_plugin = "@crates_io//:protoc-gen-tonic__protoc-gen-tonic", |
| tonic_runtime = ":tonic_runtime", |
| ) |
| |
| toolchain( |
| name = "prost_toolchain", |
| toolchain = "prost_toolchain_impl", |
| toolchain_type = "@rules_rust//proto/prost:toolchain_type", |
| ) |
| </code></pre> |
| <p>Lastly, you must register the toolchain in your <code>MODULE.bazel</code> file. For example:</p> |
| <pre><code class="language-python">register_toolchains("//toolchains:prost_toolchain") |
| </code></pre> |
| <hr /> |
| <hr /> |
| <p><a id="rust_prost_library"></a></p> |
| <h2 id="rust_prost_library"><a class="header" href="#rust_prost_library">rust_prost_library</a></h2> |
| <pre> |
| load("@rules_rust_prost//:defs.bzl", "rust_prost_library") |
| |
| rust_prost_library(<a href="rust_prost.html#rust_prost_library-name">name</a>, <a href="rust_prost.html#rust_prost_library-proto">proto</a>) |
| </pre> |
| <p>A rule for generating a Rust library using Prost.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_prost_library-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> |
| <tr><td style="text-align: left"><a id="rust_prost_library-proto"></a>proto</td><td style="text-align: left">A <code>proto_library</code> target for which to generate Rust gencode.</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> |
| </tbody></table> |
| </div> |
| <p><a id="rust_prost_toolchain"></a></p> |
| <h2 id="rust_prost_toolchain"><a class="header" href="#rust_prost_toolchain">rust_prost_toolchain</a></h2> |
| <pre> |
| load("@rules_rust_prost//:defs.bzl", "rust_prost_toolchain") |
| |
| rust_prost_toolchain(<a href="rust_prost.html#rust_prost_toolchain-name">name</a>, <a href="rust_prost.html#rust_prost_toolchain-compile_well_known_types">compile_well_known_types</a>, <a href="rust_prost.html#rust_prost_toolchain-include_transitive_deps">include_transitive_deps</a>, <a href="rust_prost.html#rust_prost_toolchain-prost_opts">prost_opts</a>, |
| <a href="rust_prost.html#rust_prost_toolchain-prost_plugin">prost_plugin</a>, <a href="rust_prost.html#rust_prost_toolchain-prost_plugin_flag">prost_plugin_flag</a>, <a href="rust_prost.html#rust_prost_toolchain-prost_runtime">prost_runtime</a>, <a href="rust_prost.html#rust_prost_toolchain-prost_types">prost_types</a>, <a href="rust_prost.html#rust_prost_toolchain-proto_compiler">proto_compiler</a>, |
| <a href="rust_prost.html#rust_prost_toolchain-tonic_opts">tonic_opts</a>, <a href="rust_prost.html#rust_prost_toolchain-tonic_plugin">tonic_plugin</a>, <a href="rust_prost.html#rust_prost_toolchain-tonic_plugin_flag">tonic_plugin_flag</a>, <a href="rust_prost.html#rust_prost_toolchain-tonic_runtime">tonic_runtime</a>) |
| </pre> |
| <p>Rust Prost toolchain rule.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_prost_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> |
| <tr><td style="text-align: left"><a id="rust_prost_toolchain-compile_well_known_types"></a>compile_well_known_types</td><td style="text-align: left">Corresponds to prost_build's <code>compile_well_known_types</code> option. If set to False, well-known-types will not be compiled by prost, and instead rely on the provided Prost types crate.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_prost_toolchain-include_transitive_deps"></a>include_transitive_deps</td><td style="text-align: left">Whether to include transitive dependencies. If set to True, all transitive dependencies will directly accessible by the dependent crate.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_prost_toolchain-prost_opts"></a>prost_opts</td><td style="text-align: left">Additional options to add to Prost.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_prost_toolchain-prost_plugin"></a>prost_plugin</td><td style="text-align: left">Additional plugins to add to Prost.</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> |
| <tr><td style="text-align: left"><a id="rust_prost_toolchain-prost_plugin_flag"></a>prost_plugin_flag</td><td style="text-align: left">Prost plugin flag format. (e.g. <code>--plugin=protoc-gen-prost=%s</code>)</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"--plugin=protoc-gen-prost=%s"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_prost_toolchain-prost_runtime"></a>prost_runtime</td><td style="text-align: left">The Prost runtime crates to use.</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> |
| <tr><td style="text-align: left"><a id="rust_prost_toolchain-prost_types"></a>prost_types</td><td style="text-align: left">The Prost types crates to use.</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> |
| <tr><td style="text-align: left"><a id="rust_prost_toolchain-proto_compiler"></a>proto_compiler</td><td style="text-align: left">The protoc compiler to use. Note that this attribute is deprecated - prefer to use --incompatible_enable_proto_toolchain_resolution.</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> |
| <tr><td style="text-align: left"><a id="rust_prost_toolchain-tonic_opts"></a>tonic_opts</td><td style="text-align: left">Additional options to add to Tonic.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_prost_toolchain-tonic_plugin"></a>tonic_plugin</td><td style="text-align: left">Additional plugins to add to Tonic.</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> |
| <tr><td style="text-align: left"><a id="rust_prost_toolchain-tonic_plugin_flag"></a>tonic_plugin_flag</td><td style="text-align: left">Tonic plugin flag format. (e.g. <code>--plugin=protoc-gen-tonic=%s</code>))</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"--plugin=protoc-gen-tonic=%s"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_prost_toolchain-tonic_runtime"></a>tonic_runtime</td><td style="text-align: left">The Tonic runtime crates to use.</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> |
| </tbody></table> |
| </div> |
| <p><a id="rust_prost_transform"></a></p> |
| <h2 id="rust_prost_transform"><a class="header" href="#rust_prost_transform">rust_prost_transform</a></h2> |
| <pre> |
| load("@rules_rust_prost//:defs.bzl", "rust_prost_transform") |
| |
| rust_prost_transform(<a href="rust_prost.html#rust_prost_transform-name">name</a>, <a href="rust_prost.html#rust_prost_transform-deps">deps</a>, <a href="rust_prost.html#rust_prost_transform-srcs">srcs</a>, <a href="rust_prost.html#rust_prost_transform-crate_name">crate_name</a>, <a href="rust_prost.html#rust_prost_transform-prost_opts">prost_opts</a>, <a href="rust_prost.html#rust_prost_transform-tonic_opts">tonic_opts</a>) |
| </pre> |
| <p>A rule for transforming the outputs of <code>ProstGenProto</code> actions.</p> |
| <p>This rule is used by adding it to the <code>data</code> attribute of <code>proto_library</code> targets. E.g.</p> |
| <pre><code class="language-python">load("@rules_proto//proto:defs.bzl", "proto_library") |
| load("@rules_rust_prost//:defs.bzl", "rust_prost_library", "rust_prost_transform") |
| |
| rust_prost_transform( |
| name = "a_transform", |
| srcs = [ |
| "a_src.rs", |
| ], |
| ) |
| |
| proto_library( |
| name = "a_proto", |
| srcs = [ |
| "a.proto", |
| ], |
| data = [ |
| ":transform", |
| ], |
| ) |
| |
| rust_prost_library( |
| name = "a_rs_proto", |
| proto = ":a_proto", |
| ) |
| </code></pre> |
| <p>The <code>rust_prost_library</code> will spawn an action on the <code>a_proto</code> target which consumes the |
| <code>a_transform</code> rule to provide a means of granularly modifying a proto library for <code>ProstGenProto</code> |
| actions with minimal impact to other consumers.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_prost_transform-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> |
| <tr><td style="text-align: left"><a id="rust_prost_transform-deps"></a>deps</td><td style="text-align: left">Additional dependencies to add to the compiled crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_prost_transform-srcs"></a>srcs</td><td style="text-align: left">Additional source files to include in generated Prost source code.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_prost_transform-crate_name"></a>crate_name</td><td style="text-align: left">The name of the crate generated by Prost. This is used to override the default name which is the name of the proto_library target.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_prost_transform-prost_opts"></a>prost_opts</td><td style="text-align: left">Additional options to add to Prost.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_prost_transform-tonic_opts"></a>tonic_opts</td><td style="text-align: left">Additional options to add to Tonic.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| </tbody></table> |
| </div><div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build --> |
| <h1 id="rules_rust_pyo3"><a class="header" href="#rules_rust_pyo3">rules_rust_pyo3</a></h1> |
| <p><a id="pyo3_toolchain"></a></p> |
| <h2 id="pyo3_toolchain"><a class="header" href="#pyo3_toolchain">pyo3_toolchain</a></h2> |
| <pre> |
| load("@rules_rust_pyo3//:defs.bzl", "pyo3_toolchain") |
| |
| pyo3_toolchain(<a href="rust_pyo3.html#pyo3_toolchain-name">name</a>) |
| </pre> |
| <p>Define a toolchain which generates config data for the PyO3 for producing extension modules on any target platform.</p> |
| <p>Note that this toolchain expects the <code>pyo3</code> crate to be built with the following features:</p> |
| <ul> |
| <li><a href="https://pyo3.rs/v0.26.0/features.html?highlight=abi3#abi3"><code>abi3</code></a></li> |
| <li><a href="https://pyo3.rs/v0.26.0/features.html?highlight=abi3#the-abi3-pyxy-features"><code>abi3-py3*</code></a> (e.g <code>abi3-py311</code>)</li> |
| <li><a href="https://pyo3.rs/v0.26.0/features.html?highlight=abi3#extension-module"><code>extension-module</code></a></li> |
| </ul> |
| <p>When using <a href="https://bazelbuild.github.io/rules_rust/crate_universe.html">rules_rust's crate_universe</a>, this data can be plubmed into the target using the following snippet.</p> |
| <pre><code class="language-python">annotations = { |
| "pyo3-build-config": [ |
| crate.annotation( |
| build_script_data = [ |
| "@rules_rust_pyo3//:current_pyo3_toolchain", |
| ], |
| build_script_env = { |
| "PYO3_CROSS": "$(PYO3_CROSS)", |
| "PYO3_CROSS_LIB_DIR": "$(PYO3_CROSS_LIB_DIR)", |
| "PYO3_CROSS_PYTHON_IMPLEMENTATION": "$(PYO3_CROSS_PYTHON_IMPLEMENTATION)", |
| "PYO3_CROSS_PYTHON_VERSION": "$(PYO3_CROSS_PYTHON_VERSION)", |
| "PYO3_NO_PYTHON": "$(PYO3_NO_PYTHON)", |
| "PYO3_PYTHON": "$(PYO3_PYTHON)", |
| }, |
| build_script_toolchains = [ |
| "@rules_rust_pyo3//:current_pyo3_toolchain", |
| ], |
| ), |
| ], |
| "pyo3-ffi": [ |
| crate.annotation( |
| build_script_data = [ |
| "@rules_rust_pyo3//:current_pyo3_toolchain", |
| ], |
| build_script_env = { |
| "PYO3_CROSS": "$(PYO3_CROSS)", |
| "PYO3_CROSS_LIB_DIR": "$(PYO3_CROSS_LIB_DIR)", |
| "PYO3_CROSS_PYTHON_IMPLEMENTATION": "$(PYO3_CROSS_PYTHON_IMPLEMENTATION)", |
| "PYO3_CROSS_PYTHON_VERSION": "$(PYO3_CROSS_PYTHON_VERSION)", |
| "PYO3_NO_PYTHON": "$(PYO3_NO_PYTHON)", |
| "PYO3_PYTHON": "$(PYO3_PYTHON)", |
| }, |
| build_script_toolchains = [ |
| "@rules_rust_pyo3//:current_pyo3_toolchain", |
| ], |
| ), |
| ], |
| }, |
| </code></pre> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="pyo3_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> |
| </tbody></table> |
| </div> |
| <p><a id="rust_pyo3_toolchain"></a></p> |
| <h2 id="rust_pyo3_toolchain"><a class="header" href="#rust_pyo3_toolchain">rust_pyo3_toolchain</a></h2> |
| <pre> |
| load("@rules_rust_pyo3//:defs.bzl", "rust_pyo3_toolchain") |
| |
| rust_pyo3_toolchain(<a href="rust_pyo3.html#rust_pyo3_toolchain-name">name</a>, <a href="rust_pyo3.html#rust_pyo3_toolchain-pyo3">pyo3</a>, <a href="rust_pyo3.html#rust_pyo3_toolchain-pyo3_introspection">pyo3_introspection</a>) |
| </pre> |
| <p>Define a toolchain for PyO3 Rust dependencies which power internal rules.</p> |
| <p>This toolchain is how the rules know which version of <code>pyo3</code> to link against.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_pyo3_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> |
| <tr><td style="text-align: left"><a id="rust_pyo3_toolchain-pyo3"></a>pyo3</td><td style="text-align: left">The PyO3 library.</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> |
| <tr><td style="text-align: left"><a id="rust_pyo3_toolchain-pyo3_introspection"></a>pyo3_introspection</td><td style="text-align: left">The PyO3 introspection library.</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> |
| </tbody></table> |
| </div> |
| <p><a id="pyo3_extension"></a></p> |
| <h2 id="pyo3_extension"><a class="header" href="#pyo3_extension">pyo3_extension</a></h2> |
| <pre> |
| load("@rules_rust_pyo3//:defs.bzl", "pyo3_extension") |
| |
| pyo3_extension(*, <a href="rust_pyo3.html#pyo3_extension-name">name</a>, <a href="rust_pyo3.html#pyo3_extension-srcs">srcs</a>, <a href="rust_pyo3.html#pyo3_extension-aliases">aliases</a>, <a href="rust_pyo3.html#pyo3_extension-compile_data">compile_data</a>, <a href="rust_pyo3.html#pyo3_extension-crate_features">crate_features</a>, <a href="rust_pyo3.html#pyo3_extension-crate_root">crate_root</a>, <a href="rust_pyo3.html#pyo3_extension-data">data</a>, <a href="rust_pyo3.html#pyo3_extension-deps">deps</a>, |
| <a href="rust_pyo3.html#pyo3_extension-edition">edition</a>, <a href="rust_pyo3.html#pyo3_extension-imports">imports</a>, <a href="rust_pyo3.html#pyo3_extension-proc_macro_deps">proc_macro_deps</a>, <a href="rust_pyo3.html#pyo3_extension-rustc_env">rustc_env</a>, <a href="rust_pyo3.html#pyo3_extension-rustc_env_files">rustc_env_files</a>, <a href="rust_pyo3.html#pyo3_extension-rustc_flags">rustc_flags</a>, <a href="rust_pyo3.html#pyo3_extension-stubs">stubs</a>, |
| <a href="rust_pyo3.html#pyo3_extension-version">version</a>, <a href="rust_pyo3.html#pyo3_extension-compilation_mode">compilation_mode</a>, <a href="rust_pyo3.html#pyo3_extension-module_name">module_name</a>, <a href="rust_pyo3.html#pyo3_extension-kwargs">**kwargs</a>) |
| </pre> |
| <p>Define a PyO3 python extension module.</p> |
| <p>This target is consumed just as a <code>py_library</code> would be.</p> |
| <p><strong>PARAMETERS</strong></p> |
| <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">Default Value</th></tr></thead><tbody> |
| <tr><td style="text-align: left"><a id="pyo3_extension-name"></a>name</td><td style="text-align: left">The name of the target.</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library. For more details see <a href="https://bazelbuild.github.io/rules_rust/defs.html#rust_shared_library">rust_shared_library</a>.</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target. For more details see <a href="https://bazelbuild.github.io/rules_rust/defs.html#rust_shared_library">rust_shared_library</a>.</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time. For more details see <a href="https://bazelbuild.github.io/rules_rust/defs.html#rust_shared_library">rust_shared_library</a>.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate. For more details see <a href="https://bazelbuild.github.io/rules_rust/defs.html#rust_shared_library">rust_shared_library</a>.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate. For more details see <a href="https://bazelbuild.github.io/rules_rust/defs.html#rust_shared_library">rust_shared_library</a>.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime. For more details see <a href="https://bazelbuild.github.io/rules_rust/defs.html#rust_shared_library">rust_shared_library</a>.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target. For more details see <a href="https://bazelbuild.github.io/rules_rust/defs.html#rust_shared_library">rust_shared_library</a>.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. For more details see <a href="https://bazelbuild.github.io/rules_rust/defs.html#rust_shared_library">rust_shared_library</a>.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-imports"></a>imports</td><td style="text-align: left">List of import directories to be added to the <code>PYTHONPATH</code>. For more details see <a href="https://bazel.build/reference/be/python#py_binary.imports">py_library.imports</a>.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target. For more details see <a href="https://bazelbuild.github.io/rules_rust/defs.html#rust_shared_library">rust_shared_library</a>.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc. For more details see <a href="https://bazelbuild.github.io/rules_rust/defs.html#rust_shared_library">rust_shared_library</a>.</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc. For more details see <a href="https://bazelbuild.github.io/rules_rust/defs.html#rust_shared_library">rust_shared_library</a>.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>. For more details see <a href="https://bazelbuild.github.io/rules_rust/defs.html#rust_shared_library">rust_shared_library</a>.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-stubs"></a>stubs</td><td style="text-align: left">Whether or not to generate stubs (<code>.pyi</code> file) for the module.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable. For more details see <a href="https://bazelbuild.github.io/rules_rust/defs.html#rust_shared_library">rust_shared_library</a>.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-compilation_mode"></a>compilation_mode</td><td style="text-align: left">The <a href="https://bazel.build/reference/command-line-reference#flag--compilation_mode">compilation_mode</a> value to build the extension for. If set to <code>"current"</code>, the current configuration will be used.</td><td style="text-align: left"><code>"opt"</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-module_name"></a>module_name</td><td style="text-align: left">A full dotted Python module path implemented by this extension (e.g. <code>foo.bar</code>).</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="pyo3_extension-kwargs"></a>kwargs</td><td style="text-align: left">Additional keyword arguments.</td><td style="text-align: left">none</td></tr> |
| </tbody></table> |
| </div><div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build --> |
| <h1 id="rules_rust_wasm_bindgen"><a class="header" href="#rules_rust_wasm_bindgen">rules_rust_wasm_bindgen</a></h1> |
| <p>Bazel rules for generating wasm modules for Javascript using <a href="https://github.com/rustwasm/wasm-bindgen">wasm-bindgen</a>.</p> |
| <h2 id="rules-11"><a class="header" href="#rules-11">Rules</a></h2> |
| <ul> |
| <li><a href="rust_wasm_bindgen.html#rust_wasm_bindgen">rust_wasm_bindgen</a></li> |
| <li><a href="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain">rust_wasm_bindgen_toolchain</a></li> |
| </ul> |
| <h2 id="setup-9"><a class="header" href="#setup-9">Setup</a></h2> |
| <p>To begin using the <code>wasm-bindgen</code> rules, add the following to your <code>MODULE.bazel</code> file:</p> |
| <pre><code class="language-python">bazel_dep(name = "rules_rust_wasm_bindgen", version = "{SEE_RELEASE_NOTES}") |
| </code></pre> |
| <p>This should enable users to start using the <a href="rust_wasm_bindgen.html#rust_wasm_bindgen">rust_wasm_bindgen</a> |
| rule. However, it's common to want to control the version of <code>wasm-bindgen</code> in the |
| workspace instead of relying on the one provided by <code>rules_rust</code>. In this case, users |
| should use the <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain">rust_wasm_bindgen_toolchain</a> rule to |
| define their own toolchains to register.</p> |
| <h2 id="interfacing-with-javascript-rules"><a class="header" href="#interfacing-with-javascript-rules">Interfacing with Javascript rules</a></h2> |
| <p>Rules for doing so can be found at <a href="https://github.com/UebelAndre/rules_js_rust_wasm_bindgen">rules_js_rust_wasm_bindgen</a></p> |
| <p><a id="rust_wasm_bindgen"></a></p> |
| <h2 id="rust_wasm_bindgen"><a class="header" href="#rust_wasm_bindgen">rust_wasm_bindgen</a></h2> |
| <pre> |
| load("@rules_rust_wasm_bindgen//:defs.bzl", "rust_wasm_bindgen") |
| |
| rust_wasm_bindgen(<a href="rust_wasm_bindgen.html#rust_wasm_bindgen-name">name</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen-bindgen_flags">bindgen_flags</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen-out_name">out_name</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen-target">target</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen-target_arch">target_arch</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen-wasm_file">wasm_file</a>) |
| </pre> |
| <p>Generates javascript and typescript bindings for a webassembly module using <a href="https://rustwasm.github.io/docs/wasm-bindgen/">wasm-bindgen</a>.</p> |
| <p>An example of this rule in use can be seen at <a href="../examples/wasm">@rules_rust//examples/wasm</a></p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen-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> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen-bindgen_flags"></a>bindgen_flags</td><td style="text-align: left">Flags to pass directly to the wasm-bindgen executable. See https://github.com/rustwasm/wasm-bindgen/ for details.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen-out_name"></a>out_name</td><td style="text-align: left">Set a custom output filename (Without extension. Defaults to target name).</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen-target"></a>target</td><td style="text-align: left">The type of output to generate. See https://rustwasm.github.io/wasm-bindgen/reference/deployment.html for details.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"bundler"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen-target_arch"></a>target_arch</td><td style="text-align: left">The target architecture to use for the wasm-bindgen command line option.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"wasm32"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen-wasm_file"></a>wasm_file</td><td style="text-align: left">The <code>.wasm</code> crate to generate bindings for.</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> |
| </tbody></table> |
| </div> |
| <p><a id="rust_wasm_bindgen_toolchain"></a></p> |
| <h2 id="rust_wasm_bindgen_toolchain"><a class="header" href="#rust_wasm_bindgen_toolchain">rust_wasm_bindgen_toolchain</a></h2> |
| <pre> |
| load("@rules_rust_wasm_bindgen//:defs.bzl", "rust_wasm_bindgen_toolchain") |
| |
| rust_wasm_bindgen_toolchain(<a href="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain-name">name</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain-browser">browser</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain-browser_type">browser_type</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain-wasm_bindgen_cli">wasm_bindgen_cli</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain-wasm_bindgen_test">wasm_bindgen_test</a>, |
| <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain-wasm_bindgen_test_runner">wasm_bindgen_test_runner</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain-webdriver">webdriver</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain-webdriver_args">webdriver_args</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain-webdriver_json">webdriver_json</a>) |
| </pre> |
| <p>The tools required for the <code>rust_wasm_bindgen</code> rule.</p> |
| <p>In cases where users want to control or change the version of <code>wasm-bindgen</code> used by <a href="rust_wasm_bindgen.html#rust_wasm_bindgen">rust_wasm_bindgen</a>, |
| a unique toolchain can be created as in the example below:</p> |
| <pre><code class="language-python">load("@rules_rust_wasm_bindgen//:defs.bzl", "rust_wasm_bindgen_toolchain") |
| |
| rust_wasm_bindgen_toolchain( |
| wasm_bindgen_cli = "//3rdparty/crates:wasm_bindgen_cli__bin", |
| ) |
| |
| toolchain( |
| name = "wasm_bindgen_toolchain", |
| toolchain = "wasm_bindgen_toolchain_impl", |
| toolchain_type = "@rules_rust_wasm_bindgen//:toolchain_type", |
| ) |
| </code></pre> |
| <p>Now that you have your own toolchain, you need to register it by |
| inserting the following statement in your <code>WORKSPACE</code> file:</p> |
| <pre><code class="language-python">register_toolchains("//my/toolchains:wasm_bindgen_toolchain") |
| </code></pre> |
| <p>For additional information, see the <a href="https://docs.bazel.build/versions/master/toolchains.html">Bazel toolchains documentation</a>.</p> |
| <p><strong>ATTRIBUTES</strong></p> |
| <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> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_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> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_toolchain-browser"></a>browser</td><td style="text-align: left">The browser entrypoint.</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> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_toolchain-browser_type"></a>browser_type</td><td style="text-align: left">The type of browser provided.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_toolchain-wasm_bindgen_cli"></a>wasm_bindgen_cli</td><td style="text-align: left">The label of a <code>wasm-bindgen-cli</code> executable.</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> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_toolchain-wasm_bindgen_test"></a>wasm_bindgen_test</td><td style="text-align: left">The label of a <code>wasm-bindgen-test</code> crate.</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> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_toolchain-wasm_bindgen_test_runner"></a>wasm_bindgen_test_runner</td><td style="text-align: left">The label of a <code>wasm-bindgen-test-runner</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> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_toolchain-webdriver"></a>webdriver</td><td style="text-align: left">The webdriver to use.</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> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_toolchain-webdriver_args"></a>webdriver_args</td><td style="text-align: left">Arguments to pass to the <code>webdriver</code> binary.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_toolchain-webdriver_json"></a>webdriver_json</td><td style="text-align: left">The <a href="https://rustwasm.github.io/wasm-bindgen/wasm-bindgen-test/browsers.html#configuring-headless-browser-capabilities"><code>webdriver.json</code> config file</a> for wasm-bindgen-test.</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> |
| </tbody></table> |
| </div> |
| <p><a id="RustWasmBindgenInfo"></a></p> |
| <h2 id="rustwasmbindgeninfo"><a class="header" href="#rustwasmbindgeninfo">RustWasmBindgenInfo</a></h2> |
| <pre> |
| load("@rules_rust_wasm_bindgen//:defs.bzl", "RustWasmBindgenInfo") |
| |
| RustWasmBindgenInfo(<a href="rust_wasm_bindgen.html#RustWasmBindgenInfo-js">js</a>, <a href="rust_wasm_bindgen.html#RustWasmBindgenInfo-root">root</a>, <a href="rust_wasm_bindgen.html#RustWasmBindgenInfo-snippets">snippets</a>, <a href="rust_wasm_bindgen.html#RustWasmBindgenInfo-ts">ts</a>, <a href="rust_wasm_bindgen.html#RustWasmBindgenInfo-wasm">wasm</a>) |
| </pre> |
| <p>Info about wasm-bindgen outputs.</p> |
| <p><strong>FIELDS</strong></p> |
| <div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th></tr></thead><tbody> |
| <tr><td style="text-align: left"><a id="RustWasmBindgenInfo-js"></a>js</td><td style="text-align: left">Depset[File]: The Javascript files produced by <code>wasm-bindgen</code>.</td></tr> |
| <tr><td style="text-align: left"><a id="RustWasmBindgenInfo-root"></a>root</td><td style="text-align: left">str: The path to the root of the <code>wasm-bindgen --out-dir</code> directory.</td></tr> |
| <tr><td style="text-align: left"><a id="RustWasmBindgenInfo-snippets"></a>snippets</td><td style="text-align: left">File: The snippets directory produced by <code>wasm-bindgen</code>.</td></tr> |
| <tr><td style="text-align: left"><a id="RustWasmBindgenInfo-ts"></a>ts</td><td style="text-align: left">Depset[File]: The Typescript files produced by <code>wasm-bindgen</code>.</td></tr> |
| <tr><td style="text-align: left"><a id="RustWasmBindgenInfo-wasm"></a>wasm</td><td style="text-align: left">File: The <code>.wasm</code> file generated by <code>wasm-bindgen</code>.</td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_wasm_bindgen_test"></a></p> |
| <h2 id="rust_wasm_bindgen_test"><a class="header" href="#rust_wasm_bindgen_test">rust_wasm_bindgen_test</a></h2> |
| <pre> |
| load("@rules_rust_wasm_bindgen//:defs.bzl", "rust_wasm_bindgen_test") |
| |
| rust_wasm_bindgen_test(*, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-name">name</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-aliases">aliases</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-compile_data">compile_data</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-crate_features">crate_features</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-data">data</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-edition">edition</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-env">env</a>, |
| <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-env_inherit">env_inherit</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-proc_macro_deps">proc_macro_deps</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-rustc_env">rustc_env</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-rustc_env_files">rustc_env_files</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-rustc_flags">rustc_flags</a>, |
| <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-target_arch">target_arch</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-version">version</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-wasm">wasm</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-tags">tags</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-kwargs">**kwargs</a>) |
| </pre> |
| <p>"A test rule for running <a href="https://rustwasm.github.io/wasm-bindgen/wasm-bindgen-test/index.html">wasm-bindgen tests</a>."</p> |
| <p><strong>PARAMETERS</strong></p> |
| <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">Default Value</th></tr></thead><tbody> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target.</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-env"></a>env</td><td style="text-align: left">Specifies additional environment variables to set when the test is executed by bazel test.</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-env_inherit"></a>env_inherit</td><td style="text-align: left">Specifies additional environment variables to inherit from the external environment when the test is executed by bazel test.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-target_arch"></a>target_arch</td><td style="text-align: left">The target architecture to use for the wasm-bindgen command line option.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left"><code>"0.0.0"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-wasm"></a>wasm</td><td style="text-align: left">The wasm target to test.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-tags"></a>tags</td><td style="text-align: left">Tags to apply to the target.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_wasm_bindgen_test-kwargs"></a>kwargs</td><td style="text-align: left">Additional keyword arguments.</td><td style="text-align: left">none</td></tr> |
| </tbody></table> |
| </div> |
| </main> |
| |
| <nav class="nav-wrapper" aria-label="Page navigation"> |
| <!-- Mobile navigation buttons --> |
| |
| |
| <div style="clear: both"></div> |
| </nav> |
| </div> |
| </div> |
| |
| <nav class="nav-wide-wrapper" aria-label="Page navigation"> |
| |
| </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 --> |
| |
| <script> |
| window.addEventListener('load', function() { |
| window.setTimeout(window.print, 100); |
| }); |
| </script> |
| |
| </div> |
| </body> |
| </html> |