| <!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> |
| <h3 id="bzlmod"><a class="header" href="#bzlmod">Bzlmod</a></h3> |
| <p>Note that rules_rust bzlmod support is still a work in progress. Most features should work, but bugs are more likely. This is not a desired end-state - please report (or better yet, help fix!) bugs you run into.</p> |
| <p>To use <code>rules_rust</code> in a project using bzlmod, add the following to your <code>MODULE.bazel</code> file:</p> |
| <pre><code class="language-python">bazel_dep(name = "rules_rust", version = "0.64.0") |
| </code></pre> |
| <p>Don't forget to substitute in your desired release's version number.</p> |
| <h3 id="workspace"><a class="header" href="#workspace">WORKSPACE</a></h3> |
| <p>To use <code>rules_rust</code> in a project using a WORKSPACE file, add the following to your <code>WORKSPACE</code> file to add the external repositories for the Rust toolchain:</p> |
| <pre><code class="language-python">load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") |
| |
| # To find additional information on this release or newer ones visit: |
| # https://github.com/bazelbuild/rules_rust/releases |
| http_archive( |
| name = "rules_rust", |
| integrity = "sha256-Weev1uz2QztBlDA88JX6A1N72SucD1V8lBsaliM0TTg=", |
| urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.48.0/rules_rust-v0.48.0.tar.gz"], |
| ) |
| |
| load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains") |
| |
| rules_rust_dependencies() |
| |
| rust_register_toolchains() |
| </code></pre> |
| <p>Don't forget to substitute in your desired release's version number and integrity hash.</p> |
| <h2 id="specifying-rust-version"><a class="header" href="#specifying-rust-version">Specifying Rust version</a></h2> |
| <h3 id="bzlmod-1"><a class="header" href="#bzlmod-1">Bzlmod</a></h3> |
| <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> |
| <h3 id="workspace-1"><a class="header" href="#workspace-1">WORKSPACE</a></h3> |
| <p>To build with a particular version of the Rust compiler when using a WORKSPACE file, pass that version to <code>rust_register_toolchains</code>:</p> |
| <pre><code class="language-python">rust_register_toolchains( |
| edition = "2021", |
| versions = [ |
| "1.79.0" |
| ], |
| ) |
| </code></pre> |
| <p>Like in the Bzlmod approach, 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.</p> |
| <pre><code class="language-python">rust_register_toolchains( |
| edition = "2021", |
| versions = [ |
| "nightly/2024-06-13", |
| ], |
| ) |
| </code></pre> |
| <p>Here too a <code>stable</code> and <code>nightly</code> toolchain will be registered by default if no versions are passed to <code>rust_register_toolchains</code>. 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 |
| also be set either in the command line or 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> |
| <h3 id="workspace-support"><a class="header" href="#workspace-support">WORKSPACE support</a></h3> |
| <p>WORKSPACE support is officially tested with Bazel 7 for as long as that is the min supported version. While it may work with later versions, compatibility with those versions is not guaranteed or actively verified.</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_protobuf.html">rust_protobuf</a>: rules for generating <a href="https://developers.google.com/protocol-buffers">protobuf</a> and <a href="https://grpc.io">gRPC</a> stubs with <a href="https://github.com/stepancheg/rust-protobuf/">rust-protobuf</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-out_binary">out_binary</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-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-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 cc_common.link are linked against <code>@bazel_tools//tools/cpp: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>"@bazel_tools//tools/cpp:malloc"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_binary-out_binary"></a>out_binary</td><td style="text-align: left">Force a target, regardless of it's <code>crate_type</code>, to always mark the file as executable. This attribute is only used to support wasm targets but is expected to be removed following a resolution to https://github.com/bazelbuild/rules_rust/issues/771.</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-platform"></a>platform</td><td style="text-align: left">Optional platform to transition the binary 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-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-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-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-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-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-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-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-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-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-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-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-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 cc_common.link are linked against <code>@bazel_tools//tools/cpp: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>"@bazel_tools//tools/cpp: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 shared 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-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-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-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-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-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-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-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-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 cc_common.link are linked against <code>@bazel_tools//tools/cpp: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>"@bazel_tools//tools/cpp: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 test 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-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-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-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-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-repo_mapping">repo_mapping</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-repo_mapping"></a>repo_mapping</td><td style="text-align: left">In <code>WORKSPACE</code> context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<br><br>For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>).<br><br>This attribute is <em>not</em> supported in <code>MODULE.bazel</code> context (when invoking a repository rule inside a module extension's implementation function).</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"></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.86.0"</code></td></tr> |
| </tbody></table> |
| </div><div style="break-before: page; page-break-before: always;"></div><h2 id="overview-2"><a class="header" href="#overview-2">Overview</a></h2> |
| <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> |
| <h4 id="bzlmod-2"><a class="header" href="#bzlmod-2">Bzlmod</a></h4> |
| <p>First, ensure <code>rules_rust</code> is setup in your workspace:</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="workspace-2"><a class="header" href="#workspace-2">WORKSPACE</a></h4> |
| <p>Alternatively, you can use the legacy WORKSPACE approach. As with Bzlmod, ensure <code>rules_rust</code> is |
| setup in your workspace.</p> |
| <p>Moreover, when loading the dependencies for the tool, you should call the function <code>rust_analyzer_dependencies()</code>:</p> |
| <pre><code class="language-python">load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies") |
| |
| rust_analyzer_dependencies() |
| </code></pre> |
| <p>Again, you can now run <code>bazel run @rules_rust//tools/rust_analyzer:gen_rust_project</code> |
| whenever dependencies change to regenerate the <code>rust-project.json</code> file.</p> |
| <p>For users who do not use <code>rust_register_toolchains</code> to register toolchains, the following can be added |
| to their WORKSPACE to register a <code>rust_analyzer_toolchain</code>. Please make sure the Rust version used in |
| this toolchain matches the version used by the currently registered toolchain or the sources/documentation |
| will not match what's being compiled with and can lead to confusing results.</p> |
| <pre><code class="language-python">load("@rules_rust//rust:repositories.bzl", "rust_analyzer_toolchain_repository") |
| |
| register_toolchains(rust_analyzer_toolchain_repository( |
| name = "rust_analyzer_toolchain", |
| # This should match the currently registered toolchain. |
| version = "1.63.0", |
| )) |
| </code></pre> |
| <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> |
| <h2 id="aspects-3"><a class="header" href="#aspects-3">Aspects</a></h2> |
| <ul> |
| <li><a href="rust_analyzer.html#rust_analyzer_aspect">rust_analyzer_aspect</a></li> |
| </ul> |
| <p><a id="rust_analyzer_aspect"></a></p> |
| <h2 id="rust_analyzer_aspect"><a class="header" href="#rust_analyzer_aspect">rust_analyzer_aspect</a></h2> |
| <pre> |
| load("@rules_rust//rust:defs.bzl", "rust_analyzer_aspect") |
| |
| rust_analyzer_aspect() |
| </pre> |
| <p>Annotates rust rules with RustAnalyzerInfo later used to build a rust-project.json</p> |
| <p><strong>ASPECT ATTRIBUTES</strong></p> |
| <div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Type</th></tr></thead><tbody> |
| <tr><td style="text-align: left">deps</td><td style="text-align: left">String</td></tr> |
| <tr><td style="text-align: left">proc_macro_deps</td><td style="text-align: left">String</td></tr> |
| <tr><td style="text-align: left">crate</td><td style="text-align: left">String</td></tr> |
| <tr><td style="text-align: left">actual</td><td style="text-align: left">String</td></tr> |
| <tr><td style="text-align: left">proto</td><td style="text-align: left">String</td></tr> |
| </tbody></table> |
| </div> |
| <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-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-4"><a class="header" href="#aspects-4">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="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. To work around |
| this, we provide rust versions of the symbol definitions annotated with |
| an unstable language attribute that instructs rustc to mangle them consistently. |
| Because of that, this is only compatible with nightly versions of the compiler.</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>TODO: how this interacts with stdlibs</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">none</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_change_rust_test_compilation_output_directory"></a></p> |
| <h2 id="incompatible_change_rust_test_compilation_output_directory"><a class="header" href="#incompatible_change_rust_test_compilation_output_directory">incompatible_change_rust_test_compilation_output_directory</a></h2> |
| <pre> |
| --@rules_rust//rust/settings:incompatible_change_rust_test_compilation_output_directory |
| </pre> |
| <p>A flag to put rust_test compilation outputs in the same directory as the rust_library compilation outputs.</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="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="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="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="incompatible_runfiles_cargo_manifest_dir"></a></p> |
| <h2 id="incompatible_runfiles_cargo_manifest_dir"><a class="header" href="#incompatible_runfiles_cargo_manifest_dir">incompatible_runfiles_cargo_manifest_dir</a></h2> |
| <pre> |
| --@rules_rust//cargo/settings:incompatible_runfiles_cargo_manifest_dir |
| </pre> |
| <p>A flag which causes <code>cargo_build_script</code> to write an explicit <code>CARGO_MANIFEST_DIR</code> directory from an action instead of using runfiles directories which cannot be passed to downstream actions.</p> |
| <p>https://github.com/bazelbuild/bazel/issues/15486</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-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-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-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-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-rust_doc">rust_doc</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>) |
| </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>See <code>@rules_rust//rust:repositories.bzl</code> for examples of defining the <code>@rust_cpuX</code> repository with the actual binaries and libraries.</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 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>"@rules_rust//ffi/cc/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-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.</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.</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//ffi/cc/global_allocator_library"</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-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_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.</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> |
| </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-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_triple">exec_triple</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-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_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-rust_analyzer_version">rust_analyzer_version</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-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">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rules_rust//ffi/cc/allocator_library"</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_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-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/2025-04-03"</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. See <a href="rust_bzlmod.html#rust_repositories">rust_repositories</a> for more details.</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">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rules_rust//ffi/cc/allocator_library"</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_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>["wasm32-unknown-unknown", "wasm32-wasip1", "wasm32-wasip2"]</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_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/2025-04-03"</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. See <a href="rust_bzlmod.html#rust_repositories">rust_repositories</a> for more details.</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.86.0", "nightly/2025-04-03"]</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-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">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rules_rust//ffi/cc/allocator_library"</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-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/2025-04-03"</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. See <a href="rust_bzlmod.html#rust_repositories">rust_repositories</a> for more details.</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.86.0"</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="rust-repositories"><a class="header" href="#rust-repositories">Rust Repositories</a></h1> |
| <p>Repository rules for defining Rust dependencies and toolchains.</p> |
| <h2 id="functions-2"><a class="header" href="#functions-2">Functions</a></h2> |
| <ul> |
| <li><a href="rust_repositories.html#rules_rust_dependencies">rules_rust_dependencies</a></li> |
| <li><a href="rust_repositories.html#rust_analyzer_toolchain_repository">rust_analyzer_toolchain_repository</a></li> |
| <li><a href="rust_repositories.html#rust_register_toolchains">rust_register_toolchains</a></li> |
| <li><a href="rust_repositories.html#rust_repositories">rust_repositories</a></li> |
| <li><a href="rust_repositories.html#rust_repository_set">rust_repository_set</a></li> |
| <li><a href="rust_repositories.html#rust_toolchain_repository">rust_toolchain_repository</a></li> |
| </ul> |
| <h2 id="repository-rules-1"><a class="header" href="#repository-rules-1">Repository Rules</a></h2> |
| <ul> |
| <li><a href="rust_repositories.html#rust_toolchain_repository_proxy">rust_toolchain_repository_proxy</a></li> |
| <li><a href="rust_repositories.html#rust_toolchain_tools_repository">rust_toolchain_tools_repository</a></li> |
| </ul> |
| <p><a id="rules_rust_dependencies"></a></p> |
| <h2 id="rules_rust_dependencies"><a class="header" href="#rules_rust_dependencies">rules_rust_dependencies</a></h2> |
| <pre> |
| load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies") |
| |
| rules_rust_dependencies() |
| </pre> |
| <p>Dependencies used in the implementation of <code>rules_rust</code>.</p> |
| <p><a id="rust_analyzer_toolchain_repository"></a></p> |
| <h2 id="rust_analyzer_toolchain_repository"><a class="header" href="#rust_analyzer_toolchain_repository">rust_analyzer_toolchain_repository</a></h2> |
| <pre> |
| load("@rules_rust//rust:repositories.bzl", "rust_analyzer_toolchain_repository") |
| |
| rust_analyzer_toolchain_repository(<a href="rust_repositories.html#rust_analyzer_toolchain_repository-name">name</a>, <a href="rust_repositories.html#rust_analyzer_toolchain_repository-version">version</a>, <a href="rust_repositories.html#rust_analyzer_toolchain_repository-exec_compatible_with">exec_compatible_with</a>, <a href="rust_repositories.html#rust_analyzer_toolchain_repository-target_compatible_with">target_compatible_with</a>, |
| <a href="rust_repositories.html#rust_analyzer_toolchain_repository-sha256s">sha256s</a>, <a href="rust_repositories.html#rust_analyzer_toolchain_repository-urls">urls</a>, <a href="rust_repositories.html#rust_analyzer_toolchain_repository-auth">auth</a>, <a href="rust_repositories.html#rust_analyzer_toolchain_repository-netrc">netrc</a>, <a href="rust_repositories.html#rust_analyzer_toolchain_repository-auth_patterns">auth_patterns</a>) |
| </pre> |
| <p>Assemble a remote rust_analyzer_toolchain target based on the given params.</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_analyzer_toolchain_repository-name"></a>name</td><td style="text-align: left">The name of the toolchain proxy repository containing the registerable toolchain.</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-version"></a>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">none</td></tr> |
| <tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-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"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-target_compatible_with"></a>target_compatible_with</td><td style="text-align: left">A list of constraints for the target platform for this toolchain.</td><td style="text-align: left"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-sha256s"></a>sha256s</td><td style="text-align: left">A dict associating tool subdirectories to sha256 hashes. See <a href="rust_repositories.html#rust_register_toolchains">rust_register_toolchains</a> for more details.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-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). Defaults to ['https://static.rust-lang.org/dist/{}.tar.xz']</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-auth"></a>auth</td><td style="text-align: left">Auth object compatible with repository_ctx.download to use when downloading files. See <a href="https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download">repository_ctx.download</a> for more details.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-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"><code>None</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><strong>RETURNS</strong></p> |
| <p>str: The name of a registerable rust_analyzer_toolchain.</p> |
| <p><a id="rust_register_toolchains"></a></p> |
| <h2 id="rust_register_toolchains"><a class="header" href="#rust_register_toolchains">rust_register_toolchains</a></h2> |
| <pre> |
| load("@rules_rust//rust:repositories.bzl", "rust_register_toolchains") |
| |
| rust_register_toolchains(*, <a href="rust_repositories.html#rust_register_toolchains-dev_components">dev_components</a>, <a href="rust_repositories.html#rust_register_toolchains-edition">edition</a>, <a href="rust_repositories.html#rust_register_toolchains-allocator_library">allocator_library</a>, <a href="rust_repositories.html#rust_register_toolchains-global_allocator_library">global_allocator_library</a>, |
| <a href="rust_repositories.html#rust_register_toolchains-register_toolchains">register_toolchains</a>, <a href="rust_repositories.html#rust_register_toolchains-rustfmt_version">rustfmt_version</a>, <a href="rust_repositories.html#rust_register_toolchains-rust_analyzer_version">rust_analyzer_version</a>, <a href="rust_repositories.html#rust_register_toolchains-sha256s">sha256s</a>, |
| <a href="rust_repositories.html#rust_register_toolchains-extra_target_triples">extra_target_triples</a>, <a href="rust_repositories.html#rust_register_toolchains-extra_rustc_flags">extra_rustc_flags</a>, <a href="rust_repositories.html#rust_register_toolchains-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="rust_repositories.html#rust_register_toolchains-strip_level">strip_level</a>, |
| <a href="rust_repositories.html#rust_register_toolchains-urls">urls</a>, <a href="rust_repositories.html#rust_register_toolchains-versions">versions</a>, <a href="rust_repositories.html#rust_register_toolchains-aliases">aliases</a>, <a href="rust_repositories.html#rust_register_toolchains-hub_name">hub_name</a>, <a href="rust_repositories.html#rust_register_toolchains-compact_windows_names">compact_windows_names</a>, <a href="rust_repositories.html#rust_register_toolchains-toolchain_triples">toolchain_triples</a>, |
| <a href="rust_repositories.html#rust_register_toolchains-rustfmt_toolchain_triples">rustfmt_toolchain_triples</a>, <a href="rust_repositories.html#rust_register_toolchains-target_settings">target_settings</a>, <a href="rust_repositories.html#rust_register_toolchains-extra_toolchain_infos">extra_toolchain_infos</a>) |
| </pre> |
| <p>Emits a default set of toolchains for Linux, MacOS, and Freebsd</p> |
| <p>Skip this macro and call the <code>rust_repository_set</code> macros directly if you need a compiler for other hosts or for additional target triples.</p> |
| <p>The <code>sha256s</code> attribute represents a dict associating tool subdirectories to sha256 hashes. As an example:</p> |
| <pre><code class="language-python">{ |
| "rust-1.46.0-x86_64-unknown-linux-gnu": "e3b98bc3440fe92817881933f9564389eccb396f5f431f33d48b979fa2fbdcf5", |
| "rustfmt-1.4.12-x86_64-unknown-linux-gnu": "1894e76913303d66bf40885a601462844eec15fca9e76a6d13c390d7000d64b0", |
| "rust-std-1.46.0-x86_64-unknown-linux-gnu": "ac04aef80423f612c0079829b504902de27a6997214eb58ab0765d02f7ec1dbc", |
| } |
| </code></pre> |
| <p>This would match for <code>exec_triple = "x86_64-unknown-linux-gnu"</code>. If not specified, rules_rust pulls from a non-exhaustive list of known checksums..</p> |
| <p>See <code>load_arbitrary_tool</code> in <code>@rules_rust//rust:repositories.bzl</code> for more details.</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_register_toolchains-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"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-edition"></a>edition</td><td style="text-align: left">The rust edition to be used by default (2015, 2018, or 2021). If absent, every target is required to specify its <code>edition</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-register_toolchains"></a>register_toolchains</td><td style="text-align: left">If true, repositories will be generated to produce and register <code>rust_toolchain</code> targets.</td><td style="text-align: left"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-rustfmt_version"></a>rustfmt_version</td><td style="text-align: left">The version of rustfmt. If none is supplied and only a single version in <code>versions</code> is given, then this defaults to that version, otherwise will default to the default nightly version.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-sha256s"></a>sha256s</td><td style="text-align: left">A dict associating tool subdirectories to sha256 hashes.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-extra_target_triples"></a>extra_target_triples</td><td style="text-align: left">Additional rust-style targets that rust toolchains should support.</td><td style="text-align: left"><code>["wasm32-unknown-unknown", "wasm32-wasip1", "wasm32-wasip2"]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-extra_rustc_flags"></a>extra_rustc_flags</td><td style="text-align: left">Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-strip_level"></a>strip_level</td><td style="text-align: left">Dictionary of target triples to strip config.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-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"><code>["https://static.rust-lang.org/dist/{}.tar.xz"]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-versions"></a>versions</td><td style="text-align: left">A list of toolchain versions to download. This parameter only accepts one versions per channel. E.g. <code>["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]</code>.</td><td style="text-align: left"><code>["1.86.0", "nightly/2025-04-03"]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-aliases"></a>aliases</td><td style="text-align: left">A mapping of "full" repository name to another name to use instead.</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-hub_name"></a>hub_name</td><td style="text-align: left">The name of the bzlmod hub repository for toolchains.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-compact_windows_names"></a>compact_windows_names</td><td style="text-align: left">Whether or not to produce compact repository names for windows toolchains. This is to avoid MAX_PATH issues.</td><td style="text-align: left"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-toolchain_triples"></a>toolchain_triples</td><td style="text-align: left">Mapping of rust target triple -> repository name to create.</td><td style="text-align: left"><code>{"aarch64-apple-darwin": "rust_macos_aarch64", "aarch64-pc-windows-msvc": "rust_windows_aarch64", "aarch64-unknown-linux-gnu": "rust_linux_aarch64", "powerpc64le-unknown-linux-gnu": "rust_linux_powerpc64le", "s390x-unknown-linux-gnu": "rust_linux_s390x", "x86_64-apple-darwin": "rust_macos_x86_64", "x86_64-pc-windows-msvc": "rust_windows_x86_64", "x86_64-unknown-freebsd": "rust_freebsd_x86_64", "x86_64-unknown-linux-gnu": "rust_linux_x86_64"}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-rustfmt_toolchain_triples"></a>rustfmt_toolchain_triples</td><td style="text-align: left">Like toolchain_triples, but for rustfmt toolchains.</td><td style="text-align: left"><code>{"aarch64-apple-darwin": "rust_macos_aarch64", "aarch64-pc-windows-msvc": "rust_windows_aarch64", "aarch64-unknown-linux-gnu": "rust_linux_aarch64", "powerpc64le-unknown-linux-gnu": "rust_linux_powerpc64le", "s390x-unknown-linux-gnu": "rust_linux_s390x", "x86_64-apple-darwin": "rust_macos_x86_64", "x86_64-pc-windows-msvc": "rust_windows_x86_64", "x86_64-unknown-freebsd": "rust_freebsd_x86_64", "x86_64-unknown-linux-gnu": "rust_linux_x86_64"}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-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"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_register_toolchains-extra_toolchain_infos"></a>extra_toolchain_infos</td><td style="text-align: left">(dict[str, dict], optional): Mapping of information about extra toolchains which were created outside of this call, which should be added to the hub repo.</td><td style="text-align: left"><code>None</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_repositories"></a></p> |
| <h2 id="rust_repositories"><a class="header" href="#rust_repositories">rust_repositories</a></h2> |
| <pre> |
| load("@rules_rust//rust:repositories.bzl", "rust_repositories") |
| |
| rust_repositories(<a href="rust_repositories.html#rust_repositories-kwargs">**kwargs</a>) |
| </pre> |
| <p><strong>Deprecated</strong>: Use <a href="rust_repositories.html#rules_rust_dependencies">rules_rust_dependencies</a> and <a href="rust_repositories.html#rust_register_toolchains">rust_register_toolchains</a> directly.</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_repositories-kwargs"></a>kwargs</td><td style="text-align: left">Keyword arguments for the <code>rust_register_toolchains</code> macro.</td><td style="text-align: left">none</td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_repository_set"></a></p> |
| <h2 id="rust_repository_set"><a class="header" href="#rust_repository_set">rust_repository_set</a></h2> |
| <pre> |
| load("@rules_rust//rust:repositories.bzl", "rust_repository_set") |
| |
| rust_repository_set(*, <a href="rust_repositories.html#rust_repository_set-name">name</a>, <a href="rust_repositories.html#rust_repository_set-versions">versions</a>, <a href="rust_repositories.html#rust_repository_set-exec_triple">exec_triple</a>, <a href="rust_repositories.html#rust_repository_set-target_settings">target_settings</a>, <a href="rust_repositories.html#rust_repository_set-allocator_library">allocator_library</a>, |
| <a href="rust_repositories.html#rust_repository_set-global_allocator_library">global_allocator_library</a>, <a href="rust_repositories.html#rust_repository_set-extra_target_triples">extra_target_triples</a>, <a href="rust_repositories.html#rust_repository_set-rustfmt_version">rustfmt_version</a>, <a href="rust_repositories.html#rust_repository_set-edition">edition</a>, |
| <a href="rust_repositories.html#rust_repository_set-dev_components">dev_components</a>, <a href="rust_repositories.html#rust_repository_set-extra_rustc_flags">extra_rustc_flags</a>, <a href="rust_repositories.html#rust_repository_set-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="rust_repositories.html#rust_repository_set-opt_level">opt_level</a>, <a href="rust_repositories.html#rust_repository_set-strip_level">strip_level</a>, |
| <a href="rust_repositories.html#rust_repository_set-sha256s">sha256s</a>, <a href="rust_repositories.html#rust_repository_set-urls">urls</a>, <a href="rust_repositories.html#rust_repository_set-auth">auth</a>, <a href="rust_repositories.html#rust_repository_set-netrc">netrc</a>, <a href="rust_repositories.html#rust_repository_set-auth_patterns">auth_patterns</a>, <a href="rust_repositories.html#rust_repository_set-register_toolchain">register_toolchain</a>, |
| <a href="rust_repositories.html#rust_repository_set-exec_compatible_with">exec_compatible_with</a>, <a href="rust_repositories.html#rust_repository_set-default_target_compatible_with">default_target_compatible_with</a>, <a href="rust_repositories.html#rust_repository_set-aliases">aliases</a>, |
| <a href="rust_repositories.html#rust_repository_set-compact_windows_names">compact_windows_names</a>) |
| </pre> |
| <p>Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains.</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_repository_set-name"></a>name</td><td style="text-align: left">The name of the generated repository</td><td style="text-align: left">none</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 versions per channel. E.g. <code>["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]</code>.</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="rust_repository_set-exec_triple"></a>exec_triple</td><td style="text-align: left">The Rust-style target that this compiler runs on</td><td style="text-align: left">none</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 config_settings that must be satisfied by the target configuration in order for this set of toolchains to be selected during toolchain resolution.</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"><code>None</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 a global allocator is used with cc_common.link.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_repository_set-extra_target_triples"></a>extra_target_triples</td><td style="text-align: left">Additional rust-style targets that this set of toolchains should support. If a map, values should be (optional) target_compatible_with lists for that particular target triple.</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 rustfmt to be associated with the toolchain.</td><td style="text-align: left"><code>None</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"><code>None</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. Requires version to be "nightly".</td><td style="text-align: left"><code>False</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">Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration.</td><td style="text-align: left"><code>None</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"><code>None</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">Dictionary of target triples to optimization config.</td><td style="text-align: left"><code>None</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">Dictionary of target triples to strip config.</td><td style="text-align: left"><code>None</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. See <a href="rust_repositories.html#rust_register_toolchains">rust_register_toolchains</a> for more details.</td><td style="text-align: left"><code>None</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"><code>["https://static.rust-lang.org/dist/{}.tar.xz"]</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. See <a href="https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download">repository_ctx.download</a> for more details.</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"><code>None</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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_repository_set-register_toolchain"></a>register_toolchain</td><td style="text-align: left">If True, the generated <code>rust_toolchain</code> target will become a registered toolchain.</td><td style="text-align: left"><code>True</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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_repository_set-default_target_compatible_with"></a>default_target_compatible_with</td><td style="text-align: left">A list of constraints for the target platform for this toolchain when the exec platform is the same as the target platform.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_repository_set-aliases"></a>aliases</td><td style="text-align: left">Replacement names to use for toolchains created by this macro.</td><td style="text-align: left"><code>{}</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_repository_set-compact_windows_names"></a>compact_windows_names</td><td style="text-align: left">Whether or not to produce compact repository names for windows toolchains. This is to avoid MAX_PATH issues.</td><td style="text-align: left"><code>True</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><strong>RETURNS</strong></p> |
| <p>dict[str, dict]: A dict of information about all generated toolchains.</p> |
| <p><a id="rust_toolchain_repository"></a></p> |
| <h2 id="rust_toolchain_repository"><a class="header" href="#rust_toolchain_repository">rust_toolchain_repository</a></h2> |
| <pre> |
| load("@rules_rust//rust:repositories.bzl", "rust_toolchain_repository") |
| |
| rust_toolchain_repository(<a href="rust_repositories.html#rust_toolchain_repository-name">name</a>, <a href="rust_repositories.html#rust_toolchain_repository-version">version</a>, <a href="rust_repositories.html#rust_toolchain_repository-exec_triple">exec_triple</a>, <a href="rust_repositories.html#rust_toolchain_repository-target_triple">target_triple</a>, <a href="rust_repositories.html#rust_toolchain_repository-exec_compatible_with">exec_compatible_with</a>, |
| <a href="rust_repositories.html#rust_toolchain_repository-target_compatible_with">target_compatible_with</a>, <a href="rust_repositories.html#rust_toolchain_repository-target_settings">target_settings</a>, <a href="rust_repositories.html#rust_toolchain_repository-channel">channel</a>, <a href="rust_repositories.html#rust_toolchain_repository-allocator_library">allocator_library</a>, |
| <a href="rust_repositories.html#rust_toolchain_repository-global_allocator_library">global_allocator_library</a>, <a href="rust_repositories.html#rust_toolchain_repository-rustfmt_version">rustfmt_version</a>, <a href="rust_repositories.html#rust_toolchain_repository-edition">edition</a>, <a href="rust_repositories.html#rust_toolchain_repository-dev_components">dev_components</a>, |
| <a href="rust_repositories.html#rust_toolchain_repository-extra_rustc_flags">extra_rustc_flags</a>, <a href="rust_repositories.html#rust_toolchain_repository-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="rust_repositories.html#rust_toolchain_repository-opt_level">opt_level</a>, <a href="rust_repositories.html#rust_toolchain_repository-strip_level">strip_level</a>, <a href="rust_repositories.html#rust_toolchain_repository-sha256s">sha256s</a>, |
| <a href="rust_repositories.html#rust_toolchain_repository-urls">urls</a>, <a href="rust_repositories.html#rust_toolchain_repository-auth">auth</a>, <a href="rust_repositories.html#rust_toolchain_repository-netrc">netrc</a>, <a href="rust_repositories.html#rust_toolchain_repository-auth_patterns">auth_patterns</a>) |
| </pre> |
| <p>Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains.</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_toolchain_repository-name"></a>name</td><td style="text-align: left">The name of the generated repository</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-version"></a>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">none</td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-exec_triple"></a>exec_triple</td><td style="text-align: left">The Rust-style target that this compiler runs on.</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-target_triple"></a>target_triple</td><td style="text-align: left">The Rust-style target to build for.</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-target_compatible_with"></a>target_compatible_with</td><td style="text-align: left">A list of constraints for the target platform for this toolchain.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-target_settings"></a>target_settings</td><td style="text-align: left">A list of config_settings 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"><code>[]</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-channel"></a>channel</td><td style="text-align: left">The channel of the Rust toolchain.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-global_allocator_library"></a>global_allocator_library</td><td style="text-align: left">Target that provides allocator functions when a global allocator is used with cc_common.link.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-rustfmt_version"></a>rustfmt_version</td><td style="text-align: left">The version of rustfmt to be associated with the toolchain.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-dev_components"></a>dev_components</td><td style="text-align: left">Whether to download the rustc-dev components. Requires version to be "nightly". Defaults to False.</td><td style="text-align: left"><code>False</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-opt_level"></a>opt_level</td><td style="text-align: left">Optimization level config for this toolchain.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-strip_level"></a>strip_level</td><td style="text-align: left">Strip level config for this toolchain.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-sha256s"></a>sha256s</td><td style="text-align: left">A dict associating tool subdirectories to sha256 hashes. See <a href="rust_repositories.html#rust_register_toolchains">rust_register_toolchains</a> for more details.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-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). Defaults to ['https://static.rust-lang.org/dist/{}.tar.xz']</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_repository-auth"></a>auth</td><td style="text-align: left">Auth object compatible with repository_ctx.download to use when downloading files. See <a href="https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download">repository_ctx.download</a> for more details.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository-auth_patterns"></a>auth_patterns</td><td style="text-align: left">A list of patterns to match against urls for which the auth object should be used.</td><td style="text-align: left"><code>None</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><strong>RETURNS</strong></p> |
| <p>dict[str, str]: Information about the registerable toolchain created by this rule.</p> |
| <p><a id="rust_toolchain_repository_proxy"></a></p> |
| <h2 id="rust_toolchain_repository_proxy"><a class="header" href="#rust_toolchain_repository_proxy">rust_toolchain_repository_proxy</a></h2> |
| <pre> |
| load("@rules_rust//rust:repositories.bzl", "rust_toolchain_repository_proxy") |
| |
| rust_toolchain_repository_proxy(<a href="rust_repositories.html#rust_toolchain_repository_proxy-name">name</a>, <a href="rust_repositories.html#rust_toolchain_repository_proxy-exec_compatible_with">exec_compatible_with</a>, <a href="rust_repositories.html#rust_toolchain_repository_proxy-repo_mapping">repo_mapping</a>, <a href="rust_repositories.html#rust_toolchain_repository_proxy-target_compatible_with">target_compatible_with</a>, |
| <a href="rust_repositories.html#rust_toolchain_repository_proxy-target_settings">target_settings</a>, <a href="rust_repositories.html#rust_toolchain_repository_proxy-toolchain">toolchain</a>, <a href="rust_repositories.html#rust_toolchain_repository_proxy-toolchain_type">toolchain_type</a>) |
| </pre> |
| <p>Generates a toolchain-bearing repository that declares the toolchains from some other rust_toolchain_repository.</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_repository_proxy-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="rust_toolchain_repository_proxy-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">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_repository_proxy-repo_mapping"></a>repo_mapping</td><td style="text-align: left">In <code>WORKSPACE</code> context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<br><br>For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>).<br><br>This attribute is <em>not</em> supported in <code>MODULE.bazel</code> context (when invoking a repository rule inside a module extension's implementation function).</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"></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_repository_proxy-target_compatible_with"></a>target_compatible_with</td><td style="text-align: left">A list of constraints for the target platform for this toolchain.</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_repository_proxy-target_settings"></a>target_settings</td><td style="text-align: left">A list of config_settings 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">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_repository_proxy-toolchain"></a>toolchain</td><td style="text-align: left">The name of the toolchain implementation target.</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_repository_proxy-toolchain_type"></a>toolchain_type</td><td style="text-align: left">The toolchain type of the toolchain to declare</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="rust_toolchain_tools_repository"></a></p> |
| <h2 id="rust_toolchain_tools_repository"><a class="header" href="#rust_toolchain_tools_repository">rust_toolchain_tools_repository</a></h2> |
| <pre> |
| load("@rules_rust//rust:repositories.bzl", "rust_toolchain_tools_repository") |
| |
| rust_toolchain_tools_repository(<a href="rust_repositories.html#rust_toolchain_tools_repository-name">name</a>, <a href="rust_repositories.html#rust_toolchain_tools_repository-allocator_library">allocator_library</a>, <a href="rust_repositories.html#rust_toolchain_tools_repository-auth">auth</a>, <a href="rust_repositories.html#rust_toolchain_tools_repository-auth_patterns">auth_patterns</a>, <a href="rust_repositories.html#rust_toolchain_tools_repository-dev_components">dev_components</a>, |
| <a href="rust_repositories.html#rust_toolchain_tools_repository-edition">edition</a>, <a href="rust_repositories.html#rust_toolchain_tools_repository-exec_triple">exec_triple</a>, <a href="rust_repositories.html#rust_toolchain_tools_repository-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="rust_repositories.html#rust_toolchain_tools_repository-extra_rustc_flags">extra_rustc_flags</a>, |
| <a href="rust_repositories.html#rust_toolchain_tools_repository-global_allocator_library">global_allocator_library</a>, <a href="rust_repositories.html#rust_toolchain_tools_repository-netrc">netrc</a>, <a href="rust_repositories.html#rust_toolchain_tools_repository-opt_level">opt_level</a>, <a href="rust_repositories.html#rust_toolchain_tools_repository-repo_mapping">repo_mapping</a>, |
| <a href="rust_repositories.html#rust_toolchain_tools_repository-rustfmt_version">rustfmt_version</a>, <a href="rust_repositories.html#rust_toolchain_tools_repository-sha256s">sha256s</a>, <a href="rust_repositories.html#rust_toolchain_tools_repository-strip_level">strip_level</a>, <a href="rust_repositories.html#rust_toolchain_tools_repository-target_triple">target_triple</a>, <a href="rust_repositories.html#rust_toolchain_tools_repository-urls">urls</a>, <a href="rust_repositories.html#rust_toolchain_tools_repository-version">version</a>) |
| </pre> |
| <p>Composes a single workspace containing the toolchain components for compiling on a given platform to a series of target platforms.</p> |
| <p>A given instance of this rule should be accompanied by a toolchain_repository_proxy invocation to declare its toolchains to Bazel; the indirection allows separating toolchain selection from toolchain fetching.</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_tools_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="rust_toolchain_tools_repository-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">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rules_rust//ffi/cc/allocator_library"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-auth"></a>auth</td><td style="text-align: left">Auth object compatible with repository_ctx.download to use when downloading files. See <a href="https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download">repository_ctx.download</a> for more details.</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_tools_repository-auth_patterns"></a>auth_patterns</td><td style="text-align: left">A list of patterns to match against urls for which the auth object should be used.</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_tools_repository-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_tools_repository-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_tools_repository-exec_triple"></a>exec_triple</td><td style="text-align: left">The Rust-style target that this compiler runs on</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_tools_repository-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_tools_repository-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_tools_repository-global_allocator_library"></a>global_allocator_library</td><td style="text-align: left">Target that provides allocator functions when a global allocator is used with cc_common.link.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rules_rust//ffi/cc/global_allocator_library"</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-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_toolchain_tools_repository-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_toolchain_tools_repository-repo_mapping"></a>repo_mapping</td><td style="text-align: left">In <code>WORKSPACE</code> context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<br><br>For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>).<br><br>This attribute is <em>not</em> supported in <code>MODULE.bazel</code> context (when invoking a repository rule inside a module extension's implementation function).</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"></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-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>""</code></td></tr> |
| <tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-sha256s"></a>sha256s</td><td style="text-align: left">A dict associating tool subdirectories to sha256 hashes. See <a href="rust_repositories.html#rust_register_toolchains">rust_register_toolchains</a> for more details.</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_tools_repository-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_tools_repository-target_triple"></a>target_triple</td><td style="text-align: left">The Rust-style target that this compiler builds for.</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_tools_repository-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_tools_repository-version"></a>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">required</td><td style="text-align: left"></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.64.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, set the following to begin using </code>crate_universe`:</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 and aliases 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 dependencies and alias definitions |
| 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") |
| load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") |
| |
| rust_library( |
| name = "lib", |
| aliases = aliases(), |
| 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, |
| ), |
| 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"], |
| 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/examples/bzlmod/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/examples/crate_universe/MODULE.bazel#L279-L291">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:extension.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/examples/bzlmod/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.1") |
| |
| # https://github.com/bazelbuild/rules_rust/releases |
| bazel_dep(name = "rules_rust", version = "0.64.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/bzlmod/">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_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_data_select">build_script_data_select</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_env_select">build_script_env_select</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.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-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-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-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_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_data_select"></a>build_script_data_select</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::data</code> attribute. Keys should be the platform triplet. Value should be a list of labels.</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="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_env_select"></a>build_script_env_select</td><td style="text-align: left">Additional environment variables to set on a crate's <code>cargo_build_script::env</code> attribute. Key should be the platform triplet. Value should be a JSON encoded dictionary mapping variable names to values, for example <code>{"FOO": "bar"}</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="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.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-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-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>.</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-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>.</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><!-- Generated with Stardoc: http://skydoc.bazel.build --> |
| <h1 id="crate-universe-1"><a class="header" href="#crate-universe-1">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 from a WORKSPACE file.</p> |
| <p>If you're using bzlmod, please see <a href="crate_universe_bzlmod.html">the bzlmod equivalent of this doc</a>.</p> |
| <h2 id="setup-6"><a class="header" href="#setup-6">Setup</a></h2> |
| <p>After loading <code>rules_rust</code> in your workspace, set the following to begin using <code>crate_universe</code>:</p> |
| <pre><code class="language-python">load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies") |
| |
| crate_universe_dependencies() |
| </code></pre> |
| <p>Note that if the current version of <code>rules_rust</code> is not a release artifact, you may need to set additional |
| flags such as <a href="crate_universe_workspace.html#crate_universe_dependencies-bootstrap"><code>bootstrap = True</code></a> on the <code>crate_universe_dependencies</code> |
| call above or <a href="crate_universe_workspace.html#crates_repository-generator_urls">crates_repository::generator_urls</a> in uses of <code>crates_repository</code>.</p> |
| <h2 id="rules-8"><a class="header" href="#rules-8">Rules</a></h2> |
| <ul> |
| <li><a href="crate_universe_workspace.html#crates_repository">crates_repository</a></li> |
| <li><a href="crate_universe_workspace.html#crates_vendor">crates_vendor</a></li> |
| </ul> |
| <h2 id="utility-macros"><a class="header" href="#utility-macros">Utility Macros</a></h2> |
| <ul> |
| <li><a href="crate_universe_workspace.html#crate_universe_dependencies">crate_universe_dependencies</a></li> |
| <li><a href="crate_universe_workspace.html#crateannotation">crate.annotation</a></li> |
| <li><a href="crate_universe_workspace.html#crateselect">crate.select</a></li> |
| <li><a href="crate_universe_workspace.html#cratespec">crate.spec</a></li> |
| <li><a href="crate_universe_workspace.html#crateworkspace_member">crate.workspace_member</a></li> |
| <li><a href="crate_universe_workspace.html#render_config">render_config</a></li> |
| <li><a href="crate_universe_workspace.html#splicing_config">splicing_config</a></li> |
| </ul> |
| <h2 id="workflows"><a class="header" href="#workflows">Workflows</a></h2> |
| <p>The <a href="crate_universe_workspace.html#crates_repository"><code>crates_repository</code></a> rule (the primary repository rule of <code>rules_rust</code>'s cargo support) supports a number of different |
| ways users can express and organize their dependencies. The most common are listed below though there are more to be found in |
| the <a href="https://github.com/bazelbuild/rules_rust/tree/main/examples/crate_universe">./examples/crate_universe</a> directory.</p> |
| <h3 id="cargo-workspaces-1"><a class="header" href="#cargo-workspaces-1">Cargo Workspaces</a></h3> |
| <p>One of the simpler ways to wire up dependencies would be to first structure your project into a <a href="https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html">Cargo workspace</a>. |
| The <code>crates_repository</code> rule can ingest a root <code>Cargo.toml</code> file and generate dependencies from there.</p> |
| <pre><code class="language-python">load("@rules_rust//crate_universe:defs.bzl", "crates_repository") |
| |
| crates_repository( |
| name = "crate_index", |
| cargo_lockfile = "//:Cargo.lock", |
| lockfile = "//:Cargo.Bazel.lock", |
| manifests = ["//:Cargo.toml"], |
| ) |
| |
| load("@crate_index//:defs.bzl", "crate_repositories") |
| |
| crate_repositories() |
| </code></pre> |
| <p>The generated <code>crates_repository</code> contains helper macros which make collecting dependencies for Bazel targets simpler. |
| Notably, the <code>all_crate_deps</code> and <code>aliases</code> macros (see <a href="crate_universe_workspace.html#dependencies-api">Dependencies API</a>) commonly allow the |
| <code>Cargo.toml</code> files to be the single source of truth for dependencies. Since these macros come from the generated |
| repository, the dependencies and alias definitions they return will automatically update BUILD targets.</p> |
| <pre><code class="language-python">load("@crate_index//:defs.bzl", "aliases", "all_crate_deps") |
| load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") |
| |
| rust_library( |
| name = "lib", |
| aliases = aliases(), |
| 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, |
| ), |
| deps = all_crate_deps( |
| normal_dev = True, |
| ), |
| proc_macro_deps = all_crate_deps( |
| proc_macro_dev = True, |
| ), |
| ) |
| </code></pre> |
| <h3 id="direct-packages"><a class="header" href="#direct-packages">Direct Packages</a></h3> |
| <p>In cases where Rust targets have heavy interractions 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/latest/lang/rust.html">Proto</a>, etc.), |
| maintaining <code>Cargo.toml</code> files may have deminishing returns as things like <a href="https://rust-analyzer.github.io/">rust-analyzer</a> begin to be confused |
| about missing targets or environment variables defined only in Bazel. In workspaces like this, it may be desirable |
| to have a "Cargo free" setup. <code>crates_repository</code> supports this through the <code>packages</code> attribute.</p> |
| <pre><code class="language-python">load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_repository", "render_config") |
| |
| crates_repository( |
| name = "crate_index", |
| cargo_lockfile = "//:Cargo.lock", |
| lockfile = "//:Cargo.Bazel.lock", |
| packages = { |
| "async-trait": crate.spec( |
| version = "0.1.51", |
| ), |
| "mockall": crate.spec( |
| version = "0.10.2", |
| ), |
| "tokio": crate.spec( |
| version = "1.12.0", |
| ), |
| }, |
| # Setting the default package name to `""` forces the use of the macros defined in this repository |
| # to always use the root package when looking for dependencies or aliases. This should be considered |
| # optional as the repository also exposes aliases for easy access to all dependencies. |
| render_config = render_config( |
| default_package_name = "" |
| ), |
| ) |
| |
| load("@crate_index//:defs.bzl", "crate_repositories") |
| |
| crate_repositories() |
| </code></pre> |
| <p>Consuming dependencies may be more ergonomic in this case through the aliases defined in the new repository.</p> |
| <pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") |
| |
| rust_library( |
| name = "lib", |
| deps = [ |
| "@crate_index//:tokio", |
| ], |
| proc_macro_deps = [ |
| "@crate_index//:async-trait", |
| ], |
| ) |
| |
| rust_test( |
| name = "unit_test", |
| crate = ":lib", |
| deps = [ |
| "@crate_index//:mockall", |
| ], |
| ) |
| </code></pre> |
| <h3 id="binary-dependencies-1"><a class="header" href="#binary-dependencies-1">Binary dependencies</a></h3> |
| <p>Neither of the above approaches supports depending on binary-only packages.</p> |
| <p>In order to depend on a Cargo package that contains binaries and no library, you |
| will need to do one of the following:</p> |
| <ul> |
| <li> |
| <p>Fork the package to add an empty lib.rs, which makes the package visible to |
| Cargo metadata and compatible with the above approaches;</p> |
| </li> |
| <li> |
| <p>Or handwrite your own build target for the binary, use <code>http_archive</code> to |
| import its source code, and use <code>crates_repository</code> to make build targets for |
| its dependencies. This is demonstrated below using the <code>rustfilt</code> crate as an |
| example.</p> |
| </li> |
| </ul> |
| <pre><code class="language-python"># in WORKSPACE.bazel |
| |
| load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") |
| |
| http_archive( |
| name = "rustfilt", |
| build_file = "//rustfilt:BUILD.rustfilt.bazel", |
| sha256 = "c8d748b182c8f95224336d20dcc5609598af612581ce60cfb29da4dc8d0091f2", |
| strip_prefix = "rustfilt-0.2.1", |
| type = "tar.gz", |
| urls = ["https://static.crates.io/crates/rustfilt/rustfilt-0.2.1.crate"], |
| ) |
| |
| load("@rules_rust//crate_universe:defs.bzl", "crates_repository") |
| |
| crates_repository( |
| name = "rustfilt_deps", |
| cargo_lockfile = "//rustfilt:Cargo.lock", |
| manifests = ["@rustfilt//:Cargo.toml"], |
| ) |
| |
| load("@rustfilt_deps//:defs.bzl", rustfilt_deps = "crate_repositories") |
| |
| rustfilt_deps() |
| </code></pre> |
| <pre><code class="language-python"># in rustfilt/BUILD.rustfilt.bazel |
| |
| load("@rules_rust//rust:defs.bzl", "rust_binary") |
| |
| rust_binary( |
| name = "rustfilt", |
| srcs = glob(["src/**/*.rs"]), |
| edition = "2018", |
| deps = [ |
| "@rustfilt_deps//:clap", |
| "@rustfilt_deps//:lazy_static", |
| "@rustfilt_deps//:regex", |
| "@rustfilt_deps//:rustc-demangle", |
| ], |
| ) |
| </code></pre> |
| <p>If you use either <code>crates_repository</code> or <code>crates_vendor</code> to depend on a Cargo |
| package that contains <em>both</em> a library crate <em>and</em> binaries, by default only the |
| library gets made available to Bazel. To generate Bazel targets for the binary |
| crates as well, you must opt in to it with an annotation on the package:</p> |
| <pre><code class="language-python">load("@rules_rust//crate_universe:defs.bzl", "crates_repository", "crate") |
| |
| crates_repository( |
| name = "crate_index", |
| annotations = { |
| "thepackage": [crate.annotation( |
| gen_binaries = True, |
| # Or, to expose just a subset of the package's binaries by name: |
| gen_binaries = ["rustfilt"], |
| )], |
| }, |
| # Or, to expose every binary of every package: |
| generate_binaries = True, |
| ... |
| ) |
| </code></pre> |
| <h2 id="dependencies-api"><a class="header" href="#dependencies-api">Dependencies API</a></h2> |
| <p>After rendering dependencies, convenience macros may also be generated to provide |
| convenient accessors to larger sections of the dependency graph.</p> |
| <ul> |
| <li><a href="crate_universe_workspace.html#aliases">aliases</a></li> |
| <li><a href="crate_universe_workspace.html#crate_deps">crate_deps</a></li> |
| <li><a href="crate_universe_workspace.html#all_crate_deps">all_crate_deps</a></li> |
| <li><a href="crate_universe_workspace.html#crate_repositories">crate_repositories</a></li> |
| </ul> |
| <h2 id="building-crates-with-complicated-dependencies"><a class="header" href="#building-crates-with-complicated-dependencies">Building crates with complicated dependencies</a></h2> |
| <p>Some crates have build.rs scripts which are complicated to run. Typically these build C++ (or other languages), or attempt to find pre-installed libraries on the build machine.</p> |
| <p>There are a few approaches to making sure these run:</p> |
| <h3 id="some-things-work-without-intervention"><a class="header" href="#some-things-work-without-intervention">Some things work without intervention</a></h3> |
| <p>Some build scripts will happily run without any support needed.</p> |
| <p>rules_rust already supplies a configured C++ toolchain as input to build script execution, and sets variables like <code>CC</code>, <code>CXX</code>, <code>LD</code>, <code>LDFLAGS</code>, etc as needed. Many crates which invoke a compiler with the default environment, or forward these env vars, will Just Work (e.g. if using <a href="https://github.com/rust-lang/cc-rs"><code>cc-rs</code></a>).</p> |
| <p>rules_rust is open to PRs which make build scripts more likely to work by default with intervention assuming they're broadly applicable (e.g. setting extra widely-known env vars is probably fine, wiring up additional toolchains like <code>cmake</code> that aren't present by default for most Bazel users probably isn't).</p> |
| <h3 id="supplying-extra-tools-to-build"><a class="header" href="#supplying-extra-tools-to-build">Supplying extra tools to build</a></h3> |
| <p>Some build scripts can be made to work by pulling in some extra files and making them available to the build script.</p> |
| <p>Commonly this is done by passing the file to the <code>build_script_data</code> annotation for the crate, and using <code>build_script_env</code> to tell the build script where the file is. That env var may often use <code>$(execroot)</code> to get the path to the label, or <code>$${pwd}/</code> as a prefix if the path given is relative to the execroot (as will frequently happen when using a toolchain).A</p> |
| <p>There is an example of this in the "complicated dependencies" section of https://github.com/bazelbuild/rules_rust/blob/main/examples/crate_universe/WORKSPACE.bazel which builds boring-sys.</p> |
| <h3 id="building-with-bazel-and-supplying-via-an-override"><a class="header" href="#building-with-bazel-and-supplying-via-an-override">Building with Bazel and supplying via an override</a></h3> |
| <p>Some build scripts have hooks to allow replacing parts that are complicated to build with output prepared by Bazel.</p> |
| <p>We can use those hooks by specifying paths (generally using the <code>build_script_data</code> and <code>build_script_env</code> annotations) and pointing them at labels which Bazel will then build. These env vars may often use <code>$(execroot)</code> to get the path to the label, or <code>$${pwd}/</code> as a prefix if the path given is relative to the execroot (as will frequently happen when using a toolchain).</p> |
| <p>There is an example of this in the "complicated dependencies" section of https://github.com/bazelbuild/rules_rust/blob/main/examples/crate_universe/WORKSPACE.bazel which builds boring-sys.</p> |
| <hr /> |
| <hr /> |
| <p><a id="crates_vendor"></a></p> |
| <h2 id="crates_vendor"><a class="header" href="#crates_vendor">crates_vendor</a></h2> |
| <pre> |
| load("@rules_rust//crate_universe:defs.bzl", "crates_vendor") |
| |
| crates_vendor(<a href="crate_universe_workspace.html#crates_vendor-name">name</a>, <a href="crate_universe_workspace.html#crates_vendor-annotations">annotations</a>, <a href="crate_universe_workspace.html#crates_vendor-bazel">bazel</a>, <a href="crate_universe_workspace.html#crates_vendor-buildifier">buildifier</a>, <a href="crate_universe_workspace.html#crates_vendor-cargo_bazel">cargo_bazel</a>, <a href="crate_universe_workspace.html#crates_vendor-cargo_config">cargo_config</a>, <a href="crate_universe_workspace.html#crates_vendor-cargo_lockfile">cargo_lockfile</a>, |
| <a href="crate_universe_workspace.html#crates_vendor-generate_binaries">generate_binaries</a>, <a href="crate_universe_workspace.html#crates_vendor-generate_build_scripts">generate_build_scripts</a>, <a href="crate_universe_workspace.html#crates_vendor-generate_cargo_toml_env_vars">generate_cargo_toml_env_vars</a>, |
| <a href="crate_universe_workspace.html#crates_vendor-generate_target_compatible_with">generate_target_compatible_with</a>, <a href="crate_universe_workspace.html#crates_vendor-lockfile">lockfile</a>, <a href="crate_universe_workspace.html#crates_vendor-manifests">manifests</a>, <a href="crate_universe_workspace.html#crates_vendor-mode">mode</a>, <a href="crate_universe_workspace.html#crates_vendor-packages">packages</a>, <a href="crate_universe_workspace.html#crates_vendor-render_config">render_config</a>, |
| <a href="crate_universe_workspace.html#crates_vendor-repository_name">repository_name</a>, <a href="crate_universe_workspace.html#crates_vendor-splicing_config">splicing_config</a>, <a href="crate_universe_workspace.html#crates_vendor-supported_platform_triples">supported_platform_triples</a>, <a href="crate_universe_workspace.html#crates_vendor-vendor_path">vendor_path</a>) |
| </pre> |
| <p>A rule for defining Rust dependencies (crates) and writing targets for them to the current workspace. |
| This rule is useful for users whose workspaces are expected to be consumed in other workspaces as the |
| rendered <code>BUILD</code> files reduce the number of workspace dependencies, allowing for easier loads. This rule |
| handles all the same <a href="crate_universe_workspace.html#workflows">workflows</a> <code>crate_universe</code> rules do.</p> |
| <p>Example:</p> |
| <p>Given the following workspace structure:</p> |
| <pre><code class="language-text">[workspace]/ |
| WORKSPACE |
| BUILD |
| Cargo.toml |
| 3rdparty/ |
| BUILD |
| src/ |
| main.rs |
| </code></pre> |
| <p>The following is something that'd be found in <code>3rdparty/BUILD</code>:</p> |
| <pre><code class="language-python">load("@rules_rust//crate_universe:defs.bzl", "crates_vendor", "crate") |
| |
| crates_vendor( |
| name = "crates_vendor", |
| annotations = { |
| "rand": [crate.annotation( |
| default_features = False, |
| features = ["small_rng"], |
| )], |
| }, |
| cargo_lockfile = "//:Cargo.Bazel.lock", |
| manifests = ["//:Cargo.toml"], |
| mode = "remote", |
| vendor_path = "crates", |
| tags = ["manual"], |
| ) |
| </code></pre> |
| <p>The above creates a target that can be run to write <code>BUILD</code> files into the <code>3rdparty</code> |
| directory next to where the target is defined. To run it, simply call:</p> |
| <pre><code class="language-shell">bazel run //3rdparty:crates_vendor |
| </code></pre> |
| <p><a id="#crates_vendor_repinning_updating_dependencies"></a></p> |
| <h3 id="repinning--updating-dependencies"><a class="header" href="#repinning--updating-dependencies">Repinning / Updating Dependencies</a></h3> |
| <p>Repinning dependencies is controlled by both the <code>CARGO_BAZEL_REPIN</code> environment variable or the <code>--repin</code> |
| flag to the <code>crates_vendor</code> binary. To update dependencies, simply add the flag ro your <code>bazel run</code> invocation.</p> |
| <pre><code class="language-shell">bazel run //3rdparty:crates_vendor -- --repin |
| </code></pre> |
| <p>Under the hood, <code>--repin</code> will trigger a <a href="https://doc.rust-lang.org/cargo/commands/cargo-update.html">cargo update</a> |
| call against the generated workspace. The following table describes how to control particular values passed to the |
| <code>cargo update</code> command.</p> |
| <div class="table-wrapper"><table><thead><tr><th>Value</th><th>Cargo command</th></tr></thead><tbody> |
| <tr><td>Any of [<code>true</code>, <code>1</code>, <code>yes</code>, <code>on</code>, <code>workspace</code>]</td><td><code>cargo update --workspace</code></td></tr> |
| <tr><td>Any of [<code>full</code>, <code>eager</code>, <code>all</code>]</td><td><code>cargo update</code></td></tr> |
| <tr><td><code>package_name</code></td><td><code>cargo upgrade --package package_name</code></td></tr> |
| <tr><td><code>package_name@1.2.3</code></td><td><code>cargo upgrade --package package_name --precise 1.2.3</code></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="crates_vendor-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="crates_vendor-annotations"></a>annotations</td><td style="text-align: left">Extra settings to apply to crates. See <a href="crate_universe_workspace.html#crateannotation">crate.annotation</a>.</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="crates_vendor-bazel"></a>bazel</td><td style="text-align: left">The path to a bazel binary used to locate the output_base for the current workspace.</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="crates_vendor-buildifier"></a>buildifier</td><td style="text-align: left">The path to a <a href="https://github.com/bazelbuild/buildtools/blob/5.0.1/buildifier/README.md">buildifier</a> binary used to format 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>"@rules_rust//crate_universe/private/vendor:buildifier"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crates_vendor-cargo_bazel"></a>cargo_bazel</td><td style="text-align: left">The cargo-bazel binary to use for vendoring. If this attribute is not set, then a <code>CARGO_BAZEL_GENERATOR_PATH</code> action env will be used.</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++cu_nr+cargo_bazel_bootstrap//:binary"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crates_vendor-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="crates_vendor-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="crates_vendor-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="crates_vendor-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="crates_vendor-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="crates_vendor-generate_target_compatible_with"></a>generate_target_compatible_with</td><td style="text-align: left">DEPRECATED: Moved to <code>render_config</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="crates_vendor-lockfile"></a>lockfile</td><td style="text-align: left">The path to a file to write rendering information. It contains the same information as the lockfile attribute of crates_repository. It is not used by crates_vendor but may be useful for code generators like gazelle.</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="crates_vendor-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="crates_vendor-mode"></a>mode</td><td style="text-align: left">Flags determining how crates should be vendored. <code>local</code> is where crate source and BUILD files are written to the repository. <code>remote</code> is where only BUILD files are written and repository rules used to fetch source code.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"remote"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crates_vendor-packages"></a>packages</td><td style="text-align: left">A set of crates (packages) specifications to depend on. See <a href="crate_universe_workspace.html#crate.spec">crate.spec</a>.</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="crates_vendor-render_config"></a>render_config</td><td style="text-align: left">The configuration flags to use for rendering. Use <code>//crate_universe:defs.bzl\%render_config</code> to generate the value for this field. If unset, the defaults defined there 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="crates_vendor-repository_name"></a>repository_name</td><td style="text-align: left">The name of the repository to generate for <code>remote</code> vendor modes. If unset, the label 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="crates_vendor-splicing_config"></a>splicing_config</td><td style="text-align: left">The configuration flags to use for splicing Cargo maniests. Use <code>//crate_universe:defs.bzl\%rsplicing_config</code> to generate the value for this field. If unset, the defaults defined there 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="crates_vendor-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-apple-ios", "aarch64-apple-ios-sim", "aarch64-linux-android", "aarch64-pc-windows-msvc", "aarch64-unknown-fuchsia", "aarch64-unknown-linux-gnu", "aarch64-unknown-nixos-gnu", "aarch64-unknown-nto-qnx710", "aarch64-unknown-uefi", "arm-unknown-linux-gnueabi", "armv7-linux-androideabi", "armv7-unknown-linux-gnueabi", "i686-apple-darwin", "i686-linux-android", "i686-pc-windows-msvc", "i686-unknown-freebsd", "i686-unknown-linux-gnu", "powerpc-unknown-linux-gnu", "riscv32imc-unknown-none-elf", "riscv64gc-unknown-linux-gnu", "riscv64gc-unknown-none-elf", "s390x-unknown-linux-gnu", "thumbv7em-none-eabi", "thumbv8m.main-none-eabi", "wasm32-unknown-emscripten", "wasm32-unknown-unknown", "wasm32-wasip1", "wasm32-wasip1-threads", "wasm32-wasip2", "x86_64-apple-darwin", "x86_64-apple-ios", "x86_64-linux-android", "x86_64-pc-windows-msvc", "x86_64-unknown-freebsd", "x86_64-unknown-fuchsia", "x86_64-unknown-linux-gnu", "x86_64-unknown-nixos-gnu", "x86_64-unknown-none", "x86_64-unknown-uefi"]</code></td></tr> |
| <tr><td style="text-align: left"><a id="crates_vendor-vendor_path"></a>vendor_path</td><td style="text-align: left">The path to a directory to write files into. Absolute paths will be treated as relative to the workspace root</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"crates"</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><a id="crate.annotation"></a></p> |
| <h2 id="crateannotation"><a class="header" href="#crateannotation">crate.annotation</a></h2> |
| <pre> |
| load("@rules_rust//crate_universe:defs.bzl", "crate") |
| |
| crate.annotation(<a href="crate_universe_workspace.html#crate.annotation-version">version</a>, <a href="crate_universe_workspace.html#crate.annotation-additive_build_file">additive_build_file</a>, <a href="crate_universe_workspace.html#crate.annotation-additive_build_file_content">additive_build_file_content</a>, <a href="crate_universe_workspace.html#crate.annotation-alias_rule">alias_rule</a>, |
| <a href="crate_universe_workspace.html#crate.annotation-build_script_compile_data">build_script_compile_data</a>, <a href="crate_universe_workspace.html#crate.annotation-build_script_data">build_script_data</a>, <a href="crate_universe_workspace.html#crate.annotation-build_script_tools">build_script_tools</a>, |
| <a href="crate_universe_workspace.html#crate.annotation-build_script_data_glob">build_script_data_glob</a>, <a href="crate_universe_workspace.html#crate.annotation-build_script_deps">build_script_deps</a>, <a href="crate_universe_workspace.html#crate.annotation-build_script_env">build_script_env</a>, <a href="crate_universe_workspace.html#crate.annotation-build_script_link_deps">build_script_link_deps</a>, |
| <a href="crate_universe_workspace.html#crate.annotation-build_script_proc_macro_deps">build_script_proc_macro_deps</a>, <a href="crate_universe_workspace.html#crate.annotation-build_script_rundir">build_script_rundir</a>, <a href="crate_universe_workspace.html#crate.annotation-build_script_rustc_env">build_script_rustc_env</a>, |
| <a href="crate_universe_workspace.html#crate.annotation-build_script_toolchains">build_script_toolchains</a>, <a href="crate_universe_workspace.html#crate.annotation-build_script_use_default_shell_env">build_script_use_default_shell_env</a>, <a href="crate_universe_workspace.html#crate.annotation-compile_data">compile_data</a>, |
| <a href="crate_universe_workspace.html#crate.annotation-compile_data_glob">compile_data_glob</a>, <a href="crate_universe_workspace.html#crate.annotation-compile_data_glob_excludes">compile_data_glob_excludes</a>, <a href="crate_universe_workspace.html#crate.annotation-crate_features">crate_features</a>, <a href="crate_universe_workspace.html#crate.annotation-data">data</a>, <a href="crate_universe_workspace.html#crate.annotation-data_glob">data_glob</a>, <a href="crate_universe_workspace.html#crate.annotation-deps">deps</a>, |
| <a href="crate_universe_workspace.html#crate.annotation-extra_aliased_targets">extra_aliased_targets</a>, <a href="crate_universe_workspace.html#crate.annotation-gen_binaries">gen_binaries</a>, <a href="crate_universe_workspace.html#crate.annotation-disable_pipelining">disable_pipelining</a>, <a href="crate_universe_workspace.html#crate.annotation-gen_build_script">gen_build_script</a>, |
| <a href="crate_universe_workspace.html#crate.annotation-patch_args">patch_args</a>, <a href="crate_universe_workspace.html#crate.annotation-patch_tool">patch_tool</a>, <a href="crate_universe_workspace.html#crate.annotation-patches">patches</a>, <a href="crate_universe_workspace.html#crate.annotation-proc_macro_deps">proc_macro_deps</a>, <a href="crate_universe_workspace.html#crate.annotation-rustc_env">rustc_env</a>, <a href="crate_universe_workspace.html#crate.annotation-rustc_env_files">rustc_env_files</a>, |
| <a href="crate_universe_workspace.html#crate.annotation-rustc_flags">rustc_flags</a>, <a href="crate_universe_workspace.html#crate.annotation-shallow_since">shallow_since</a>, <a href="crate_universe_workspace.html#crate.annotation-override_targets">override_targets</a>) |
| </pre> |
| <p>A collection of extra attributes and settings for a particular crate</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="crate.annotation-version"></a>version</td><td style="text-align: left">The version or semver-conditions to match with a crate. The wildcard <code>*</code> matches any version, including prerelease versions.</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"><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"><code>None</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_workspace.html#render_config">render_config</a>'s 'default_alias_rule'.</td><td style="text-align: left"><code>None</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"><code>None</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"><code>None</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"><code>None</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"><code>None</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"><code>None</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 when running the crate's <code>cargo_build_script</code> - sets that target's <code>build_script_env</code> attribute.</td><td style="text-align: left"><code>None</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"><code>None</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"><code>None</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"><code>None</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 when compiling the crate's <code>cargo_build_script</code> - sets that target's <code>rustc_env</code> attribute.</td><td style="text-align: left"><code>None</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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-build_script_use_default_shell_env"></a>build_script_use_default_shell_env</td><td style="text-align: left">Whether or not to include the default shell environment for the build script action.</td><td style="text-align: left"><code>None</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"><code>None</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"><code>None</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 excluded from a crate's <code>rust_library::compile_data</code> attribute.</td><td style="text-align: left"><code>None</code></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"><code>None</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"><code>None</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"><code>None</code></td></tr> |
| <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"><code>None</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"><code>None</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. Or <code>True</code> to generate all, <code>False</code> to generate none.</td><td style="text-align: left"><code>None</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"><code>False</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.</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"><code>None</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"><code>None</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"><code>None</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"><code>None</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"><code>None</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"><code>None</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"><code>None</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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="crate.annotation-override_targets"></a>override_targets</td><td style="text-align: left">A dictionary of alternate targets to use when something depends on this crate to allow the parent repo to provide its own version of this dependency. Keys can be <code>proc-macro</code>, <code>custom-build</code>, <code>lib</code>, <code>bin</code>.</td><td style="text-align: left"><code>None</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><strong>RETURNS</strong></p> |
| <p>string: A json encoded string containing the specified version and separately all other inputs.</p> |
| <p><a id="crate.select"></a></p> |
| <h2 id="crateselect"><a class="header" href="#crateselect">crate.select</a></h2> |
| <pre> |
| load("@rules_rust//crate_universe:defs.bzl", "crate") |
| |
| crate.select(<a href="crate_universe_workspace.html#crate.select-common">common</a>, <a href="crate_universe_workspace.html#crate.select-selects">selects</a>) |
| </pre> |
| <p>A Starlark Select for <code>crate.annotation()</code>.</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="crate.select-common"></a>common</td><td style="text-align: left">A value that applies to all configurations.</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="crate.select-selects"></a>selects</td><td style="text-align: left">A dict of <code>target_triple</code> to values.</td><td style="text-align: left">none</td></tr> |
| </tbody></table> |
| </div> |
| <p><strong>RETURNS</strong></p> |
| <p>struct: A struct representing the Starlark Select.</p> |
| <p><a id="crate.spec"></a></p> |
| <h2 id="cratespec"><a class="header" href="#cratespec">crate.spec</a></h2> |
| <pre> |
| load("@rules_rust//crate_universe:defs.bzl", "crate") |
| |
| crate.spec(<a href="crate_universe_workspace.html#crate.spec-package">package</a>, <a href="crate_universe_workspace.html#crate.spec-version">version</a>, <a href="crate_universe_workspace.html#crate.spec-artifact">artifact</a>, <a href="crate_universe_workspace.html#crate.spec-lib">lib</a>, <a href="crate_universe_workspace.html#crate.spec-default_features">default_features</a>, <a href="crate_universe_workspace.html#crate.spec-features">features</a>, <a href="crate_universe_workspace.html#crate.spec-git">git</a>, <a href="crate_universe_workspace.html#crate.spec-branch">branch</a>, <a href="crate_universe_workspace.html#crate.spec-tag">tag</a>, <a href="crate_universe_workspace.html#crate.spec-rev">rev</a>) |
| </pre> |
| <p>A constructor for a crate dependency.</p> |
| <p>See <a href="https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html">specifying dependencies</a> in the Cargo book for more details.</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="crate.spec-package"></a>package</td><td style="text-align: left">The explicit name of the package (used when attempting to alias a crate).</td><td style="text-align: left"><code>None</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>.</td><td style="text-align: left"><code>None</code></td></tr> |
| <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"><code>None</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"><code>None</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"><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"><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>.</td><td style="text-align: left"><code>None</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"><code>None</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"><code>None</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"><code>None</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><strong>RETURNS</strong></p> |
| <p>string: A json encoded string of all inputs</p> |
| <p><a id="crate.workspace_member"></a></p> |
| <h2 id="crateworkspace_member"><a class="header" href="#crateworkspace_member">crate.workspace_member</a></h2> |
| <pre> |
| load("@rules_rust//crate_universe:defs.bzl", "crate") |
| |
| crate.workspace_member(<a href="crate_universe_workspace.html#crate.workspace_member-version">version</a>, <a href="crate_universe_workspace.html#crate.workspace_member-sha256">sha256</a>) |
| </pre> |
| <p>Define information for extra workspace members</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="crate.workspace_member-version"></a>version</td><td style="text-align: left">The semver of the crate to download. Must be an exact version.</td><td style="text-align: left">none</td></tr> |
| <tr><td style="text-align: left"><a id="crate.workspace_member-sha256"></a>sha256</td><td style="text-align: left">The sha256 checksum of the <code>.crate</code> file.</td><td style="text-align: left"><code>None</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><strong>RETURNS</strong></p> |
| <p>string: A json encoded string of all inputs</p> |
| <p><a id="render_config"></a></p> |
| <h2 id="render_config-1"><a class="header" href="#render_config-1">render_config</a></h2> |
| <pre> |
| load("@rules_rust//crate_universe:defs.bzl", "render_config") |
| |
| render_config(<a href="crate_universe_workspace.html#render_config-build_file_template">build_file_template</a>, <a href="crate_universe_workspace.html#render_config-crate_label_template">crate_label_template</a>, <a href="crate_universe_workspace.html#render_config-crate_alias_template">crate_alias_template</a>, |
| <a href="crate_universe_workspace.html#render_config-crate_repository_template">crate_repository_template</a>, <a href="crate_universe_workspace.html#render_config-crates_module_template">crates_module_template</a>, <a href="crate_universe_workspace.html#render_config-default_alias_rule">default_alias_rule</a>, |
| <a href="crate_universe_workspace.html#render_config-default_package_name">default_package_name</a>, <a href="crate_universe_workspace.html#render_config-generate_cargo_toml_env_vars">generate_cargo_toml_env_vars</a>, <a href="crate_universe_workspace.html#render_config-generate_target_compatible_with">generate_target_compatible_with</a>, |
| <a href="crate_universe_workspace.html#render_config-platforms_template">platforms_template</a>, <a href="crate_universe_workspace.html#render_config-regen_command">regen_command</a>, <a href="crate_universe_workspace.html#render_config-vendor_mode">vendor_mode</a>, <a href="crate_universe_workspace.html#render_config-generate_rules_license_metadata">generate_rules_license_metadata</a>) |
| </pre> |
| <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>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="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"><code>"//:BUILD.{name}-{version}.bazel"</code></td></tr> |
| <tr><td style="text-align: left"><a id="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"><code>"@{repository}__{name}-{version}//:{target}"</code></td></tr> |
| <tr><td style="text-align: left"><a id="render_config-crate_alias_template"></a>crate_alias_template</td><td style="text-align: left">The template to use when referring to generated aliases within the external repository. The available format keys are [<code>{repository}</code>, <code>{name}</code>, <code>{version}</code>].</td><td style="text-align: left"><code>"//:{name}-{version}"</code></td></tr> |
| <tr><td style="text-align: left"><a id="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"><code>"{repository}__{name}-{version}"</code></td></tr> |
| <tr><td style="text-align: left"><a id="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"><code>"//:{file}"</code></td></tr> |
| <tr><td style="text-align: left"><a id="render_config-default_alias_rule"></a>default_alias_rule</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"><code>"alias"</code></td></tr> |
| <tr><td style="text-align: left"><a id="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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="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. This is expected to be true except when bootstrapping.</td><td style="text-align: left"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="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"><code>True</code></td></tr> |
| <tr><td style="text-align: left"><a id="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"><code>"@rules_rust//rust/platform:{triple}"</code></td></tr> |
| <tr><td style="text-align: left"><a id="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"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="render_config-vendor_mode"></a>vendor_mode</td><td style="text-align: left">An optional configuration for rendirng content to be rendered into repositories.</td><td style="text-align: left"><code>None</code></td></tr> |
| <tr><td style="text-align: left"><a id="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"><code>False</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><strong>RETURNS</strong></p> |
| <p>string: A json encoded struct to match the Rust <code>config::RenderConfig</code> struct</p> |
| <p><a id="splicing_config"></a></p> |
| <h2 id="splicing_config-1"><a class="header" href="#splicing_config-1">splicing_config</a></h2> |
| <pre> |
| load("@rules_rust//crate_universe:defs.bzl", "splicing_config") |
| |
| splicing_config(<a href="crate_universe_workspace.html#splicing_config-resolver_version">resolver_version</a>) |
| </pre> |
| <p>Various settings used to configure Cargo manifest splicing behavior.</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="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"><code>"2"</code></td></tr> |
| </tbody></table> |
| </div> |
| <p><strong>RETURNS</strong></p> |
| <p>str: A json encoded string of the parameters provided</p> |
| <p><a id="crates_repository"></a></p> |
| <h2 id="crates_repository"><a class="header" href="#crates_repository">crates_repository</a></h2> |
| <pre> |
| load("@rules_rust//crate_universe:defs.bzl", "crates_repository") |
| |
| crates_repository(<a href="crate_universe_workspace.html#crates_repository-name">name</a>, <a href="crate_universe_workspace.html#crates_repository-annotations">annotations</a>, <a href="crate_universe_workspace.html#crates_repository-cargo_config">cargo_config</a>, <a href="crate_universe_workspace.html#crates_repository-cargo_lockfile">cargo_lockfile</a>, |
| <a href="crate_universe_workspace.html#crates_repository-compressed_windows_toolchain_names">compressed_windows_toolchain_names</a>, <a href="crate_universe_workspace.html#crates_repository-generate_binaries">generate_binaries</a>, <a href="crate_universe_workspace.html#crates_repository-generate_build_scripts">generate_build_scripts</a>, |
| <a href="crate_universe_workspace.html#crates_repository-generate_target_compatible_with">generate_target_compatible_with</a>, <a href="crate_universe_workspace.html#crates_repository-generator">generator</a>, <a href="crate_universe_workspace.html#crates_repository-generator_sha256s">generator_sha256s</a>, <a href="crate_universe_workspace.html#crates_repository-generator_urls">generator_urls</a>, |
| <a href="crate_universe_workspace.html#crates_repository-isolated">isolated</a>, <a href="crate_universe_workspace.html#crates_repository-lockfile">lockfile</a>, <a href="crate_universe_workspace.html#crates_repository-manifests">manifests</a>, <a href="crate_universe_workspace.html#crates_repository-packages">packages</a>, <a href="crate_universe_workspace.html#crates_repository-quiet">quiet</a>, <a href="crate_universe_workspace.html#crates_repository-render_config">render_config</a>, <a href="crate_universe_workspace.html#crates_repository-repin_instructions">repin_instructions</a>, |
| <a href="crate_universe_workspace.html#crates_repository-repo_mapping">repo_mapping</a>, <a href="crate_universe_workspace.html#crates_repository-rust_toolchain_cargo_template">rust_toolchain_cargo_template</a>, <a href="crate_universe_workspace.html#crates_repository-rust_toolchain_rustc_template">rust_toolchain_rustc_template</a>, |
| <a href="crate_universe_workspace.html#crates_repository-rust_version">rust_version</a>, <a href="crate_universe_workspace.html#crates_repository-skip_cargo_lockfile_overwrite">skip_cargo_lockfile_overwrite</a>, <a href="crate_universe_workspace.html#crates_repository-splicing_config">splicing_config</a>, |
| <a href="crate_universe_workspace.html#crates_repository-supported_platform_triples">supported_platform_triples</a>) |
| </pre> |
| <p>A rule for defining and downloading Rust dependencies (crates). This rule |
| handles all the same <a href="crate_universe_workspace.html#workflows">workflows</a> <code>crate_universe</code> rules do.</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>Example:</p> |
| <p>Given the following workspace structure:</p> |
| <pre><code class="language-text">[workspace]/ |
| WORKSPACE.bazel |
| BUILD.bazel |
| Cargo.toml |
| Cargo.Bazel.lock |
| src/ |
| main.rs |
| </code></pre> |
| <p>The following is something that'd be found in the <code>WORKSPACE</code> file:</p> |
| <pre><code class="language-python">load("@rules_rust//crate_universe:defs.bzl", "crates_repository", "crate") |
| |
| crates_repository( |
| name = "crate_index", |
| annotations = { |
| "rand": [crate.annotation( |
| default_features = False, |
| features = ["small_rng"], |
| )], |
| }, |
| cargo_lockfile = "//:Cargo.Bazel.lock", |
| lockfile = "//:cargo-bazel-lock.json", |
| manifests = ["//:Cargo.toml"], |
| # Should match the version represented by the currently registered `rust_toolchain`. |
| rust_version = "1.60.0", |
| ) |
| </code></pre> |
| <p>The above will create an external repository which contains aliases and macros for accessing |
| Rust targets found in the dependency graph defined by the given manifests.</p> |
| <p><strong>NOTE</strong>: The <code>cargo_lockfile</code> and <code>lockfile</code> must be manually created. The rule unfortunately does not yet create |
| it on its own. When initially setting up this rule, an empty file should be created and then |
| populated by repinning dependencies.</p> |
| <h3 id="repinning--updating-dependencies-1"><a class="header" href="#repinning--updating-dependencies-1">Repinning / Updating Dependencies</a></h3> |
| <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>crate_index</code>, the easiest way to |
| repin dependencies is to run:</p> |
| <pre><code class="language-shell">CARGO_BAZEL_REPIN=1 bazel sync --only=crate_index |
| </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. The following table shows translations from environment |
| variable values to the equivalent <a href="https://doc.rust-lang.org/cargo/commands/cargo-update.html">cargo update</a> command |
| that is called behind the scenes to update dependencies.</p> |
| <div class="table-wrapper"><table><thead><tr><th>Value</th><th>Cargo command</th></tr></thead><tbody> |
| <tr><td>Any of [<code>true</code>, <code>1</code>, <code>yes</code>, <code>on</code>, <code>workspace</code>]</td><td><code>cargo update --workspace</code></td></tr> |
| <tr><td>Any of [<code>full</code>, <code>eager</code>, <code>all</code>]</td><td><code>cargo update</code></td></tr> |
| <tr><td><code>package_name</code></td><td><code>cargo upgrade --package package_name</code></td></tr> |
| <tr><td><code>package_name@1.2.3</code></td><td><code>cargo upgrade --package package_name@1.2.3</code></td></tr> |
| <tr><td><code>package_name@1.2.3=4.5.6</code></td><td><code>cargo upgrade --package package_name@1.2.3 --precise=4.5.6</code></td></tr> |
| </tbody></table> |
| </div> |
| <p>If the <code>crates_repository</code> is used multiple times in the same Bazel workspace (e.g. for multiple independent |
| Rust workspaces), it may additionally be useful to use the <code>CARGO_BAZEL_REPIN_ONLY</code> environment variable, which |
| limits execution of the repinning to one or multiple instances of the <code>crates_repository</code> rule via a comma-delimited |
| allowlist:</p> |
| <pre><code class="language-shell">CARGO_BAZEL_REPIN=1 CARGO_BAZEL_REPIN_ONLY=crate_index bazel sync --only=crate_index |
| </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="crates_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="crates_repository-annotations"></a>annotations</td><td style="text-align: left">Extra settings to apply to crates. See <a href="crate_universe_workspace.html#crateannotation">crate.annotation</a>.</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="crates_repository-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="crates_repository-cargo_lockfile"></a>cargo_lockfile</td><td style="text-align: left">The path used to store the <code>crates_repository</code> specific <a href="https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html">Cargo.lock</a> file. In the case that your <code>crates_repository</code> corresponds directly with an existing <code>Cargo.toml</code> file which has a paired <code>Cargo.lock</code> file, that <code>Cargo.lock</code> file should be used here, which will keep the versions used by cargo and bazel in sync.</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="crates_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="crates_repository-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="crates_repository-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="crates_repository-generate_target_compatible_with"></a>generate_target_compatible_with</td><td style="text-align: left">DEPRECATED: Moved to <code>render_config</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="crates_repository-generator"></a>generator</td><td style="text-align: left">The absolute label of a generator. Eg. <code>@cargo_bazel_bootstrap//:cargo-bazel</code>. This is typically used when bootstrapping</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="crates_repository-generator_sha256s"></a>generator_sha256s</td><td style="text-align: left">Dictionary of <code>host_triple</code> -> <code>sha256</code> for a <code>cargo-bazel</code> binary.</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="crates_repository-generator_urls"></a>generator_urls</td><td style="text-align: left">URL template from which to download the <code>cargo-bazel</code> binary. <code>{host_triple}</code> and will be filled in according to the host platform.</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="crates_repository-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="crates_repository-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.If you already have a <code>MODULE.bazel.lock</code> file, you don't need this.If you don't have a <code>MODULE.bazel.lock</code> file, the <code>lockfile</code> will save you generation time.</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="crates_repository-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="crates_repository-packages"></a>packages</td><td style="text-align: left">A set of crates (packages) specifications to depend on. See <a href="crate_universe_workspace.html#crate.spec">crate.spec</a>.</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="crates_repository-quiet"></a>quiet</td><td style="text-align: left">If stdout and stderr should not be printed to the terminal.</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="crates_repository-render_config"></a>render_config</td><td style="text-align: left">The configuration flags to use for rendering. Use <code>//crate_universe:defs.bzl\%render_config</code> to generate the value for this field. If unset, the defaults defined there 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="crates_repository-repin_instructions"></a>repin_instructions</td><td style="text-align: left">Instructions to re-pin the repository if required. Many people have wrapper scripts for keeping dependencies up to date, and would like to point users to that instead of the default.</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="crates_repository-repo_mapping"></a>repo_mapping</td><td style="text-align: left">In <code>WORKSPACE</code> context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<br><br>For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>).<br><br>This attribute is <em>not</em> supported in <code>MODULE.bazel</code> context (when invoking a repository rule inside a module extension's implementation function).</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"></td></tr> |
| <tr><td style="text-align: left"><a id="crates_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>{cfg}</code> (eg. 'exec'), <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="crates_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>{cfg}</code> (eg. 'exec'), <code>{channel}</code> (eg. 'stable'), and <code>{tool}</code> (eg. 'cargo.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="crates_repository-rust_version"></a>rust_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.86.0"</code></td></tr> |
| <tr><td style="text-align: left"><a id="crates_repository-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="crates_repository-splicing_config"></a>splicing_config</td><td style="text-align: left">The configuration flags to use for splicing Cargo maniests. Use <code>//crate_universe:defs.bzl\%rsplicing_config</code> to generate the value for this field. If unset, the defaults defined there 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="crates_repository-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><strong>ENVIRONMENT VARIABLES</strong></p> |
| <p>This repository rule depends on the following environment variables:</p> |
| <ul> |
| <li><code>CARGO_BAZEL_GENERATOR_URL</code></li> |
| <li><code>CARGO_BAZEL_GENERATOR_SHA256</code></li> |
| <li><code>CARGO_BAZEL_REPIN</code></li> |
| <li><code>REPIN</code></li> |
| <li><code>CARGO_BAZEL_REPIN_ONLY</code></li> |
| <li><code>CARGO_BAZEL_ISOLATED</code></li> |
| <li><code>CARGO_BAZEL_DEBUG</code></li> |
| <li><code>CARGO_BAZEL_TIMEOUT</code></li> |
| </ul> |
| <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="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-9"><a class="header" href="#rules-9">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-7"><a class="header" href="#setup-7">Setup</a></h2> |
| <h3 id="bzlmod-3"><a class="header" href="#bzlmod-3">Bzlmod</a></h3> |
| <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> |
| <h3 id="workspace-3"><a class="header" href="#workspace-3">Workspace</a></h3> |
| <p>Or add the following if you're still using <code>WORKSPACE</code> to add the |
| external repositories for the Rust bindgen toolchain (in addition to the <a href="https://bazelbuild.github.io/rules_rust/#setup">rust rules setup</a>):</p> |
| <pre><code class="language-python">load("@rules_rust_bindgen//:repositories.bzl", "rust_bindgen_dependencies", "rust_bindgen_register_toolchains") |
| |
| rust_bindgen_dependencies() |
| |
| rust_bindgen_register_toolchains() |
| |
| load("@rules_rust_bindgen//:transitive_repositories.bzl", "rust_bindgen_transitive_dependencies") |
| |
| rust_bindgen_transitive_dependencies() |
| </code></pre> |
| <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 then no Bindgen related calls should be added to your WORKSPACE and instead |
| users should define their own repositories using something akin to <a href="https://bazelbuild.github.io/rules_rust/crate_universe_workspace.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 that provides bindgen's runtime dependency on libclang.</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-10"><a class="header" href="#rules-10">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-8"><a class="header" href="#setup-8">Setup</a></h2> |
| <h3 id="bzlmod-4"><a class="header" href="#bzlmod-4">bzlmod</a></h3> |
| <pre><code class="language-python">bazel_dep(name = "rules_rust_mdbook", version = "{SEE_RELEASE_NOTES}") |
| </code></pre> |
| <h3 id="workspace-4"><a class="header" href="#workspace-4">WORKSPACE</a></h3> |
| <pre><code class="language-python">load("@rules_rust_mdbook//:repositories.bzl", "mdbook_register_toolchains", "rules_mdbook_dependencies") |
| |
| rules_mdbook_dependencies() |
| |
| mdbook_register_toolchains() |
| |
| load("@rules_rust_mdbook//:repositories_transitive.bzl", "rules_mdbook_transitive_deps") |
| |
| rules_mdbook_transitive_deps() |
| </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-11"><a class="header" href="#rules-11">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-9"><a class="header" href="#setup-9">Setup</a></h2> |
| <pre><code class="language-python">load("@rules_rust//proto/prost:repositories.bzl", "rust_prost_dependencies") |
| |
| rust_prost_dependencies() |
| |
| load("@rules_rust//proto/prost:transitive_repositories.bzl", "rust_prost_transitive_repositories") |
| |
| rust_prost_transitive_repositories() |
| </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>WORKSPACE</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_protobuf"><a class="header" href="#rules_rust_protobuf">rules_rust_protobuf</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/stepancheg/rust-protobuf/"><code>rust-protobuf</code></a>.</p> |
| <h2 id="setup-10"><a class="header" href="#setup-10">Setup</a></h2> |
| <p>To use the Rust proto rules, add the following to your <code>WORKSPACE</code> file to add the |
| external repositories for the Rust proto toolchain (in addition to the <a href="..">rust rules setup</a>):</p> |
| <pre><code class="language-python">load("@rules_rust//proto/protobuf:repositories.bzl", "rust_proto_protobuf_dependencies", "rust_proto_protobuf_register_toolchains") |
| |
| rust_proto_protobuf_dependencies() |
| |
| rust_proto_protobuf_register_toolchains() |
| |
| load("@rules_rust//proto/protobuf:transitive_repositories.bzl", "rust_proto_protobuf_transitive_repositories") |
| |
| rust_proto_protobuf_transitive_repositories() |
| </code></pre> |
| <p>This will load the required dependencies for the <a href="https://github.com/stepancheg/rust-protobuf/"><code>rust-protobuf</code></a> rules. It will also |
| register a default toolchain for the <code>rust_proto_library</code> and <code>rust_grpc_library</code> rules.</p> |
| <p>To customize the <code>rust_proto_library</code> and <code>rust_grpc_library</code> toolchain, please see the section |
| <a href="rust_protobuf.html#custom-proto-deps">Customizing <code>rust-protobuf</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-rust-protobuf-dependencies"><a class="header" href="#customizing-rust-protobuf-dependencies"><a name="custom-proto-deps">Customizing <code>rust-protobuf</code> Dependencies</a></h4> |
| <p>These rules depend on the <a href="https://crates.io/crates/protobuf"><code>protobuf</code></a> and |
| the <a href="https://crates.io/crates/grpc"><code>grpc</code></a> crates in addition to the <a href="https://github.com/google/protobuf">protobuf |
| compiler</a>. To obtain these crates, |
| <code>rust_proto_repositories</code> imports the given crates using BUILD files generated with |
| <a href="./crate_universe.html">crate_universe</a>.</p> |
| <p>If you want to either change the protobuf and gRPC rust compilers, or to |
| simply use <a href="./crate_universe.html">crate_universe</a> in a more |
| complex scenario (with more dependencies), you must redefine those |
| dependencies.</p> |
| <p>To do this, once you've imported the needed dependencies (see our |
| <a href="https://github.com/bazelbuild/rules_rust/blob/main/proto/protobuf/3rdparty/BUILD.bazel">@rules_rust//proto/protobuf/3rdparty/BUILD.bazel</a> |
| file to see the default dependencies), you need to create your own toolchain. |
| To do so you can create a BUILD file with your toolchain definition, for example:</p> |
| <pre><code class="language-python">load("@rules_rust//proto:toolchain.bzl", "rust_proto_toolchain") |
| |
| rust_proto_toolchain( |
| name = "proto-toolchain-impl", |
| # Path to the protobuf compiler. |
| protoc = "@com_google_protobuf//:protoc", |
| # Protobuf compiler plugin to generate rust gRPC stubs. |
| grpc_plugin = "//3rdparty/crates:cargo_bin_protoc_gen_rust_grpc", |
| # Protobuf compiler plugin to generate rust protobuf stubs. |
| proto_plugin = "//3rdparty/crates:cargo_bin_protoc_gen_rust", |
| ) |
| |
| toolchain( |
| name = "proto-toolchain", |
| toolchain = ":proto-toolchain-impl", |
| toolchain_type = "@rules_rust//proto/protobuf: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:proto-toolchain") |
| </code></pre> |
| <p>Finally, you might want to set the <code>rust_deps</code> attribute in |
| <code>rust_proto_library</code> and <code>rust_grpc_library</code> to change the compile-time |
| dependencies:</p> |
| <pre><code class="language-python">rust_proto_library( |
| ... |
| rust_deps = ["//3rdparty/crates:protobuf"], |
| ... |
| ) |
| |
| rust_grpc_library( |
| ... |
| rust_deps = [ |
| "//3rdparty/crates:protobuf", |
| "//3rdparty/crates:grpc", |
| "//3rdparty/crates:tls_api", |
| "//3rdparty/crates:tls_api_stub", |
| ], |
| ... |
| ) |
| </code></pre> |
| <p><strong>Note</strong>: Ideally, we would inject those dependencies from the toolchain, |
| but due to <a href="https://github.com/bazelbuild/bazel/issues/6889">bazelbuild/bazel#6889</a> |
| all dependencies added via the toolchain ends-up being in the wrong |
| configuration.</p> |
| <hr /> |
| <hr /> |
| <p><a id="rust_grpc_library"></a></p> |
| <h2 id="rust_grpc_library"><a class="header" href="#rust_grpc_library">rust_grpc_library</a></h2> |
| <pre> |
| load("@rules_rust_protobuf//:defs.bzl", "rust_grpc_library") |
| |
| rust_grpc_library(<a href="rust_protobuf.html#rust_grpc_library-name">name</a>, <a href="rust_protobuf.html#rust_grpc_library-deps">deps</a>, <a href="rust_protobuf.html#rust_grpc_library-crate_name">crate_name</a>, <a href="rust_protobuf.html#rust_grpc_library-rust_deps">rust_deps</a>, <a href="rust_protobuf.html#rust_grpc_library-rustc_flags">rustc_flags</a>) |
| </pre> |
| <p>Builds a Rust library crate from a set of <code>proto_library</code>s suitable for gRPC.</p> |
| <p>Example:</p> |
| <pre><code class="language-python">load("@rules_rust_protobuf//:defs.bzl", "rust_grpc_library") |
| |
| proto_library( |
| name = "my_proto", |
| srcs = ["my.proto"] |
| ) |
| |
| rust_grpc_library( |
| name = "rust", |
| deps = [":my_proto"], |
| ) |
| |
| rust_binary( |
| name = "my_service", |
| srcs = ["my_service.rs"], |
| deps = [":rust"], |
| ) |
| </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_grpc_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_grpc_library-deps"></a>deps</td><td style="text-align: left">List of proto_library dependencies that will be built. One crate for each proto_library will be created with the corresponding gRPC stubs.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</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_grpc_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_grpc_library-rust_deps"></a>rust_deps</td><td style="text-align: left">The crates the generated library depends 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_grpc_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> |
| </tbody></table> |
| </div> |
| <p><a id="rust_proto_library"></a></p> |
| <h2 id="rust_proto_library"><a class="header" href="#rust_proto_library">rust_proto_library</a></h2> |
| <pre> |
| load("@rules_rust_protobuf//:defs.bzl", "rust_proto_library") |
| |
| rust_proto_library(<a href="rust_protobuf.html#rust_proto_library-name">name</a>, <a href="rust_protobuf.html#rust_proto_library-deps">deps</a>, <a href="rust_protobuf.html#rust_proto_library-crate_name">crate_name</a>, <a href="rust_protobuf.html#rust_proto_library-rust_deps">rust_deps</a>, <a href="rust_protobuf.html#rust_proto_library-rustc_flags">rustc_flags</a>) |
| </pre> |
| <p>Builds a Rust library crate from a set of <code>proto_library</code>s.</p> |
| <p>Example:</p> |
| <pre><code class="language-python">load("@rules_rust_protobuf//:defs.bzl", "rust_proto_library") |
| |
| proto_library( |
| name = "my_proto", |
| srcs = ["my.proto"] |
| ) |
| |
| rust_proto_library( |
| name = "rust", |
| deps = [":my_proto"], |
| ) |
| |
| rust_binary( |
| name = "my_proto_binary", |
| srcs = ["my_proto_binary.rs"], |
| deps = [":rust"], |
| ) |
| </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_proto_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_proto_library-deps"></a>deps</td><td style="text-align: left">List of proto_library dependencies that will be built. One crate for each proto_library will be created with the corresponding stubs.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</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_proto_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_proto_library-rust_deps"></a>rust_deps</td><td style="text-align: left">The crates the generated library depends 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_proto_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> |
| </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-12"><a class="header" href="#rules-12">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-11"><a class="header" href="#setup-11">Setup</a></h2> |
| <p>To begin using the <code>wasm-bindgen</code> rules, users can load the necessary dependencies |
| in their workspace by adding the following to their <code>WORKSPACE.bazel</code> file.</p> |
| <pre><code class="language-python">load("@rules_rust_wasm_bindgen//:repositories.bzl", "rust_wasm_bindgen_dependencies", "rust_wasm_bindgen_register_toolchains") |
| |
| rust_wasm_bindgen_dependencies() |
| |
| rust_wasm_bindgen_register_toolchains() |
| </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 avoid calling <code>rust_wasm_bindgen_register_toolchains</code> and instead 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 in the workspace.</p> |
| <h2 id="interfacing-with-javascript-rules"><a class="header" href="#interfacing-with-javascript-rules">Interfacing with Javascript rules</a></h2> |
| <p>While it's recommended for users to maintain their own , in the |
| <code>@rules_rust_wasm_bindgen</code> package there exists interface sub-packages for various |
| Javascript Bazel rules. E.g. <code>aspect_rules_js</code>. The rules defined there are a more |
| convenient way to use <code>rust_wasm_bindgen</code> with the associated javascript rules due |
| to the inclusion of additional providers. Each directory contains a <code>defs.bzl</code> file |
| that defines the different variants of <code>rust_wasm_bindgen</code>. (e.g. <code>js_rust_wasm_bindgen</code> |
| for the <code>rules_js</code> submodule).</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_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-deps">deps</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_test-data">data</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-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>) |
| </pre> |
| <p>Rules for running <a href="https://rustwasm.github.io/wasm-bindgen/wasm-bindgen-test/index.html">wasm-bindgen tests</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_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_wasm_bindgen_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_wasm_bindgen_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_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<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_wasm_bindgen_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_wasm_bindgen_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_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">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_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_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">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_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_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.<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_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.<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_wasm_bindgen_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_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">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_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> |
| <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"><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> |
| </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> |