fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
ba7abedc
gh-pages
1<!DOCTYPE HTML > 2< html lang ="en "class ="light sidebar-visible "dir ="ltr "> 3< head > 4<!-- Book generated using mdBook --> 5< meta charset ="UTF-8 "> 6< title > rules_rust</ title > 7< meta name ="robots "content ="noindex "> 8 9 10<!-- Custom HTML head --> 11 12< meta name ="description "content =""> 13< meta name ="viewport "content ="width=device-width, initial-scale=1 "> 14< meta name ="theme-color "content ="#ffffff "> 15 16< link rel ="icon "href ="favicon.svg "> 17< link rel ="shortcut icon "href ="favicon.png "> 18< link rel ="stylesheet "href ="css/variables.css "> 19< link rel ="stylesheet "href ="css/general.css "> 20< link rel ="stylesheet "href ="css/chrome.css "> 21< link rel ="stylesheet "href ="css/print.css "media ="> 22 23<!-- Fonts --> 24< link rel ="stylesheet "href ="FontAwesome/css/font-awesome.css "> 25< link rel ="stylesheet "href ="fonts/fonts.css "> 26 27<!-- Highlight.js Stylesheets --> 28< link rel ="stylesheet "href ="highlight.css "> 29< link rel ="stylesheet "href ="tomorrow-night.css "> 30< link rel ="stylesheet "href ="ayu-highlight.css "> 31 32<!-- Custom theme stylesheets --> 33 34 35<!-- Provide site root to javascript --> 36< script > 37var path_to_root = "" ; 38var default_theme = window . matchMedia ( "(prefers-color-scheme: dark)" ). matches ?"navy" :"light" ; 39</ script > 40<!-- Start loading toc.js asap --> 41< script src ="toc.js "></ script > 42</ head > 43< body > 44< div id ="body-container "> 45<!-- Work around some values being stored in localStorage wrapped in quotes --> 46< script > 47try { 48var theme = localStorage . getItem ( 'mdbook-theme' ); 49var sidebar = localStorage . getItem ( 'mdbook-sidebar' ); 50 51if ( theme . startsWith ( '"' ) && theme . endsWith ( '"' )) { 52localStorage . setItem ( 'mdbook-theme' , theme . slice ( 1 , theme . length - 1 )); 53} 54 55if ( sidebar . startsWith ( '"' ) && sidebar . endsWith ( '"' )) { 56localStorage . setItem ( 'mdbook-sidebar' , sidebar . slice ( 1 , sidebar . length - 1 )); 57} 58} catch ( e ) { } 59</ script > 60 61<!-- Set the theme before any content is loaded, prevents flash --> 62< script > 63var theme ; 64try { theme = localStorage . getItem ( 'mdbook-theme' ); } catch ( e ) { } 65if ( theme === null || theme === undefined ) { theme = default_theme ; } 66const html = document . documentElement ; 67html . classList . remove ( 'light' ) 68html . classList . add ( theme ); 69html . classList . add ( "js" ); 70</ script > 71 72< input type ="checkbox "id ="sidebar-toggle-anchor "class ="hidden "> 73 74<!-- Hide / unhide sidebar before it is displayed --> 75< script > 76var sidebar = null ; 77var sidebar_toggle = document . getElementById ( "sidebar-toggle-anchor" ); 78if ( document . body . clientWidth >= 1080 ) { 79try { sidebar = localStorage . getItem ( 'mdbook-sidebar' ); } catch ( e ) { } 80sidebar = sidebar || 'visible' ; 81} else { 82sidebar = 'hidden' ; 83} 84sidebar_toggle . checked = sidebar === 'visible' ; 85html . classList . remove ( 'sidebar-visible' ); 86html . classList . add ( "sidebar-" + sidebar ); 87</ script > 88 89< nav id ="sidebar "class ="sidebar "aria-label ="Table of contents "> 90<!-- populated by js --> 91< mdbook-sidebar-scrollbox class ="sidebar-scrollbox "></ mdbook-sidebar-scrollbox > 92< noscript > 93< iframe class ="sidebar-iframe-outer "src ="toc.html "></ iframe > 94</ noscript > 95< div id ="sidebar-resize-handle "class ="sidebar-resize-handle "> 96< div class ="sidebar-resize-indicator "></ div > 97</ div > 98</ nav > 99 100< div id ="page-wrapper "class ="page-wrapper "> 101 102< div class ="page "> 103< div id ="menu-bar-hover-placeholder "></ div > 104< div id ="menu-bar "class ="menu-bar sticky "> 105< div class ="left-buttons "> 106< 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 "> 107< i class ="fa fa-bars "></ i > 108</ label > 109< 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 "> 110< i class ="fa fa-paint-brush "></ i > 111</ button > 112< ul id ="theme-list "class ="theme-popup "aria-label ="Themes "role ="menu "> 113< li role ="none ">< button role ="menuitem "class ="theme "id ="light "> Light</ button ></ li > 114< li role ="none ">< button role ="menuitem "class ="theme "id ="rust "> Rust</ button ></ li > 115< li role ="none ">< button role ="menuitem "class ="theme "id ="coal "> Coal</ button ></ li > 116< li role ="none ">< button role ="menuitem "class ="theme "id ="navy "> Navy</ button ></ li > 117< li role ="none ">< button role ="menuitem "class ="theme "id ="ayu "> Ayu</ button ></ li > 118</ ul > 119< 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 "> 120< i class ="fa fa-search "></ i > 121</ button > 122</ div > 123 124< h1 class ="menu-title "> rules_rust</ h1 > 125 126< div class ="right-buttons "> 127< a href ="print.html "title ="Print this book "aria-label ="Print this book "> 128< i id ="print-button "class ="fa fa-print "></ i > 129</ a > 130< a href ="https://github.com/bazelbuild/rules_rust "title ="Git repository "aria-label ="Git repository "> 131< i id ="git-repository-button "class ="fa fa-github "></ i > 132</ a > 133 134</ div > 135</ div > 136 137< div id ="search-wrapper "class ="hidden "> 138< form id ="searchbar-outer "class ="searchbar-outer "> 139< input type ="search "id ="searchbar "name ="searchbar "placeholder ="Search this book ... "aria-controls ="searchresults-outer "aria-describedby ="searchresults-header "> 140</ form > 141< div id ="searchresults-outer "class ="searchresults-outer hidden "> 142< div id ="searchresults-header "class ="searchresults-header "></ div > 143< ul id ="searchresults "> 144</ ul > 145</ div > 146</ div > 147 148<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM --> 149< script > 150document . getElementById ( 'sidebar-toggle' ). setAttribute ( 'aria-expanded' , sidebar === 'visible' ); 151document . getElementById ( 'sidebar' ). setAttribute ( 'aria-hidden' , sidebar !== 'visible' ); 152Array . from ( document . querySelectorAll ( '#sidebar a' )). forEach ( function ( link ) { 153link . setAttribute ( 'tabIndex' , sidebar === 'visible' ?0 :- 1 ); 154}); 155</ script > 156 157< div id ="content "class ="content "> 158< main > 159< h1 id ="rules-rust ">< a class ="header "href ="#rules-rust "> Rules Rust</ a ></ h1 > 160< 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 > 161<!-- TODO: Render generated docs on the github pages site again, https://bazelbuild.github.io/rules_rust/ --> 162< p >< a name ="setup "></ a ></ p > 163< h2 id ="setup ">< a class ="header "href ="#setup "> Setup</ a ></ h2 > 164< 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 > 165< h3 id ="bzlmod ">< a class ="header "href ="#bzlmod "> Bzlmod</ a ></ h3 > 166< 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 > 167< p > To use< code > rules_rust</ code > in a project using bzlmod, add the following to your< code > MODULE.bazel</ code > file:</ p > 168< pre >< code class ="language-python "> bazel_dep(name = "rules_rust", version = "0.48.0") 169</ code ></ pre > 170< p > Don't forget to substitute in your desired release's version number.</ p > 171< h3 id ="workspace ">< a class ="header "href ="#workspace "> WORKSPACE</ a ></ h3 > 172< 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 > 173< pre >< code class ="language-python "> load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 174 175# To find additional information on this release or newer ones visit: 176# https://github.com/bazelbuild/rules_rust/releases 177http_archive( 178 name = "rules_rust", 179 integrity = "sha256-Weev1uz2QztBlDA88JX6A1N72SucD1V8lBsaliM0TTg=", 180 urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.48.0/rules_rust-v0.48.0.tar.gz"], 181) 182 183load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains") 184 185rules_rust_dependencies() 186 187rust_register_toolchains() 188</ code ></ pre > 189< p > Don't forget to substitute in your desired release's version number and integrity hash.</ p > 190< h2 id ="specifying-rust-version ">< a class ="header "href ="#specifying-rust-version "> Specifying Rust version</ a ></ h2 > 191< p > To build with a particular version of the Rust compiler, pass that version to< a href ="flatten.html#rust_register_toolchains ">< code > rust_register_toolchains</ code ></ a > :</ p > 192< pre >< code class ="language-python "> rust_register_toolchains( 193 edition = "2021", 194 versions = [ 195 "1.79.0" 196 ], 197) 198</ code ></ pre > 199< 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.</ p > 200< pre >< code class ="language-python "> rust_register_toolchains( 201 edition = "2021", 202 versions = [ 203 "nightly/2024-06-13", 204 ], 205) 206</ code ></ pre > 207< p > By default, a< code > stable</ code > and< code > nightly</ code > toolchain will be registered if no versions are passed to< code > rust_register_toolchains</ code > . However, 208if 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 a build setting must 209also be set in the project's< code > .bazelrc</ code > file.</ p > 210< pre >< code class ="language-text "> build --@rules_rust//rust/toolchain/channel=nightly 211</ code ></ pre > 212< p > Failure to do so will result in rules attempting to match a< code > stable</ code > toolchain when one was not registered.</ p > 213< h2 id ="supported-bazel-versions ">< a class ="header "href ="#supported-bazel-versions "> Supported bazel versions</ a ></ h2 > 214< p > The oldest version of Bazel the< code > main</ code > branch is tested against is< code > 7.3.1</ code > . Previous versions may still be functional in certain environments, but this is the minimum version we strive to fully support.</ p > 215< 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 > 216< h2 id ="supported-platforms ">< a class ="header "href ="#supported-platforms "> Supported platforms</ a ></ h2 > 217< p > We aim to support Linux and macOS.</ p > 218< 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 > 219< p > Windows support for some features requires< code > --enable_runfiles</ code > to be passed to Bazel, we recommend putting it in your bazelrc. See< a href ="https://bazel.build/configure/windows "> Using Bazel on Windows</ a > for more Windows-specific recommendations.</ p > 220< div style ="break-before: page; page-break-before: always; "></ div >< h1 id ="rules ">< a class ="header "href ="#rules "> Rules</ a ></ h1 > 221< ul > 222< li >< a href ="defs.html "> defs</ a > : standard rust rules for building and testing libraries and binaries.</ li > 223< li >< a href ="rust_doc.html "> rustdoc</ a > : rules for generating and testing rust documentation.</ li > 224< li >< a href ="rust_clippy.html "> clippy</ a > : rules for running< a href ="https://github.com/rust-lang/rust-clippy#readme "> clippy</ a > .</ li > 225< li >< a href ="rust_fmt.html "> rustfmt</ a > : rules for running< a href ="https://github.com/rust-lang/rustfmt#readme "> rustfmt</ a > .</ li > 226< 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 > 227< li >< a href ="external_crates.html "> crate_universe</ a > : Rules for generating Bazel targets for external crate dependencies.</ li > 228</ ul > 229< h2 id ="experimental-rules ">< a class ="header "href ="#experimental-rules "> Experimental rules</ a ></ h2 > 230< ul > 231< 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 > 232</ ul > 233< h2 id ="3rd-party-rules ">< a class ="header "href ="#3rd-party-rules "> 3rd party rules</ a ></ h2 > 234< ul > 235< li >< a href ="rust_bindgen.html "> rust_bindgen</ a > : rules for generating C++ bindings.</ li > 236< 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 > 237< 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 > 238< 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 > 239</ ul > 240< h2 id ="full-api ">< a class ="header "href ="#full-api "> Full API</ a ></ h2 > 241< p > You can also browse the< a href ="flatten.html "> full API in one page</ a > .</ p > 242< div style ="break-before: page; page-break-before: always; "></ div > <!-- Generated with Stardoc: http://skydoc.bazel.build --> 243< h1 id ="rust ">< a class ="header "href ="#rust "> Rust</ a ></ h1 > 244< ul > 245< li >< a href ="rust.html#rust_binary "> rust_binary</ a ></ li > 246< li >< a href ="rust.html#rust_library "> rust_library</ a ></ li > 247< li >< a href ="rust.html#rust_library_group "> rust_library_group</ a ></ li > 248< li >< a href ="rust.html#rust_static_library "> rust_static_library</ a ></ li > 249< li >< a href ="rust.html#rust_shared_library "> rust_shared_library</ a ></ li > 250< li >< a href ="rust.html#rust_proc_macro "> rust_proc_macro</ a ></ li > 251< li >< a href ="rust.html#rust_test "> rust_test</ a ></ li > 252< li >< a href ="rust.html#rust_test_suite "> rust_test_suite</ a ></ li > 253< li >< a href ="rust.html#error_format "> error_format</ a ></ li > 254< li >< a href ="rust.html#extra_rustc_flag "> extra_rustc_flag</ a ></ li > 255< li >< a href ="rust.html#extra_rustc_flags "> extra_rustc_flags</ a ></ li > 256< li >< a href ="rust.html#capture_clippy_output "> capture_clippy_output</ a ></ li > 257</ ul > 258< p >< a id ="capture_clippy_output "></ a ></ p > 259< h2 id ="capture_clippy_output ">< a class ="header "href ="#capture_clippy_output "> capture_clippy_output</ a ></ h2 > 260< pre > 261capture_clippy_output(< a href ="rust.html#capture_clippy_output-name "> name</ a > ) 262</ pre > 263< p > Control whether to print clippy output or store it to a file, using the configured error_format.</ p > 264< p >< strong > ATTRIBUTES</ strong ></ p > 265< 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 > 266< tr >< td style ="text-align: left ">< a id ="capture_clippy_output-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 > 267</ tbody ></ table > 268</ div > 269< p >< a id ="error_format "></ a ></ p > 270< h2 id ="error_format ">< a class ="header "href ="#error_format "> error_format</ a ></ h2 > 271< pre > 272error_format(< a href ="rust.html#error_format-name "> name</ a > ) 273</ pre > 274< p > Change the< a href ="https://doc.rust-lang.org/rustc/command-line-arguments.html#option-error-format "> --error-format</ a > flag from the command line with< code > --@rules_rust//rust/settings:error_format</ code > . See rustc documentation for valid values.</ p > 275< p >< strong > ATTRIBUTES</ strong ></ p > 276< 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 > 277< tr >< td style ="text-align: left ">< a id ="error_format-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 > 278</ tbody ></ table > 279</ div > 280< p >< a id ="extra_rustc_flag "></ a ></ p > 281< h2 id ="extra_rustc_flag ">< a class ="header "href ="#extra_rustc_flag "> extra_rustc_flag</ a ></ h2 > 282< pre > 283extra_rustc_flag(< a href ="rust.html#extra_rustc_flag-name "> name</ a > ) 284</ pre > 285< p > Add additional rustc_flag from the command line with< code > --@rules_rust//rust/settings:extra_rustc_flag</ code > . Multiple uses are accumulated and appended after the extra_rustc_flags.</ p > 286< p >< strong > ATTRIBUTES</ strong ></ p > 287< 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 > 288< tr >< td style ="text-align: left ">< a id ="extra_rustc_flag-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 > 289</ tbody ></ table > 290</ div > 291< p >< a id ="extra_rustc_flags "></ a ></ p > 292< h2 id ="extra_rustc_flags ">< a class ="header "href ="#extra_rustc_flags "> extra_rustc_flags</ a ></ h2 > 293< pre > 294extra_rustc_flags(< a href ="rust.html#extra_rustc_flags-name "> name</ a > ) 295</ pre > 296< p > Add additional rustc_flags from the command line with< code > --@rules_rust//rust/settings:extra_rustc_flags</ code > . This flag should only be used for flags that need to be applied across the entire build. For options that apply to individual crates, use the rustc_flags attribute on the individual crate's rule instead. NOTE: These flags not applied to the exec configuration (proc-macros, cargo_build_script, etc); use< code > --@rules_rust//rust/settings:extra_exec_rustc_flags</ code > to apply flags to the exec configuration.</ p > 297< p >< strong > ATTRIBUTES</ strong ></ p > 298< 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 > 299< tr >< td style ="text-align: left ">< a id ="extra_rustc_flags-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 > 300</ tbody ></ table > 301</ div > 302< p >< a id ="rust_binary "></ a ></ p > 303< h2 id ="rust_binary ">< a class ="header "href ="#rust_binary "> rust_binary</ a ></ h2 > 304< pre > 305rust_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-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 > , 306< 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 > , 307< a href ="rust.html#rust_binary-linker_script "> linker_script</ 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 > , 308< 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 > ) 309</ pre > 310< p > Builds a Rust binary crate.</ p > 311< p > Example:</ p > 312< p > Suppose you have the following directory structure for a Rust project with a 313library crate,< code > hello_lib</ code > , and a binary crate,< code > hello_world</ code > that uses the 314< code > hello_lib</ code > library:</ p > 315< pre >< code class ="language-output "> [workspace]/ 316 WORKSPACE 317 hello_lib/ 318 BUILD 319 src/ 320 lib.rs 321 hello_world/ 322 BUILD 323 src/ 324 main.rs 325</ code ></ pre > 326< p >< code > hello_lib/src/lib.rs</ code > :</ p > 327< pre >< pre class ="playground ">< code class ="language-rust ">< span class ="boring "> #![allow(unused)] 328</ span >< span class ="boring "> fn main() { 329</ span > pub struct Greeter { 330 greeting: String, 331} 332 333impl Greeter { 334 pub fn new(greeting: &str) -> Greeter { 335 Greeter { greeting: greeting.to_string(), } 336 } 337 338 pub fn greet(&self, thing: &str) { 339 println!("{} {}", &self.greeting, thing); 340 } 341} 342< span class ="boring "> }</ span ></ code ></ pre ></ pre > 343< p >< code > hello_lib/BUILD</ code > :</ p > 344< pre >< code class ="language-python "> package(default_visibility = ["//visibility:public"]) 345 346load("@rules_rust//rust:defs.bzl", "rust_library") 347 348rust_library( 349 name = "hello_lib", 350 srcs = ["src/lib.rs"], 351) 352</ code ></ pre > 353< p >< code > hello_world/src/main.rs</ code > :</ p > 354< pre >< pre class ="playground ">< code class ="language-rust "> extern crate hello_lib; 355 356fn main() { 357 let hello = hello_lib::Greeter::new("Hello"); 358 hello.greet("world"); 359}</ code ></ pre ></ pre > 360< p >< code > hello_world/BUILD</ code > :</ p > 361< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_binary") 362 363rust_binary( 364 name = "hello_world", 365 srcs = ["src/main.rs"], 366 deps = ["//hello_lib"], 367) 368</ code ></ pre > 369< p > Build and run< code > hello_world</ code > :</ p > 370< pre >< code > $ bazel run //hello_world 371INFO: Found 1 target... 372Target //examples/rust/hello_world:hello_world up-to-date: 373bazel-bin/examples/rust/hello_world/hello_world 374INFO: Elapsed time: 1.308s, Critical Path: 1.22s 375 376INFO: Running command line: bazel-bin/examples/rust/hello_world/hello_world 377Hello world 378</ code ></ pre > 379< p > On Windows, a PDB file containing debugging information is available under 380the key< code > pdb_file</ code > in< code > OutputGroupInfo</ code > . Similarly on macOS, a dSYM folder 381is available under the key< code > dsym_folder</ code > in< code > OutputGroupInfo</ code > .</ p > 382< p >< strong > ATTRIBUTES</ strong ></ p > 383< 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 > 384< 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 > 385< 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 > 386< 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 > 387< 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 > 388< 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 > 389< 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 > 390< 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 > 391< 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 > 392< 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 > 393< 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 > 394< 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 > 395< 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 > 396< 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 > 397< 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 > 398< 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 > 399< 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 > 400< 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 > 401< 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 > 402< 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 > 403< 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 > 404< 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 > 405< 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 > 406< 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 > 407< 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 > 408< 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 > 409</ tbody ></ table > 410</ div > 411< p >< a id ="rust_library "></ a ></ p > 412< h2 id ="rust_library ">< a class ="header "href ="#rust_library "> rust_library</ a ></ h2 > 413< pre > 414rust_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-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 > , 415< 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-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 > , 416< 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 > ) 417</ pre > 418< p > Builds a Rust library crate.</ p > 419< p > Example:</ p > 420< p > Suppose you have the following directory structure for a simple Rust library crate:</ p > 421< pre >< code class ="language-output "> [workspace]/ 422 WORKSPACE 423 hello_lib/ 424 BUILD 425 src/ 426 greeter.rs 427 lib.rs 428</ code ></ pre > 429< p >< code > hello_lib/src/greeter.rs</ code > :</ p > 430< pre >< pre class ="playground ">< code class ="language-rust ">< span class ="boring "> #![allow(unused)] 431</ span >< span class ="boring "> fn main() { 432</ span > pub struct Greeter { 433 greeting: String, 434} 435 436impl Greeter { 437 pub fn new(greeting: &str) -> Greeter { 438 Greeter { greeting: greeting.to_string(), } 439 } 440 441 pub fn greet(&self, thing: &str) { 442 println!("{} {}", &self.greeting, thing); 443 } 444} 445< span class ="boring "> }</ span ></ code ></ pre ></ pre > 446< p >< code > hello_lib/src/lib.rs</ code > :</ p > 447< pre >< pre class ="playground ">< code class ="language-rust ">< span class ="boring "> #![allow(unused)] 448</ span >< span class ="boring "> fn main() { 449</ span > pub mod greeter; 450< span class ="boring "> }</ span ></ code ></ pre ></ pre > 451< p >< code > hello_lib/BUILD</ code > :</ p > 452< pre >< code class ="language-python "> package(default_visibility = ["//visibility:public"]) 453 454load("@rules_rust//rust:defs.bzl", "rust_library") 455 456rust_library( 457 name = "hello_lib", 458 srcs = [ 459 "src/greeter.rs", 460 "src/lib.rs", 461 ], 462) 463</ code ></ pre > 464< p > Build the library:</ p > 465< pre >< code class ="language-output "> $ bazel build //hello_lib 466INFO: Found 1 target... 467Target //examples/rust/hello_lib:hello_lib up-to-date: 468bazel-bin/examples/rust/hello_lib/libhello_lib.rlib 469INFO: Elapsed time: 1.245s, Critical Path: 1.01s 470</ code ></ pre > 471< p >< strong > ATTRIBUTES</ strong ></ p > 472< 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 > 473< 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 > 474< 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 > 475< 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 > 476< 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 > 477< 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 > 478< 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 > 479< 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 > 480< 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 > 481< 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 > 482< 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 > 483< 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 > 484< 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 > 485< 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 > 486< 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 > 487< 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 > 488< 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 > 489< 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 > 490< 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 > 491</ tbody ></ table > 492</ div > 493< p >< a id ="rust_library_group "></ a ></ p > 494< h2 id ="rust_library_group ">< a class ="header "href ="#rust_library_group "> rust_library_group</ a ></ h2 > 495< pre > 496rust_library_group(< a href ="rust.html#rust_library_group-name "> name</ a > ,< a href ="rust.html#rust_library_group-deps "> deps</ a > ) 497</ pre > 498< p > Functions as an alias for a set of dependencies.</ p > 499< p > Specifically, the following are equivalent:</ p > 500< pre >< code class ="language-starlark "> rust_library_group( 501 name = "crate_group", 502 deps = [ 503 ":crate1", 504 ":crate2", 505 ], 506) 507 508rust_library( 509 name = "foobar", 510 deps = [":crate_group"], 511 ... 512) 513</ code ></ pre > 514< p > and</ p > 515< pre >< code class ="language-starlark "> rust_library( 516 name = "foobar", 517 deps = [ 518 ":crate1", 519 ":crate2", 520 ], 521 ... 522) 523</ code ></ pre > 524< p >< strong > ATTRIBUTES</ strong ></ p > 525< 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 > 526< 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 > 527< 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 > 528</ tbody ></ table > 529</ div > 530< p >< a id ="rust_proc_macro "></ a ></ p > 531< h2 id ="rust_proc_macro ">< a class ="header "href ="#rust_proc_macro "> rust_proc_macro</ a ></ h2 > 532< pre > 533rust_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-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 > , 534< 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-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 > , 535< 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 > ) 536</ pre > 537< p > Builds a Rust proc-macro crate.</ p > 538< p >< strong > ATTRIBUTES</ strong ></ p > 539< 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 > 540< 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 > 541< 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 > 542< 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 > 543< 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 > 544< 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 > 545< 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 > 546< 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 > 547< 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 > 548< 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 > 549< 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 > 550< 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 > 551< 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 > 552< 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 > 553< 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 > 554< 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 > 555< 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 > 556< 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 > 557</ tbody ></ table > 558</ div > 559< p >< a id ="rust_shared_library "></ a ></ p > 560< h2 id ="rust_shared_library ">< a class ="header "href ="#rust_shared_library "> rust_shared_library</ a ></ h2 > 561< pre > 562rust_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-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 > , 563< 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-malloc "> malloc</ a > , 564< 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 > , 565< a href ="rust.html#rust_shared_library-version "> version</ a > ) 566</ pre > 567< p > Builds a Rust shared library.</ p > 568< p > This shared library will contain all transitively reachable crates and native objects. 569It is meant to be used when producing an artifact that is then consumed by some other build system 570(for example to produce a shared library that Python program links against).</ p > 571< p > This rule provides CcInfo, so it can be used everywhere Bazel expects< code > rules_cc</ code > .</ p > 572< p > When building the whole binary in Bazel, use< code > rust_library</ code > instead.</ p > 573< p >< strong > ATTRIBUTES</ strong ></ p > 574< 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 > 575< 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 > 576< 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 > 577< 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 > 578< 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 > 579< 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 > 580< 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 > 581< 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 > 582< 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 > 583< 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 > 584< 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 > 585< 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 > 586< 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 > 587< 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 > 588< 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 > 589< 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 > 590< 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 > 591< 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 > 592< 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 > 593< 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 > 594< 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 > 595</ tbody ></ table > 596</ div > 597< p >< a id ="rust_static_library "></ a ></ p > 598< h2 id ="rust_static_library ">< a class ="header "href ="#rust_static_library "> rust_static_library</ a ></ h2 > 599< pre > 600rust_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-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 > , 601< 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-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 > , 602< 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 > ) 603</ pre > 604< p > Builds a Rust static library.</ p > 605< p > This static library will contain all transitively reachable crates and native objects. 606It is meant to be used when producing an artifact that is then consumed by some other build system 607(for example to produce an archive that Python program links against).</ p > 608< p > This rule provides CcInfo, so it can be used everywhere Bazel expects< code > rules_cc</ code > .</ p > 609< p > When building the whole binary in Bazel, use< code > rust_library</ code > instead.</ p > 610< p >< strong > ATTRIBUTES</ strong ></ p > 611< 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 > 612< 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 > 613< 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 > 614< 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 > 615< 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 > 616< 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 > 617< 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 > 618< 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 > 619< 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 > 620< 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 > 621< 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 > 622< 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 > 623< 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 > 624< 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 > 625< 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 > 626< 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 > 627< 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 > 628< 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 > 629< 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 > 630</ tbody ></ table > 631</ div > 632< p >< a id ="rust_test "></ a ></ p > 633< h2 id ="rust_test ">< a class ="header "href ="#rust_test "> rust_test</ a ></ h2 > 634< pre > 635rust_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-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 > , 636< 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-malloc "> malloc</ a > , 637< 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 > , 638< a href ="rust.html#rust_test-use_libtest_harness "> use_libtest_harness</ a > ,< a href ="rust.html#rust_test-version "> version</ a > ) 639</ pre > 640< p > Builds a Rust test crate.</ p > 641< p > Examples:</ p > 642< p > Suppose you have the following directory structure for a Rust library crate with unit test code in the library sources:</ p > 643< pre >< code class ="language-output "> [workspace]/ 644 WORKSPACE 645 hello_lib/ 646 BUILD 647 src/ 648 lib.rs 649</ code ></ pre > 650< p >< code > hello_lib/src/lib.rs</ code > :</ p > 651< pre >< pre class ="playground ">< code class ="language-rust ">< span class ="boring "> #![allow(unused)] 652</ span >< span class ="boring "> fn main() { 653</ span > pub struct Greeter { 654 greeting: String, 655} 656 657impl Greeter { 658 pub fn new(greeting: &str) -> Greeter { 659 Greeter { greeting: greeting.to_string(), } 660 } 661 662 pub fn greet(&self, thing: &str) -> String { 663 format!("{} {}", &self.greeting, thing) 664 } 665} 666 667#[cfg(test)] 668mod test { 669 use super::Greeter; 670 671 #[test] 672 fn test_greeting() { 673 let hello = Greeter::new("Hi"); 674 assert_eq!("Hi Rust", hello.greet("Rust")); 675 } 676} 677< span class ="boring "> }</ span ></ code ></ pre ></ pre > 678< p > To build and run the tests, simply add a< code > rust_test</ code > rule with no< code > srcs</ code > 679and only depends on the< code > hello_lib</ code > < code > rust_library</ code > target via the 680< code > crate</ code > attribute:</ p > 681< p >< code > hello_lib/BUILD</ code > :</ p > 682< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 683 684rust_library( 685 name = "hello_lib", 686 srcs = ["src/lib.rs"], 687) 688 689rust_test( 690 name = "hello_lib_test", 691 crate = ":hello_lib", 692 # You may add other deps that are specific to the test configuration 693 deps = ["//some/dev/dep"], 694) 695</ code ></ pre > 696< p > Run the test with< code > bazel test //hello_lib:hello_lib_test</ code > .</ p > 697< h3 id ="example-test-directory ">< a class ="header "href ="#example-test-directory "> Example:< code > test</ code > directory</ a ></ h3 > 698< 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 > 699< pre >< code class ="language-output "> [workspace]/ 700 WORKSPACE 701 hello_lib/ 702 BUILD 703 src/ 704 lib.rs 705 tests/ 706 greeting.rs 707</ code ></ pre > 708< p >< code > hello_lib/tests/greeting.rs</ code > :</ p > 709< pre >< pre class ="playground ">< code class ="language-rust ">< span class ="boring "> #![allow(unused)] 710</ span >< span class ="boring "> fn main() { 711</ span > extern crate hello_lib; 712 713use hello_lib; 714 715#[test] 716fn test_greeting() { 717 let hello = greeter::Greeter::new("Hello"); 718 assert_eq!("Hello world", hello.greeting("world")); 719} 720< span class ="boring "> }</ span ></ code ></ pre ></ pre > 721< p > To build the< code > greeting.rs</ code > integration test, simply add a< code > rust_test</ code > target 722with< code > greeting.rs</ code > in< code > srcs</ code > and a dependency on the< code > hello_lib</ code > target:</ p > 723< p >< code > hello_lib/BUILD</ code > :</ p > 724< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 725 726rust_library( 727 name = "hello_lib", 728 srcs = ["src/lib.rs"], 729) 730 731rust_test( 732 name = "greeting_test", 733 srcs = ["tests/greeting.rs"], 734 deps = [":hello_lib"], 735) 736</ code ></ pre > 737< p > Run the test with< code > bazel test //hello_lib:greeting_test</ code > .</ p > 738< p >< strong > ATTRIBUTES</ strong ></ p > 739< 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 > 740< 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 > 741< 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 > 742< 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 > 743< 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 > 744< 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 > 745< 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 > 746< 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 > 747< 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 > 748< 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 > 749< 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 > 750< 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 > 751< 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 > 752< 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 > 753< 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 > 754< 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 > 755< 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 > 756< 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 > 757< 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 > 758< 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 > 759< 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 > 760< 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 > 761< 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 > 762< 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 > 763< 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 > 764</ tbody ></ table > 765</ div > 766< p >< a id ="rust_test_suite "></ a ></ p > 767< h2 id ="rust_test_suite ">< a class ="header "href ="#rust_test_suite "> rust_test_suite</ a ></ h2 > 768< pre > 769rust_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 > ) 770</ pre > 771< p > A rule for creating a test suite for a set of< code > rust_test</ code > targets.</ p > 772< 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 773directory structure:</ p > 774< pre >< code class ="language-text "> [crate]/ 775 BUILD.bazel 776 src/ 777 lib.rs 778 main.rs 779 tests/ 780 integrated_test_a.rs 781 integrated_test_b.rs 782 integrated_test_c.rs 783 patterns/ 784 fibonacci_test.rs 785 helpers/ 786 mod.rs 787</ code ></ pre > 788< 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 > 789and a< a href ="https://docs.bazel.build/versions/master/be/general.html#test_suite "> test_suite</ a > which encapsulates all tests.</ p > 790< pre >< code class ="language-python "> load("//rust:defs.bzl", "rust_binary", "rust_library", "rust_test_suite") 791 792rust_library( 793 name = "math_lib", 794 srcs = ["src/lib.rs"], 795) 796 797rust_binary( 798 name = "math_bin", 799 srcs = ["src/main.rs"], 800) 801 802rust_test_suite( 803 name = "integrated_tests_suite", 804 srcs = glob(["tests/**"]), 805 shared_srcs=glob(["tests/helpers/**"]), 806 deps = [":math_lib"], 807) 808</ code ></ pre > 809< p >< strong > PARAMETERS</ strong ></ p > 810< 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 > 811< 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 > 812< 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 > 813< 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 > 814< 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 underyling< 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 > 815</ tbody ></ table > 816</ div >< div style ="break-before: page; page-break-before: always; "></ div > <!-- Generated with Stardoc: http://skydoc.bazel.build --> 817< h1 id ="rust-doc ">< a class ="header "href ="#rust-doc "> Rust Doc</ a ></ h1 > 818< ul > 819< li >< a href ="rust_doc.html#rust_doc "> rust_doc</ a ></ li > 820< li >< a href ="rust_doc.html#rust_doc_test "> rust_doc_test</ a ></ li > 821</ ul > 822< p >< a id ="rust_doc "></ a ></ p > 823< h2 id ="rust_doc ">< a class ="header "href ="#rust_doc "> rust_doc</ a ></ h2 > 824< pre > 825rust_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-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 > , 826< a href ="rust_doc.html#rust_doc-rustc_flags "> rustc_flags</ a > ,< a href ="rust_doc.html#rust_doc-rustdoc_flags "> rustdoc_flags</ a > ) 827</ pre > 828< p > Generates code documentation.</ p > 829< p > Example: 830Suppose you have the following directory structure for a Rust library crate:</ p > 831< pre >< code > [workspace]/ 832 WORKSPACE 833 hello_lib/ 834 BUILD 835 src/ 836 lib.rs 837</ code ></ pre > 838< 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 > 839< pre >< code class ="language-python "> package(default_visibility = ["//visibility:public"]) 840 841load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc") 842 843rust_library( 844 name = "hello_lib", 845 srcs = ["src/lib.rs"], 846) 847 848rust_doc( 849 name = "hello_lib_doc", 850 crate = ":hello_lib", 851) 852</ code ></ pre > 853< 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 > 854< p >< strong > ATTRIBUTES</ strong ></ p > 855< 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 > 856< 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 > 857< 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 > 858< 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 > 859< 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 > 860< 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 > 861< 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 > 862< 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 > 863< 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 > 864</ tbody ></ table > 865</ div > 866< p >< a id ="rust_doc_test "></ a ></ p > 867< h2 id ="rust_doc_test ">< a class ="header "href ="#rust_doc_test "> rust_doc_test</ a ></ h2 > 868< pre > 869rust_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-proc_macro_deps "> proc_macro_deps</ a > ) 870</ pre > 871< p > Runs Rust documentation tests.</ p > 872< p > Example:</ p > 873< p > Suppose you have the following directory structure for a Rust library crate:</ p > 874< pre >< code class ="language-output "> [workspace]/ 875WORKSPACE 876hello_lib/ 877 BUILD 878 src/ 879 lib.rs 880</ code ></ pre > 881< 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 > 882< pre >< code class ="language-python "> package(default_visibility = ["//visibility:public"]) 883 884load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc_test") 885 886rust_library( 887 name = "hello_lib", 888 srcs = ["src/lib.rs"], 889) 890 891rust_doc_test( 892 name = "hello_lib_doc_test", 893 crate = ":hello_lib", 894) 895</ code ></ pre > 896< 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 > 897< p >< strong > ATTRIBUTES</ strong ></ p > 898< 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 > 899< 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 > 900< 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 > 901< 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 > 902< 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 > 903</ tbody ></ table > 904</ div >< div style ="break-before: page; page-break-before: always; "></ div > <!-- Generated with Stardoc: http://skydoc.bazel.build --> 905< h1 id ="rust-clippy ">< a class ="header "href ="#rust-clippy "> Rust Clippy</ a ></ h1 > 906< ul > 907< li >< a href ="rust_clippy.html#rust_clippy "> rust_clippy</ a ></ li > 908< li >< a href ="rust_clippy.html#rust_clippy_aspect "> rust_clippy_aspect</ a ></ li > 909</ ul > 910< h2 id ="overview ">< a class ="header "href ="#overview "> Overview</ a ></ h2 > 911< 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 912expansive list of lints and the justification can be found in their< a href ="https://rust-lang.github.io/rust-clippy/ "> documentation</ a > .</ p > 913< h3 id ="setup-1 ">< a class ="header "href ="#setup-1 "> Setup</ a ></ h3 > 914< p > Simply add the following to the< code > .bazelrc</ code > file in the root of your workspace:</ p > 915< pre >< code class ="language-text "> build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect 916build --output_groups=+clippy_checks 917</ code ></ pre > 918< p > This will enable clippy on all< a href ="./defs.html "> Rust targets</ a > .</ p > 919< p > Note that targets tagged with< code > no-clippy</ code > will not perform clippy checks</ p > 920< p > To use a local clippy.toml, add the following flag to your< code > .bazelrc</ code > . Note that due to 921the upstream implementation of clippy, this file must be named either< code > .clippy.toml</ code > or 922< code > clippy.toml</ code > . Using a custom config file requires Rust 1.34.0 or newer.</ p > 923< pre >< code class ="language-text "> build --@rules_rust//rust/settings:clippy.toml=//:clippy.toml 924</ code ></ pre > 925< p >< a id ="rust_clippy "></ a ></ p > 926< h2 id ="rust_clippy ">< a class ="header "href ="#rust_clippy "> rust_clippy</ a ></ h2 > 927< pre > 928rust_clippy(< a href ="rust_clippy.html#rust_clippy-name "> name</ a > ,< a href ="rust_clippy.html#rust_clippy-deps "> deps</ a > ) 929</ pre > 930< p > Executes the clippy checker on a specific target.</ p > 931< p > Similar to< code > rust_clippy_aspect</ code > , but allows specifying a list of dependencies within the build system.</ p > 932< p > For example, given the following example targets:</ p > 933< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 934 935rust_library( 936 name = "hello_lib", 937 srcs = ["src/lib.rs"], 938) 939 940rust_test( 941 name = "greeting_test", 942 srcs = ["tests/greeting.rs"], 943 deps = [":hello_lib"], 944) 945</ code ></ pre > 946< p > Rust clippy can be set as a build target with the following:</ p > 947< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_clippy") 948 949rust_clippy( 950 name = "hello_library_clippy", 951 testonly = True, 952 deps = [ 953 ":hello_lib", 954 ":greeting_test", 955 ], 956) 957</ code ></ pre > 958< p >< strong > ATTRIBUTES</ strong ></ p > 959< 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 > 960< 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 > 961< 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 > 962</ tbody ></ table > 963</ div > 964< p >< a id ="rust_clippy_aspect "></ a ></ p > 965< h2 id ="rust_clippy_aspect ">< a class ="header "href ="#rust_clippy_aspect "> rust_clippy_aspect</ a ></ h2 > 966< pre > 967rust_clippy_aspect(< a href ="rust_clippy.html#rust_clippy_aspect-name "> name</ a > ) 968</ pre > 969< p > Executes the clippy checker on specified targets.</ p > 970< p > This aspect applies to existing rust_library, rust_test, and rust_binary rules.</ p > 971< p > As an example, if the following is defined in< code > examples/hello_lib/BUILD.bazel</ code > :</ p > 972< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 973 974rust_library( 975 name = "hello_lib", 976 srcs = ["src/lib.rs"], 977) 978 979rust_test( 980 name = "greeting_test", 981 srcs = ["tests/greeting.rs"], 982 deps = [":hello_lib"], 983) 984</ code ></ pre > 985< p > Then the targets can be analyzed with clippy using the following command:</ p > 986< pre >< code class ="language-output "> $ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect --output_groups=clippy_checks //hello_lib:all 987</ code ></ pre > 988< p >< strong > ASPECT ATTRIBUTES</ strong ></ p > 989< p >< strong > ATTRIBUTES</ strong ></ p > 990< 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 > 991< tr >< td style ="text-align: left ">< a id ="rust_clippy_aspect-name "></ a > name</ td >< td style ="text-align: left "> A unique name for this target.</ td >< td style ="text-align: left ">< a href ="https://bazel.build/concepts/labels#target-names "> Name</ a ></ td >< td style ="text-align: left "> required</ td >< td style ="text-align: left "></ td ></ tr > 992</ tbody ></ table > 993</ div >< div style ="break-before: page; page-break-before: always; "></ div > <!-- Generated with Stardoc: http://skydoc.bazel.build --> 994< h1 id ="rust-fmt ">< a class ="header "href ="#rust-fmt "> Rust Fmt</ a ></ h1 > 995< ul > 996< li >< a href ="rust_fmt.html#rustfmt_aspect "> rustfmt_aspect</ a ></ li > 997< li >< a href ="rust_fmt.html#rustfmt_test "> rustfmt_test</ a ></ li > 998< li >< a href ="rust_fmt.html#rustfmt_toolchain "> rustfmt_toolchain</ a ></ li > 999</ ul > 1000< h2 id ="overview-1 ">< a class ="header "href ="#overview-1 "> Overview</ a ></ h2 > 1001< p >< a href ="https://github.com/rust-lang/rustfmt#readme "> Rustfmt</ a > is a tool for formatting Rust code according to style guidelines. 1002By 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 1003has been formalized through the< a href ="https://github.com/rust-lang-nursery/fmt-rfcs "> style RFC process</ a > . A complete list of all 1004configuration options can be found in the< a href ="https://rust-lang.github.io/rustfmt/ "> Rustfmt GitHub Pages</ a > .</ p > 1005< h3 id ="setup-2 ">< a class ="header "href ="#setup-2 "> Setup</ a ></ h3 > 1006< p > Formatting your Rust targets' source code requires no setup outside of loading< code > rules_rust</ code > 1007in your workspace. Simply run< code > bazel run @rules_rust//:rustfmt</ code > to format source code.</ p > 1008< 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 > 1009< pre >< code class ="language-text "> bazel build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect --output_groups=rustfmt_checks 1010</ code ></ pre > 1011< p > Add the following to a< code > .bazelrc</ code > file to enable this check during the build phase.</ p > 1012< pre >< code class ="language-text "> build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect 1013build --output_groups=+rustfmt_checks 1014</ code ></ pre > 1015< p > It's recommended to only enable this aspect in your CI environment so formatting issues do not 1016impact user's ability to rapidly iterate on changes.</ p > 1017< p > The< code > rustfmt_aspect</ code > also uses a< code > --@rules_rust//rust/settings:rustfmt.toml</ code > setting which determines the 1018< a href ="https://rust-lang.github.io/rustfmt/ "> configuration file</ a > used by the formatter (< code > @rules_rust//tools/rustfmt</ code > ) and the aspect 1019(< code > rustfmt_aspect</ code > ). This flag can be added to your< code > .bazelrc</ code > file to ensure a consistent config 1020file is used whenever< code > rustfmt</ code > is run:</ p > 1021< pre >< code class ="language-text "> build --@rules_rust//rust/settings:rustfmt.toml=//:rustfmt.toml 1022</ code ></ pre > 1023< h3 id ="tips ">< a class ="header "href ="#tips "> Tips</ a ></ h3 > 1024< p > Any target which uses Bazel generated sources will cause the< code > @rules_rust//tools/rustfmt</ code > tool to fail with 1025< 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 > 1026is recommended to be set in the workspace's< code > rustfmt.toml</ code > file which allows rustfmt to run on these targets 1027without failing.</ p > 1028< p >< a id ="rustfmt_test "></ a ></ p > 1029< h2 id ="rustfmt_test ">< a class ="header "href ="#rustfmt_test "> rustfmt_test</ a ></ h2 > 1030< pre > 1031rustfmt_test(< a href ="rust_fmt.html#rustfmt_test-name "> name</ a > ,< a href ="rust_fmt.html#rustfmt_test-targets "> targets</ a > ) 1032</ pre > 1033< p > A test rule for performing< code > rustfmt --check</ code > on a set of targets</ p > 1034< p >< strong > ATTRIBUTES</ strong ></ p > 1035< 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 > 1036< 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 > 1037< 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 > 1038</ tbody ></ table > 1039</ div > 1040< p >< a id ="rustfmt_toolchain "></ a ></ p > 1041< h2 id ="rustfmt_toolchain ">< a class ="header "href ="#rustfmt_toolchain "> rustfmt_toolchain</ a ></ h2 > 1042< pre > 1043rustfmt_toolchain(< a href ="rust_fmt.html#rustfmt_toolchain-name "> name</ a > ,< a href ="rust_fmt.html#rustfmt_toolchain-rustc "> rustc</ a > ,< a href ="rust_fmt.html#rustfmt_toolchain-rustc_lib "> rustc_lib</ a > ,< a href ="rust_fmt.html#rustfmt_toolchain-rustfmt "> rustfmt</ a > ) 1044</ pre > 1045< p > A toolchain for< a href ="https://rust-lang.github.io/rustfmt/ "> rustfmt</ a ></ p > 1046< p >< strong > ATTRIBUTES</ strong ></ p > 1047< 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 > 1048< 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 > 1049< 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 > 1050< 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 > 1051< 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 > 1052</ tbody ></ table > 1053</ div > 1054< p >< a id ="rustfmt_aspect "></ a ></ p > 1055< h2 id ="rustfmt_aspect ">< a class ="header "href ="#rustfmt_aspect "> rustfmt_aspect</ a ></ h2 > 1056< pre > 1057rustfmt_aspect(< a href ="rust_fmt.html#rustfmt_aspect-name "> name</ a > ) 1058</ pre > 1059< p > This aspect is used to gather information about a crate for use in rustfmt and perform rustfmt checks</ p > 1060< p > Output Groups:</ p > 1061< ul > 1062< li >< code > rustfmt_checks</ code > : Executes< code > rustfmt --check</ code > on the specified target.</ li > 1063</ ul > 1064< 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 > 1065used at runtime.</ p > 1066< p > This aspect is executed on any target which provides the< code > CrateInfo</ code > provider. However 1067users may tag a target with< code > no-rustfmt</ code > or< code > no-format</ code > to have it skipped. Additionally, 1068generated source files are also ignored by this aspect.</ p > 1069< p >< strong > ASPECT ATTRIBUTES</ strong ></ p > 1070< p >< strong > ATTRIBUTES</ strong ></ p > 1071< 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 > 1072< tr >< td style ="text-align: left ">< a id ="rustfmt_aspect-name "></ a > name</ td >< td style ="text-align: left "> A unique name for this target.</ td >< td style ="text-align: left ">< a href ="https://bazel.build/concepts/labels#target-names "> Name</ a ></ td >< td style ="text-align: left "> required</ td >< td style ="text-align: left "></ td ></ tr > 1073</ tbody ></ table > 1074</ div >< div style ="break-before: page; page-break-before: always; "></ div > <!-- Generated with Stardoc: http://skydoc.bazel.build --> 1075< h1 id ="cargo ">< a class ="header "href ="#cargo "> Cargo</ a ></ h1 > 1076< ul > 1077< li >< a href ="cargo.html#cargo_bootstrap_repository "> cargo_bootstrap_repository</ a ></ li > 1078< li >< a href ="cargo.html#cargo_build_script "> cargo_build_script</ a ></ li > 1079< li >< a href ="cargo.html#cargo_dep_env "> cargo_dep_env</ a ></ li > 1080< li >< a href ="cargo.html#cargo_env "> cargo_env</ a ></ li > 1081</ ul > 1082< p >< a id ="cargo_dep_env "></ a ></ p > 1083< h2 id ="cargo_dep_env ">< a class ="header "href ="#cargo_dep_env "> cargo_dep_env</ a ></ h2 > 1084< pre > 1085cargo_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 > ) 1086</ pre > 1087< 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 > 1088< p >< strong > ATTRIBUTES</ strong ></ p > 1089< 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 > 1090< 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 > 1091< 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 > 1092< 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 > 1093</ tbody ></ table > 1094</ div > 1095< p >< a id ="cargo_build_script "></ a ></ p > 1096< h2 id ="cargo_build_script ">< a class ="header "href ="#cargo_build_script "> cargo_build_script</ a ></ h2 > 1097< pre > 1098cargo_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 > , 1099< 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-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 > , 1100< 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 > , 1101< a href ="cargo.html#cargo_build_script-pkg_name "> pkg_name</ a > ,< a href ="cargo.html#cargo_build_script-kwargs "> kwargs</ a > ) 1102</ pre > 1103< p > Compile and execute a rust build script to generate build attributes</ p > 1104< p > This rules take the same arguments as rust_binary.</ p > 1105< p > Example:</ p > 1106< p > Suppose you have a crate with a cargo build script< code > build.rs</ code > :</ p > 1107< pre >< code class ="language-output "> [workspace]/ 1108 hello_lib/ 1109 BUILD 1110 build.rs 1111 src/ 1112 lib.rs 1113</ code ></ pre > 1114< p > Then you want to use the build script in the following:</ p > 1115< p >< code > hello_lib/BUILD</ code > :</ p > 1116< pre >< code class ="language-python "> package(default_visibility = ["//visibility:public"]) 1117 1118load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library") 1119load("@rules_rust//cargo:defs.bzl", "cargo_build_script") 1120 1121# This will run the build script from the root of the workspace, and 1122# collect the outputs. 1123cargo_build_script( 1124 name = "build_script", 1125 srcs = ["build.rs"], 1126 # Optional environment variables passed during build.rs compilation 1127 rustc_env = { 1128 "CARGO_PKG_VERSION": "0.1.2", 1129 }, 1130 # Optional environment variables passed during build.rs execution. 1131 # Note that as the build script's working directory is not execroot, 1132 # execpath/location will return an absolute path, instead of a relative 1133 # one. 1134 build_script_env = { 1135 "SOME_TOOL_OR_FILE": "$(execpath @tool//:binary)" 1136 }, 1137 # Optional data/tool dependencies 1138 data = ["@tool//:binary"], 1139) 1140 1141rust_library( 1142 name = "hello_lib", 1143 srcs = [ 1144 "src/lib.rs", 1145 ], 1146 deps = [":build_script"], 1147) 1148</ code ></ pre > 1149< 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 > 1150< p >< strong > PARAMETERS</ strong ></ p > 1151< 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 > 1152< 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 > 1153< 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 > 1154< 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 > 1155< 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 > 1156< tr >< td style ="text-align: left ">< a id ="cargo_build_script-srcs "></ a > srcs</ td >< td style ="text-align: left "> Souce 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 > 1157< 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 > 1158< 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 > 1159< 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 > 1160< 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 > 1161< 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 > 1162< 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 > 1163< 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 > 1164< 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 > 1165< 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 > 1166< 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 > 1167< 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 > 1168< 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 > 1169< 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 > 1170< 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 > 1171< 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 > 1172< 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 > 1173< 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 > 1174< 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 > 1175< 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_scirpt_run</ code > target.</ td >< td style ="text-align: left "> none</ td ></ tr > 1176</ tbody ></ table > 1177</ div > 1178< p >< a id ="cargo_env "></ a ></ p > 1179< h2 id ="cargo_env ">< a class ="header "href ="#cargo_env "> cargo_env</ a ></ h2 > 1180< pre > 1181cargo_env(< a href ="cargo.html#cargo_env-env "> env</ a > ) 1182</ pre > 1183< p > A helper for generating platform specific environment variables</ p > 1184< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_common") 1185load("@rules_rust//cargo:defs.bzl", "cargo_bootstrap_repository", "cargo_env") 1186 1187cargo_bootstrap_repository( 1188 name = "bootstrapped_bin", 1189 cargo_lockfile = "//:Cargo.lock", 1190 cargo_toml = "//:Cargo.toml", 1191 srcs = ["//:resolver_srcs"], 1192 version = rust_common.default_version, 1193 binary = "my-crate-binary", 1194 env = { 1195 "x86_64-unknown-linux-gnu": cargo_env({ 1196 "FOO": "BAR", 1197 }), 1198 }, 1199 env_label = { 1200 "aarch64-unknown-linux-musl": cargo_env({ 1201 "DOC": "//:README.md", 1202 }), 1203 } 1204) 1205</ code ></ pre > 1206< p >< strong > PARAMETERS</ strong ></ p > 1207< 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 > 1208< 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 > 1209</ tbody ></ table > 1210</ div > 1211< p >< strong > RETURNS</ strong ></ p > 1212< p > str: A json encoded string of the environment variables</ p > 1213< p >< a id ="cargo_bootstrap_repository "></ a ></ p > 1214< h2 id ="cargo_bootstrap_repository ">< a class ="header "href ="#cargo_bootstrap_repository "> cargo_bootstrap_repository</ a ></ h2 > 1215< pre > 1216cargo_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 > , 1217< 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 > , 1218< 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 > , 1219< a href ="cargo.html#cargo_bootstrap_repository-version "> version</ a > ) 1220</ pre > 1221< p > A rule for bootstrapping a Rust binary using< a href ="https://doc.rust-lang.org/cargo/ "> Cargo</ a ></ p > 1222< p >< strong > ATTRIBUTES</ strong ></ p > 1223< 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 > 1224< 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 > 1225< tr >< td style ="text-align: left ">< a id ="cargo_bootstrap_repository-srcs "></ a > srcs</ td >< td style ="text-align: left "> Souce 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 > 1226< 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 > 1227< 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 > 1228< 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 > 1229< 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 > 1230< 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 > 1231< 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 "> Wether 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 > 1232< 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 > 1233< 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 > 1234< 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 > 1235< 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 > 1236< 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 > 1237< 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 > 1238< 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.83.0"</ code ></ td ></ tr > 1239</ tbody ></ table > 1240</ div >< div style ="break-before: page; page-break-before: always; "></ div > <!-- Generated with Stardoc: http://skydoc.bazel.build --> 1241< h1 id ="rust-analyzer ">< a class ="header "href ="#rust-analyzer "> Rust Analyzer</ a ></ h1 > 1242< ul > 1243< li >< a href ="rust_analyzer.html#rust_analyzer_aspect "> rust_analyzer_aspect</ a ></ li > 1244< li >< a href ="rust_analyzer.html#rust_analyzer_toolchain "> rust_analyzer_toolchain</ a ></ li > 1245</ ul > 1246< h2 id ="overview-2 ">< a class ="header "href ="#overview-2 "> Overview</ a ></ h2 > 1247< p > For< a href ="https://rust-analyzer.github.io/manual.html#non-cargo-based-projects "> non-Cargo projects</ a > , 1248< a href ="https://rust-analyzer.github.io/ "> rust-analyzer</ a > depends on a< code > rust-project.json</ code > file at the 1249root of the project that describes its structure. The< code > rust_analyzer</ code > rule facilitates generating 1250such a file.</ p > 1251< h3 id ="setup-3 ">< a class ="header "href ="#setup-3 "> Setup</ a ></ h3 > 1252< p > First, ensure< code > rules_rust</ code > is setup in your workspace. By default,< code > rust_register_toolchains</ code > will 1253ensure a< a href ="rust_analyzer.html#rust_analyzer_toolchain "> rust_analyzer_toolchain</ a > is registered within the WORKSPACE.</ p > 1254< p > Next, load the dependencies for the< code > rust-project.json</ code > generator tool:</ p > 1255< pre >< code class ="language-python "> load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies") 1256 1257rust_analyzer_dependencies() 1258</ code ></ pre > 1259< p > Finally, run< code > bazel run @rules_rust//tools/rust_analyzer:gen_rust_project</ code > 1260whenever dependencies change to regenerate the< code > rust-project.json</ code > file. It 1261should be added to< code > .gitignore</ code > because it is effectively a build artifact. 1262Once the< code > rust-project.json</ code > has been generated in the project root, 1263rust-analyzer can pick it up upon restart.</ p > 1264< p > For users who do not use< code > rust_register_toolchains</ code > to register toolchains, the following can be added 1265to their WORKSPACE to register a< code > rust_analyzer_toolchain</ code > . Please make sure the Rust version used in 1266this toolchain matches the version used by the currently registered toolchain or the sources/documentation 1267will not match what's being compiled with and can lead to confusing results.</ p > 1268< pre >< code class ="language-python "> load("@rules_rust//rust:repositories.bzl", "rust_analyzer_toolchain_repository") 1269 1270register_toolchains(rust_analyzer_toolchain_repository( 1271 name = "rust_analyzer_toolchain", 1272 # This should match the currently registered toolchain. 1273 version = "1.63.0", 1274)) 1275</ code ></ pre > 1276< h4 id ="vscode ">< a class ="header "href ="#vscode "> VSCode</ a ></ h4 > 1277< p > To set this up using< a href ="https://code.visualstudio.com/ "> VSCode</ a > , users should first install the 1278< a href ="https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer "> rust_analyzer plugin</ a > . 1279With that in place, the following task can be added to the< code > .vscode/tasks.json</ code > file of the workspace 1280to ensure a< code > rust-project.json</ code > file is created and up to date when the editor is opened.</ p > 1281< pre >< code class ="language-json "> { 1282 "version": "2.0.0", 1283 "tasks": [ 1284 { 1285 "label": "Generate rust-project.json", 1286 "command": "bazel", 1287 "args": [ 1288 "run", 1289 "//tools/rust_analyzer:gen_rust_project" 1290 ], 1291 "options": { 1292 "cwd": "${workspaceFolder}" 1293 }, 1294 "group": "build", 1295 "problemMatcher": [], 1296 "presentation": { 1297 "reveal": "never", 1298 "panel": "dedicated", 1299 }, 1300 "runOptions": { 1301 "runOn": "folderOpen" 1302 } 1303 }, 1304 ] 1305} 1306</ code ></ pre > 1307< h4 id ="alternative-vscode-option-prototype ">< a class ="header "href ="#alternative-vscode-option-prototype "> Alternative vscode option (prototype)</ a ></ h4 > 1308< p > Add the following to your bazelrc:</ p > 1309< pre >< code > build --@rules_rust//rust/settings:rustc_output_diagnostics=true --output_groups=+rust_lib_rustc_output,+rust_metadata_rustc_output 1310</ code ></ pre > 1311< 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 > 1312< p >< a id ="rust_analyzer_toolchain "></ a ></ p > 1313< h2 id ="rust_analyzer_toolchain ">< a class ="header "href ="#rust_analyzer_toolchain "> rust_analyzer_toolchain</ a ></ h2 > 1314< pre > 1315rust_analyzer_toolchain(< a href ="rust_analyzer.html#rust_analyzer_toolchain-name "> name</ a > ,< a href ="rust_analyzer.html#rust_analyzer_toolchain-proc_macro_srv "> proc_macro_srv</ a > ,< a href ="rust_analyzer.html#rust_analyzer_toolchain-rustc "> rustc</ a > ,< a href ="rust_analyzer.html#rust_analyzer_toolchain-rustc_srcs "> rustc_srcs</ a > ) 1316</ pre > 1317< p > A toolchain for< a href ="https://rust-analyzer.github.io/ "> rust-analyzer</ a > .</ p > 1318< p >< strong > ATTRIBUTES</ strong ></ p > 1319< 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 > 1320< 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 > 1321< 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 > 1322< 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 > 1323< 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 > 1324</ tbody ></ table > 1325</ div > 1326< p >< a id ="rust_analyzer_aspect "></ a ></ p > 1327< h2 id ="rust_analyzer_aspect ">< a class ="header "href ="#rust_analyzer_aspect "> rust_analyzer_aspect</ a ></ h2 > 1328< pre > 1329rust_analyzer_aspect(< a href ="rust_analyzer.html#rust_analyzer_aspect-name "> name</ a > ) 1330</ pre > 1331< p > Annotates rust rules with RustAnalyzerInfo later used to build a rust-project.json</ p > 1332< p >< strong > ASPECT ATTRIBUTES</ strong ></ p > 1333< div class ="table-wrapper ">< table >< thead >< tr >< th style ="text-align: left "> Name</ th >< th style ="text-align: left "> Type</ th ></ tr ></ thead >< tbody > 1334< tr >< td style ="text-align: left "> deps</ td >< td style ="text-align: left "> String</ td ></ tr > 1335< tr >< td style ="text-align: left "> proc_macro_deps</ td >< td style ="text-align: left "> String</ td ></ tr > 1336< tr >< td style ="text-align: left "> crate</ td >< td style ="text-align: left "> String</ td ></ tr > 1337< tr >< td style ="text-align: left "> actual</ td >< td style ="text-align: left "> String</ td ></ tr > 1338< tr >< td style ="text-align: left "> proto</ td >< td style ="text-align: left "> String</ td ></ tr > 1339</ tbody ></ table > 1340</ div > 1341< p >< strong > ATTRIBUTES</ strong ></ p > 1342< 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 > 1343< tr >< td style ="text-align: left ">< a id ="rust_analyzer_aspect-name "></ a > name</ td >< td style ="text-align: left "> A unique name for this target.</ td >< td style ="text-align: left ">< a href ="https://bazel.build/concepts/labels#target-names "> Name</ a ></ td >< td style ="text-align: left "> required</ td >< td style ="text-align: left "></ td ></ tr > 1344</ tbody ></ table > 1345</ div >< div style ="break-before: page; page-break-before: always; "></ div >< h1 id ="rust-rules ">< a class ="header "href ="#rust-rules "> Rust rules</ a ></ h1 > 1346< ul > 1347< li >< a href ="flatten.html#CrateInfo "> CrateInfo</ a ></ li > 1348< li >< a href ="flatten.html#DepInfo "> DepInfo</ a ></ li > 1349< li >< a href ="flatten.html#StdLibInfo "> StdLibInfo</ a ></ li > 1350< li >< a href ="flatten.html#capture_clippy_output "> capture_clippy_output</ a ></ li > 1351< li >< a href ="flatten.html#cargo_bootstrap_repository "> cargo_bootstrap_repository</ a ></ li > 1352< li >< a href ="flatten.html#cargo_build_script "> cargo_build_script</ a ></ li > 1353< li >< a href ="flatten.html#cargo_dep_env "> cargo_dep_env</ a ></ li > 1354< li >< a href ="flatten.html#cargo_env "> cargo_env</ a ></ li > 1355< li >< a href ="flatten.html#error_format "> error_format</ a ></ li > 1356< li >< a href ="flatten.html#extra_rustc_flag "> extra_rustc_flag</ a ></ li > 1357< li >< a href ="flatten.html#extra_rustc_flags "> extra_rustc_flags</ a ></ li > 1358< li >< a href ="flatten.html#fail_when_enabled "> fail_when_enabled</ a ></ li > 1359< li >< a href ="flatten.html#incompatible_flag "> incompatible_flag</ a ></ li > 1360< li >< a href ="flatten.html#rules_rust_dependencies "> rules_rust_dependencies</ a ></ li > 1361< li >< a href ="flatten.html#rust_analyzer_aspect "> rust_analyzer_aspect</ a ></ li > 1362< li >< a href ="flatten.html#rust_analyzer_toolchain "> rust_analyzer_toolchain</ a ></ li > 1363< li >< a href ="flatten.html#rust_analyzer_toolchain_repository "> rust_analyzer_toolchain_repository</ a ></ li > 1364< li >< a href ="flatten.html#rust_binary "> rust_binary</ a ></ li > 1365< li >< a href ="flatten.html#rust_clippy "> rust_clippy</ a ></ li > 1366< li >< a href ="flatten.html#rust_clippy_aspect "> rust_clippy_aspect</ a ></ li > 1367< li >< a href ="flatten.html#rust_doc "> rust_doc</ a ></ li > 1368< li >< a href ="flatten.html#rust_doc_test "> rust_doc_test</ a ></ li > 1369< li >< a href ="flatten.html#rust_library "> rust_library</ a ></ li > 1370< li >< a href ="flatten.html#rust_library_group "> rust_library_group</ a ></ li > 1371< li >< a href ="flatten.html#rust_proc_macro "> rust_proc_macro</ a ></ li > 1372< li >< a href ="flatten.html#rust_register_toolchains "> rust_register_toolchains</ a ></ li > 1373< li >< a href ="flatten.html#rust_repositories "> rust_repositories</ a ></ li > 1374< li >< a href ="flatten.html#rust_repository_set "> rust_repository_set</ a ></ li > 1375< li >< a href ="flatten.html#rust_shared_library "> rust_shared_library</ a ></ li > 1376< li >< a href ="flatten.html#rust_static_library "> rust_static_library</ a ></ li > 1377< li >< a href ="flatten.html#rust_stdlib_filegroup "> rust_stdlib_filegroup</ a ></ li > 1378< li >< a href ="flatten.html#rust_test "> rust_test</ a ></ li > 1379< li >< a href ="flatten.html#rust_test_suite "> rust_test_suite</ a ></ li > 1380< li >< a href ="flatten.html#rust_toolchain "> rust_toolchain</ a ></ li > 1381< li >< a href ="flatten.html#rust_toolchain_repository "> rust_toolchain_repository</ a ></ li > 1382< li >< a href ="flatten.html#rust_toolchain_repository_proxy "> rust_toolchain_repository_proxy</ a ></ li > 1383< li >< a href ="flatten.html#rust_toolchain_tools_repository "> rust_toolchain_tools_repository</ a ></ li > 1384< li >< a href ="flatten.html#rustfmt_aspect "> rustfmt_aspect</ a ></ li > 1385< li >< a href ="flatten.html#rustfmt_test "> rustfmt_test</ a ></ li > 1386< li >< a href ="flatten.html#rustfmt_toolchain "> rustfmt_toolchain</ a ></ li > 1387</ ul > 1388< p >< a id ="capture_clippy_output "></ a ></ p > 1389< h2 id ="capture_clippy_output-1 ">< a class ="header "href ="#capture_clippy_output-1 "> capture_clippy_output</ a ></ h2 > 1390< pre > 1391capture_clippy_output(< a href ="flatten.html#capture_clippy_output-name "> name</ a > ) 1392</ pre > 1393< p > Control whether to print clippy output or store it to a file, using the configured error_format.</ p > 1394< p >< strong > ATTRIBUTES</ strong ></ p > 1395< 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 > 1396< tr >< td style ="text-align: left ">< a id ="capture_clippy_output-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 > 1397</ tbody ></ table > 1398</ div > 1399< p >< a id ="cargo_dep_env "></ a ></ p > 1400< h2 id ="cargo_dep_env-1 ">< a class ="header "href ="#cargo_dep_env-1 "> cargo_dep_env</ a ></ h2 > 1401< pre > 1402cargo_dep_env(< a href ="flatten.html#cargo_dep_env-name "> name</ a > ,< a href ="flatten.html#cargo_dep_env-src "> src</ a > ,< a href ="flatten.html#cargo_dep_env-out_dir "> out_dir</ a > ) 1403</ pre > 1404< 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 > 1405< p >< strong > ATTRIBUTES</ strong ></ p > 1406< 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 > 1407< 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 > 1408< 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 > 1409< 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 > 1410</ tbody ></ table > 1411</ div > 1412< p >< a id ="error_format "></ a ></ p > 1413< h2 id ="error_format-1 ">< a class ="header "href ="#error_format-1 "> error_format</ a ></ h2 > 1414< pre > 1415error_format(< a href ="flatten.html#error_format-name "> name</ a > ) 1416</ pre > 1417< p > Change the< a href ="https://doc.rust-lang.org/rustc/command-line-arguments.html#option-error-format "> --error-format</ a > flag from the command line with< code > --@rules_rust//rust/settings:error_format</ code > . See rustc documentation for valid values.</ p > 1418< p >< strong > ATTRIBUTES</ strong ></ p > 1419< 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 > 1420< tr >< td style ="text-align: left ">< a id ="error_format-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 > 1421</ tbody ></ table > 1422</ div > 1423< p >< a id ="extra_rustc_flag "></ a ></ p > 1424< h2 id ="extra_rustc_flag-1 ">< a class ="header "href ="#extra_rustc_flag-1 "> extra_rustc_flag</ a ></ h2 > 1425< pre > 1426extra_rustc_flag(< a href ="flatten.html#extra_rustc_flag-name "> name</ a > ) 1427</ pre > 1428< p > Add additional rustc_flag from the command line with< code > --@rules_rust//rust/settings:extra_rustc_flag</ code > . Multiple uses are accumulated and appended after the extra_rustc_flags.</ p > 1429< p >< strong > ATTRIBUTES</ strong ></ p > 1430< 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 > 1431< tr >< td style ="text-align: left ">< a id ="extra_rustc_flag-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 > 1432</ tbody ></ table > 1433</ div > 1434< p >< a id ="extra_rustc_flags "></ a ></ p > 1435< h2 id ="extra_rustc_flags-1 ">< a class ="header "href ="#extra_rustc_flags-1 "> extra_rustc_flags</ a ></ h2 > 1436< pre > 1437extra_rustc_flags(< a href ="flatten.html#extra_rustc_flags-name "> name</ a > ) 1438</ pre > 1439< p > Add additional rustc_flags from the command line with< code > --@rules_rust//rust/settings:extra_rustc_flags</ code > . This flag should only be used for flags that need to be applied across the entire build. For options that apply to individual crates, use the rustc_flags attribute on the individual crate's rule instead. NOTE: These flags not applied to the exec configuration (proc-macros, cargo_build_script, etc); use< code > --@rules_rust//rust/settings:extra_exec_rustc_flags</ code > to apply flags to the exec configuration.</ p > 1440< p >< strong > ATTRIBUTES</ strong ></ p > 1441< 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 > 1442< tr >< td style ="text-align: left ">< a id ="extra_rustc_flags-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 > 1443</ tbody ></ table > 1444</ div > 1445< p >< a id ="incompatible_flag "></ a ></ p > 1446< h2 id ="incompatible_flag ">< a class ="header "href ="#incompatible_flag "> incompatible_flag</ a ></ h2 > 1447< pre > 1448incompatible_flag(< a href ="flatten.html#incompatible_flag-name "> name</ a > ,< a href ="flatten.html#incompatible_flag-issue "> issue</ a > ) 1449</ pre > 1450< p > A rule defining an incompatible flag.</ p > 1451< p >< strong > ATTRIBUTES</ strong ></ p > 1452< 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 > 1453< tr >< td style ="text-align: left ">< a id ="incompatible_flag-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 > 1454< tr >< td style ="text-align: left ">< a id ="incompatible_flag-issue "></ a > issue</ td >< td style ="text-align: left "> The link to the github issue associated with this flag</ td >< td style ="text-align: left "> String</ td >< td style ="text-align: left "> required</ td >< td style ="text-align: left "></ td ></ tr > 1455</ tbody ></ table > 1456</ div > 1457< p >< a id ="rust_analyzer_toolchain "></ a ></ p > 1458< h2 id ="rust_analyzer_toolchain-1 ">< a class ="header "href ="#rust_analyzer_toolchain-1 "> rust_analyzer_toolchain</ a ></ h2 > 1459< pre > 1460rust_analyzer_toolchain(< a href ="flatten.html#rust_analyzer_toolchain-name "> name</ a > ,< a href ="flatten.html#rust_analyzer_toolchain-proc_macro_srv "> proc_macro_srv</ a > ,< a href ="flatten.html#rust_analyzer_toolchain-rustc "> rustc</ a > ,< a href ="flatten.html#rust_analyzer_toolchain-rustc_srcs "> rustc_srcs</ a > ) 1461</ pre > 1462< p > A toolchain for< a href ="https://rust-analyzer.github.io/ "> rust-analyzer</ a > .</ p > 1463< p >< strong > ATTRIBUTES</ strong ></ p > 1464< 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 > 1465< 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 > 1466< 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 > 1467< 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 > 1468< 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 > 1469</ tbody ></ table > 1470</ div > 1471< p >< a id ="rust_binary "></ a ></ p > 1472< h2 id ="rust_binary-1 ">< a class ="header "href ="#rust_binary-1 "> rust_binary</ a ></ h2 > 1473< pre > 1474rust_binary(< a href ="flatten.html#rust_binary-name "> name</ a > ,< a href ="flatten.html#rust_binary-deps "> deps</ a > ,< a href ="flatten.html#rust_binary-srcs "> srcs</ a > ,< a href ="flatten.html#rust_binary-data "> data</ a > ,< a href ="flatten.html#rust_binary-aliases "> aliases</ a > ,< a href ="flatten.html#rust_binary-alwayslink "> alwayslink</ a > ,< a href ="flatten.html#rust_binary-binary_name "> binary_name</ a > ,< a href ="flatten.html#rust_binary-compile_data "> compile_data</ a > ,< a href ="flatten.html#rust_binary-crate_features "> crate_features</ a > , 1475< a href ="flatten.html#rust_binary-crate_name "> crate_name</ a > ,< a href ="flatten.html#rust_binary-crate_root "> crate_root</ a > ,< a href ="flatten.html#rust_binary-crate_type "> crate_type</ a > ,< a href ="flatten.html#rust_binary-edition "> edition</ a > ,< a href ="flatten.html#rust_binary-env "> env</ a > ,< a href ="flatten.html#rust_binary-experimental_use_cc_common_link "> experimental_use_cc_common_link</ a > , 1476< a href ="flatten.html#rust_binary-linker_script "> linker_script</ a > ,< a href ="flatten.html#rust_binary-malloc "> malloc</ a > ,< a href ="flatten.html#rust_binary-out_binary "> out_binary</ a > ,< a href ="flatten.html#rust_binary-platform "> platform</ a > ,< a href ="flatten.html#rust_binary-proc_macro_deps "> proc_macro_deps</ a > ,< a href ="flatten.html#rust_binary-rustc_env "> rustc_env</ a > ,< a href ="flatten.html#rust_binary-rustc_env_files "> rustc_env_files</ a > , 1477< a href ="flatten.html#rust_binary-rustc_flags "> rustc_flags</ a > ,< a href ="flatten.html#rust_binary-stamp "> stamp</ a > ,< a href ="flatten.html#rust_binary-version "> version</ a > ) 1478</ pre > 1479< p > Builds a Rust binary crate.</ p > 1480< p > Example:</ p > 1481< p > Suppose you have the following directory structure for a Rust project with a 1482library crate,< code > hello_lib</ code > , and a binary crate,< code > hello_world</ code > that uses the 1483< code > hello_lib</ code > library:</ p > 1484< pre >< code class ="language-output "> [workspace]/ 1485 WORKSPACE 1486 hello_lib/ 1487 BUILD 1488 src/ 1489 lib.rs 1490 hello_world/ 1491 BUILD 1492 src/ 1493 main.rs 1494</ code ></ pre > 1495< p >< code > hello_lib/src/lib.rs</ code > :</ p > 1496< pre >< pre class ="playground ">< code class ="language-rust ">< span class ="boring "> #![allow(unused)] 1497</ span >< span class ="boring "> fn main() { 1498</ span > pub struct Greeter { 1499 greeting: String, 1500} 1501 1502impl Greeter { 1503 pub fn new(greeting: &str) -> Greeter { 1504 Greeter { greeting: greeting.to_string(), } 1505 } 1506 1507 pub fn greet(&self, thing: &str) { 1508 println!("{} {}", &self.greeting, thing); 1509 } 1510} 1511< span class ="boring "> }</ span ></ code ></ pre ></ pre > 1512< p >< code > hello_lib/BUILD</ code > :</ p > 1513< pre >< code class ="language-python "> package(default_visibility = ["//visibility:public"]) 1514 1515load("@rules_rust//rust:defs.bzl", "rust_library") 1516 1517rust_library( 1518 name = "hello_lib", 1519 srcs = ["src/lib.rs"], 1520) 1521</ code ></ pre > 1522< p >< code > hello_world/src/main.rs</ code > :</ p > 1523< pre >< pre class ="playground ">< code class ="language-rust "> extern crate hello_lib; 1524 1525fn main() { 1526 let hello = hello_lib::Greeter::new("Hello"); 1527 hello.greet("world"); 1528}</ code ></ pre ></ pre > 1529< p >< code > hello_world/BUILD</ code > :</ p > 1530< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_binary") 1531 1532rust_binary( 1533 name = "hello_world", 1534 srcs = ["src/main.rs"], 1535 deps = ["//hello_lib"], 1536) 1537</ code ></ pre > 1538< p > Build and run< code > hello_world</ code > :</ p > 1539< pre >< code > $ bazel run //hello_world 1540INFO: Found 1 target... 1541Target //examples/rust/hello_world:hello_world up-to-date: 1542bazel-bin/examples/rust/hello_world/hello_world 1543INFO: Elapsed time: 1.308s, Critical Path: 1.22s 1544 1545INFO: Running command line: bazel-bin/examples/rust/hello_world/hello_world 1546Hello world 1547</ code ></ pre > 1548< p > On Windows, a PDB file containing debugging information is available under 1549the key< code > pdb_file</ code > in< code > OutputGroupInfo</ code > . Similarly on macOS, a dSYM folder 1550is available under the key< code > dsym_folder</ code > in< code > OutputGroupInfo</ code > .</ p > 1551< p >< strong > ATTRIBUTES</ strong ></ p > 1552< 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 > 1553< 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 > 1554< 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 > 1555< 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 > 1556< 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 > 1557< 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 > 1558< 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 > 1559< 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 > 1560< 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 > 1561< 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 > 1562< 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 > 1563< 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 > 1564< 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 > 1565< 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 > 1566< 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 > 1567< 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 > 1568< 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 > 1569< 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 > 1570< 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 > 1571< 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 > 1572< 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 > 1573< 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 > 1574< 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 > 1575< 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 > 1576< 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 > 1577< 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 > 1578</ tbody ></ table > 1579</ div > 1580< p >< a id ="rust_clippy "></ a ></ p > 1581< h2 id ="rust_clippy-1 ">< a class ="header "href ="#rust_clippy-1 "> rust_clippy</ a ></ h2 > 1582< pre > 1583rust_clippy(< a href ="flatten.html#rust_clippy-name "> name</ a > ,< a href ="flatten.html#rust_clippy-deps "> deps</ a > ) 1584</ pre > 1585< p > Executes the clippy checker on a specific target.</ p > 1586< p > Similar to< code > rust_clippy_aspect</ code > , but allows specifying a list of dependencies within the build system.</ p > 1587< p > For example, given the following example targets:</ p > 1588< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 1589 1590rust_library( 1591 name = "hello_lib", 1592 srcs = ["src/lib.rs"], 1593) 1594 1595rust_test( 1596 name = "greeting_test", 1597 srcs = ["tests/greeting.rs"], 1598 deps = [":hello_lib"], 1599) 1600</ code ></ pre > 1601< p > Rust clippy can be set as a build target with the following:</ p > 1602< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_clippy") 1603 1604rust_clippy( 1605 name = "hello_library_clippy", 1606 testonly = True, 1607 deps = [ 1608 ":hello_lib", 1609 ":greeting_test", 1610 ], 1611) 1612</ code ></ pre > 1613< p >< strong > ATTRIBUTES</ strong ></ p > 1614< 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 > 1615< 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 > 1616< 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 > 1617</ tbody ></ table > 1618</ div > 1619< p >< a id ="rust_doc "></ a ></ p > 1620< h2 id ="rust_doc-1 ">< a class ="header "href ="#rust_doc-1 "> rust_doc</ a ></ h2 > 1621< pre > 1622rust_doc(< a href ="flatten.html#rust_doc-name "> name</ a > ,< a href ="flatten.html#rust_doc-crate "> crate</ a > ,< a href ="flatten.html#rust_doc-html_after_content "> html_after_content</ a > ,< a href ="flatten.html#rust_doc-html_before_content "> html_before_content</ a > ,< a href ="flatten.html#rust_doc-html_in_header "> html_in_header</ a > ,< a href ="flatten.html#rust_doc-markdown_css "> markdown_css</ a > , 1623< a href ="flatten.html#rust_doc-rustc_flags "> rustc_flags</ a > ,< a href ="flatten.html#rust_doc-rustdoc_flags "> rustdoc_flags</ a > ) 1624</ pre > 1625< p > Generates code documentation.</ p > 1626< p > Example: 1627Suppose you have the following directory structure for a Rust library crate:</ p > 1628< pre >< code > [workspace]/ 1629 WORKSPACE 1630 hello_lib/ 1631 BUILD 1632 src/ 1633 lib.rs 1634</ code ></ pre > 1635< 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 > 1636< pre >< code class ="language-python "> package(default_visibility = ["//visibility:public"]) 1637 1638load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc") 1639 1640rust_library( 1641 name = "hello_lib", 1642 srcs = ["src/lib.rs"], 1643) 1644 1645rust_doc( 1646 name = "hello_lib_doc", 1647 crate = ":hello_lib", 1648) 1649</ code ></ pre > 1650< 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 > 1651< p >< strong > ATTRIBUTES</ strong ></ p > 1652< 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 > 1653< 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 > 1654< 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 > 1655< 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 > 1656< 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 > 1657< 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 > 1658< 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 > 1659< 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 > 1660< 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 > 1661</ tbody ></ table > 1662</ div > 1663< p >< a id ="rust_doc_test "></ a ></ p > 1664< h2 id ="rust_doc_test-1 ">< a class ="header "href ="#rust_doc_test-1 "> rust_doc_test</ a ></ h2 > 1665< pre > 1666rust_doc_test(< a href ="flatten.html#rust_doc_test-name "> name</ a > ,< a href ="flatten.html#rust_doc_test-deps "> deps</ a > ,< a href ="flatten.html#rust_doc_test-crate "> crate</ a > ,< a href ="flatten.html#rust_doc_test-proc_macro_deps "> proc_macro_deps</ a > ) 1667</ pre > 1668< p > Runs Rust documentation tests.</ p > 1669< p > Example:</ p > 1670< p > Suppose you have the following directory structure for a Rust library crate:</ p > 1671< pre >< code class ="language-output "> [workspace]/ 1672WORKSPACE 1673hello_lib/ 1674 BUILD 1675 src/ 1676 lib.rs 1677</ code ></ pre > 1678< 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 > 1679< pre >< code class ="language-python "> package(default_visibility = ["//visibility:public"]) 1680 1681load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc_test") 1682 1683rust_library( 1684 name = "hello_lib", 1685 srcs = ["src/lib.rs"], 1686) 1687 1688rust_doc_test( 1689 name = "hello_lib_doc_test", 1690 crate = ":hello_lib", 1691) 1692</ code ></ pre > 1693< 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 > 1694< p >< strong > ATTRIBUTES</ strong ></ p > 1695< 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 > 1696< 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 > 1697< 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 > 1698< 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 > 1699< 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 > 1700</ tbody ></ table > 1701</ div > 1702< p >< a id ="rust_library "></ a ></ p > 1703< h2 id ="rust_library-1 ">< a class ="header "href ="#rust_library-1 "> rust_library</ a ></ h2 > 1704< pre > 1705rust_library(< a href ="flatten.html#rust_library-name "> name</ a > ,< a href ="flatten.html#rust_library-deps "> deps</ a > ,< a href ="flatten.html#rust_library-srcs "> srcs</ a > ,< a href ="flatten.html#rust_library-data "> data</ a > ,< a href ="flatten.html#rust_library-aliases "> aliases</ a > ,< a href ="flatten.html#rust_library-alwayslink "> alwayslink</ a > ,< a href ="flatten.html#rust_library-compile_data "> compile_data</ a > ,< a href ="flatten.html#rust_library-crate_features "> crate_features</ a > ,< a href ="flatten.html#rust_library-crate_name "> crate_name</ a > , 1706< a href ="flatten.html#rust_library-crate_root "> crate_root</ a > ,< a href ="flatten.html#rust_library-disable_pipelining "> disable_pipelining</ a > ,< a href ="flatten.html#rust_library-edition "> edition</ a > ,< a href ="flatten.html#rust_library-proc_macro_deps "> proc_macro_deps</ a > ,< a href ="flatten.html#rust_library-rustc_env "> rustc_env</ a > ,< a href ="flatten.html#rust_library-rustc_env_files "> rustc_env_files</ a > , 1707< a href ="flatten.html#rust_library-rustc_flags "> rustc_flags</ a > ,< a href ="flatten.html#rust_library-stamp "> stamp</ a > ,< a href ="flatten.html#rust_library-version "> version</ a > ) 1708</ pre > 1709< p > Builds a Rust library crate.</ p > 1710< p > Example:</ p > 1711< p > Suppose you have the following directory structure for a simple Rust library crate:</ p > 1712< pre >< code class ="language-output "> [workspace]/ 1713 WORKSPACE 1714 hello_lib/ 1715 BUILD 1716 src/ 1717 greeter.rs 1718 lib.rs 1719</ code ></ pre > 1720< p >< code > hello_lib/src/greeter.rs</ code > :</ p > 1721< pre >< pre class ="playground ">< code class ="language-rust ">< span class ="boring "> #![allow(unused)] 1722</ span >< span class ="boring "> fn main() { 1723</ span > pub struct Greeter { 1724 greeting: String, 1725} 1726 1727impl Greeter { 1728 pub fn new(greeting: &str) -> Greeter { 1729 Greeter { greeting: greeting.to_string(), } 1730 } 1731 1732 pub fn greet(&self, thing: &str) { 1733 println!("{} {}", &self.greeting, thing); 1734 } 1735} 1736< span class ="boring "> }</ span ></ code ></ pre ></ pre > 1737< p >< code > hello_lib/src/lib.rs</ code > :</ p > 1738< pre >< pre class ="playground ">< code class ="language-rust ">< span class ="boring "> #![allow(unused)] 1739</ span >< span class ="boring "> fn main() { 1740</ span > pub mod greeter; 1741< span class ="boring "> }</ span ></ code ></ pre ></ pre > 1742< p >< code > hello_lib/BUILD</ code > :</ p > 1743< pre >< code class ="language-python "> package(default_visibility = ["//visibility:public"]) 1744 1745load("@rules_rust//rust:defs.bzl", "rust_library") 1746 1747rust_library( 1748 name = "hello_lib", 1749 srcs = [ 1750 "src/greeter.rs", 1751 "src/lib.rs", 1752 ], 1753) 1754</ code ></ pre > 1755< p > Build the library:</ p > 1756< pre >< code class ="language-output "> $ bazel build //hello_lib 1757INFO: Found 1 target... 1758Target //examples/rust/hello_lib:hello_lib up-to-date: 1759bazel-bin/examples/rust/hello_lib/libhello_lib.rlib 1760INFO: Elapsed time: 1.245s, Critical Path: 1.01s 1761</ code ></ pre > 1762< p >< strong > ATTRIBUTES</ strong ></ p > 1763< 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 > 1764< 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 > 1765< 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 > 1766< 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 > 1767< 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 > 1768< 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 > 1769< 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 > 1770< 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 > 1771< 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 > 1772< 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 > 1773< 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 > 1774< 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 > 1775< 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 > 1776< 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 > 1777< 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 > 1778< 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 > 1779< 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 > 1780< 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 > 1781< 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 > 1782</ tbody ></ table > 1783</ div > 1784< p >< a id ="rust_library_group "></ a ></ p > 1785< h2 id ="rust_library_group-1 ">< a class ="header "href ="#rust_library_group-1 "> rust_library_group</ a ></ h2 > 1786< pre > 1787rust_library_group(< a href ="flatten.html#rust_library_group-name "> name</ a > ,< a href ="flatten.html#rust_library_group-deps "> deps</ a > ) 1788</ pre > 1789< p > Functions as an alias for a set of dependencies.</ p > 1790< p > Specifically, the following are equivalent:</ p > 1791< pre >< code class ="language-starlark "> rust_library_group( 1792 name = "crate_group", 1793 deps = [ 1794 ":crate1", 1795 ":crate2", 1796 ], 1797) 1798 1799rust_library( 1800 name = "foobar", 1801 deps = [":crate_group"], 1802 ... 1803) 1804</ code ></ pre > 1805< p > and</ p > 1806< pre >< code class ="language-starlark "> rust_library( 1807 name = "foobar", 1808 deps = [ 1809 ":crate1", 1810 ":crate2", 1811 ], 1812 ... 1813) 1814</ code ></ pre > 1815< p >< strong > ATTRIBUTES</ strong ></ p > 1816< 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 > 1817< 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 > 1818< 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 > 1819</ tbody ></ table > 1820</ div > 1821< p >< a id ="rust_proc_macro "></ a ></ p > 1822< h2 id ="rust_proc_macro-1 ">< a class ="header "href ="#rust_proc_macro-1 "> rust_proc_macro</ a ></ h2 > 1823< pre > 1824rust_proc_macro(< a href ="flatten.html#rust_proc_macro-name "> name</ a > ,< a href ="flatten.html#rust_proc_macro-deps "> deps</ a > ,< a href ="flatten.html#rust_proc_macro-srcs "> srcs</ a > ,< a href ="flatten.html#rust_proc_macro-data "> data</ a > ,< a href ="flatten.html#rust_proc_macro-aliases "> aliases</ a > ,< a href ="flatten.html#rust_proc_macro-alwayslink "> alwayslink</ a > ,< a href ="flatten.html#rust_proc_macro-compile_data "> compile_data</ a > ,< a href ="flatten.html#rust_proc_macro-crate_features "> crate_features</ a > , 1825< a href ="flatten.html#rust_proc_macro-crate_name "> crate_name</ a > ,< a href ="flatten.html#rust_proc_macro-crate_root "> crate_root</ a > ,< a href ="flatten.html#rust_proc_macro-edition "> edition</ a > ,< a href ="flatten.html#rust_proc_macro-proc_macro_deps "> proc_macro_deps</ a > ,< a href ="flatten.html#rust_proc_macro-rustc_env "> rustc_env</ a > ,< a href ="flatten.html#rust_proc_macro-rustc_env_files "> rustc_env_files</ a > , 1826< a href ="flatten.html#rust_proc_macro-rustc_flags "> rustc_flags</ a > ,< a href ="flatten.html#rust_proc_macro-stamp "> stamp</ a > ,< a href ="flatten.html#rust_proc_macro-version "> version</ a > ) 1827</ pre > 1828< p > Builds a Rust proc-macro crate.</ p > 1829< p >< strong > ATTRIBUTES</ strong ></ p > 1830< 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 > 1831< 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 > 1832< 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 > 1833< 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 > 1834< 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 > 1835< 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 > 1836< 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 > 1837< 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 > 1838< 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 > 1839< 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 > 1840< 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 > 1841< 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 > 1842< 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 > 1843< 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 > 1844< 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 > 1845< 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 > 1846< 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 > 1847< 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 > 1848</ tbody ></ table > 1849</ div > 1850< p >< a id ="rust_shared_library "></ a ></ p > 1851< h2 id ="rust_shared_library-1 ">< a class ="header "href ="#rust_shared_library-1 "> rust_shared_library</ a ></ h2 > 1852< pre > 1853rust_shared_library(< a href ="flatten.html#rust_shared_library-name "> name</ a > ,< a href ="flatten.html#rust_shared_library-deps "> deps</ a > ,< a href ="flatten.html#rust_shared_library-srcs "> srcs</ a > ,< a href ="flatten.html#rust_shared_library-data "> data</ a > ,< a href ="flatten.html#rust_shared_library-aliases "> aliases</ a > ,< a href ="flatten.html#rust_shared_library-alwayslink "> alwayslink</ a > ,< a href ="flatten.html#rust_shared_library-compile_data "> compile_data</ a > ,< a href ="flatten.html#rust_shared_library-crate_features "> crate_features</ a > , 1854< a href ="flatten.html#rust_shared_library-crate_name "> crate_name</ a > ,< a href ="flatten.html#rust_shared_library-crate_root "> crate_root</ a > ,< a href ="flatten.html#rust_shared_library-edition "> edition</ a > ,< a href ="flatten.html#rust_shared_library-experimental_use_cc_common_link "> experimental_use_cc_common_link</ a > ,< a href ="flatten.html#rust_shared_library-malloc "> malloc</ a > , 1855< a href ="flatten.html#rust_shared_library-platform "> platform</ a > ,< a href ="flatten.html#rust_shared_library-proc_macro_deps "> proc_macro_deps</ a > ,< a href ="flatten.html#rust_shared_library-rustc_env "> rustc_env</ a > ,< a href ="flatten.html#rust_shared_library-rustc_env_files "> rustc_env_files</ a > ,< a href ="flatten.html#rust_shared_library-rustc_flags "> rustc_flags</ a > ,< a href ="flatten.html#rust_shared_library-stamp "> stamp</ a > , 1856< a href ="flatten.html#rust_shared_library-version "> version</ a > ) 1857</ pre > 1858< p > Builds a Rust shared library.</ p > 1859< p > This shared library will contain all transitively reachable crates and native objects. 1860It is meant to be used when producing an artifact that is then consumed by some other build system 1861(for example to produce a shared library that Python program links against).</ p > 1862< p > This rule provides CcInfo, so it can be used everywhere Bazel expects< code > rules_cc</ code > .</ p > 1863< p > When building the whole binary in Bazel, use< code > rust_library</ code > instead.</ p > 1864< p >< strong > ATTRIBUTES</ strong ></ p > 1865< 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 > 1866< 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 > 1867< 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 > 1868< 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 > 1869< 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 > 1870< 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 > 1871< 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 > 1872< 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 > 1873< 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 > 1874< 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 > 1875< 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 > 1876< 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 > 1877< 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 > 1878< 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 > 1879< 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 > 1880< 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 > 1881< 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 > 1882< 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 > 1883< 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 > 1884< 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 > 1885< 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 > 1886</ tbody ></ table > 1887</ div > 1888< p >< a id ="rust_static_library "></ a ></ p > 1889< h2 id ="rust_static_library-1 ">< a class ="header "href ="#rust_static_library-1 "> rust_static_library</ a ></ h2 > 1890< pre > 1891rust_static_library(< a href ="flatten.html#rust_static_library-name "> name</ a > ,< a href ="flatten.html#rust_static_library-deps "> deps</ a > ,< a href ="flatten.html#rust_static_library-srcs "> srcs</ a > ,< a href ="flatten.html#rust_static_library-data "> data</ a > ,< a href ="flatten.html#rust_static_library-aliases "> aliases</ a > ,< a href ="flatten.html#rust_static_library-alwayslink "> alwayslink</ a > ,< a href ="flatten.html#rust_static_library-compile_data "> compile_data</ a > ,< a href ="flatten.html#rust_static_library-crate_features "> crate_features</ a > , 1892< a href ="flatten.html#rust_static_library-crate_name "> crate_name</ a > ,< a href ="flatten.html#rust_static_library-crate_root "> crate_root</ a > ,< a href ="flatten.html#rust_static_library-edition "> edition</ a > ,< a href ="flatten.html#rust_static_library-platform "> platform</ a > ,< a href ="flatten.html#rust_static_library-proc_macro_deps "> proc_macro_deps</ a > ,< a href ="flatten.html#rust_static_library-rustc_env "> rustc_env</ a > , 1893< a href ="flatten.html#rust_static_library-rustc_env_files "> rustc_env_files</ a > ,< a href ="flatten.html#rust_static_library-rustc_flags "> rustc_flags</ a > ,< a href ="flatten.html#rust_static_library-stamp "> stamp</ a > ,< a href ="flatten.html#rust_static_library-version "> version</ a > ) 1894</ pre > 1895< p > Builds a Rust static library.</ p > 1896< p > This static library will contain all transitively reachable crates and native objects. 1897It is meant to be used when producing an artifact that is then consumed by some other build system 1898(for example to produce an archive that Python program links against).</ p > 1899< p > This rule provides CcInfo, so it can be used everywhere Bazel expects< code > rules_cc</ code > .</ p > 1900< p > When building the whole binary in Bazel, use< code > rust_library</ code > instead.</ p > 1901< p >< strong > ATTRIBUTES</ strong ></ p > 1902< 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 > 1903< 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 > 1904< 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 > 1905< 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 > 1906< 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 > 1907< 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 > 1908< 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 > 1909< 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 > 1910< 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 > 1911< 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 > 1912< 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 > 1913< 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 > 1914< 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 > 1915< 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 > 1916< 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 > 1917< 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 > 1918< 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 > 1919< 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 > 1920< 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 > 1921</ tbody ></ table > 1922</ div > 1923< p >< a id ="rust_stdlib_filegroup "></ a ></ p > 1924< h2 id ="rust_stdlib_filegroup ">< a class ="header "href ="#rust_stdlib_filegroup "> rust_stdlib_filegroup</ a ></ h2 > 1925< pre > 1926rust_stdlib_filegroup(< a href ="flatten.html#rust_stdlib_filegroup-name "> name</ a > ,< a href ="flatten.html#rust_stdlib_filegroup-srcs "> srcs</ a > ) 1927</ pre > 1928< p > A dedicated filegroup-like rule for Rust stdlib artifacts.</ p > 1929< p >< strong > ATTRIBUTES</ strong ></ p > 1930< 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 > 1931< tr >< td style ="text-align: left ">< a id ="rust_stdlib_filegroup-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 > 1932< tr >< td style ="text-align: left ">< a id ="rust_stdlib_filegroup-srcs "></ a > srcs</ td >< td style ="text-align: left "> The list of targets/files that are components of the rust-stdlib file group</ 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 > 1933</ tbody ></ table > 1934</ div > 1935< p >< a id ="rust_test "></ a ></ p > 1936< h2 id ="rust_test-1 ">< a class ="header "href ="#rust_test-1 "> rust_test</ a ></ h2 > 1937< pre > 1938rust_test(< a href ="flatten.html#rust_test-name "> name</ a > ,< a href ="flatten.html#rust_test-deps "> deps</ a > ,< a href ="flatten.html#rust_test-srcs "> srcs</ a > ,< a href ="flatten.html#rust_test-data "> data</ a > ,< a href ="flatten.html#rust_test-aliases "> aliases</ a > ,< a href ="flatten.html#rust_test-alwayslink "> alwayslink</ a > ,< a href ="flatten.html#rust_test-compile_data "> compile_data</ a > ,< a href ="flatten.html#rust_test-crate "> crate</ a > ,< a href ="flatten.html#rust_test-crate_features "> crate_features</ a > , 1939< a href ="flatten.html#rust_test-crate_name "> crate_name</ a > ,< a href ="flatten.html#rust_test-crate_root "> crate_root</ a > ,< a href ="flatten.html#rust_test-edition "> edition</ a > ,< a href ="flatten.html#rust_test-env "> env</ a > ,< a href ="flatten.html#rust_test-env_inherit "> env_inherit</ a > ,< a href ="flatten.html#rust_test-experimental_use_cc_common_link "> experimental_use_cc_common_link</ a > ,< a href ="flatten.html#rust_test-malloc "> malloc</ a > , 1940< a href ="flatten.html#rust_test-platform "> platform</ a > ,< a href ="flatten.html#rust_test-proc_macro_deps "> proc_macro_deps</ a > ,< a href ="flatten.html#rust_test-rustc_env "> rustc_env</ a > ,< a href ="flatten.html#rust_test-rustc_env_files "> rustc_env_files</ a > ,< a href ="flatten.html#rust_test-rustc_flags "> rustc_flags</ a > ,< a href ="flatten.html#rust_test-stamp "> stamp</ a > , 1941< a href ="flatten.html#rust_test-use_libtest_harness "> use_libtest_harness</ a > ,< a href ="flatten.html#rust_test-version "> version</ a > ) 1942</ pre > 1943< p > Builds a Rust test crate.</ p > 1944< p > Examples:</ p > 1945< p > Suppose you have the following directory structure for a Rust library crate with unit test code in the library sources:</ p > 1946< pre >< code class ="language-output "> [workspace]/ 1947 WORKSPACE 1948 hello_lib/ 1949 BUILD 1950 src/ 1951 lib.rs 1952</ code ></ pre > 1953< p >< code > hello_lib/src/lib.rs</ code > :</ p > 1954< pre >< pre class ="playground ">< code class ="language-rust ">< span class ="boring "> #![allow(unused)] 1955</ span >< span class ="boring "> fn main() { 1956</ span > pub struct Greeter { 1957 greeting: String, 1958} 1959 1960impl Greeter { 1961 pub fn new(greeting: &str) -> Greeter { 1962 Greeter { greeting: greeting.to_string(), } 1963 } 1964 1965 pub fn greet(&self, thing: &str) -> String { 1966 format!("{} {}", &self.greeting, thing) 1967 } 1968} 1969 1970#[cfg(test)] 1971mod test { 1972 use super::Greeter; 1973 1974 #[test] 1975 fn test_greeting() { 1976 let hello = Greeter::new("Hi"); 1977 assert_eq!("Hi Rust", hello.greet("Rust")); 1978 } 1979} 1980< span class ="boring "> }</ span ></ code ></ pre ></ pre > 1981< p > To build and run the tests, simply add a< code > rust_test</ code > rule with no< code > srcs</ code > 1982and only depends on the< code > hello_lib</ code > < code > rust_library</ code > target via the 1983< code > crate</ code > attribute:</ p > 1984< p >< code > hello_lib/BUILD</ code > :</ p > 1985< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 1986 1987rust_library( 1988 name = "hello_lib", 1989 srcs = ["src/lib.rs"], 1990) 1991 1992rust_test( 1993 name = "hello_lib_test", 1994 crate = ":hello_lib", 1995 # You may add other deps that are specific to the test configuration 1996 deps = ["//some/dev/dep"], 1997) 1998</ code ></ pre > 1999< p > Run the test with< code > bazel test //hello_lib:hello_lib_test</ code > .</ p > 2000< h3 id ="example-test-directory-1 ">< a class ="header "href ="#example-test-directory-1 "> Example:< code > test</ code > directory</ a ></ h3 > 2001< 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 > 2002< pre >< code class ="language-output "> [workspace]/ 2003 WORKSPACE 2004 hello_lib/ 2005 BUILD 2006 src/ 2007 lib.rs 2008 tests/ 2009 greeting.rs 2010</ code ></ pre > 2011< p >< code > hello_lib/tests/greeting.rs</ code > :</ p > 2012< pre >< pre class ="playground ">< code class ="language-rust ">< span class ="boring "> #![allow(unused)] 2013</ span >< span class ="boring "> fn main() { 2014</ span > extern crate hello_lib; 2015 2016use hello_lib; 2017 2018#[test] 2019fn test_greeting() { 2020 let hello = greeter::Greeter::new("Hello"); 2021 assert_eq!("Hello world", hello.greeting("world")); 2022} 2023< span class ="boring "> }</ span ></ code ></ pre ></ pre > 2024< p > To build the< code > greeting.rs</ code > integration test, simply add a< code > rust_test</ code > target 2025with< code > greeting.rs</ code > in< code > srcs</ code > and a dependency on the< code > hello_lib</ code > target:</ p > 2026< p >< code > hello_lib/BUILD</ code > :</ p > 2027< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 2028 2029rust_library( 2030 name = "hello_lib", 2031 srcs = ["src/lib.rs"], 2032) 2033 2034rust_test( 2035 name = "greeting_test", 2036 srcs = ["tests/greeting.rs"], 2037 deps = [":hello_lib"], 2038) 2039</ code ></ pre > 2040< p > Run the test with< code > bazel test //hello_lib:greeting_test</ code > .</ p > 2041< p >< strong > ATTRIBUTES</ strong ></ p > 2042< 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 > 2043< 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 > 2044< 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 > 2045< 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 > 2046< 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 > 2047< 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 > 2048< 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 > 2049< 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 > 2050< 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 > 2051< 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 > 2052< 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 > 2053< 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 > 2054< 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 > 2055< 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 > 2056< 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 > 2057< 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 > 2058< 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 > 2059< 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 > 2060< 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 > 2061< 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 > 2062< 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 > 2063< 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 > 2064< 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 > 2065< 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 > 2066< 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 > 2067</ tbody ></ table > 2068</ div > 2069< p >< a id ="rust_toolchain "></ a ></ p > 2070< h2 id ="rust_toolchain ">< a class ="header "href ="#rust_toolchain "> rust_toolchain</ a ></ h2 > 2071< pre > 2072rust_toolchain(< a href ="flatten.html#rust_toolchain-name "> name</ a > ,< a href ="flatten.html#rust_toolchain-allocator_library "> allocator_library</ a > ,< a href ="flatten.html#rust_toolchain-binary_ext "> binary_ext</ a > ,< a href ="flatten.html#rust_toolchain-cargo "> cargo</ a > ,< a href ="flatten.html#rust_toolchain-cargo_clippy "> cargo_clippy</ a > ,< a href ="flatten.html#rust_toolchain-clippy_driver "> clippy_driver</ a > ,< a href ="flatten.html#rust_toolchain-debug_info "> debug_info</ a > , 2073< a href ="flatten.html#rust_toolchain-default_edition "> default_edition</ a > ,< a href ="flatten.html#rust_toolchain-dylib_ext "> dylib_ext</ a > ,< a href ="flatten.html#rust_toolchain-env "> env</ a > ,< a href ="flatten.html#rust_toolchain-exec_triple "> exec_triple</ a > ,< a href ="flatten.html#rust_toolchain-experimental_link_std_dylib "> experimental_link_std_dylib</ a > , 2074< a href ="flatten.html#rust_toolchain-experimental_use_cc_common_link "> experimental_use_cc_common_link</ a > ,< a href ="flatten.html#rust_toolchain-extra_exec_rustc_flags "> extra_exec_rustc_flags</ a > ,< a href ="flatten.html#rust_toolchain-extra_rustc_flags "> extra_rustc_flags</ a > , 2075< a href ="flatten.html#rust_toolchain-extra_rustc_flags_for_crate_types "> extra_rustc_flags_for_crate_types</ a > ,< a href ="flatten.html#rust_toolchain-global_allocator_library "> global_allocator_library</ a > ,< a href ="flatten.html#rust_toolchain-llvm_cov "> llvm_cov</ a > ,< a href ="flatten.html#rust_toolchain-llvm_profdata "> llvm_profdata</ a > , 2076< a href ="flatten.html#rust_toolchain-llvm_tools "> llvm_tools</ a > ,< a href ="flatten.html#rust_toolchain-opt_level "> opt_level</ a > ,< a href ="flatten.html#rust_toolchain-per_crate_rustc_flags "> per_crate_rustc_flags</ a > ,< a href ="flatten.html#rust_toolchain-rust_doc "> rust_doc</ a > ,< a href ="flatten.html#rust_toolchain-rust_std "> rust_std</ a > ,< a href ="flatten.html#rust_toolchain-rustc "> rustc</ a > ,< a href ="flatten.html#rust_toolchain-rustc_lib "> rustc_lib</ a > , 2077< a href ="flatten.html#rust_toolchain-rustfmt "> rustfmt</ a > ,< a href ="flatten.html#rust_toolchain-staticlib_ext "> staticlib_ext</ a > ,< a href ="flatten.html#rust_toolchain-stdlib_linkflags "> stdlib_linkflags</ a > ,< a href ="flatten.html#rust_toolchain-strip_level "> strip_level</ a > ,< a href ="flatten.html#rust_toolchain-target_json "> target_json</ a > ,< a href ="flatten.html#rust_toolchain-target_triple "> target_triple</ a > ) 2078</ pre > 2079< p > Declares a Rust toolchain for use.</ p > 2080< p > This is for declaring a custom toolchain, eg. for configuring a particular version of rust or supporting a new platform.</ p > 2081< p > Example:</ p > 2082< 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 > 2083< pre >< code class ="language-python "> load('@rules_rust//rust:toolchain.bzl', 'rust_toolchain') 2084 2085rust_toolchain( 2086 name = "rust_cpuX_impl", 2087 binary_ext = "", 2088 dylib_ext = ".so", 2089 exec_triple = "cpuX-unknown-linux-gnu", 2090 rust_doc = "@rust_cpuX//:rustdoc", 2091 rust_std = "@rust_cpuX//:rust_std", 2092 rustc = "@rust_cpuX//:rustc", 2093 rustc_lib = "@rust_cpuX//:rustc_lib", 2094 staticlib_ext = ".a", 2095 stdlib_linkflags = ["-lpthread", "-ldl"], 2096 target_triple = "cpuX-unknown-linux-gnu", 2097) 2098 2099toolchain( 2100 name = "rust_cpuX", 2101 exec_compatible_with = [ 2102 "@platforms//cpu:cpuX", 2103 "@platforms//os:linux", 2104 ], 2105 target_compatible_with = [ 2106 "@platforms//cpu:cpuX", 2107 "@platforms//os:linux", 2108 ], 2109 toolchain = ":rust_cpuX_impl", 2110) 2111</ code ></ pre > 2112< 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 > 2113< 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 > 2114< p >< strong > ATTRIBUTES</ strong ></ p > 2115< 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 > 2116< 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 > 2117< 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 > 2118< 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 > 2119< 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 > 2120< 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 > 2121< 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 > 2122< 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 > 2123< 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 > 2124< 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 > 2125< 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 > 2126< 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 > 2127< 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 > 2128< 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 > 2129< 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 > 2130< 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 > 2131< 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 > 2132< 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 > 2133< 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 > 2134< 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 > 2135< 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 > 2136< 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 > 2137< 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 > 2138< 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 > 2139< 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 > 2140< 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 > 2141< 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 > 2142< 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 ="flatten.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 > 2143< 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 > 2144< 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 > 2145< 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 > 2146< 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 > 2147< 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 > 2148</ tbody ></ table > 2149</ div > 2150< p >< a id ="rustfmt_test "></ a ></ p > 2151< h2 id ="rustfmt_test-1 ">< a class ="header "href ="#rustfmt_test-1 "> rustfmt_test</ a ></ h2 > 2152< pre > 2153rustfmt_test(< a href ="flatten.html#rustfmt_test-name "> name</ a > ,< a href ="flatten.html#rustfmt_test-targets "> targets</ a > ) 2154</ pre > 2155< p > A test rule for performing< code > rustfmt --check</ code > on a set of targets</ p > 2156< p >< strong > ATTRIBUTES</ strong ></ p > 2157< 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 > 2158< 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 > 2159< 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 > 2160</ tbody ></ table > 2161</ div > 2162< p >< a id ="rustfmt_toolchain "></ a ></ p > 2163< h2 id ="rustfmt_toolchain-1 ">< a class ="header "href ="#rustfmt_toolchain-1 "> rustfmt_toolchain</ a ></ h2 > 2164< pre > 2165rustfmt_toolchain(< a href ="flatten.html#rustfmt_toolchain-name "> name</ a > ,< a href ="flatten.html#rustfmt_toolchain-rustc "> rustc</ a > ,< a href ="flatten.html#rustfmt_toolchain-rustc_lib "> rustc_lib</ a > ,< a href ="flatten.html#rustfmt_toolchain-rustfmt "> rustfmt</ a > ) 2166</ pre > 2167< p > A toolchain for< a href ="https://rust-lang.github.io/rustfmt/ "> rustfmt</ a ></ p > 2168< p >< strong > ATTRIBUTES</ strong ></ p > 2169< 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 > 2170< 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 > 2171< 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 > 2172< 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 > 2173< 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 > 2174</ tbody ></ table > 2175</ div > 2176< p >< a id ="CrateInfo "></ a ></ p > 2177< h2 id ="crateinfo ">< a class ="header "href ="#crateinfo "> CrateInfo</ a ></ h2 > 2178< pre > 2179CrateInfo(< a href ="flatten.html#CrateInfo-aliases "> aliases</ a > ,< a href ="flatten.html#CrateInfo-compile_data "> compile_data</ a > ,< a href ="flatten.html#CrateInfo-compile_data_targets "> compile_data_targets</ a > ,< a href ="flatten.html#CrateInfo-data "> data</ a > ,< a href ="flatten.html#CrateInfo-deps "> deps</ a > ,< a href ="flatten.html#CrateInfo-edition "> edition</ a > ,< a href ="flatten.html#CrateInfo-is_test "> is_test</ a > ,< a href ="flatten.html#CrateInfo-metadata "> metadata</ a > ,< a href ="flatten.html#CrateInfo-name "> name</ a > , 2180< a href ="flatten.html#CrateInfo-output "> output</ a > ,< a href ="flatten.html#CrateInfo-owner "> owner</ a > ,< a href ="flatten.html#CrateInfo-proc_macro_deps "> proc_macro_deps</ a > ,< a href ="flatten.html#CrateInfo-root "> root</ a > ,< a href ="flatten.html#CrateInfo-rustc_env "> rustc_env</ a > ,< a href ="flatten.html#CrateInfo-rustc_env_files "> rustc_env_files</ a > ,< a href ="flatten.html#CrateInfo-rustc_output "> rustc_output</ a > , 2181< a href ="flatten.html#CrateInfo-rustc_rmeta_output "> rustc_rmeta_output</ a > ,< a href ="flatten.html#CrateInfo-srcs "> srcs</ a > ,< a href ="flatten.html#CrateInfo-std_dylib "> std_dylib</ a > ,< a href ="flatten.html#CrateInfo-type "> type</ a > ,< a href ="flatten.html#CrateInfo-wrapped_crate_type "> wrapped_crate_type</ a > ) 2182</ pre > 2183< p > A provider containing general Crate information.</ p > 2184< p >< strong > FIELDS</ strong ></ p > 2185< div class ="table-wrapper ">< table >< thead >< tr >< th style ="text-align: left "> Name</ th >< th style ="text-align: left "> Description</ th ></ tr ></ thead >< tbody > 2186< tr >< td style ="text-align: left ">< a id ="CrateInfo-aliases "></ a > aliases</ td >< td style ="text-align: left "> Dict[Label, String]: Renamed and aliased crates</ td ></ tr > 2187< tr >< td style ="text-align: left ">< a id ="CrateInfo-compile_data "></ a > compile_data</ td >< td style ="text-align: left "> depset[File]: Compile data required by this crate.</ td ></ tr > 2188< tr >< td style ="text-align: left ">< a id ="CrateInfo-compile_data_targets "></ a > compile_data_targets</ td >< td style ="text-align: left "> depset[Label]: Compile data targets required by this crate.</ td ></ tr > 2189< tr >< td style ="text-align: left ">< a id ="CrateInfo-data "></ a > data</ td >< td style ="text-align: left "> depset[File]: Compile data required by crates that use the current crate as a proc-macro.</ td ></ tr > 2190< tr >< td style ="text-align: left ">< a id ="CrateInfo-deps "></ a > deps</ td >< td style ="text-align: left "> depset[DepVariantInfo]: This crate's (rust or cc) dependencies' providers.</ td ></ tr > 2191< tr >< td style ="text-align: left ">< a id ="CrateInfo-edition "></ a > edition</ td >< td style ="text-align: left "> str: The edition of this crate.</ td ></ tr > 2192< tr >< td style ="text-align: left ">< a id ="CrateInfo-is_test "></ a > is_test</ td >< td style ="text-align: left "> bool: If the crate is being compiled in a test context</ td ></ tr > 2193< tr >< td style ="text-align: left ">< a id ="CrateInfo-metadata "></ a > metadata</ td >< td style ="text-align: left "> File: The output from rustc from producing the output file. It is optional.</ td ></ tr > 2194< tr >< td style ="text-align: left ">< a id ="CrateInfo-name "></ a > name</ td >< td style ="text-align: left "> str: The name of this crate.</ td ></ tr > 2195< tr >< td style ="text-align: left ">< a id ="CrateInfo-output "></ a > output</ td >< td style ="text-align: left "> File: The output File that will be produced, depends on crate type.</ td ></ tr > 2196< tr >< td style ="text-align: left ">< a id ="CrateInfo-owner "></ a > owner</ td >< td style ="text-align: left "> Label: The label of the target that produced this CrateInfo</ td ></ tr > 2197< tr >< td style ="text-align: left ">< a id ="CrateInfo-proc_macro_deps "></ a > proc_macro_deps</ td >< td style ="text-align: left "> depset[DepVariantInfo]: This crate's rust proc_macro dependencies' providers.</ td ></ tr > 2198< tr >< td style ="text-align: left ">< a id ="CrateInfo-root "></ a > root</ td >< td style ="text-align: left "> File: The source File entrypoint to this crate, eg. lib.rs</ td ></ tr > 2199< tr >< td style ="text-align: left ">< a id ="CrateInfo-rustc_env "></ a > rustc_env</ td >< td style ="text-align: left "> Dict[String, String]: Additional< code > "key": "value"</ code > environment variables to set for rustc.</ td ></ tr > 2200< tr >< td style ="text-align: left ">< a id ="CrateInfo-rustc_env_files "></ a > rustc_env_files</ td >< td style ="text-align: left "> [File]: Files containing additional environment variables to set for rustc.</ td ></ tr > 2201< tr >< td style ="text-align: left ">< a id ="CrateInfo-rustc_output "></ a > rustc_output</ td >< td style ="text-align: left "> File: The output from rustc from producing the output file. It is optional.</ td ></ tr > 2202< tr >< td style ="text-align: left ">< a id ="CrateInfo-rustc_rmeta_output "></ a > rustc_rmeta_output</ td >< td style ="text-align: left "> File: The rmeta file produced for this crate. It is optional.</ td ></ tr > 2203< tr >< td style ="text-align: left ">< a id ="CrateInfo-srcs "></ a > srcs</ td >< td style ="text-align: left "> depset[File]: All source Files that are part of the crate.</ td ></ tr > 2204< tr >< td style ="text-align: left ">< a id ="CrateInfo-std_dylib "></ a > std_dylib</ td >< td style ="text-align: left "> File: libstd.so file</ td ></ tr > 2205< tr >< td style ="text-align: left ">< a id ="CrateInfo-type "></ a > type</ td >< td style ="text-align: left "> str: The type of this crate (see< a href ="https://doc.rust-lang.org/rustc/command-line-arguments.html#--crate-type-a-list-of-types-of-crates-for-the-compiler-to-emit "> rustc --crate-type</ a > ).</ td ></ tr > 2206< tr >< td style ="text-align: left ">< a id ="CrateInfo-wrapped_crate_type "></ a > wrapped_crate_type</ td >< td style ="text-align: left "> str, optional: The original crate type for targets generated using a previously defined crate (typically tests using the< code > rust_test::crate</ code > attribute)</ td ></ tr > 2207</ tbody ></ table > 2208</ div > 2209< p >< a id ="DepInfo "></ a ></ p > 2210< h2 id ="depinfo ">< a class ="header "href ="#depinfo "> DepInfo</ a ></ h2 > 2211< pre > 2212DepInfo(< a href ="flatten.html#DepInfo-dep_env "> dep_env</ a > ,< a href ="flatten.html#DepInfo-direct_crates "> direct_crates</ a > ,< a href ="flatten.html#DepInfo-link_search_path_files "> link_search_path_files</ a > ,< a href ="flatten.html#DepInfo-transitive_build_infos "> transitive_build_infos</ a > , 2213< a href ="flatten.html#DepInfo-transitive_crate_outputs "> transitive_crate_outputs</ a > ,< a href ="flatten.html#DepInfo-transitive_crates "> transitive_crates</ a > ,< a href ="flatten.html#DepInfo-transitive_data "> transitive_data</ a > ,< a href ="flatten.html#DepInfo-transitive_metadata_outputs "> transitive_metadata_outputs</ a > , 2214< a href ="flatten.html#DepInfo-transitive_noncrates "> transitive_noncrates</ a > ,< a href ="flatten.html#DepInfo-transitive_proc_macro_data "> transitive_proc_macro_data</ a > ) 2215</ pre > 2216< p > A provider containing information about a Crate's dependencies.</ p > 2217< p >< strong > FIELDS</ strong ></ p > 2218< div class ="table-wrapper ">< table >< thead >< tr >< th style ="text-align: left "> Name</ th >< th style ="text-align: left "> Description</ th ></ tr ></ thead >< tbody > 2219< tr >< td style ="text-align: left ">< a id ="DepInfo-dep_env "></ a > dep_env</ td >< td style ="text-align: left "> File: File with environment variables direct dependencies build scripts rely upon.</ td ></ tr > 2220< tr >< td style ="text-align: left ">< a id ="DepInfo-direct_crates "></ a > direct_crates</ td >< td style ="text-align: left "> depset[AliasableDepInfo]</ td ></ tr > 2221< tr >< td style ="text-align: left ">< a id ="DepInfo-link_search_path_files "></ a > link_search_path_files</ td >< td style ="text-align: left "> depset[File]: All transitive files containing search paths to pass to the linker</ td ></ tr > 2222< tr >< td style ="text-align: left ">< a id ="DepInfo-transitive_build_infos "></ a > transitive_build_infos</ td >< td style ="text-align: left "> depset[BuildInfo]</ td ></ tr > 2223< tr >< td style ="text-align: left ">< a id ="DepInfo-transitive_crate_outputs "></ a > transitive_crate_outputs</ td >< td style ="text-align: left "> depset[File]: All transitive crate outputs.</ td ></ tr > 2224< tr >< td style ="text-align: left ">< a id ="DepInfo-transitive_crates "></ a > transitive_crates</ td >< td style ="text-align: left "> depset[CrateInfo]</ td ></ tr > 2225< tr >< td style ="text-align: left ">< a id ="DepInfo-transitive_data "></ a > transitive_data</ td >< td style ="text-align: left "> depset[File]: Data of all transitive non-macro dependencies.</ td ></ tr > 2226< tr >< td style ="text-align: left ">< a id ="DepInfo-transitive_metadata_outputs "></ a > transitive_metadata_outputs</ td >< td style ="text-align: left "> depset[File]: All transitive metadata dependencies (.rmeta, for crates that provide them) and all transitive object dependencies (.rlib) for crates that don't provide metadata.</ td ></ tr > 2227< tr >< td style ="text-align: left ">< a id ="DepInfo-transitive_noncrates "></ a > transitive_noncrates</ td >< td style ="text-align: left "> depset[LinkerInput]: All transitive dependencies that aren't crates.</ td ></ tr > 2228< tr >< td style ="text-align: left ">< a id ="DepInfo-transitive_proc_macro_data "></ a > transitive_proc_macro_data</ td >< td style ="text-align: left "> depset[File]: Data of all transitive proc-macro dependencies, and non-macro dependencies of those macros.</ td ></ tr > 2229</ tbody ></ table > 2230</ div > 2231< p >< a id ="StdLibInfo "></ a ></ p > 2232< h2 id ="stdlibinfo ">< a class ="header "href ="#stdlibinfo "> StdLibInfo</ a ></ h2 > 2233< pre > 2234StdLibInfo(< a href ="flatten.html#StdLibInfo-alloc_files "> alloc_files</ a > ,< a href ="flatten.html#StdLibInfo-between_alloc_and_core_files "> between_alloc_and_core_files</ a > ,< a href ="flatten.html#StdLibInfo-between_core_and_std_files "> between_core_and_std_files</ a > ,< a href ="flatten.html#StdLibInfo-core_files "> core_files</ a > , 2235< a href ="flatten.html#StdLibInfo-dot_a_files "> dot_a_files</ a > ,< a href ="flatten.html#StdLibInfo-memchr_files "> memchr_files</ a > ,< a href ="flatten.html#StdLibInfo-panic_files "> panic_files</ a > ,< a href ="flatten.html#StdLibInfo-self_contained_files "> self_contained_files</ a > ,< a href ="flatten.html#StdLibInfo-srcs "> srcs</ a > ,< a href ="flatten.html#StdLibInfo-std_dylib "> std_dylib</ a > ,< a href ="flatten.html#StdLibInfo-std_files "> std_files</ a > , 2236< a href ="flatten.html#StdLibInfo-std_rlibs "> std_rlibs</ a > ,< a href ="flatten.html#StdLibInfo-test_files "> test_files</ a > ) 2237</ pre > 2238< p > A collection of files either found within the< code > rust-stdlib</ code > artifact or generated based on existing files.</ p > 2239< p >< strong > FIELDS</ strong ></ p > 2240< div class ="table-wrapper ">< table >< thead >< tr >< th style ="text-align: left "> Name</ th >< th style ="text-align: left "> Description</ th ></ tr ></ thead >< tbody > 2241< tr >< td style ="text-align: left ">< a id ="StdLibInfo-alloc_files "></ a > alloc_files</ td >< td style ="text-align: left "> List[File]:< code > .a</ code > files related to the< code > alloc</ code > module.</ td ></ tr > 2242< tr >< td style ="text-align: left ">< a id ="StdLibInfo-between_alloc_and_core_files "></ a > between_alloc_and_core_files</ td >< td style ="text-align: left "> List[File]:< code > .a</ code > files related to the< code > compiler_builtins</ code > module.</ td ></ tr > 2243< tr >< td style ="text-align: left ">< a id ="StdLibInfo-between_core_and_std_files "></ a > between_core_and_std_files</ td >< td style ="text-align: left "> List[File]:< code > .a</ code > files related to all modules except< code > adler</ code > ,< code > alloc</ code > ,< code > compiler_builtins</ code > ,< code > core</ code > , and< code > std</ code > .</ td ></ tr > 2244< tr >< td style ="text-align: left ">< a id ="StdLibInfo-core_files "></ a > core_files</ td >< td style ="text-align: left "> List[File]:< code > .a</ code > files related to the< code > core</ code > and< code > adler</ code > modules</ td ></ tr > 2245< tr >< td style ="text-align: left ">< a id ="StdLibInfo-dot_a_files "></ a > dot_a_files</ td >< td style ="text-align: left "> Depset[File]: Generated< code > .a</ code > files</ td ></ tr > 2246< tr >< td style ="text-align: left ">< a id ="StdLibInfo-memchr_files "></ a > memchr_files</ td >< td style ="text-align: left "> Depset[File]:< code > .a</ code > files associated with the< code > memchr</ code > module.</ td ></ tr > 2247< tr >< td style ="text-align: left ">< a id ="StdLibInfo-panic_files "></ a > panic_files</ td >< td style ="text-align: left "> Depset[File]:< code > .a</ code > files associated with< code > panic_unwind</ code > and< code > panic_abort</ code > .</ td ></ tr > 2248< tr >< td style ="text-align: left ">< a id ="StdLibInfo-self_contained_files "></ a > self_contained_files</ td >< td style ="text-align: left "> List[File]: All< code > .o</ code > files from the< code > self-contained</ code > directory.</ td ></ tr > 2249< tr >< td style ="text-align: left ">< a id ="StdLibInfo-srcs "></ a > srcs</ td >< td style ="text-align: left "> List[Target]: All targets from the original< code > srcs</ code > attribute.</ td ></ tr > 2250< tr >< td style ="text-align: left ">< a id ="StdLibInfo-std_dylib "></ a > std_dylib</ td >< td style ="text-align: left "> File: libstd.so file</ td ></ tr > 2251< tr >< td style ="text-align: left ">< a id ="StdLibInfo-std_files "></ a > std_files</ td >< td style ="text-align: left "> Depset[File]:< code > .a</ code > files associated with the< code > std</ code > module.</ td ></ tr > 2252< tr >< td style ="text-align: left ">< a id ="StdLibInfo-std_rlibs "></ a > std_rlibs</ td >< td style ="text-align: left "> List[File]: All< code > .rlib</ code > files</ td ></ tr > 2253< tr >< td style ="text-align: left ">< a id ="StdLibInfo-test_files "></ a > test_files</ td >< td style ="text-align: left "> Depset[File]:< code > .a</ code > files associated with the< code > test</ code > module.</ td ></ tr > 2254</ tbody ></ table > 2255</ div > 2256< p >< a id ="cargo_build_script "></ a ></ p > 2257< h2 id ="cargo_build_script-1 ">< a class ="header "href ="#cargo_build_script-1 "> cargo_build_script</ a ></ h2 > 2258< pre > 2259cargo_build_script(< a href ="flatten.html#cargo_build_script-name "> name</ a > ,< a href ="flatten.html#cargo_build_script-edition "> edition</ a > ,< a href ="flatten.html#cargo_build_script-crate_name "> crate_name</ a > ,< a href ="flatten.html#cargo_build_script-crate_root "> crate_root</ a > ,< a href ="flatten.html#cargo_build_script-srcs "> srcs</ a > ,< a href ="flatten.html#cargo_build_script-crate_features "> crate_features</ a > ,< a href ="flatten.html#cargo_build_script-version "> version</ a > ,< a href ="flatten.html#cargo_build_script-deps "> deps</ a > , 2260< a href ="flatten.html#cargo_build_script-link_deps "> link_deps</ a > ,< a href ="flatten.html#cargo_build_script-proc_macro_deps "> proc_macro_deps</ a > ,< a href ="flatten.html#cargo_build_script-build_script_env "> build_script_env</ a > ,< a href ="flatten.html#cargo_build_script-data "> data</ a > ,< a href ="flatten.html#cargo_build_script-compile_data "> compile_data</ a > ,< a href ="flatten.html#cargo_build_script-tools "> tools</ a > ,< a href ="flatten.html#cargo_build_script-links "> links</ a > , 2261< a href ="flatten.html#cargo_build_script-rundir "> rundir</ a > ,< a href ="flatten.html#cargo_build_script-rustc_env "> rustc_env</ a > ,< a href ="flatten.html#cargo_build_script-rustc_env_files "> rustc_env_files</ a > ,< a href ="flatten.html#cargo_build_script-rustc_flags "> rustc_flags</ a > ,< a href ="flatten.html#cargo_build_script-visibility "> visibility</ a > ,< a href ="flatten.html#cargo_build_script-tags "> tags</ a > ,< a href ="flatten.html#cargo_build_script-aliases "> aliases</ a > , 2262< a href ="flatten.html#cargo_build_script-pkg_name "> pkg_name</ a > ,< a href ="flatten.html#cargo_build_script-kwargs "> kwargs</ a > ) 2263</ pre > 2264< p > Compile and execute a rust build script to generate build attributes</ p > 2265< p > This rules take the same arguments as rust_binary.</ p > 2266< p > Example:</ p > 2267< p > Suppose you have a crate with a cargo build script< code > build.rs</ code > :</ p > 2268< pre >< code class ="language-output "> [workspace]/ 2269 hello_lib/ 2270 BUILD 2271 build.rs 2272 src/ 2273 lib.rs 2274</ code ></ pre > 2275< p > Then you want to use the build script in the following:</ p > 2276< p >< code > hello_lib/BUILD</ code > :</ p > 2277< pre >< code class ="language-python "> package(default_visibility = ["//visibility:public"]) 2278 2279load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library") 2280load("@rules_rust//cargo:defs.bzl", "cargo_build_script") 2281 2282# This will run the build script from the root of the workspace, and 2283# collect the outputs. 2284cargo_build_script( 2285 name = "build_script", 2286 srcs = ["build.rs"], 2287 # Optional environment variables passed during build.rs compilation 2288 rustc_env = { 2289 "CARGO_PKG_VERSION": "0.1.2", 2290 }, 2291 # Optional environment variables passed during build.rs execution. 2292 # Note that as the build script's working directory is not execroot, 2293 # execpath/location will return an absolute path, instead of a relative 2294 # one. 2295 build_script_env = { 2296 "SOME_TOOL_OR_FILE": "$(execpath @tool//:binary)" 2297 }, 2298 # Optional data/tool dependencies 2299 data = ["@tool//:binary"], 2300) 2301 2302rust_library( 2303 name = "hello_lib", 2304 srcs = [ 2305 "src/lib.rs", 2306 ], 2307 deps = [":build_script"], 2308) 2309</ code ></ pre > 2310< 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 > 2311< p >< strong > PARAMETERS</ strong ></ p > 2312< 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 > 2313< 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 > 2314< 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 > 2315< 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 > 2316< 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 > 2317< tr >< td style ="text-align: left ">< a id ="cargo_build_script-srcs "></ a > srcs</ td >< td style ="text-align: left "> Souce 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 > 2318< 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 > 2319< 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 > 2320< 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 > 2321< 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 > 2322< 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 > 2323< 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 > 2324< 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 > 2325< 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 > 2326< 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 > 2327< 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 > 2328< 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 > 2329< 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 > 2330< 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 > 2331< 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 > 2332< 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 > 2333< 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 > 2334< 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 > 2335< 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 > 2336< 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_scirpt_run</ code > target.</ td >< td style ="text-align: left "> none</ td ></ tr > 2337</ tbody ></ table > 2338</ div > 2339< p >< a id ="cargo_env "></ a ></ p > 2340< h2 id ="cargo_env-1 ">< a class ="header "href ="#cargo_env-1 "> cargo_env</ a ></ h2 > 2341< pre > 2342cargo_env(< a href ="flatten.html#cargo_env-env "> env</ a > ) 2343</ pre > 2344< p > A helper for generating platform specific environment variables</ p > 2345< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_common") 2346load("@rules_rust//cargo:defs.bzl", "cargo_bootstrap_repository", "cargo_env") 2347 2348cargo_bootstrap_repository( 2349 name = "bootstrapped_bin", 2350 cargo_lockfile = "//:Cargo.lock", 2351 cargo_toml = "//:Cargo.toml", 2352 srcs = ["//:resolver_srcs"], 2353 version = rust_common.default_version, 2354 binary = "my-crate-binary", 2355 env = { 2356 "x86_64-unknown-linux-gnu": cargo_env({ 2357 "FOO": "BAR", 2358 }), 2359 }, 2360 env_label = { 2361 "aarch64-unknown-linux-musl": cargo_env({ 2362 "DOC": "//:README.md", 2363 }), 2364 } 2365) 2366</ code ></ pre > 2367< p >< strong > PARAMETERS</ strong ></ p > 2368< 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 > 2369< 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 > 2370</ tbody ></ table > 2371</ div > 2372< p >< strong > RETURNS</ strong ></ p > 2373< p > str: A json encoded string of the environment variables</ p > 2374< p >< a id ="rules_rust_dependencies "></ a ></ p > 2375< h2 id ="rules_rust_dependencies ">< a class ="header "href ="#rules_rust_dependencies "> rules_rust_dependencies</ a ></ h2 > 2376< pre > 2377rules_rust_dependencies() 2378</ pre > 2379< p > Dependencies used in the implementation of< code > rules_rust</ code > .</ p > 2380< p >< a id ="rust_analyzer_toolchain_repository "></ a ></ p > 2381< h2 id ="rust_analyzer_toolchain_repository ">< a class ="header "href ="#rust_analyzer_toolchain_repository "> rust_analyzer_toolchain_repository</ a ></ h2 > 2382< pre > 2383rust_analyzer_toolchain_repository(< a href ="flatten.html#rust_analyzer_toolchain_repository-name "> name</ a > ,< a href ="flatten.html#rust_analyzer_toolchain_repository-version "> version</ a > ,< a href ="flatten.html#rust_analyzer_toolchain_repository-exec_compatible_with "> exec_compatible_with</ a > ,< a href ="flatten.html#rust_analyzer_toolchain_repository-target_compatible_with "> target_compatible_with</ a > , 2384< a href ="flatten.html#rust_analyzer_toolchain_repository-sha256s "> sha256s</ a > ,< a href ="flatten.html#rust_analyzer_toolchain_repository-urls "> urls</ a > ,< a href ="flatten.html#rust_analyzer_toolchain_repository-auth "> auth</ a > ,< a href ="flatten.html#rust_analyzer_toolchain_repository-netrc "> netrc</ a > ,< a href ="flatten.html#rust_analyzer_toolchain_repository-auth_patterns "> auth_patterns</ a > ) 2385</ pre > 2386< p > Assemble a remote rust_analyzer_toolchain target based on the given params.</ p > 2387< p >< strong > PARAMETERS</ strong ></ p > 2388< 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 > 2389< 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 contianing the registerable toolchain.</ td >< td style ="text-align: left "> none</ td ></ tr > 2390< 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 > 2391< 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 > 2392< 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 > 2393< 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 ="flatten.html#rust_register_toolchains "> rust_register_toolchains</ a > for more details.</ td >< td style ="text-align: left ">< code > None</ code ></ td ></ tr > 2394< 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 > 2395< 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 > 2396< 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 > 2397< 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 > 2398</ tbody ></ table > 2399</ div > 2400< p >< strong > RETURNS</ strong ></ p > 2401< p > str: The name of a registerable rust_analyzer_toolchain.</ p > 2402< p >< a id ="rust_register_toolchains "></ a ></ p > 2403< h2 id ="rust_register_toolchains ">< a class ="header "href ="#rust_register_toolchains "> rust_register_toolchains</ a ></ h2 > 2404< pre > 2405rust_register_toolchains(< a href ="flatten.html#rust_register_toolchains-dev_components "> dev_components</ a > ,< a href ="flatten.html#rust_register_toolchains-edition "> edition</ a > ,< a href ="flatten.html#rust_register_toolchains-allocator_library "> allocator_library</ a > ,< a href ="flatten.html#rust_register_toolchains-global_allocator_library "> global_allocator_library</ a > , 2406< a href ="flatten.html#rust_register_toolchains-register_toolchains "> register_toolchains</ a > ,< a href ="flatten.html#rust_register_toolchains-rustfmt_version "> rustfmt_version</ a > ,< a href ="flatten.html#rust_register_toolchains-rust_analyzer_version "> rust_analyzer_version</ a > ,< a href ="flatten.html#rust_register_toolchains-sha256s "> sha256s</ a > , 2407< a href ="flatten.html#rust_register_toolchains-extra_target_triples "> extra_target_triples</ a > ,< a href ="flatten.html#rust_register_toolchains-extra_rustc_flags "> extra_rustc_flags</ a > ,< a href ="flatten.html#rust_register_toolchains-extra_exec_rustc_flags "> extra_exec_rustc_flags</ a > ,< a href ="flatten.html#rust_register_toolchains-urls "> urls</ a > , 2408< a href ="flatten.html#rust_register_toolchains-versions "> versions</ a > ,< a href ="flatten.html#rust_register_toolchains-aliases "> aliases</ a > ,< a href ="flatten.html#rust_register_toolchains-hub_name "> hub_name</ a > ,< a href ="flatten.html#rust_register_toolchains-compact_windows_names "> compact_windows_names</ a > ) 2409</ pre > 2410< p > Emits a default set of toolchains for Linux, MacOS, and Freebsd</ p > 2411< 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 > 2412< p > The< code > sha256s</ code > attribute represents a dict associating tool subdirectories to sha256 hashes. As an example:</ p > 2413< pre >< code class ="language-python "> { 2414 "rust-1.46.0-x86_64-unknown-linux-gnu": "e3b98bc3440fe92817881933f9564389eccb396f5f431f33d48b979fa2fbdcf5", 2415 "rustfmt-1.4.12-x86_64-unknown-linux-gnu": "1894e76913303d66bf40885a601462844eec15fca9e76a6d13c390d7000d64b0", 2416 "rust-std-1.46.0-x86_64-unknown-linux-gnu": "ac04aef80423f612c0079829b504902de27a6997214eb58ab0765d02f7ec1dbc", 2417} 2418</ code ></ pre > 2419< 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 > 2420< p > See< code > load_arbitrary_tool</ code > in< code > @rules_rust//rust:repositories.bzl</ code > for more details.</ p > 2421< p >< strong > PARAMETERS</ strong ></ p > 2422< 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 > 2423< 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 > 2424< 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 > 2425< 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 > 2426< 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 > 2427< 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 > 2428< 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 > 2429< 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 > 2430< 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 > 2431< 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"]</ code ></ td ></ tr > 2432< 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 > 2433< 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 > 2434< 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 > 2435< 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.83.0", "nightly/2024-11-28"]</ code ></ td ></ tr > 2436< 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 > 2437< 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 > 2438< 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 > 2439</ tbody ></ table > 2440</ div > 2441< p >< a id ="rust_repositories "></ a ></ p > 2442< h2 id ="rust_repositories ">< a class ="header "href ="#rust_repositories "> rust_repositories</ a ></ h2 > 2443< pre > 2444rust_repositories(< a href ="flatten.html#rust_repositories-kwargs "> kwargs</ a > ) 2445</ pre > 2446< p >< strong > Deprecated</ strong > : Use< a href ="flatten.html#rules_rust_dependencies "> rules_rust_dependencies</ a > and< a href ="flatten.html#rust_register_toolchains "> rust_register_toolchains</ a > directly.</ p > 2447< p >< strong > PARAMETERS</ strong ></ p > 2448< 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 > 2449< 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 > 2450</ tbody ></ table > 2451</ div > 2452< p >< a id ="rust_repository_set "></ a ></ p > 2453< h2 id ="rust_repository_set ">< a class ="header "href ="#rust_repository_set "> rust_repository_set</ a ></ h2 > 2454< pre > 2455rust_repository_set(< a href ="flatten.html#rust_repository_set-name "> name</ a > ,< a href ="flatten.html#rust_repository_set-versions "> versions</ a > ,< a href ="flatten.html#rust_repository_set-exec_triple "> exec_triple</ a > ,< a href ="flatten.html#rust_repository_set-target_settings "> target_settings</ a > ,< a href ="flatten.html#rust_repository_set-allocator_library "> allocator_library</ a > , 2456< a href ="flatten.html#rust_repository_set-global_allocator_library "> global_allocator_library</ a > ,< a href ="flatten.html#rust_repository_set-extra_target_triples "> extra_target_triples</ a > ,< a href ="flatten.html#rust_repository_set-rustfmt_version "> rustfmt_version</ a > ,< a href ="flatten.html#rust_repository_set-edition "> edition</ a > , 2457< a href ="flatten.html#rust_repository_set-dev_components "> dev_components</ a > ,< a href ="flatten.html#rust_repository_set-extra_rustc_flags "> extra_rustc_flags</ a > ,< a href ="flatten.html#rust_repository_set-extra_exec_rustc_flags "> extra_exec_rustc_flags</ a > ,< a href ="flatten.html#rust_repository_set-opt_level "> opt_level</ a > ,< a href ="flatten.html#rust_repository_set-sha256s "> sha256s</ a > , 2458< a href ="flatten.html#rust_repository_set-urls "> urls</ a > ,< a href ="flatten.html#rust_repository_set-auth "> auth</ a > ,< a href ="flatten.html#rust_repository_set-netrc "> netrc</ a > ,< a href ="flatten.html#rust_repository_set-auth_patterns "> auth_patterns</ a > ,< a href ="flatten.html#rust_repository_set-register_toolchain "> register_toolchain</ a > ,< a href ="flatten.html#rust_repository_set-exec_compatible_with "> exec_compatible_with</ a > , 2459< a href ="flatten.html#rust_repository_set-default_target_compatible_with "> default_target_compatible_with</ a > ,< a href ="flatten.html#rust_repository_set-aliases "> aliases</ a > ,< a href ="flatten.html#rust_repository_set-compact_windows_names "> compact_windows_names</ a > ) 2460</ pre > 2461< p > Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains.</ p > 2462< p >< strong > PARAMETERS</ strong ></ p > 2463< 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 > 2464< 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 > 2465< 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 paramter 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 > 2466< 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 > 2467< 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 > 2468< 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 > 2469< 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 > 2470< 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 > 2471< 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 > 2472< 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 > 2473< 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 > 2474< 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 > 2475< 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 > 2476< 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 optimiztion config.</ td >< td style ="text-align: left ">< code > None</ code ></ td ></ tr > 2477< 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 ="flatten.html#rust_register_toolchains "> rust_register_toolchains</ a > for more details.</ td >< td style ="text-align: left ">< code > None</ code ></ td ></ tr > 2478< 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 > 2479< 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 > 2480< 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 > 2481< 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 > 2482< 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 > 2483< 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 > 2484< 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 > 2485< 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 > 2486< 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 > 2487</ tbody ></ table > 2488</ div > 2489< p >< a id ="rust_test_suite "></ a ></ p > 2490< h2 id ="rust_test_suite-1 ">< a class ="header "href ="#rust_test_suite-1 "> rust_test_suite</ a ></ h2 > 2491< pre > 2492rust_test_suite(< a href ="flatten.html#rust_test_suite-name "> name</ a > ,< a href ="flatten.html#rust_test_suite-srcs "> srcs</ a > ,< a href ="flatten.html#rust_test_suite-shared_srcs "> shared_srcs</ a > ,< a href ="flatten.html#rust_test_suite-kwargs "> kwargs</ a > ) 2493</ pre > 2494< p > A rule for creating a test suite for a set of< code > rust_test</ code > targets.</ p > 2495< 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 2496directory structure:</ p > 2497< pre >< code class ="language-text "> [crate]/ 2498 BUILD.bazel 2499 src/ 2500 lib.rs 2501 main.rs 2502 tests/ 2503 integrated_test_a.rs 2504 integrated_test_b.rs 2505 integrated_test_c.rs 2506 patterns/ 2507 fibonacci_test.rs 2508 helpers/ 2509 mod.rs 2510</ code ></ pre > 2511< p > The rule can be used to generate< a href ="flatten.html#rust_test "> rust_test</ a > targets for each source file under< code > tests</ code > 2512and a< a href ="https://docs.bazel.build/versions/master/be/general.html#test_suite "> test_suite</ a > which encapsulates all tests.</ p > 2513< pre >< code class ="language-python "> load("//rust:defs.bzl", "rust_binary", "rust_library", "rust_test_suite") 2514 2515rust_library( 2516 name = "math_lib", 2517 srcs = ["src/lib.rs"], 2518) 2519 2520rust_binary( 2521 name = "math_bin", 2522 srcs = ["src/main.rs"], 2523) 2524 2525rust_test_suite( 2526 name = "integrated_tests_suite", 2527 srcs = glob(["tests/**"]), 2528 shared_srcs=glob(["tests/helpers/**"]), 2529 deps = [":math_lib"], 2530) 2531</ code ></ pre > 2532< p >< strong > PARAMETERS</ strong ></ p > 2533< 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 > 2534< 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 > 2535< 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 > 2536< 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 > 2537< 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 underyling< a href ="flatten.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 > 2538</ tbody ></ table > 2539</ div > 2540< p >< a id ="rust_toolchain_repository "></ a ></ p > 2541< h2 id ="rust_toolchain_repository ">< a class ="header "href ="#rust_toolchain_repository "> rust_toolchain_repository</ a ></ h2 > 2542< pre > 2543rust_toolchain_repository(< a href ="flatten.html#rust_toolchain_repository-name "> name</ a > ,< a href ="flatten.html#rust_toolchain_repository-version "> version</ a > ,< a href ="flatten.html#rust_toolchain_repository-exec_triple "> exec_triple</ a > ,< a href ="flatten.html#rust_toolchain_repository-target_triple "> target_triple</ a > ,< a href ="flatten.html#rust_toolchain_repository-exec_compatible_with "> exec_compatible_with</ a > , 2544< a href ="flatten.html#rust_toolchain_repository-target_compatible_with "> target_compatible_with</ a > ,< a href ="flatten.html#rust_toolchain_repository-target_settings "> target_settings</ a > ,< a href ="flatten.html#rust_toolchain_repository-channel "> channel</ a > ,< a href ="flatten.html#rust_toolchain_repository-allocator_library "> allocator_library</ a > , 2545< a href ="flatten.html#rust_toolchain_repository-global_allocator_library "> global_allocator_library</ a > ,< a href ="flatten.html#rust_toolchain_repository-rustfmt_version "> rustfmt_version</ a > ,< a href ="flatten.html#rust_toolchain_repository-edition "> edition</ a > ,< a href ="flatten.html#rust_toolchain_repository-dev_components "> dev_components</ a > , 2546< a href ="flatten.html#rust_toolchain_repository-extra_rustc_flags "> extra_rustc_flags</ a > ,< a href ="flatten.html#rust_toolchain_repository-extra_exec_rustc_flags "> extra_exec_rustc_flags</ a > ,< a href ="flatten.html#rust_toolchain_repository-opt_level "> opt_level</ a > ,< a href ="flatten.html#rust_toolchain_repository-sha256s "> sha256s</ a > ,< a href ="flatten.html#rust_toolchain_repository-urls "> urls</ a > ,< a href ="flatten.html#rust_toolchain_repository-auth "> auth</ a > , 2547< a href ="flatten.html#rust_toolchain_repository-netrc "> netrc</ a > ,< a href ="flatten.html#rust_toolchain_repository-auth_patterns "> auth_patterns</ a > ) 2548</ pre > 2549< p > Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains.</ p > 2550< p >< strong > PARAMETERS</ strong ></ p > 2551< 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 > 2552< 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 > 2553< 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 > 2554< 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 > 2555< 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 > 2556< 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 > 2557< 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 > 2558< 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 > 2559< 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 > 2560< 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 > 2561< 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 > 2562< 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 > 2563< 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 > 2564< 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 > 2565< 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 > 2566< 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 > 2567< 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 > 2568< 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 ="flatten.html#rust_register_toolchains "> rust_register_toolchains</ a > for more details.</ td >< td style ="text-align: left ">< code > None</ code ></ td ></ tr > 2569< 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 > 2570< 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 > 2571< 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 > 2572< 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 > 2573</ tbody ></ table > 2574</ div > 2575< p >< strong > RETURNS</ strong ></ p > 2576< p > str: The name of the registerable toolchain created by this rule.</ p > 2577< p >< a id ="rust_analyzer_aspect "></ a ></ p > 2578< h2 id ="rust_analyzer_aspect-1 ">< a class ="header "href ="#rust_analyzer_aspect-1 "> rust_analyzer_aspect</ a ></ h2 > 2579< pre > 2580rust_analyzer_aspect(< a href ="flatten.html#rust_analyzer_aspect-name "> name</ a > ) 2581</ pre > 2582< p > Annotates rust rules with RustAnalyzerInfo later used to build a rust-project.json</ p > 2583< p >< strong > ASPECT ATTRIBUTES</ strong ></ p > 2584< div class ="table-wrapper ">< table >< thead >< tr >< th style ="text-align: left "> Name</ th >< th style ="text-align: left "> Type</ th ></ tr ></ thead >< tbody > 2585< tr >< td style ="text-align: left "> deps</ td >< td style ="text-align: left "> String</ td ></ tr > 2586< tr >< td style ="text-align: left "> proc_macro_deps</ td >< td style ="text-align: left "> String</ td ></ tr > 2587< tr >< td style ="text-align: left "> crate</ td >< td style ="text-align: left "> String</ td ></ tr > 2588< tr >< td style ="text-align: left "> actual</ td >< td style ="text-align: left "> String</ td ></ tr > 2589< tr >< td style ="text-align: left "> proto</ td >< td style ="text-align: left "> String</ td ></ tr > 2590</ tbody ></ table > 2591</ div > 2592< p >< strong > ATTRIBUTES</ strong ></ p > 2593< 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 > 2594< tr >< td style ="text-align: left ">< a id ="rust_analyzer_aspect-name "></ a > name</ td >< td style ="text-align: left "> A unique name for this target.</ td >< td style ="text-align: left ">< a href ="https://bazel.build/concepts/labels#target-names "> Name</ a ></ td >< td style ="text-align: left "> required</ td >< td style ="text-align: left "></ td ></ tr > 2595</ tbody ></ table > 2596</ div > 2597< p >< a id ="rust_clippy_aspect "></ a ></ p > 2598< h2 id ="rust_clippy_aspect-1 ">< a class ="header "href ="#rust_clippy_aspect-1 "> rust_clippy_aspect</ a ></ h2 > 2599< pre > 2600rust_clippy_aspect(< a href ="flatten.html#rust_clippy_aspect-name "> name</ a > ) 2601</ pre > 2602< p > Executes the clippy checker on specified targets.</ p > 2603< p > This aspect applies to existing rust_library, rust_test, and rust_binary rules.</ p > 2604< p > As an example, if the following is defined in< code > examples/hello_lib/BUILD.bazel</ code > :</ p > 2605< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 2606 2607rust_library( 2608 name = "hello_lib", 2609 srcs = ["src/lib.rs"], 2610) 2611 2612rust_test( 2613 name = "greeting_test", 2614 srcs = ["tests/greeting.rs"], 2615 deps = [":hello_lib"], 2616) 2617</ code ></ pre > 2618< p > Then the targets can be analyzed with clippy using the following command:</ p > 2619< pre >< code class ="language-output "> $ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect --output_groups=clippy_checks //hello_lib:all 2620</ code ></ pre > 2621< p >< strong > ASPECT ATTRIBUTES</ strong ></ p > 2622< p >< strong > ATTRIBUTES</ strong ></ p > 2623< 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 > 2624< tr >< td style ="text-align: left ">< a id ="rust_clippy_aspect-name "></ a > name</ td >< td style ="text-align: left "> A unique name for this target.</ td >< td style ="text-align: left ">< a href ="https://bazel.build/concepts/labels#target-names "> Name</ a ></ td >< td style ="text-align: left "> required</ td >< td style ="text-align: left "></ td ></ tr > 2625</ tbody ></ table > 2626</ div > 2627< p >< a id ="rustfmt_aspect "></ a ></ p > 2628< h2 id ="rustfmt_aspect-1 ">< a class ="header "href ="#rustfmt_aspect-1 "> rustfmt_aspect</ a ></ h2 > 2629< pre > 2630rustfmt_aspect(< a href ="flatten.html#rustfmt_aspect-name "> name</ a > ) 2631</ pre > 2632< p > This aspect is used to gather information about a crate for use in rustfmt and perform rustfmt checks</ p > 2633< p > Output Groups:</ p > 2634< ul > 2635< li >< code > rustfmt_checks</ code > : Executes< code > rustfmt --check</ code > on the specified target.</ li > 2636</ ul > 2637< 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 > 2638used at runtime.</ p > 2639< p > This aspect is executed on any target which provides the< code > CrateInfo</ code > provider. However 2640users may tag a target with< code > no-rustfmt</ code > or< code > no-format</ code > to have it skipped. Additionally, 2641generated source files are also ignored by this aspect.</ p > 2642< p >< strong > ASPECT ATTRIBUTES</ strong ></ p > 2643< p >< strong > ATTRIBUTES</ strong ></ p > 2644< 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 > 2645< tr >< td style ="text-align: left ">< a id ="rustfmt_aspect-name "></ a > name</ td >< td style ="text-align: left "> A unique name for this target.</ td >< td style ="text-align: left ">< a href ="https://bazel.build/concepts/labels#target-names "> Name</ a ></ td >< td style ="text-align: left "> required</ td >< td style ="text-align: left "></ td ></ tr > 2646</ tbody ></ table > 2647</ div > 2648< p >< a id ="cargo_bootstrap_repository "></ a ></ p > 2649< h2 id ="cargo_bootstrap_repository-1 ">< a class ="header "href ="#cargo_bootstrap_repository-1 "> cargo_bootstrap_repository</ a ></ h2 > 2650< pre > 2651cargo_bootstrap_repository(< a href ="flatten.html#cargo_bootstrap_repository-name "> name</ a > ,< a href ="flatten.html#cargo_bootstrap_repository-srcs "> srcs</ a > ,< a href ="flatten.html#cargo_bootstrap_repository-binary "> binary</ a > ,< a href ="flatten.html#cargo_bootstrap_repository-build_mode "> build_mode</ a > ,< a href ="flatten.html#cargo_bootstrap_repository-cargo_config "> cargo_config</ a > ,< a href ="flatten.html#cargo_bootstrap_repository-cargo_lockfile "> cargo_lockfile</ a > ,< a href ="flatten.html#cargo_bootstrap_repository-cargo_toml "> cargo_toml</ a > , 2652< a href ="flatten.html#cargo_bootstrap_repository-compressed_windows_toolchain_names "> compressed_windows_toolchain_names</ a > ,< a href ="flatten.html#cargo_bootstrap_repository-env "> env</ a > ,< a href ="flatten.html#cargo_bootstrap_repository-env_label "> env_label</ a > ,< a href ="flatten.html#cargo_bootstrap_repository-repo_mapping "> repo_mapping</ a > , 2653< a href ="flatten.html#cargo_bootstrap_repository-rust_toolchain_cargo_template "> rust_toolchain_cargo_template</ a > ,< a href ="flatten.html#cargo_bootstrap_repository-rust_toolchain_rustc_template "> rust_toolchain_rustc_template</ a > ,< a href ="flatten.html#cargo_bootstrap_repository-timeout "> timeout</ a > , 2654< a href ="flatten.html#cargo_bootstrap_repository-version "> version</ a > ) 2655</ pre > 2656< p > A rule for bootstrapping a Rust binary using< a href ="https://doc.rust-lang.org/cargo/ "> Cargo</ a ></ p > 2657< p >< strong > ATTRIBUTES</ strong ></ p > 2658< 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 > 2659< 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 > 2660< tr >< td style ="text-align: left ">< a id ="cargo_bootstrap_repository-srcs "></ a > srcs</ td >< td style ="text-align: left "> Souce 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 > 2661< 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 > 2662< 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 > 2663< 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 > 2664< 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 > 2665< 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 > 2666< 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 "> Wether 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 > 2667< 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 ="flatten.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 > 2668< 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 ="flatten.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 > 2669< 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 > 2670< 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 > 2671< 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 > 2672< 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 > 2673< 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.83.0"</ code ></ td ></ tr > 2674</ tbody ></ table > 2675</ div > 2676< p >< a id ="rust_toolchain_repository_proxy "></ a ></ p > 2677< h2 id ="rust_toolchain_repository_proxy ">< a class ="header "href ="#rust_toolchain_repository_proxy "> rust_toolchain_repository_proxy</ a ></ h2 > 2678< pre > 2679rust_toolchain_repository_proxy(< a href ="flatten.html#rust_toolchain_repository_proxy-name "> name</ a > ,< a href ="flatten.html#rust_toolchain_repository_proxy-exec_compatible_with "> exec_compatible_with</ a > ,< a href ="flatten.html#rust_toolchain_repository_proxy-repo_mapping "> repo_mapping</ a > ,< a href ="flatten.html#rust_toolchain_repository_proxy-target_compatible_with "> target_compatible_with</ a > , 2680< a href ="flatten.html#rust_toolchain_repository_proxy-target_settings "> target_settings</ a > ,< a href ="flatten.html#rust_toolchain_repository_proxy-toolchain "> toolchain</ a > ,< a href ="flatten.html#rust_toolchain_repository_proxy-toolchain_type "> toolchain_type</ a > ) 2681</ pre > 2682< p > Generates a toolchain-bearing repository that declares the toolchains from some other rust_toolchain_repository.</ p > 2683< p >< strong > ATTRIBUTES</ strong ></ p > 2684< 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 > 2685< 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 > 2686< 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 > 2687< 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 > 2688< 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 > 2689< 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 > 2690< 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 > 2691< 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 > 2692</ tbody ></ table > 2693</ div > 2694< p >< a id ="rust_toolchain_tools_repository "></ a ></ p > 2695< h2 id ="rust_toolchain_tools_repository ">< a class ="header "href ="#rust_toolchain_tools_repository "> rust_toolchain_tools_repository</ a ></ h2 > 2696< pre > 2697rust_toolchain_tools_repository(< a href ="flatten.html#rust_toolchain_tools_repository-name "> name</ a > ,< a href ="flatten.html#rust_toolchain_tools_repository-allocator_library "> allocator_library</ a > ,< a href ="flatten.html#rust_toolchain_tools_repository-auth "> auth</ a > ,< a href ="flatten.html#rust_toolchain_tools_repository-auth_patterns "> auth_patterns</ a > ,< a href ="flatten.html#rust_toolchain_tools_repository-dev_components "> dev_components</ a > , 2698< a href ="flatten.html#rust_toolchain_tools_repository-edition "> edition</ a > ,< a href ="flatten.html#rust_toolchain_tools_repository-exec_triple "> exec_triple</ a > ,< a href ="flatten.html#rust_toolchain_tools_repository-extra_exec_rustc_flags "> extra_exec_rustc_flags</ a > ,< a href ="flatten.html#rust_toolchain_tools_repository-extra_rustc_flags "> extra_rustc_flags</ a > , 2699< a href ="flatten.html#rust_toolchain_tools_repository-global_allocator_library "> global_allocator_library</ a > ,< a href ="flatten.html#rust_toolchain_tools_repository-netrc "> netrc</ a > ,< a href ="flatten.html#rust_toolchain_tools_repository-opt_level "> opt_level</ a > ,< a href ="flatten.html#rust_toolchain_tools_repository-repo_mapping "> repo_mapping</ a > , 2700< a href ="flatten.html#rust_toolchain_tools_repository-rustfmt_version "> rustfmt_version</ a > ,< a href ="flatten.html#rust_toolchain_tools_repository-sha256s "> sha256s</ a > ,< a href ="flatten.html#rust_toolchain_tools_repository-target_triple "> target_triple</ a > ,< a href ="flatten.html#rust_toolchain_tools_repository-urls "> urls</ a > ,< a href ="flatten.html#rust_toolchain_tools_repository-version "> version</ a > ) 2701</ pre > 2702< p > Composes a single workspace containing the toolchain components for compiling on a given platform to a series of target platforms.</ p > 2703< 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 > 2704< p >< strong > ATTRIBUTES</ strong ></ p > 2705< 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 > 2706< 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 > 2707< 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 > 2708< 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 > 2709< 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 > 2710< 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 > 2711< 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 > 2712< 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 > 2713< 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 > 2714< 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 > 2715< 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 > 2716< 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 > 2717< 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 > 2718< 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 > 2719< 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 > 2720< 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 ="flatten.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 > 2721< 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 > 2722< 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 > 2723< 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 > 2724</ tbody ></ table > 2725</ 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 > 2726< p >< a href ="crate_universe.html "> crate_universe</ 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 > 2727< div style ="break-before: page; page-break-before: always; "></ div > <!-- Generated with Stardoc: http://skydoc.bazel.build --> 2728< h1 id ="crate-universe ">< a class ="header "href ="#crate-universe "> Crate Universe</ a ></ h1 > 2729< p > Crate Universe is a set of Bazel rule for generating Rust targets using Cargo.</ p > 2730< p > This doc describes using crate_universe with bzlmod.</ p > 2731< p > If you're using a WORKSPACE file, please see< a href ="crate_universe.html "> the WORKSPACE equivalent of this doc</ a > .</ p > 2732< p > There are some examples of using crate_universe with bzlmod in the< a href ="../examples/bzlmod "> example folder</ a > .</ p > 2733< h1 id ="table-of-contents ">< a class ="header "href ="#table-of-contents "> Table of Contents</ a ></ h1 > 2734< ol > 2735< li >< a href ="crate_universe_bzlmod.html#Setup "> Setup</ a ></ li > 2736< li >< a href ="crate_universe_bzlmod.html#dependencies "> Dependencies</ a > 2737< ul > 2738< li >< a href ="crate_universe_bzlmod.html#cargo-workspaces "> Cargo Workspace</ a ></ li > 2739< li >< a href ="crate_universe_bzlmod.html#direct-dependencies "> Direct Packages</ a ></ li > 2740< li >< a href ="crate_universe_bzlmod.html#vendored-dependencies "> Vendored Dependencies</ a ></ li > 2741</ ul > 2742</ li > 2743< li >< a href ="crate_universe_bzlmod.html#crate "> Crate reference</ a > 2744< ul > 2745< li >< a href ="crate_universe_bzlmod.html#from_cargo "> from_cargo</ a ></ li > 2746< li >< a href ="crate_universe_bzlmod.html#from_specs "> from_specs</ a ></ li > 2747</ ul > 2748</ li > 2749</ ol > 2750< h2 id ="setup-4 ">< a class ="header "href ="#setup-4 "> Setup</ a ></ h2 > 2751< p > To use rules_rust in a project using bzlmod, add the following to your MODULE.bazel file:</ p > 2752< pre >< code class ="language-starlark "> bazel_dep(name = "rules_rust", version = "0.49.3") 2753</ code ></ pre > 2754< p > You find the latest version on the< a href ="https://github.com/bazelbuild/rules_rust/releases "> release page</ a > .</ p > 2755< p > After adding< code > rules_rust</ code > in your MODULE.bazel, set the following to begin using< code > crate_universe</ code > :</ p > 2756< pre >< code class ="language-starlark "> crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate") 2757// # ... Dependencies 2758use_repo(crate, "crates") 2759</ code ></ pre > 2760< h2 id ="dependencies ">< a class ="header "href ="#dependencies "> Dependencies</ a ></ h2 > 2761< p > There are three different ways to declare dependencies in your MODULE.</ p > 2762< ol > 2763< li > Cargo workspace</ li > 2764< li > Direct Dependencies</ li > 2765< li > Vendored Dependencies</ li > 2766</ ol > 2767< h3 id ="cargo-workspaces ">< a class ="header "href ="#cargo-workspaces "> Cargo Workspaces</ a ></ h3 > 2768< p > One of the simpler ways to wire up dependencies would be to first structure your project into a Cargo workspace. 2769The crates_repository rule can ingest a root Cargo.toml file and generate Bazel dependencies from there. 2770You find a complete example in the in the< a href ="../examples/bzlmod/all_crate_deps "> example folder</ a > .</ p > 2771< pre >< code class ="language-starlark "> crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate") 2772 2773crate.from_cargo( 2774 name = "crates", 2775 cargo_lockfile = "//:Cargo.lock", 2776 manifests = ["//:Cargo.toml"], 2777) 2778use_repo(crate, "crates") 2779</ code ></ pre > 2780< p > The generated crates_repository contains helper macros which make collecting dependencies for Bazel targets simpler. 2781Notably, the all_crate_deps and aliases macros ( 2782see< a href ="https://bazelbuild.github.io/rules_rust/crate_universe.html#dependencies-api "> Dependencies API</ a > ) commonly allow the 2783Cargo.toml files to be the single source of truth for dependencies. 2784Since these macros come from the generated repository, the dependencies and alias definitions 2785they return will automatically update BUILD targets. In your BUILD files, 2786you use these macros for a Rust library as shown below:</ p > 2787< pre >< code class ="language-starlark "> load("@crate_index//:defs.bzl", "aliases", "all_crate_deps") 2788load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 2789 2790rust_library( 2791 name = "lib", 2792 aliases = aliases(), 2793 deps = all_crate_deps( 2794 normal = True, 2795 ), 2796 proc_macro_deps = all_crate_deps( 2797 proc_macro = True, 2798 ), 2799) 2800 2801rust_test( 2802 name = "unit_test", 2803 crate = ":lib", 2804 aliases = aliases( 2805 normal_dev = True, 2806 proc_macro_dev = True, 2807 ), 2808 deps = all_crate_deps( 2809 normal_dev = True, 2810 ), 2811 proc_macro_deps = all_crate_deps( 2812 proc_macro_dev = True, 2813 ), 2814) 2815</ code ></ pre > 2816< p > For a Rust binary that does not depend on any macro, use the following configuration 2817in your build file:</ p > 2818< pre >< code class ="language-starlark "> rust_binary( 2819 name = "bin", 2820 srcs = ["src/main.rs"], 2821 deps = all_crate_deps(normal = True), 2822) 2823</ code ></ pre > 2824< p > You have to repin before your first build to ensure all Bazel targets for the macros 2825are generated.</ p > 2826< p > Dependency syncing and updating is done in the repository rule which means it's done during the 2827analysis phase of builds. As mentioned in the environments variable table above, the< code > CARGO_BAZEL_REPIN</ code > 2828(or< code > REPIN</ code > ) environment variables can be used to force the rule to update dependencies and potentially 2829render a new lockfile. Given an instance of this repository rule named< code > crates</ code > , the easiest way to 2830repin dependencies is to run:</ p > 2831< pre >< code class ="language-shell "> CARGO_BAZEL_REPIN=1 bazel sync --only=crates 2832</ code ></ pre > 2833< p > This will result in all dependencies being updated for a project. The< code > CARGO_BAZEL_REPIN</ code > 2834environment variable can also be used to customize how dependencies are updated. 2835For more details about repin,< a href ="https://bazelbuild.github.io/rules_rust/crate_universe.html#crates_vendor "> please refer to the documentation</ a > .</ p > 2836< h3 id ="direct-dependencies ">< a class ="header "href ="#direct-dependencies "> Direct Dependencies</ a ></ h3 > 2837< 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 > , 2838etc.), maintaining Cargo.toml files may have diminishing returns as things like rust-analyzer 2839begin to be confused about missing targets or environment variables defined only in Bazel. 2840In situations like this, it may be desirable to have a âCargo freeâ setup. You find an example in the in the< a href ="../examples/bzlmod/hello_world_no_cargo "> example folder</ a > .</ p > 2841< p > crates_repository supports this through the packages attribute, 2842as shown below.</ p > 2843< pre >< code class ="language-starlark "> crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate") 2844 2845crate.spec(package = "serde", features = ["derive"], version = "1.0") 2846crate.spec(package = "serde_json", version = "1.0") 2847crate.spec(package = "tokio", default_features=False, features = ["macros", "net", "rt-multi-thread"], version = "1.38") 2848 2849crate.from_specs() 2850use_repo(crate, "crates") 2851</ code ></ pre > 2852< p > Consuming dependencies may be more ergonomic in this case through the aliases defined in the new repository. 2853In your BUILD files, you use direct dependencies as shown below:</ p > 2854< pre >< code class ="language-starlark "> rust_binary( 2855 name = "bin", 2856 crate_root = "src/main.rs", 2857 srcs = glob([ 2858 "src/*.rs", 2859 ]), 2860 deps = [ 2861 # External crates 2862 "@crates//:serde", 2863 "@crates//:serde_json", 2864 "@crates//:tokio", 2865 ], 2866 visibility = ["//visibility:public"], 2867) 2868</ code ></ pre > 2869< p > Notice, direct dependencies do not need repining. 2870Only a cargo workspace needs updating whenever the underlying Cargo.toml file changed.</ p > 2871< h3 id ="vendored-dependencies ">< a class ="header "href ="#vendored-dependencies "> Vendored Dependencies</ a ></ h3 > 2872< p > In some cases, it is require that all external dependencies are vendored, meaning downloaded 2873and stored in the workspace. This helps, for example, to conduct licence scans, apply custom patches, 2874or to ensure full build reproducibility since no download error could possibly occur. 2875You find a complete example in the in the< a href ="../examples/bzlmod/all_deps_vendor "> example folder</ a > .</ p > 2876< p > For the setup, you need to add the skylib in addition to the rust rules to your MODUE.bazel.</ p > 2877< pre >< code class ="language-starlark "> module( 2878 name = "deps_vendored", 2879 version = "0.0.0" 2880) 2881############################################################################### 2882# B A Z E L C E N T R A L R E G I S T R Y # https://registry.bazel.build/ 2883############################################################################### 2884# https://github.com/bazelbuild/bazel-skylib/releases/ 2885bazel_dep(name = "bazel_skylib", version = "1.7.1") 2886 2887# https://github.com/bazelbuild/rules_rust/releases 2888bazel_dep(name = "rules_rust", version = "0.49.3") 2889 2890############################################################################### 2891# T O O L C H A I N S 2892############################################################################### 2893 2894# Rust toolchain 2895RUST_EDITION = "2021" 2896RUST_VERSION = "1.80.1" 2897 2898rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") 2899rust.toolchain( 2900 edition = RUST_EDITION, 2901 versions = [RUST_VERSION], 2902) 2903use_repo(rust, "rust_toolchains") 2904register_toolchains("@rust_toolchains//:all") 2905 2906############################################################################### 2907# R U S T C R A T E S 2908############################################################################### 2909crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate") 2910</ code ></ pre > 2911< p > Note, it is important to load the crate_universe rules otherwise you will get an error 2912as the rule set is needed in the vendored target.</ p > 2913< p > Assuming you have a package called< code > basic</ code > in which you want to vendor dependencies, 2914then you create a folder< code > basic/3rdparty</ code > . The folder name can be arbitrary, 2915but by convention, its either thirdparty or 3rdparty to indicate vendored dependencies. 2916In the 3rdparty folder, you add a target crates_vendor to declare your dependencies to vendor. 2917In the example, we vendor a specific version of bzip2.</ p > 2918< pre >< code class ="language-starlark "> load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor") 2919 2920crates_vendor( 2921 name = "crates_vendor", 2922 annotations = { 2923 "bzip2-sys": [crate.annotation( 2924 gen_build_script = True, 2925 )], 2926 }, 2927 cargo_lockfile = "Cargo.Bazel.lock", 2928 generate_build_scripts = False, 2929 mode = "remote", 2930 packages = { 2931 "bzip2": crate.spec( 2932 version = "=0.3.3", 2933 ), 2934 }, 2935 repository_name = "basic", 2936 tags = ["manual"], 2937) 2938</ code ></ pre > 2939< p > Next, you have to run< code > Cargo build</ code > to generate a Cargo.lock file with all resolved dependencies. 2940Then, you rename Cargo.lock to Cargo.Bazel.lock and place it inside the< code > basic/3rdparty</ code > folder.</ p > 2941< p > At this point, you have the following folder and files:</ p > 2942< pre >< code > basic 2943 âââ 3rdparty 2944 â âââ BUILD.bazel 2945 â âââ Cargo.Bazel.lock 2946</ code ></ pre > 2947< p > Now you can run the< code > crates_vendor</ code > target:</ p > 2948< p >< code > bazel run //basic/3rdparty:crates_vendor</ code ></ p > 2949< p > This generates a crate folders with all configurations for the vendored dependencies.</ p > 2950< pre >< code > basic 2951 âââ 3rdparty 2952 â âââ cratea 2953 â âââ BUILD.bazel 2954 â âââ Cargo.Bazel.lock 2955</ code ></ pre > 2956< p > Suppose you have an application in< code > basic/src</ code > that is defined in< code > basic/BUILD.bazel</ code > and 2957that depends on a vendored dependency. You find a list of all available vendored dependencies 2958in the BUILD file of the generated folder:< code > basic/3rdparty/crates/BUILD.bazel</ code > 2959You declare a vendored dependency in you target as following:</ p > 2960< pre >< code class ="language-starlark "> load("@rules_rust//rust:defs.bzl", "rust_binary") 2961 2962rust_binary( 2963 name = "hello_sys", 2964 srcs = ["src/main.rs"], 2965 deps = ["//basic/3rdparty/crates:bzip2"], 2966 visibility = ["//visibility:public"], 2967) 2968</ code ></ pre > 2969< p > Note, the vendored dependency is not yet accessible because you have to define first 2970how to load the vendored dependencies. For that, you first create a file< code > sys_deps.bzl</ code > 2971and add the following content:</ p > 2972< pre >< code class ="language-starlark "> # rename the default name "crate_repositories" in case you import multiple vendored folders. 2973load("//basic/3rdparty/crates:defs.bzl", basic_crate_repositories = "crate_repositories") 2974 2975def sys_deps(): 2976 # Load the vendored dependencies 2977 basic_crate_repositories() 2978</ code ></ pre > 2979< p > This is straightforward, you import the generated crate_repositories from the crates folder, 2980rename it to avoid name clashes in case you import from multiple vendored folders, and then 2981just load the vendored dependencies.</ p > 2982< p > In a WORKSPACE configuration, you would just load and call sys_deps(), but in a MODULE configuration, you cannot do that. 2983Instead, you create a new file< code > WORKSPACE.bzlmod</ code > and add the following content.</ p > 2984< pre >< code class ="language-starlark "> load("//:sys_deps.bzl", "sys_deps") 2985sys_deps() 2986</ code ></ pre > 2987< p > Now, you can build the project as usual.</ p > 2988< 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 > 2989< p >< a id ="crate "></ a ></ p > 2990< h2 id ="crate ">< a class ="header "href ="#crate "> crate</ a ></ h2 > 2991< pre > 2992crate = use_extension("@rules_rust//crate_universe:docs_bzlmod.bzl", "crate") 2993crate.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 > , 2994< a href ="crate_universe_bzlmod.html#crate.annotation-build_script_data "> build_script_data</ a > ,< a href ="crate_universe_bzlmod.html#crate.annotation-build_script_data_glob "> build_script_data_glob</ a > ,< a href ="crate_universe_bzlmod.html#crate.annotation-build_script_deps "> build_script_deps</ a > ,< a href ="crate_universe_bzlmod.html#crate.annotation-build_script_env "> build_script_env</ a > , 2995< 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 > , 2996< 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-crate "> crate</ a > , 2997< 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 > , 2998< 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 > , 2999< 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 > , 3000< 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 > , 3001< 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 > ) 3002crate.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 > , 3003< a href ="crate_universe_bzlmod.html#crate.from_cargo-manifests "> manifests</ a > ,< a href ="crate_universe_bzlmod.html#crate.from_cargo-splicing_config "> splicing_config</ a > ,< a href ="crate_universe_bzlmod.html#crate.from_cargo-supported_platform_triples "> supported_platform_triples</ a > ) 3004crate.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-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-splicing_config "> splicing_config</ a > , 3005< a href ="crate_universe_bzlmod.html#crate.from_specs-supported_platform_triples "> supported_platform_triples</ a > ) 3006crate.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-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 > ) 3007</ pre > 3008< p > Crate universe module extensions.</ p > 3009< p >< strong > TAG CLASSES</ strong ></ p > 3010< p >< a id ="crate.annotation "></ a ></ p > 3011< h3 id ="annotation ">< a class ="header "href ="#annotation "> annotation</ a ></ h3 > 3012< p >< strong > Attributes</ strong ></ p > 3013< 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 > 3014< 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 > 3015< 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 > 3016< 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 > 3017< 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 > 3018< 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 > 3019< 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 > 3020< 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 > 3021< 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 > 3022< 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 > 3023< 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 > 3024< 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 > 3025< 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 > 3026< 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 > 3027< 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 > 3028< 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 > 3029< 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 > 3030< 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 > 3031< 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 > 3032< 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 > 3033< 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 > 3034< 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 > 3035< 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 > 3036< 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 > 3037< tr >< td style ="text-align: left ">< a id ="crate.annotation-gen_build_script "></ a > gen_build_script</ td >< td style ="text-align: left "> An authorative 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 > 3038< 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 taget 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 > 3039< 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 taget 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 > 3040< 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 taget 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 > 3041< 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 taget 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 > 3042< 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 > 3043< 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 > 3044< 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 > 3045< 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 > 3046< 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 > 3047< 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 > 3048< 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 > 3049< 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 > 3050< 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 > 3051< 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 > 3052</ tbody ></ table > 3053</ div > 3054< p >< a id ="crate.from_cargo "></ a ></ p > 3055< h3 id ="from_cargo ">< a class ="header "href ="#from_cargo "> from_cargo</ a ></ h3 > 3056< p > Generates a repo @crates from a Cargo.toml / Cargo.lock pair.</ p > 3057< p >< strong > Attributes</ strong ></ p > 3058< 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 > 3059< 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 > 3060< 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 > 3061< 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 > 3062< 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 > 3063< 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 > 3064< 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 > 3065< tr >< td style ="text-align: left ">< a id ="crate.from_cargo-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 > 3066< 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-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", "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-none-elf", "s390x-unknown-linux-gnu", "thumbv7em-none-eabi", "thumbv8m.main-none-eabi", "wasm32-unknown-unknown", "wasm32-wasip1", "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"]</ code ></ td ></ tr > 3067</ tbody ></ table > 3068</ div > 3069< p >< a id ="crate.from_specs "></ a ></ p > 3070< h3 id ="from_specs ">< a class ="header "href ="#from_specs "> from_specs</ a ></ h3 > 3071< p > Generates a repo @crates from the defined< code > spec</ code > tags.</ p > 3072< p >< strong > Attributes</ strong ></ p > 3073< 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 > 3074< 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 > 3075< 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 > 3076< 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 > 3077< 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 > 3078< tr >< td style ="text-align: left ">< a id ="crate.from_specs-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 > 3079< 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-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", "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-none-elf", "s390x-unknown-linux-gnu", "thumbv7em-none-eabi", "thumbv8m.main-none-eabi", "wasm32-unknown-unknown", "wasm32-wasip1", "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"]</ code ></ td ></ tr > 3080</ tbody ></ table > 3081</ div > 3082< p >< a id ="crate.spec "></ a ></ p > 3083< h3 id ="spec ">< a class ="header "href ="#spec "> spec</ a ></ h3 > 3084< p >< strong > Attributes</ strong ></ p > 3085< 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 > 3086< 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 > 3087< 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 > 3088< 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 > 3089< 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 > 3090< 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 > 3091< 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 > 3092< 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 > 3093< 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 > 3094< 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 > 3095< 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 > 3096</ tbody ></ table > 3097</ div >< div style ="break-before: page; page-break-before: always; "></ div > <!-- Generated with Stardoc: http://skydoc.bazel.build --> 3098< h1 id ="crate-universe-1 ">< a class ="header "href ="#crate-universe-1 "> Crate Universe</ a ></ h1 > 3099< p > Crate Universe is a set of Bazel rule for generating Rust targets using Cargo.</ p > 3100< p > This doc describes using crate_universe from a WORKSPACE file.</ p > 3101< p > If you're using bzlmod, please see< a href ="crate_universe_bzlmod.html "> the bzlmod equivalent of this doc</ a > .</ p > 3102< h2 id ="setup-5 ">< a class ="header "href ="#setup-5 "> Setup</ a ></ h2 > 3103< p > After loading< code > rules_rust</ code > in your workspace, set the following to begin using< code > crate_universe</ code > :</ p > 3104< pre >< code class ="language-python "> load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies") 3105 3106crate_universe_dependencies() 3107</ code ></ pre > 3108< p > Note that if the current version of< code > rules_rust</ code > is not a release artifact, you may need to set additional 3109flags such as< a href ="crate_universe.html#crate_universe_dependencies-bootstrap ">< code > bootstrap = True</ code ></ a > on the< code > crate_universe_dependencies</ code > 3110call above or< a href ="crate_universe.html#crates_repository-generator_urls "> crates_repository::generator_urls</ a > in uses of< code > crates_repository</ code > .</ p > 3111< h2 id ="rules-1 ">< a class ="header "href ="#rules-1 "> Rules</ a ></ h2 > 3112< ul > 3113< li >< a href ="crate_universe.html#crates_repository "> crates_repository</ a ></ li > 3114< li >< a href ="crate_universe.html#crates_vendor "> crates_vendor</ a ></ li > 3115</ ul > 3116< h2 id ="utility-macros ">< a class ="header "href ="#utility-macros "> Utility Macros</ a ></ h2 > 3117< ul > 3118< li >< a href ="crate_universe.html#crate_universe_dependencies "> crate_universe_dependencies</ a ></ li > 3119< li >< a href ="crate_universe.html#crateannotation "> crate.annotation</ a ></ li > 3120< li >< a href ="crate_universe.html#crateselect "> crate.select</ a ></ li > 3121< li >< a href ="crate_universe.html#cratespec "> crate.spec</ a ></ li > 3122< li >< a href ="crate_universe.html#crateworkspace_member "> crate.workspace_member</ a ></ li > 3123< li >< a href ="crate_universe.html#render_config "> render_config</ a ></ li > 3124< li >< a href ="crate_universe.html#splicing_config "> splicing_config</ a ></ li > 3125</ ul > 3126< h2 id ="workflows ">< a class ="header "href ="#workflows "> Workflows</ a ></ h2 > 3127< p > The< a href ="crate_universe.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 3128ways users can express and organize their dependencies. The most common are listed below though there are more to be found in 3129the< a href ="https://github.com/bazelbuild/rules_rust/tree/main/examples/crate_universe "> ./examples/crate_universe</ a > directory.</ p > 3130< h3 id ="cargo-workspaces-1 ">< a class ="header "href ="#cargo-workspaces-1 "> Cargo Workspaces</ a ></ h3 > 3131< 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 > . 3132The< code > crates_repository</ code > rule can ingest a root< code > Cargo.toml</ code > file and generate dependencies from there.</ p > 3133< pre >< code class ="language-python "> load("@rules_rust//crate_universe:defs.bzl", "crates_repository") 3134 3135crates_repository( 3136 name = "crate_index", 3137 cargo_lockfile = "//:Cargo.lock", 3138 lockfile = "//:Cargo.Bazel.lock", 3139 manifests = ["//:Cargo.toml"], 3140) 3141 3142load("@crate_index//:defs.bzl", "crate_repositories") 3143 3144crate_repositories() 3145</ code ></ pre > 3146< p > The generated< code > crates_repository</ code > contains helper macros which make collecting dependencies for Bazel targets simpler. 3147Notably, the< code > all_crate_deps</ code > and< code > aliases</ code > macros (see< a href ="crate_universe.html#dependencies-api "> Dependencies API</ a > ) commonly allow the 3148< code > Cargo.toml</ code > files to be the single source of truth for dependencies. Since these macros come from the generated 3149repository, the dependencies and alias definitions they return will automatically update BUILD targets.</ p > 3150< pre >< code class ="language-python "> load("@crate_index//:defs.bzl", "aliases", "all_crate_deps") 3151load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 3152 3153rust_library( 3154 name = "lib", 3155 aliases = aliases(), 3156 deps = all_crate_deps( 3157 normal = True, 3158 ), 3159 proc_macro_deps = all_crate_deps( 3160 proc_macro = True, 3161 ), 3162) 3163 3164rust_test( 3165 name = "unit_test", 3166 crate = ":lib", 3167 aliases = aliases( 3168 normal_dev = True, 3169 proc_macro_dev = True, 3170 ), 3171 deps = all_crate_deps( 3172 normal_dev = True, 3173 ), 3174 proc_macro_deps = all_crate_deps( 3175 proc_macro_dev = True, 3176 ), 3177) 3178</ code ></ pre > 3179< h3 id ="direct-packages ">< a class ="header "href ="#direct-packages "> Direct Packages</ a ></ h3 > 3180< p > In cases where Rust targets have heavy interractions with other Bazel targests (< 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.), 3181maintaining< 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 3182about missing targets or environment variables defined only in Bazel. In workspaces like this, it may be desirable 3183to have a "Cargo free" setup.< code > crates_repository</ code > supports this through the< code > packages</ code > attribute.</ p > 3184< pre >< code class ="language-python "> load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_repository", "render_config") 3185 3186crates_repository( 3187 name = "crate_index", 3188 cargo_lockfile = "//:Cargo.lock", 3189 lockfile = "//:Cargo.Bazel.lock", 3190 packages = { 3191 "async-trait": crate.spec( 3192 version = "0.1.51", 3193 ), 3194 "mockall": crate.spec( 3195 version = "0.10.2", 3196 ), 3197 "tokio": crate.spec( 3198 version = "1.12.0", 3199 ), 3200 }, 3201 # Setting the default package name to `""` forces the use of the macros defined in this repository 3202 # to always use the root package when looking for dependencies or aliases. This should be considered 3203 # optional as the repository also exposes alises for easy access to all dependencies. 3204 render_config = render_config( 3205 default_package_name = "" 3206 ), 3207) 3208 3209load("@crate_index//:defs.bzl", "crate_repositories") 3210 3211crate_repositories() 3212</ code ></ pre > 3213< p > Consuming dependencies may be more ergonomic in this case through the aliases defined in the new repository.</ p > 3214< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 3215 3216rust_library( 3217 name = "lib", 3218 deps = [ 3219 "@crate_index//:tokio", 3220 ], 3221 proc_macro_deps = [ 3222 "@crate_index//:async-trait", 3223 ], 3224) 3225 3226rust_test( 3227 name = "unit_test", 3228 crate = ":lib", 3229 deps = [ 3230 "@crate_index//:mockall", 3231 ], 3232) 3233</ code ></ pre > 3234< h3 id ="binary-dependencies ">< a class ="header "href ="#binary-dependencies "> Binary dependencies</ a ></ h3 > 3235< p > Neither of the above approaches supports depending on binary-only packages.</ p > 3236< p > In order to depend on a Cargo package that contains binaries and no library, you 3237will need to do one of the following:</ p > 3238< ul > 3239< li > 3240< p > Fork the package to add an empty lib.rs, which makes the package visible to 3241Cargo metadata and compatible with the above approaches;</ p > 3242</ li > 3243< li > 3244< p > Or handwrite your own build target for the binary, use< code > http_archive</ code > to 3245import its source code, and use< code > crates_repository</ code > to make build targets for 3246its dependencies. This is demonstrated below using the< code > rustfilt</ code > crate as an 3247example.</ p > 3248</ li > 3249</ ul > 3250< pre >< code class ="language-python "> # in WORKSPACE.bazel 3251 3252load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 3253 3254http_archive( 3255 name = "rustfilt", 3256 build_file = "//rustfilt:BUILD.rustfilt.bazel", 3257 sha256 = "c8d748b182c8f95224336d20dcc5609598af612581ce60cfb29da4dc8d0091f2", 3258 strip_prefix = "rustfilt-0.2.1", 3259 type = "tar.gz", 3260 urls = ["https://static.crates.io/crates/rustfilt/rustfilt-0.2.1.crate"], 3261) 3262 3263load("@rules_rust//crate_universe:defs.bzl", "crates_repository") 3264 3265crates_repository( 3266 name = "rustfilt_deps", 3267 cargo_lockfile = "//rustfilt:Cargo.lock", 3268 manifests = ["@rustfilt//:Cargo.toml"], 3269) 3270 3271load("@rustfilt_deps//:defs.bzl", rustfilt_deps = "crate_repositories") 3272 3273rustfilt_deps() 3274</ code ></ pre > 3275< pre >< code class ="language-python "> # in rustfilt/BUILD.rustfilt.bazel 3276 3277load("@rules_rust//rust:defs.bzl", "rust_binary") 3278 3279rust_binary( 3280 name = "rustfilt", 3281 srcs = glob(["src/**/*.rs"]), 3282 edition = "2018", 3283 deps = [ 3284 "@rustfilt_deps//:clap", 3285 "@rustfilt_deps//:lazy_static", 3286 "@rustfilt_deps//:regex", 3287 "@rustfilt_deps//:rustc-demangle", 3288 ], 3289) 3290</ code ></ pre > 3291< p > If you use either< code > crates_repository</ code > or< code > crates_vendor</ code > to depend on a Cargo 3292package that contains< em > both</ em > a library crate< em > and</ em > binaries, by default only the 3293library gets made available to Bazel. To generate Bazel targets for the binary 3294crates as well, you must opt in to it with an annotation on the package:</ p > 3295< pre >< code class ="language-python "> load("@rules_rust//crate_universe:defs.bzl", "crates_repository", "crate") 3296 3297crates_repository( 3298 name = "crate_index", 3299 annotations = { 3300 "thepackage": [crate.annotation( 3301 gen_binaries = True, 3302 # Or, to expose just a subset of the package's binaries by name: 3303 gen_binaries = ["rustfilt"], 3304 )], 3305 }, 3306 # Or, to expose every binary of every package: 3307 generate_binaries = True, 3308 ... 3309) 3310</ code ></ pre > 3311< h2 id ="dependencies-api ">< a class ="header "href ="#dependencies-api "> Dependencies API</ a ></ h2 > 3312< p > After rendering dependencies, convenience macros may also be generated to provide 3313convenient accessors to larger sections of the dependency graph.</ p > 3314< ul > 3315< li >< a href ="crate_universe.html#aliases "> aliases</ a ></ li > 3316< li >< a href ="crate_universe.html#crate_deps "> crate_deps</ a ></ li > 3317< li >< a href ="crate_universe.html#all_crate_deps "> all_crate_deps</ a ></ li > 3318< li >< a href ="crate_universe.html#crate_repositories "> crate_repositories</ a ></ li > 3319</ ul > 3320< h2 id ="building-crates-with-complicated-dependencies ">< a class ="header "href ="#building-crates-with-complicated-dependencies "> Building crates with complicated dependencies</ a ></ h2 > 3321< 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 > 3322< p > There are a few approaches to making sure these run:</ p > 3323< h3 id ="some-things-work-without-intervention ">< a class ="header "href ="#some-things-work-without-intervention "> Some things work without intervention</ a ></ h3 > 3324< p > Some build scripts will happily run without any support needed.</ p > 3325< 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 > 3326< 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 > 3327< h3 id ="supplying-extra-tools-to-build ">< a class ="header "href ="#supplying-extra-tools-to-build "> Supplying extra tools to build</ a ></ h3 > 3328< p > Some build scripts can be made to work by pulling in some extra files and making them available to the build script.</ p > 3329< 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 > 3330< 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 libz-ng-sys.</ p > 3331< 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 > 3332< p > Some build scripts have hooks to allow replacing parts that are complicated to build with output prepared by Bazel.</ p > 3333< 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 > 3334< 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 > 3335< hr /> 3336< hr /> 3337< p >< a id ="crates_vendor "></ a ></ p > 3338< h2 id ="crates_vendor ">< a class ="header "href ="#crates_vendor "> crates_vendor</ a ></ h2 > 3339< pre > 3340crates_vendor(< a href ="crate_universe.html#crates_vendor-name "> name</ a > ,< a href ="crate_universe.html#crates_vendor-annotations "> annotations</ a > ,< a href ="crate_universe.html#crates_vendor-bazel "> bazel</ a > ,< a href ="crate_universe.html#crates_vendor-buildifier "> buildifier</ a > ,< a href ="crate_universe.html#crates_vendor-cargo_bazel "> cargo_bazel</ a > ,< a href ="crate_universe.html#crates_vendor-cargo_config "> cargo_config</ a > ,< a href ="crate_universe.html#crates_vendor-cargo_lockfile "> cargo_lockfile</ a > , 3341< a href ="crate_universe.html#crates_vendor-generate_binaries "> generate_binaries</ a > ,< a href ="crate_universe.html#crates_vendor-generate_build_scripts "> generate_build_scripts</ a > ,< a href ="crate_universe.html#crates_vendor-generate_target_compatible_with "> generate_target_compatible_with</ a > ,< a href ="crate_universe.html#crates_vendor-manifests "> manifests</ a > , 3342< a href ="crate_universe.html#crates_vendor-mode "> mode</ a > ,< a href ="crate_universe.html#crates_vendor-packages "> packages</ a > ,< a href ="crate_universe.html#crates_vendor-render_config "> render_config</ a > ,< a href ="crate_universe.html#crates_vendor-repository_name "> repository_name</ a > ,< a href ="crate_universe.html#crates_vendor-splicing_config "> splicing_config</ a > , 3343< a href ="crate_universe.html#crates_vendor-supported_platform_triples "> supported_platform_triples</ a > ,< a href ="crate_universe.html#crates_vendor-vendor_path "> vendor_path</ a > ) 3344</ pre > 3345< p > A rule for defining Rust dependencies (crates) and writing targets for them to the current workspace. 3346This rule is useful for users whose workspaces are expected to be consumed in other workspaces as the 3347rendered< code > BUILD</ code > files reduce the number of workspace dependencies, allowing for easier loads. This rule 3348handles all the same< a href ="crate_universe.html#workflows "> workflows</ a > < code > crate_universe</ code > rules do.</ p > 3349< p > Example:</ p > 3350< p > Given the following workspace structure:</ p > 3351< pre >< code class ="language-text "> [workspace]/ 3352 WORKSPACE 3353 BUILD 3354 Cargo.toml 3355 3rdparty/ 3356 BUILD 3357 src/ 3358 main.rs 3359</ code ></ pre > 3360< p > The following is something that'd be found in< code > 3rdparty/BUILD</ code > :</ p > 3361< pre >< code class ="language-python "> load("@rules_rust//crate_universe:defs.bzl", "crates_vendor", "crate") 3362 3363crates_vendor( 3364 name = "crates_vendor", 3365 annotations = { 3366 "rand": [crate.annotation( 3367 default_features = False, 3368 features = ["small_rng"], 3369 )], 3370 }, 3371 cargo_lockfile = "//:Cargo.Bazel.lock", 3372 manifests = ["//:Cargo.toml"], 3373 mode = "remote", 3374 vendor_path = "crates", 3375 tags = ["manual"], 3376) 3377</ code ></ pre > 3378< p > The above creates a target that can be run to write< code > BUILD</ code > files into the< code > 3rdparty</ code > 3379directory next to where the target is defined. To run it, simply call:</ p > 3380< pre >< code class ="language-shell "> bazel run //3rdparty:crates_vendor 3381</ code ></ pre > 3382< p >< a id ="#crates_vendor_repinning_updating_dependencies "></ a ></ p > 3383< h3 id ="repinning--updating-dependencies ">< a class ="header "href ="#repinning--updating-dependencies "> Repinning / Updating Dependencies</ a ></ h3 > 3384< p > Repinning dependencies is controlled by both the< code > CARGO_BAZEL_REPIN</ code > environment variable or the< code > --repin</ code > 3385flag to the< code > crates_vendor</ code > binary. To update dependencies, simply add the flag ro your< code > bazel run</ code > invocation.</ p > 3386< pre >< code class ="language-shell "> bazel run //3rdparty:crates_vendor -- --repin 3387</ code ></ pre > 3388< 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 > 3389call against the generated workspace. The following table describes how to control particular values passed to the 3390< code > cargo update</ code > command.</ p > 3391< div class ="table-wrapper ">< table >< thead >< tr >< th > Value</ th >< th > Cargo command</ th ></ tr ></ thead >< tbody > 3392< 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 > 3393< tr >< td > Any of [< code > full</ code > ,< code > eager</ code > ,< code > all</ code > ]</ td >< td >< code > cargo update</ code ></ td ></ tr > 3394< tr >< td >< code > package_name</ code ></ td >< td >< code > cargo upgrade --package package_name</ code ></ td ></ tr > 3395< tr >< td >< code > package_name@1.2.3</ code ></ td >< td >< code > cargo upgrade --package package_name --precise 1.2.3</ code ></ td ></ tr > 3396</ tbody ></ table > 3397</ div > 3398< p >< strong > ATTRIBUTES</ strong ></ p > 3399< 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 > 3400< 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 > 3401< 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.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 > 3402< 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 > 3403< 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 > 3404< 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~cargo_bazel_bootstrap//:binary"</ code ></ td ></ tr > 3405< 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 > 3406< 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 > 3407< 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 > 3408< 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 > 3409< 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 > 3410< 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 > 3411< 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 > 3412< 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.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 > 3413< 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 > 3414< 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 > 3415< 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 > 3416< 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", "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-none-elf", "s390x-unknown-linux-gnu", "thumbv7em-none-eabi", "thumbv8m.main-none-eabi", "wasm32-unknown-unknown", "wasm32-wasip1", "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"]</ code ></ td ></ tr > 3417< 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 > 3418</ tbody ></ table > 3419</ div > 3420< p >< a id ="aliases "></ a ></ p > 3421< h2 id ="aliases ">< a class ="header "href ="#aliases "> aliases</ a ></ h2 > 3422< pre > 3423aliases(< a href ="crate_universe.html#aliases-normal "> normal</ a > ,< a href ="crate_universe.html#aliases-normal_dev "> normal_dev</ a > ,< a href ="crate_universe.html#aliases-proc_macro "> proc_macro</ a > ,< a href ="crate_universe.html#aliases-proc_macro_dev "> proc_macro_dev</ a > ,< a href ="crate_universe.html#aliases-build "> build</ a > ,< a href ="crate_universe.html#aliases-build_proc_macro "> build_proc_macro</ a > ,< a href ="crate_universe.html#aliases-package_name "> package_name</ a > ) 3424</ pre > 3425< p > Produces a map of Crate alias names to their original label</ p > 3426< p > If no dependency kinds are specified,< code > normal</ code > and< code > proc_macro</ code > are used by default. 3427Setting any one flag will otherwise determine the contents of the returned dict.</ p > 3428< p >< strong > PARAMETERS</ strong ></ p > 3429< 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 > 3430< tr >< td style ="text-align: left ">< a id ="aliases-normal "></ a > normal</ td >< td style ="text-align: left "> If True, normal dependencies are included in the output list.</ td >< td style ="text-align: left ">< code > False</ code ></ td ></ tr > 3431< tr >< td style ="text-align: left ">< a id ="aliases-normal_dev "></ a > normal_dev</ td >< td style ="text-align: left "> If True, normal dev dependencies will be included in the output list..</ td >< td style ="text-align: left ">< code > False</ code ></ td ></ tr > 3432< tr >< td style ="text-align: left ">< a id ="aliases-proc_macro "></ a > proc_macro</ td >< td style ="text-align: left "> If True, proc_macro dependencies are included in the output list.</ td >< td style ="text-align: left ">< code > False</ code ></ td ></ tr > 3433< tr >< td style ="text-align: left ">< a id ="aliases-proc_macro_dev "></ a > proc_macro_dev</ td >< td style ="text-align: left "> If True, dev proc_macro dependencies are included in the output list.</ td >< td style ="text-align: left ">< code > False</ code ></ td ></ tr > 3434< tr >< td style ="text-align: left ">< a id ="aliases-build "></ a > build</ td >< td style ="text-align: left "> If True, build dependencies are included in the output list.</ td >< td style ="text-align: left ">< code > False</ code ></ td ></ tr > 3435< tr >< td style ="text-align: left ">< a id ="aliases-build_proc_macro "></ a > build_proc_macro</ td >< td style ="text-align: left "> If True, build proc_macro dependencies are included in the output list.</ td >< td style ="text-align: left ">< code > False</ code ></ td ></ tr > 3436< tr >< td style ="text-align: left ">< a id ="aliases-package_name "></ a > package_name</ td >< td style ="text-align: left "> The package name of the set of dependencies to look up. Defaults to< code > native.package_name()</ code > when unset.</ td >< td style ="text-align: left ">< code > None</ code ></ td ></ tr > 3437</ tbody ></ table > 3438</ div > 3439< p >< strong > RETURNS</ strong ></ p > 3440< p > dict: The aliases of all associated packages</ p > 3441< p >< a id ="all_crate_deps "></ a ></ p > 3442< h2 id ="all_crate_deps ">< a class ="header "href ="#all_crate_deps "> all_crate_deps</ a ></ h2 > 3443< pre > 3444all_crate_deps(< a href ="crate_universe.html#all_crate_deps-normal "> normal</ a > ,< a href ="crate_universe.html#all_crate_deps-normal_dev "> normal_dev</ a > ,< a href ="crate_universe.html#all_crate_deps-proc_macro "> proc_macro</ a > ,< a href ="crate_universe.html#all_crate_deps-proc_macro_dev "> proc_macro_dev</ a > ,< a href ="crate_universe.html#all_crate_deps-build "> build</ a > ,< a href ="crate_universe.html#all_crate_deps-build_proc_macro "> build_proc_macro</ a > , 3445< a href ="crate_universe.html#all_crate_deps-package_name "> package_name</ a > ) 3446</ pre > 3447< p > Finds the fully qualified label of all requested direct crate dependencies for the package where this macro is called.</ p > 3448< p > If no parameters are set, all normal dependencies are returned. Setting any one flag will 3449otherwise impact the contents of the returned list.</ p > 3450< p >< strong > PARAMETERS</ strong ></ p > 3451< 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 > 3452< tr >< td style ="text-align: left ">< a id ="all_crate_deps-normal "></ a > normal</ td >< td style ="text-align: left "> If True, normal dependencies are included in the output list.</ td >< td style ="text-align: left ">< code > False</ code ></ td ></ tr > 3453< tr >< td style ="text-align: left ">< a id ="all_crate_deps-normal_dev "></ a > normal_dev</ td >< td style ="text-align: left "> If True, normal dev dependencies will be included in the output list..</ td >< td style ="text-align: left ">< code > False</ code ></ td ></ tr > 3454< tr >< td style ="text-align: left ">< a id ="all_crate_deps-proc_macro "></ a > proc_macro</ td >< td style ="text-align: left "> If True, proc_macro dependencies are included in the output list.</ td >< td style ="text-align: left ">< code > False</ code ></ td ></ tr > 3455< tr >< td style ="text-align: left ">< a id ="all_crate_deps-proc_macro_dev "></ a > proc_macro_dev</ td >< td style ="text-align: left "> If True, dev proc_macro dependencies are included in the output list.</ td >< td style ="text-align: left ">< code > False</ code ></ td ></ tr > 3456< tr >< td style ="text-align: left ">< a id ="all_crate_deps-build "></ a > build</ td >< td style ="text-align: left "> If True, build dependencies are included in the output list.</ td >< td style ="text-align: left ">< code > False</ code ></ td ></ tr > 3457< tr >< td style ="text-align: left ">< a id ="all_crate_deps-build_proc_macro "></ a > build_proc_macro</ td >< td style ="text-align: left "> If True, build proc_macro dependencies are included in the output list.</ td >< td style ="text-align: left ">< code > False</ code ></ td ></ tr > 3458< tr >< td style ="text-align: left ">< a id ="all_crate_deps-package_name "></ a > package_name</ td >< td style ="text-align: left "> The package name of the set of dependencies to look up. Defaults to< code > native.package_name()</ code > when unset.</ td >< td style ="text-align: left ">< code > None</ code ></ td ></ tr > 3459</ tbody ></ table > 3460</ div > 3461< p >< strong > RETURNS</ strong ></ p > 3462< p > list: A list of labels to generated rust targets (str)</ p > 3463< p >< a id ="crate.annotation "></ a ></ p > 3464< h2 id ="crateannotation ">< a class ="header "href ="#crateannotation "> crate.annotation</ a ></ h2 > 3465< pre > 3466crate.annotation(< a href ="crate_universe.html#crate.annotation-version "> version</ a > ,< a href ="crate_universe.html#crate.annotation-additive_build_file "> additive_build_file</ a > ,< a href ="crate_universe.html#crate.annotation-additive_build_file_content "> additive_build_file_content</ a > ,< a href ="crate_universe.html#crate.annotation-alias_rule "> alias_rule</ a > , 3467< a href ="crate_universe.html#crate.annotation-build_script_compile_data "> build_script_compile_data</ a > ,< a href ="crate_universe.html#crate.annotation-build_script_data "> build_script_data</ a > ,< a href ="crate_universe.html#crate.annotation-build_script_tools "> build_script_tools</ a > , 3468< a href ="crate_universe.html#crate.annotation-build_script_data_glob "> build_script_data_glob</ a > ,< a href ="crate_universe.html#crate.annotation-build_script_deps "> build_script_deps</ a > ,< a href ="crate_universe.html#crate.annotation-build_script_env "> build_script_env</ a > , 3469< a href ="crate_universe.html#crate.annotation-build_script_proc_macro_deps "> build_script_proc_macro_deps</ a > ,< a href ="crate_universe.html#crate.annotation-build_script_rundir "> build_script_rundir</ a > ,< a href ="crate_universe.html#crate.annotation-build_script_rustc_env "> build_script_rustc_env</ a > , 3470< a href ="crate_universe.html#crate.annotation-build_script_toolchains "> build_script_toolchains</ a > ,< a href ="crate_universe.html#crate.annotation-compile_data "> compile_data</ a > ,< a href ="crate_universe.html#crate.annotation-compile_data_glob "> compile_data_glob</ a > ,< a href ="crate_universe.html#crate.annotation-crate_features "> crate_features</ a > ,< a href ="crate_universe.html#crate.annotation-data "> data</ a > , 3471< a href ="crate_universe.html#crate.annotation-data_glob "> data_glob</ a > ,< a href ="crate_universe.html#crate.annotation-deps "> deps</ a > ,< a href ="crate_universe.html#crate.annotation-extra_aliased_targets "> extra_aliased_targets</ a > ,< a href ="crate_universe.html#crate.annotation-gen_binaries "> gen_binaries</ a > ,< a href ="crate_universe.html#crate.annotation-disable_pipelining "> disable_pipelining</ a > , 3472< a href ="crate_universe.html#crate.annotation-gen_build_script "> gen_build_script</ a > ,< a href ="crate_universe.html#crate.annotation-patch_args "> patch_args</ a > ,< a href ="crate_universe.html#crate.annotation-patch_tool "> patch_tool</ a > ,< a href ="crate_universe.html#crate.annotation-patches "> patches</ a > ,< a href ="crate_universe.html#crate.annotation-proc_macro_deps "> proc_macro_deps</ a > ,< a href ="crate_universe.html#crate.annotation-rustc_env "> rustc_env</ a > , 3473< a href ="crate_universe.html#crate.annotation-rustc_env_files "> rustc_env_files</ a > ,< a href ="crate_universe.html#crate.annotation-rustc_flags "> rustc_flags</ a > ,< a href ="crate_universe.html#crate.annotation-shallow_since "> shallow_since</ a > ,< a href ="crate_universe.html#crate.annotation-override_targets "> override_targets</ a > ) 3474</ pre > 3475< p > A collection of extra attributes and settings for a particular crate</ p > 3476< p >< strong > PARAMETERS</ strong ></ p > 3477< 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 > 3478< 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 > 3479< 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 > 3480< 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 > 3481< 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.html#render_config "> render_config</ a > 's 'default_alias_rule'.</ td >< td style ="text-align: left ">< code > None</ code ></ td ></ tr > 3482< 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 > 3483< 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 > 3484< 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 > 3485< 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 > 3486< 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 > 3487< 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 ">< code > None</ code ></ td ></ tr > 3488< 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 > 3489< 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 > 3490< 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 ">< code > None</ code ></ td ></ tr > 3491< 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 > 3492< 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 > 3493< 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 > 3494< 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 > 3495< 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 > 3496< 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 > 3497< 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 > 3498< 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 > 3499< 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 > 3500< 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 > 3501< tr >< td style ="text-align: left ">< a id ="crate.annotation-gen_build_script "></ a > gen_build_script</ td >< td style ="text-align: left "> An authorative 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 > 3502< 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 > 3503< 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 > 3504< 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 > 3505< 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 > 3506< 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 > 3507< 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 > 3508< 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 > 3509< 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 > 3510< 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-marco</ code > ,< code > custom-build</ code > ,< code > lib</ code > ,< code > bin</ code > .</ td >< td style ="text-align: left ">< code > None</ code ></ td ></ tr > 3511</ tbody ></ table > 3512</ div > 3513< p >< strong > RETURNS</ strong ></ p > 3514< p > string: A json encoded string containing the specified version and separately all other inputs.</ p > 3515< p >< a id ="crate.select "></ a ></ p > 3516< h2 id ="crateselect ">< a class ="header "href ="#crateselect "> crate.select</ a ></ h2 > 3517< pre > 3518crate.select(< a href ="crate_universe.html#crate.select-common "> common</ a > ,< a href ="crate_universe.html#crate.select-selects "> selects</ a > ) 3519</ pre > 3520< p > A Starlark Select for< code > crate.annotation()</ code > .</ p > 3521< p >< strong > PARAMETERS</ strong ></ p > 3522< 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 > 3523< 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 > 3524< 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 > 3525</ tbody ></ table > 3526</ div > 3527< p >< strong > RETURNS</ strong ></ p > 3528< p > struct: A struct representing the Starlark Select.</ p > 3529< p >< a id ="crate.spec "></ a ></ p > 3530< h2 id ="cratespec ">< a class ="header "href ="#cratespec "> crate.spec</ a ></ h2 > 3531< pre > 3532crate.spec(< a href ="crate_universe.html#crate.spec-package "> package</ a > ,< a href ="crate_universe.html#crate.spec-version "> version</ a > ,< a href ="crate_universe.html#crate.spec-artifact "> artifact</ a > ,< a href ="crate_universe.html#crate.spec-lib "> lib</ a > ,< a href ="crate_universe.html#crate.spec-default_features "> default_features</ a > ,< a href ="crate_universe.html#crate.spec-features "> features</ a > ,< a href ="crate_universe.html#crate.spec-git "> git</ a > ,< a href ="crate_universe.html#crate.spec-branch "> branch</ a > ,< a href ="crate_universe.html#crate.spec-tag "> tag</ a > ,< a href ="crate_universe.html#crate.spec-rev "> rev</ a > ) 3533</ pre > 3534< p > A constructor for a crate dependency.</ p > 3535< 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 > 3536< p >< strong > PARAMETERS</ strong ></ p > 3537< 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 > 3538< 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 > 3539< 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 > 3540< 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 > 3541< 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 > 3542< 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 > 3543< 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 > 3544< 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 > 3545< 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 > 3546< 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 > 3547< 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 > 3548</ tbody ></ table > 3549</ div > 3550< p >< strong > RETURNS</ strong ></ p > 3551< p > string: A json encoded string of all inputs</ p > 3552< p >< a id ="crate.workspace_member "></ a ></ p > 3553< h2 id ="crateworkspace_member ">< a class ="header "href ="#crateworkspace_member "> crate.workspace_member</ a ></ h2 > 3554< pre > 3555crate.workspace_member(< a href ="crate_universe.html#crate.workspace_member-version "> version</ a > ,< a href ="crate_universe.html#crate.workspace_member-sha256 "> sha256</ a > ) 3556</ pre > 3557< p > Define information for extra workspace members</ p > 3558< p >< strong > PARAMETERS</ strong ></ p > 3559< 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 > 3560< 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 > 3561< 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 > 3562</ tbody ></ table > 3563</ div > 3564< p >< strong > RETURNS</ strong ></ p > 3565< p > string: A json encoded string of all inputs</ p > 3566< p >< a id ="crate_deps "></ a ></ p > 3567< h2 id ="crate_deps ">< a class ="header "href ="#crate_deps "> crate_deps</ a ></ h2 > 3568< pre > 3569crate_deps(< a href ="crate_universe.html#crate_deps-deps "> deps</ a > ,< a href ="crate_universe.html#crate_deps-package_name "> package_name</ a > ) 3570</ pre > 3571< p > Finds the fully qualified label of the requested crates for the package where this macro is called.</ p > 3572< p >< strong > PARAMETERS</ strong ></ p > 3573< 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 > 3574< tr >< td style ="text-align: left ">< a id ="crate_deps-deps "></ a > deps</ td >< td style ="text-align: left "> The desired list of crate targets.</ td >< td style ="text-align: left "> none</ td ></ tr > 3575< tr >< td style ="text-align: left ">< a id ="crate_deps-package_name "></ a > package_name</ td >< td style ="text-align: left "> The package name of the set of dependencies to look up. Defaults to< code > native.package_name()</ code > .</ td >< td style ="text-align: left ">< code > None</ code ></ td ></ tr > 3576</ tbody ></ table > 3577</ div > 3578< p >< strong > RETURNS</ strong ></ p > 3579< p > list: A list of labels to generated rust targets (str)</ p > 3580< p >< a id ="crate_repositories "></ a ></ p > 3581< h2 id ="crate_repositories ">< a class ="header "href ="#crate_repositories "> crate_repositories</ a ></ h2 > 3582< pre > 3583crate_repositories() 3584</ pre > 3585< p > A macro for defining repositories for all generated crates.</ p > 3586< p >< strong > RETURNS</ strong ></ p > 3587< p > A list of repos visible to the module through the module extension.</ p > 3588< p >< a id ="crate_universe_dependencies "></ a ></ p > 3589< h2 id ="crate_universe_dependencies ">< a class ="header "href ="#crate_universe_dependencies "> crate_universe_dependencies</ a ></ h2 > 3590< pre > 3591crate_universe_dependencies(< a href ="crate_universe.html#crate_universe_dependencies-rust_version "> rust_version</ a > ,< a href ="crate_universe.html#crate_universe_dependencies-bootstrap "> bootstrap</ a > ,< a href ="crate_universe.html#crate_universe_dependencies-kwargs "> kwargs</ a > ) 3592</ pre > 3593< p > Define dependencies of the< code > cargo-bazel</ code > Rust target</ p > 3594< p >< strong > PARAMETERS</ strong ></ p > 3595< 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 > 3596< tr >< td style ="text-align: left ">< a id ="crate_universe_dependencies-rust_version "></ a > rust_version</ td >< td style ="text-align: left "> The version of rust to use when generating dependencies.</ td >< td style ="text-align: left ">< code > "1.83.0"</ code ></ td ></ tr > 3597< tr >< td style ="text-align: left ">< a id ="crate_universe_dependencies-bootstrap "></ a > bootstrap</ td >< td style ="text-align: left "> If true, a< code > cargo_bootstrap_repository</ code > target will be generated.</ td >< td style ="text-align: left ">< code > False</ code ></ td ></ tr > 3598< tr >< td style ="text-align: left ">< a id ="crate_universe_dependencies-kwargs "></ a > kwargs</ td >< td style ="text-align: left "> Arguments to pass through to cargo_bazel_bootstrap.</ td >< td style ="text-align: left "> none</ td ></ tr > 3599</ tbody ></ table > 3600</ div > 3601< p >< strong > RETURNS</ strong ></ p > 3602< p > list[struct(repo=str, is_dev_dep=bool)]: A list of the repositories 3603defined by this macro.</ p > 3604< p >< a id ="render_config "></ a ></ p > 3605< h2 id ="render_config ">< a class ="header "href ="#render_config "> render_config</ a ></ h2 > 3606< pre > 3607render_config(< a href ="crate_universe.html#render_config-build_file_template "> build_file_template</ a > ,< a href ="crate_universe.html#render_config-crate_label_template "> crate_label_template</ a > ,< a href ="crate_universe.html#render_config-crate_repository_template "> crate_repository_template</ a > , 3608< a href ="crate_universe.html#render_config-crates_module_template "> crates_module_template</ a > ,< a href ="crate_universe.html#render_config-default_alias_rule "> default_alias_rule</ a > ,< a href ="crate_universe.html#render_config-default_package_name "> default_package_name</ a > , 3609< a href ="crate_universe.html#render_config-generate_target_compatible_with "> generate_target_compatible_with</ a > ,< a href ="crate_universe.html#render_config-platforms_template "> platforms_template</ a > ,< a href ="crate_universe.html#render_config-regen_command "> regen_command</ a > ,< a href ="crate_universe.html#render_config-vendor_mode "> vendor_mode</ a > , 3610< a href ="crate_universe.html#render_config-generate_rules_license_metadata "> generate_rules_license_metadata</ a > ) 3611</ pre > 3612< p > Various settings used to configure rendered outputs</ p > 3613< p > The template parameters each support a select number of format keys. A description of each key 3614can be found below where the supported keys for each template can be found in the parameter docs</ p > 3615< div class ="table-wrapper ">< table >< thead >< tr >< th > key</ th >< th > definition</ th ></ tr ></ thead >< tbody > 3616< tr >< td >< code > name</ code ></ td >< td > The name of the crate. Eg< code > tokio</ code ></ td ></ tr > 3617< tr >< td >< code > repository</ code ></ td >< td > The rendered repository name for the crate. Directly relates to< code > crate_repository_template</ code > .</ td ></ tr > 3618< tr >< td >< code > triple</ code ></ td >< td > A platform triple. Eg< code > x86_64-unknown-linux-gnu</ code ></ td ></ tr > 3619< tr >< td >< code > version</ code ></ td >< td > The crate version. Eg< code > 1.2.3</ code ></ td ></ tr > 3620< tr >< td >< code > target</ code ></ td >< td > The library or binary target of the crate</ td ></ tr > 3621< tr >< td >< code > file</ code ></ td >< td > The basename of a file</ td ></ tr > 3622</ tbody ></ table > 3623</ div > 3624< p >< strong > PARAMETERS</ strong ></ p > 3625< 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 > 3626< 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 > 3627< 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 > 3628< 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 > 3629< 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 > 3630< 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 > 3631< 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 > 3632< 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 > 3633< 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 > 3634< 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 > 3635< 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 > 3636< 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 metedata</ td >< td style ="text-align: left ">< code > False</ code ></ td ></ tr > 3637</ tbody ></ table > 3638</ div > 3639< p >< strong > RETURNS</ strong ></ p > 3640< p > string: A json encoded struct to match the Rust< code > config::RenderConfig</ code > struct</ p > 3641< p >< a id ="splicing_config "></ a ></ p > 3642< h2 id ="splicing_config ">< a class ="header "href ="#splicing_config "> splicing_config</ a ></ h2 > 3643< pre > 3644splicing_config(< a href ="crate_universe.html#splicing_config-resolver_version "> resolver_version</ a > ) 3645</ pre > 3646< p > Various settings used to configure Cargo manifest splicing behavior.</ p > 3647< p >< strong > PARAMETERS</ strong ></ p > 3648< 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 > 3649< 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 > 3650</ tbody ></ table > 3651</ div > 3652< p >< strong > RETURNS</ strong ></ p > 3653< p > str: A json encoded string of the parameters provided</ p > 3654< p >< a id ="crates_repository "></ a ></ p > 3655< h2 id ="crates_repository ">< a class ="header "href ="#crates_repository "> crates_repository</ a ></ h2 > 3656< pre > 3657crates_repository(< a href ="crate_universe.html#crates_repository-name "> name</ a > ,< a href ="crate_universe.html#crates_repository-annotations "> annotations</ a > ,< a href ="crate_universe.html#crates_repository-cargo_config "> cargo_config</ a > ,< a href ="crate_universe.html#crates_repository-cargo_lockfile "> cargo_lockfile</ a > , 3658< a href ="crate_universe.html#crates_repository-compressed_windows_toolchain_names "> compressed_windows_toolchain_names</ a > ,< a href ="crate_universe.html#crates_repository-generate_binaries "> generate_binaries</ a > ,< a href ="crate_universe.html#crates_repository-generate_build_scripts "> generate_build_scripts</ a > , 3659< a href ="crate_universe.html#crates_repository-generate_target_compatible_with "> generate_target_compatible_with</ a > ,< a href ="crate_universe.html#crates_repository-generator "> generator</ a > ,< a href ="crate_universe.html#crates_repository-generator_sha256s "> generator_sha256s</ a > ,< a href ="crate_universe.html#crates_repository-generator_urls "> generator_urls</ a > , 3660< a href ="crate_universe.html#crates_repository-isolated "> isolated</ a > ,< a href ="crate_universe.html#crates_repository-lockfile "> lockfile</ a > ,< a href ="crate_universe.html#crates_repository-manifests "> manifests</ a > ,< a href ="crate_universe.html#crates_repository-packages "> packages</ a > ,< a href ="crate_universe.html#crates_repository-quiet "> quiet</ a > ,< a href ="crate_universe.html#crates_repository-render_config "> render_config</ a > ,< a href ="crate_universe.html#crates_repository-repin_instructions "> repin_instructions</ a > , 3661< a href ="crate_universe.html#crates_repository-repo_mapping "> repo_mapping</ a > ,< a href ="crate_universe.html#crates_repository-rust_toolchain_cargo_template "> rust_toolchain_cargo_template</ a > ,< a href ="crate_universe.html#crates_repository-rust_toolchain_rustc_template "> rust_toolchain_rustc_template</ a > , 3662< a href ="crate_universe.html#crates_repository-rust_version "> rust_version</ a > ,< a href ="crate_universe.html#crates_repository-splicing_config "> splicing_config</ a > ,< a href ="crate_universe.html#crates_repository-supported_platform_triples "> supported_platform_triples</ a > ) 3663</ pre > 3664< p > A rule for defining and downloading Rust dependencies (crates). This rule 3665handles all the same< a href ="crate_universe.html#workflows "> workflows</ a > < code > crate_universe</ code > rules do.</ p > 3666< p > Environment Variables:</ p > 3667< div class ="table-wrapper ">< table >< thead >< tr >< th > variable</ th >< th > usage</ th ></ tr ></ thead >< tbody > 3668< 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 > 3669< 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 > 3670< tr >< td >< code > CARGO_BAZEL_ISOLATED</ code ></ td >< td > An authorative flag as to whether or not the< code > CARGO_HOME</ code > environment variable should be isolated from the host configuration</ td ></ tr > 3671< 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.html#repinning--updating-dependencies "> Repinning / Updating Dependencies</ a > for more details.</ td ></ tr > 3672< 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 > 3673</ tbody ></ table > 3674</ div > 3675< p > Example:</ p > 3676< p > Given the following workspace structure:</ p > 3677< pre >< code class ="language-text "> [workspace]/ 3678 WORKSPACE.bazel 3679 BUILD.bazel 3680 Cargo.toml 3681 Cargo.Bazel.lock 3682 src/ 3683 main.rs 3684</ code ></ pre > 3685< p > The following is something that'd be found in the< code > WORKSPACE</ code > file:</ p > 3686< pre >< code class ="language-python "> load("@rules_rust//crate_universe:defs.bzl", "crates_repository", "crate") 3687 3688crates_repository( 3689 name = "crate_index", 3690 annotations = { 3691 "rand": [crate.annotation( 3692 default_features = False, 3693 features = ["small_rng"], 3694 )], 3695 }, 3696 cargo_lockfile = "//:Cargo.Bazel.lock", 3697 lockfile = "//:cargo-bazel-lock.json", 3698 manifests = ["//:Cargo.toml"], 3699 # Should match the version represented by the currently registered `rust_toolchain`. 3700 rust_version = "1.60.0", 3701) 3702</ code ></ pre > 3703< p > The above will create an external repository which contains aliases and macros for accessing 3704Rust targets found in the dependency graph defined by the given manifests.</ p > 3705< p >< strong > NOTE</ strong > : The< code > cargo_lockfile</ code > and< code > lockfile</ code > must be manually created. The rule unfortunately does not yet create 3706it on its own. When initially setting up this rule, an empty file should be created and then 3707populated by repinning dependencies.</ p > 3708< h3 id ="repinning--updating-dependencies-1 ">< a class ="header "href ="#repinning--updating-dependencies-1 "> Repinning / Updating Dependencies</ a ></ h3 > 3709< p > Dependency syncing and updating is done in the repository rule which means it's done during the 3710analysis phase of builds. As mentioned in the environments variable table above, the< code > CARGO_BAZEL_REPIN</ code > 3711(or< code > REPIN</ code > ) environment variables can be used to force the rule to update dependencies and potentially 3712render a new lockfile. Given an instance of this repository rule named< code > crate_index</ code > , the easiest way to 3713repin dependencies is to run:</ p > 3714< pre >< code class ="language-shell "> CARGO_BAZEL_REPIN=1 bazel sync --only=crate_index 3715</ code ></ pre > 3716< p > This will result in all dependencies being updated for a project. The< code > CARGO_BAZEL_REPIN</ code > environment variable 3717can also be used to customize how dependencies are updated. The following table shows translations from environment 3718variable values to the equivilant< a href ="https://doc.rust-lang.org/cargo/commands/cargo-update.html "> cargo update</ a > command 3719that is called behind the scenes to update dependencies.</ p > 3720< div class ="table-wrapper ">< table >< thead >< tr >< th > Value</ th >< th > Cargo command</ th ></ tr ></ thead >< tbody > 3721< 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 > 3722< tr >< td > Any of [< code > full</ code > ,< code > eager</ code > ,< code > all</ code > ]</ td >< td >< code > cargo update</ code ></ td ></ tr > 3723< tr >< td >< code > package_name</ code ></ td >< td >< code > cargo upgrade --package package_name</ code ></ td ></ tr > 3724< tr >< td >< code > package_name@1.2.3</ code ></ td >< td >< code > cargo upgrade --package package_name@1.2.3</ code ></ td ></ tr > 3725< 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 > 3726</ tbody ></ table > 3727</ div > 3728< p > If the< code > crates_repository</ code > is used multiple times in the same Bazel workspace (e.g. for multiple independent 3729Rust workspaces), it may additionally be useful to use the< code > CARGO_BAZEL_REPIN_ONLY</ code > environment variable, which 3730limits execution of the repinning to one or multiple instances of the< code > crates_repository</ code > rule via a comma-delimited 3731allowlist:</ p > 3732< pre >< code class ="language-shell "> CARGO_BAZEL_REPIN=1 CARGO_BAZEL_REPIN_ONLY=crate_index bazel sync --only=crate_index 3733</ code ></ pre > 3734< p >< strong > ATTRIBUTES</ strong ></ p > 3735< 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 > 3736< 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 > 3737< 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.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 > 3738< 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 > 3739< 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 > 3740< 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 "> Wether 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 > 3741< 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 > 3742< 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 > 3743< 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 > 3744< 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 > 3745< 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 > 3746< 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 > 3747< 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 controled 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 > 3748< 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.</ 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 > 3749< 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 > 3750< 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.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 > 3751< 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 > 3752< 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 > 3753< 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 > 3754< 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 > 3755< 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 > 3756< 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 > 3757< 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.83.0"</ code ></ td ></ tr > 3758< 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 > 3759< 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-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", "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-none-elf", "s390x-unknown-linux-gnu", "thumbv7em-none-eabi", "thumbv8m.main-none-eabi", "wasm32-unknown-unknown", "wasm32-wasip1", "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"]</ code ></ td ></ tr > 3760</ tbody ></ table > 3761</ div > 3762< p >< strong > ENVIRONMENT VARIABLES</ strong ></ p > 3763< p > This repository rule depends on the following environment variables:</ p > 3764< ul > 3765< li >< code > CARGO_BAZEL_GENERATOR_URL</ code ></ li > 3766< li >< code > CARGO_BAZEL_GENERATOR_SHA256</ code ></ li > 3767< li >< code > CARGO_BAZEL_REPIN</ code ></ li > 3768< li >< code > REPIN</ code ></ li > 3769< li >< code > CARGO_BAZEL_REPIN_ONLY</ code ></ li > 3770< li >< code > CARGO_BAZEL_ISOLATED</ code ></ li > 3771< li >< code > CARGO_BAZEL_DEBUG</ code ></ li > 3772</ ul > 3773< div style ="break-before: page; page-break-before: always; "></ div >< h1 id ="upstream-tooling ">< a class ="header "href ="#upstream-tooling "> Upstream Tooling</ a ></ h1 > 3774< 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 > 3775< pre >< code class ="language-console "> % bazel query @rules_rust//tools/upstream_wrapper 3776@rules_rust//tools/upstream_wrapper:cargo 3777@rules_rust//tools/upstream_wrapper:cargo_clippy 3778@rules_rust//tools/upstream_wrapper:rustc 3779@rules_rust//tools/upstream_wrapper:rustfmt 3780</ code ></ pre > 3781< p > You can run them via< code > bazel run</ code > , e.g.< code > bazel run @rules_rust//tools/upstream_wrapper:cargo -- check</ code > .</ p > 3782< div style ="break-before: page; page-break-before: always; "></ div >< h1 id ="extensions ">< a class ="header "href ="#extensions "> Extensions</ a ></ h1 > 3783< p > Bazel rules for interfacing with other rules and integrations with popular 3rd party tools.</ p > 3784< h2 id ="setup-6 ">< a class ="header "href ="#setup-6 "> Setup</ a ></ h2 > 3785< p > The extension rules are released with each release of< code > rules_rust</ code > (core) which 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 > 3786< h3 id ="bzlmod-1 ">< a class ="header "href ="#bzlmod-1 "> Bzlmod</ a ></ h3 > 3787< 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 > 3788< p > To use< code > rules_rust</ code > extensions in a project using bzlmod, add the following to your< code > MODULE.bazel</ code > file:</ p > 3789< pre >< code class ="language-python "> bazel_dep(name = "rules_rust_{EXTENSION}", version = "{VERSION}") 3790</ code ></ pre > 3791< p > Don't forget to substitute in your desired release's version number and< code > {EXTENSION}</ code > with the 3792name of the desired extension. E.g.:</ p > 3793< pre >< code class ="language-python "> bazel_dep(name = "rules_rust_bindgen", version = "0.55.0") 3794</ code ></ pre > 3795< h3 id ="workspace-1 ">< a class ="header "href ="#workspace-1 "> WORKSPACE</ a ></ h3 > 3796< p > To use< code > rules_rust</ code > extensions 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 > 3797< pre >< code class ="language-python "> load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 3798 3799# To find additional information on this release or newer ones visit: 3800# https://github.com/bazelbuild/rules_rust/releases 3801http_archive( 3802 name = "rules_rust_{EXTENSION}", 3803 # See releases page 3804) 3805 3806# Refer to the documentation of the desired rules for how to load other necessary dependencies. 3807</ code ></ pre > 3808< p > Don't forget to substitute in your desired release's version number, integrity hash, and< code > {EXTENSION}</ code > with the name of the desired extension.</ p > 3809< div style ="break-before: page; page-break-before: always; "></ div > <!-- Generated with Stardoc: http://skydoc.bazel.build --> 3810< h1 id ="rules_rust_bindgen ">< a class ="header "href ="#rules_rust_bindgen "> rules_rust_bindgen</ a ></ h1 > 3811< 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 > 3812< h2 id ="rules-2 ">< a class ="header "href ="#rules-2 "> Rules</ a ></ h2 > 3813< ul > 3814< li >< a href ="rust_bindgen.html#rust_bindgen "> rust_bindgen</ a ></ li > 3815< li >< a href ="rust_bindgen.html#rust_bindgen_library "> rust_bindgen_library</ a ></ li > 3816< li >< a href ="rust_bindgen.html#rust_bindgen_toolchain "> rust_bindgen_toolchain</ a ></ li > 3817</ ul > 3818< h2 id ="setup-7 ">< a class ="header "href ="#setup-7 "> Setup</ a ></ h2 > 3819< p > To use the Rust bindgen rules, add the following to your< code > WORKSPACE</ code > file to add the 3820external repositories for the Rust bindgen toolchain (in addition to the< a href ="https://bazelbuild.github.io/rules_rust/#setup "> rust rules setup</ a > ):</ p > 3821< pre >< code class ="language-python "> load("@rules_rust_bindgen//:repositories.bzl", "rust_bindgen_dependencies", "rust_bindgen_register_toolchains") 3822 3823rust_bindgen_dependencies() 3824 3825rust_bindgen_register_toolchains() 3826 3827load("@rules_rust_bindgen//:transitive_repositories.bzl", "rust_bindgen_transitive_dependencies") 3828 3829rust_bindgen_transitive_dependencies() 3830</ code ></ pre > 3831< 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 3832source. If this is found to be undesirable then no Bindgen related calls should be added to your WORKSPACE and instead 3833users should define their own repositories using something akin to< a href ="https://bazelbuild.github.io/rules_rust/crate_universe.html "> crate_universe</ a > and define their own 3834toolchains following the instructions for< a href ="rust_bindgen.html#rust_bindgen_toolchain "> rust_bindgen_toolchain</ a > .</ p > 3835< hr /> 3836< hr /> 3837< p >< a id ="rust_bindgen "></ a ></ p > 3838< h2 id ="rust_bindgen ">< a class ="header "href ="#rust_bindgen "> rust_bindgen</ a ></ h2 > 3839< pre > 3840rust_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 > , 3841< a href ="rust_bindgen.html#rust_bindgen-wrap_static_fns "> wrap_static_fns</ a > ) 3842</ pre > 3843< p > Generates a rust source file from a cc_library and a header.</ p > 3844< p >< strong > ATTRIBUTES</ strong ></ p > 3845< 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 > 3846< 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 > 3847< 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 > 3848< 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 > 3849< 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 > 3850< 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 > 3851< 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 > 3852< 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 > 3853</ tbody ></ table > 3854</ div > 3855< p >< a id ="rust_bindgen_toolchain "></ a ></ p > 3856< h2 id ="rust_bindgen_toolchain ">< a class ="header "href ="#rust_bindgen_toolchain "> rust_bindgen_toolchain</ a ></ h2 > 3857< pre > 3858rust_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 > ) 3859</ pre > 3860< p > The tools required for the< code > rust_bindgen</ code > rule.</ p > 3861< p > This rule depends on the< a href ="https://crates.io/crates/bindgen ">< code > bindgen</ code ></ a > binary crate, and it 3862in turn depends on both a clang binary and the clang library. To obtain these dependencies, 3863< code > rust_bindgen_dependencies</ code > imports bindgen and its dependencies.</ p > 3864< pre >< code class ="language-python "> load("@rules_rust_bindgen//:defs.bzl", "rust_bindgen_toolchain") 3865 3866rust_bindgen_toolchain( 3867 name = "bindgen_toolchain_impl", 3868 bindgen = "//my/rust:bindgen", 3869 clang = "//my/clang:clang", 3870 libclang = "//my/clang:libclang.so", 3871 libstdcxx = "//my/cpp:libstdc++", 3872) 3873 3874toolchain( 3875 name = "bindgen_toolchain", 3876 toolchain = "bindgen_toolchain_impl", 3877 toolchain_type = "@rules_rust_bindgen//:toolchain_type", 3878) 3879</ code ></ pre > 3880< p > This toolchain will then need to be registered in the current< code > WORKSPACE</ code > . 3881For additional information, see the< a href ="https://docs.bazel.build/versions/master/toolchains.html "> Bazel toolchains documentation</ a > .</ p > 3882< p >< strong > ATTRIBUTES</ strong ></ p > 3883< 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 > 3884< 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 > 3885< 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 > 3886< 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 > 3887< 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 > 3888< 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 > 3889< 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 > 3890</ tbody ></ table > 3891</ div > 3892< p >< a id ="rust_bindgen_library "></ a ></ p > 3893< h2 id ="rust_bindgen_library ">< a class ="header "href ="#rust_bindgen_library "> rust_bindgen_library</ a ></ h2 > 3894< pre > 3895rust_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 > , 3896< 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 > ) 3897</ pre > 3898< p > Generates a rust source file for< code > header</ code > , and builds a rust_library.</ p > 3899< p > Arguments are the same as< code > rust_bindgen</ code > , and< code > kwargs</ code > are passed directly to rust_library.</ p > 3900< p >< strong > PARAMETERS</ strong ></ p > 3901< 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 > 3902< 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 > 3903< 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 > 3904< 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 > 3905< 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 > 3906< 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 > 3907< 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 > 3908< 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 > 3909< 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 > 3910</ tbody ></ table > 3911</ div >< div style ="break-before: page; page-break-before: always; "></ div > <!-- Generated with Stardoc: http://skydoc.bazel.build --> 3912< h1 id ="rules_rust_prost ">< a class ="header "href ="#rules_rust_prost "> rules_rust_prost</ a ></ h1 > 3913< 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 3914using< a href ="https://github.com/tokio-rs/prost "> Prost</ a > and< a href ="https://github.com/tokio-rs/tonic "> Tonic</ a ></ p > 3915< h2 id ="rules-3 ">< a class ="header "href ="#rules-3 "> Rules</ a ></ h2 > 3916< ul > 3917< li >< a href ="rust_prost.html#rust_prost_library "> rust_prost_library</ a ></ li > 3918< li >< a href ="rust_prost.html#rust_prost_toolchain "> rust_prost_toolchain</ a ></ li > 3919</ ul > 3920< h2 id ="setup-8 ">< a class ="header "href ="#setup-8 "> Setup</ a ></ h2 > 3921< pre >< code class ="language-python "> load("@rules_rust//proto/prost:repositories.bzl", "rust_prost_dependencies") 3922 3923rust_prost_dependencies() 3924 3925load("@rules_rust//proto/prost:transitive_repositories.bzl", "rust_prost_transitive_repositories") 3926 3927rust_prost_transitive_repositories() 3928</ code ></ pre > 3929< p > The< code > prost</ code > and< code > tonic</ code > rules do not specify a default toolchain in order to avoid mismatched 3930dependency issues. To setup the< code > prost</ code > and< code > tonic</ code > toolchain, please see the section 3931< a href ="rust_prost.html#custom-prost-deps "> Customizing< code > prost</ code > and< code > tonic</ code > Dependencies</ a > .</ p > 3932< p > For additional information about Bazel toolchains, see< a href ="https://docs.bazel.build/versions/master/toolchains.html "> here</ a > .</ p > 3933< 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 > 3934< 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 3935for 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 > 3936< p > To get access to these crates, you can use the< a href ="./crate_universe.html "> crate_universe</ a > repository 3937rules. For example:</ p > 3938< pre >< code class ="language-python "> load("//crate_universe:defs.bzl", "crate", "crates_repository") 3939 3940crates_repository( 3941 name = "crates_io", 3942 annotations = { 3943 "protoc-gen-prost": [crate.annotation( 3944 gen_binaries = ["protoc-gen-prost"], 3945 patch_args = [ 3946 "-p1", 3947 ], 3948 patches = [ 3949 # Note: You will need to use this patch until a version greater than `0.2.2` of 3950 # `protoc-gen-prost` is released. 3951 "@rules_rust//proto/prost/private/3rdparty/patches:protoc-gen-prost.patch", 3952 ], 3953 )], 3954 "protoc-gen-tonic": [crate.annotation( 3955 gen_binaries = ["protoc-gen-tonic"], 3956 )], 3957 }, 3958 cargo_lockfile = "Cargo.Bazel.lock", 3959 mode = "remote", 3960 packages = { 3961 "prost": crate.spec( 3962 version = "0", 3963 ), 3964 "prost-types": crate.spec( 3965 version = "0", 3966 ), 3967 "protoc-gen-prost": crate.spec( 3968 version = "0", 3969 ), 3970 "protoc-gen-tonic": crate.spec( 3971 version = "0", 3972 ), 3973 "tonic": crate.spec( 3974 version = "0", 3975 ), 3976 }, 3977 repository_name = "rules_rust_prost", 3978 tags = ["manual"], 3979) 3980</ code ></ pre > 3981< p > You can then define a toolchain with the< code > rust_prost_toolchain</ code > rule which uses the crates 3982defined above. For example:</ p > 3983< pre >< code class ="language-python "> load("@rules_rust//proto/prost:defs.bzl", "rust_prost_toolchain") 3984load("@rules_rust//rust:defs.bzl", "rust_library_group") 3985 3986rust_library_group( 3987 name = "prost_runtime", 3988 deps = [ 3989 "@crates_io//:prost", 3990 ], 3991) 3992 3993rust_library_group( 3994 name = "tonic_runtime", 3995 deps = [ 3996 ":prost_runtime", 3997 "@crates_io//:tonic", 3998 ], 3999) 4000 4001rust_prost_toolchain( 4002 name = "prost_toolchain_impl", 4003 prost_plugin = "@crates_io//:protoc-gen-prost__protoc-gen-prost", 4004 prost_runtime = ":prost_runtime", 4005 prost_types = "@crates_io//:prost-types", 4006 proto_compiler = "@com_google_protobuf//:protoc", 4007 tonic_plugin = "@crates_io//:protoc-gen-tonic__protoc-gen-tonic", 4008 tonic_runtime = ":tonic_runtime", 4009) 4010 4011toolchain( 4012 name = "prost_toolchain", 4013 toolchain = "prost_toolchain_impl", 4014 toolchain_type = "@rules_rust//proto/prost:toolchain_type", 4015) 4016</ code ></ pre > 4017< p > Lastly, you must register the toolchain in your< code > WORKSPACE</ code > file. For example:</ p > 4018< pre >< code class ="language-python "> register_toolchains("//toolchains:prost_toolchain") 4019</ code ></ pre > 4020< hr /> 4021< hr /> 4022< p >< a id ="rust_prost_toolchain "></ a ></ p > 4023< h2 id ="rust_prost_toolchain ">< a class ="header "href ="#rust_prost_toolchain "> rust_prost_toolchain</ a ></ h2 > 4024< pre > 4025rust_prost_toolchain(< a href ="rust_prost.html#rust_prost_toolchain-name "> name</ 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 > , 4026< 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 > , 4027< 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 > ) 4028</ pre > 4029< p > Rust Prost toolchain rule.</ p > 4030< p >< strong > ATTRIBUTES</ strong ></ p > 4031< 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 > 4032< 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 > 4033< 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 > 4034< 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 > 4035< 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 > 4036< 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 > 4037< 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 > 4038< 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 > 4039< 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 > 4040< 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 > 4041< 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 > 4042< 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 > 4043< 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 > 4044</ tbody ></ table > 4045</ div > 4046< p >< a id ="rust_prost_library "></ a ></ p > 4047< h2 id ="rust_prost_library ">< a class ="header "href ="#rust_prost_library "> rust_prost_library</ a ></ h2 > 4048< pre > 4049rust_prost_library(< a href ="rust_prost.html#rust_prost_library-name "> name</ a > ,< a href ="rust_prost.html#rust_prost_library-kwargs "> kwargs</ a > ) 4050</ pre > 4051< p > A rule for generating a Rust library using Prost.</ p > 4052< p >< strong > PARAMETERS</ strong ></ p > 4053< 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 > 4054< tr >< td style ="text-align: left ">< a id ="rust_prost_library-name "></ a > name</ td >< td style ="text-align: left "> The name of the target.</ td >< td style ="text-align: left "> none</ td ></ tr > 4055< tr >< td style ="text-align: left ">< a id ="rust_prost_library-kwargs "></ a > kwargs</ td >< td style ="text-align: left "> Additional keyword arguments for the underlying< code > rust_prost_library</ code > rule.</ td >< td style ="text-align: left "> none</ td ></ tr > 4056</ tbody ></ table > 4057</ div >< div style ="break-before: page; page-break-before: always; "></ div > <!-- Generated with Stardoc: http://skydoc.bazel.build --> 4058< h1 id ="rules_rust_protobuf ">< a class ="header "href ="#rules_rust_protobuf "> rules_rust_protobuf</ a ></ h1 > 4059< 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 4060using< a href ="https://github.com/stepancheg/rust-protobuf/ ">< code > rust-protobuf</ code ></ a > .</ p > 4061< h2 id ="setup-9 ">< a class ="header "href ="#setup-9 "> Setup</ a ></ h2 > 4062< p > To use the Rust proto rules, add the following to your< code > WORKSPACE</ code > file to add the 4063external repositories for the Rust proto toolchain (in addition to the< a href =".. "> rust rules setup</ a > ):</ p > 4064< pre >< code class ="language-python "> load("@rules_rust//proto/protobuf:repositories.bzl", "rust_proto_protobuf_dependencies", "rust_proto_protobuf_register_toolchains") 4065 4066rust_proto_protobuf_dependencies() 4067 4068rust_proto_protobuf_register_toolchains() 4069 4070load("@rules_rust//proto/protobuf:transitive_repositories.bzl", "rust_proto_protobuf_transitive_repositories") 4071 4072rust_proto_protobuf_transitive_repositories() 4073</ code ></ pre > 4074< 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 4075register a default toolchain for the< code > rust_proto_library</ code > and< code > rust_grpc_library</ code > rules.</ p > 4076< p > To customize the< code > rust_proto_library</ code > and< code > rust_grpc_library</ code > toolchain, please see the section 4077< a href ="rust_protobuf.html#custom-proto-deps "> Customizing< code > rust-protobuf</ code > Dependencies</ a > .</ p > 4078< p > For additional information about Bazel toolchains, see< a href ="https://docs.bazel.build/versions/master/toolchains.html "> here</ a > .</ p > 4079< 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 > 4080< p > These rules depend on the< a href ="https://crates.io/crates/protobuf ">< code > protobuf</ code ></ a > and 4081the< a href ="https://crates.io/crates/grpc ">< code > grpc</ code ></ a > crates in addition to the< a href ="https://github.com/google/protobuf "> protobuf 4082compiler</ a > . To obtain these crates, 4083< code > rust_proto_repositories</ code > imports the given crates using BUILD files generated with 4084< a href ="./crate_universe.html "> crate_universe</ a > .</ p > 4085< p > If you want to either change the protobuf and gRPC rust compilers, or to 4086simply use< a href ="./crate_universe.html "> crate_universe</ a > in a more 4087complex scenario (with more dependencies), you must redefine those 4088dependencies.</ p > 4089< p > To do this, once you've imported the needed dependencies (see our 4090< a href ="https://github.com/bazelbuild/rules_rust/blob/main/proto/protobuf/3rdparty/BUILD.bazel "> @rules_rust//proto/protobuf/3rdparty/BUILD.bazel</ a > 4091file to see the default dependencies), you need to create your own toolchain. 4092To do so you can create a BUILD file with your toolchain definition, for example:</ p > 4093< pre >< code class ="language-python "> load("@rules_rust//proto:toolchain.bzl", "rust_proto_toolchain") 4094 4095rust_proto_toolchain( 4096 name = "proto-toolchain-impl", 4097 # Path to the protobuf compiler. 4098 protoc = "@com_google_protobuf//:protoc", 4099 # Protobuf compiler plugin to generate rust gRPC stubs. 4100 grpc_plugin = "//3rdparty/crates:cargo_bin_protoc_gen_rust_grpc", 4101 # Protobuf compiler plugin to generate rust protobuf stubs. 4102 proto_plugin = "//3rdparty/crates:cargo_bin_protoc_gen_rust", 4103) 4104 4105toolchain( 4106 name = "proto-toolchain", 4107 toolchain = ":proto-toolchain-impl", 4108 toolchain_type = "@rules_rust//proto/protobuf:toolchain_type", 4109) 4110</ code ></ pre > 4111< p > Now that you have your own toolchain, you need to register it by 4112inserting the following statement in your< code > WORKSPACE</ code > file:</ p > 4113< pre >< code class ="language-python "> register_toolchains("//my/toolchains:proto-toolchain") 4114</ code ></ pre > 4115< p > Finally, you might want to set the< code > rust_deps</ code > attribute in 4116< code > rust_proto_library</ code > and< code > rust_grpc_library</ code > to change the compile-time 4117dependencies:</ p > 4118< pre >< code class ="language-python "> rust_proto_library( 4119 ... 4120 rust_deps = ["//3rdparty/crates:protobuf"], 4121 ... 4122) 4123 4124rust_grpc_library( 4125 ... 4126 rust_deps = [ 4127 "//3rdparty/crates:protobuf", 4128 "//3rdparty/crates:grpc", 4129 "//3rdparty/crates:tls_api", 4130 "//3rdparty/crates:tls_api_stub", 4131 ], 4132 ... 4133) 4134</ code ></ pre > 4135< p >< strong > Note</ strong > : Ideally, we would inject those dependencies from the toolchain, 4136but due to< a href ="https://github.com/bazelbuild/bazel/issues/6889 "> bazelbuild/bazel#6889</ a > 4137all dependencies added via the toolchain ends-up being in the wrong 4138configuration.</ p > 4139< hr /> 4140< hr /> 4141< p >< a id ="rust_grpc_library "></ a ></ p > 4142< h2 id ="rust_grpc_library ">< a class ="header "href ="#rust_grpc_library "> rust_grpc_library</ a ></ h2 > 4143< pre > 4144rust_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 > ) 4145</ pre > 4146< p > Builds a Rust library crate from a set of< code > proto_library</ code > s suitable for gRPC.</ p > 4147< p > Example:</ p > 4148< pre >< code class ="language-python "> load("@rules_rust_protobuf//:defs.bzl", "rust_grpc_library") 4149 4150proto_library( 4151 name = "my_proto", 4152 srcs = ["my.proto"] 4153) 4154 4155rust_grpc_library( 4156 name = "rust", 4157 deps = [":my_proto"], 4158) 4159 4160rust_binary( 4161 name = "my_service", 4162 srcs = ["my_service.rs"], 4163 deps = [":rust"], 4164) 4165</ code ></ pre > 4166< p >< strong > ATTRIBUTES</ strong ></ p > 4167< 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 > 4168< 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 > 4169< 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 > 4170< 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 > 4171< 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 > 4172< 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 > 4173</ tbody ></ table > 4174</ div > 4175< p >< a id ="rust_proto_library "></ a ></ p > 4176< h2 id ="rust_proto_library ">< a class ="header "href ="#rust_proto_library "> rust_proto_library</ a ></ h2 > 4177< pre > 4178rust_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 > ) 4179</ pre > 4180< p > Builds a Rust library crate from a set of< code > proto_library</ code > s.</ p > 4181< p > Example:</ p > 4182< pre >< code class ="language-python "> load("@rules_rust_protobuf//:defs.bzl", "rust_proto_library") 4183 4184proto_library( 4185 name = "my_proto", 4186 srcs = ["my.proto"] 4187) 4188 4189rust_proto_library( 4190 name = "rust", 4191 deps = [":my_proto"], 4192) 4193 4194rust_binary( 4195 name = "my_proto_binary", 4196 srcs = ["my_proto_binary.rs"], 4197 deps = [":rust"], 4198) 4199</ code ></ pre > 4200< p >< strong > ATTRIBUTES</ strong ></ p > 4201< 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 > 4202< 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 > 4203< 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 > 4204< 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 > 4205< 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 > 4206< 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 > 4207</ tbody ></ table > 4208</ div >< div style ="break-before: page; page-break-before: always; "></ div > <!-- Generated with Stardoc: http://skydoc.bazel.build --> 4209< h1 id ="rules_rust_wasm_bindgen ">< a class ="header "href ="#rules_rust_wasm_bindgen "> rules_rust_wasm_bindgen</ a ></ h1 > 4210< p > Bazel rules for generating wasm modules for Javascript using< a href ="https://github.com/rustwasm/wasm-bindgen "> wasm-bindgen</ a > .</ p > 4211< h2 id ="rules-4 ">< a class ="header "href ="#rules-4 "> Rules</ a ></ h2 > 4212< ul > 4213< li >< a href ="rust_wasm_bindgen.html#rust_wasm_bindgen "> rust_wasm_bindgen</ a ></ li > 4214< li >< a href ="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain "> rust_wasm_bindgen_toolchain</ a ></ li > 4215</ ul > 4216< h2 id ="setup-10 ">< a class ="header "href ="#setup-10 "> Setup</ a ></ h2 > 4217< p > To begin using the< code > wasm-bindgen</ code > rules, users can load the necessary dependencies 4218in their workspace by adding the following to their< code > WORKSPACE.bazel</ code > file.</ p > 4219< pre >< code class ="language-python "> load("@rules_rust_wasm_bindgen//:repositories.bzl", "rust_wasm_bindgen_dependencies", "rust_wasm_bindgen_register_toolchains") 4220 4221rust_wasm_bindgen_dependencies() 4222 4223rust_wasm_bindgen_register_toolchains() 4224</ code ></ pre > 4225< p > This should enable users to start using the< a href ="rust_wasm_bindgen.html#rust_wasm_bindgen "> rust_wasm_bindgen</ a > 4226rule. However, it's common to want to control the version of< code > wasm-bindgen</ code > in the 4227workspace instead of relying on the one provided by< code > rules_rust</ code > . In this case, users 4228should avoid calling< code > rust_wasm_bindgen_register_toolchains</ code > and instead use the 4229< a href ="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain "> rust_wasm_bindgen_toolchain</ a > rule to define their own 4230toolchains to register in the workspace.</ p > 4231< h2 id ="interfacing-with-javascript-rules ">< a class ="header "href ="#interfacing-with-javascript-rules "> Interfacing with Javascript rules</ a ></ h2 > 4232< p > While it's recommended for users to mantain their own , in the 4233< code > @rules_rust_wasm_bindgen</ code > package there exists interface sub-packages for various 4234Javascript Bazel rules. E.g.< code > aspect_rules_js</ code > . The rules defined there are a more 4235convenient way to use< code > rust_wasm_bindgen</ code > with the associated javascript rules due 4236to the inclusion of additional providers. Each directory contains a< code > defs.bzl</ code > file 4237that defines the different variants of< code > rust_wasm_bindgen</ code > . (e.g.< code > js_rust_wasm_bindgen</ code > 4238for the< code > rules_js</ code > submodule).</ p > 4239< p >< a id ="rust_wasm_bindgen "></ a ></ p > 4240< h2 id ="rust_wasm_bindgen ">< a class ="header "href ="#rust_wasm_bindgen "> rust_wasm_bindgen</ a ></ h2 > 4241< pre > 4242rust_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-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 > ) 4243</ pre > 4244< p > Generates javascript and typescript bindings for a webassembly module using< a href ="https://rustwasm.github.io/docs/wasm-bindgen/ "> wasm-bindgen</ a > .</ p > 4245< p > An example of this rule in use can be seen at< a href ="../examples/wasm "> @rules_rust//examples/wasm</ a ></ p > 4246< p >< strong > ATTRIBUTES</ strong ></ p > 4247< 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 > 4248< 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 > 4249< 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 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 > 4250< 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 > 4251< 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 > 4252< 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 > file or 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 > 4253</ tbody ></ table > 4254</ div > 4255< p >< a id ="rust_wasm_bindgen_toolchain "></ a ></ p > 4256< h2 id ="rust_wasm_bindgen_toolchain ">< a class ="header "href ="#rust_wasm_bindgen_toolchain "> rust_wasm_bindgen_toolchain</ a ></ h2 > 4257< pre > 4258rust_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-bindgen "> bindgen</ a > ) 4259</ pre > 4260< p > The tools required for the< code > rust_wasm_bindgen</ code > rule.</ p > 4261< 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 > , 4262a unique toolchain can be created as in the example below:</ p > 4263< pre >< code class ="language-python "> load("@rules_rust_bindgen//:defs.bzl", "rust_bindgen_toolchain") 4264 4265rust_bindgen_toolchain( 4266 bindgen = "//3rdparty/crates:wasm_bindgen_cli__bin", 4267) 4268 4269toolchain( 4270 name = "wasm_bindgen_toolchain", 4271 toolchain = "wasm_bindgen_toolchain_impl", 4272 toolchain_type = "@rules_rust_wasm_bindgen//:toolchain_type", 4273) 4274</ code ></ pre > 4275< p > Now that you have your own toolchain, you need to register it by 4276inserting the following statement in your< code > WORKSPACE</ code > file:</ p > 4277< pre >< code class ="language-python "> register_toolchains("//my/toolchains:wasm_bindgen_toolchain") 4278</ code ></ pre > 4279< p > For additional information, see the< a href ="https://docs.bazel.build/versions/master/toolchains.html "> Bazel toolchains documentation</ a > .</ p > 4280< p >< strong > ATTRIBUTES</ strong ></ p > 4281< 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 > 4282< 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 > 4283< tr >< td style ="text-align: left ">< a id ="rust_wasm_bindgen_toolchain-bindgen "></ a > bindgen</ 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 > 4284</ tbody ></ table > 4285</ div > 4286< p >< a id ="RustWasmBindgenInfo "></ a ></ p > 4287< h2 id ="rustwasmbindgeninfo ">< a class ="header "href ="#rustwasmbindgeninfo "> RustWasmBindgenInfo</ a ></ h2 > 4288< pre > 4289RustWasmBindgenInfo(< a href ="rust_wasm_bindgen.html#RustWasmBindgenInfo-js "> js</ a > ,< a href ="rust_wasm_bindgen.html#RustWasmBindgenInfo-ts "> ts</ a > ,< a href ="rust_wasm_bindgen.html#RustWasmBindgenInfo-wasm "> wasm</ a > ) 4290</ pre > 4291< p > Info about wasm-bindgen outputs.</ p > 4292< p >< strong > FIELDS</ strong ></ p > 4293< div class ="table-wrapper ">< table >< thead >< tr >< th style ="text-align: left "> Name</ th >< th style ="text-align: left "> Description</ th ></ tr ></ thead >< tbody > 4294< 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 > 4295< 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 > 4296< 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 > 4297</ tbody ></ table > 4298</ div > 4299</ main > 4300 4301< nav class ="nav-wrapper "aria-label ="Page navigation "> 4302<!-- Mobile navigation buttons --> 4303 4304 4305< div style ="clear: both "></ div > 4306</ nav > 4307</ div > 4308</ div > 4309 4310< nav class ="nav-wide-wrapper "aria-label ="Page navigation "> 4311 4312</ nav > 4313 4314</ div > 4315 4316 4317 4318 4319< script > 4320window . playground_copyable = true ; 4321</ script > 4322 4323 4324< script src ="elasticlunr.min.js "></ script > 4325< script src ="mark.min.js "></ script > 4326< script src ="searcher.js "></ script > 4327 4328< script src ="clipboard.min.js "></ script > 4329< script src ="highlight.js "></ script > 4330< script src ="book.js "></ script > 4331 4332<!-- Custom JS scripts --> 4333 4334< script > 4335window . addEventListener ( 'load' , function () { 4336window . setTimeout ( window . , 100 ); 4337}); 4338</ script > 4339 4340</ div > 4341</ body > 4342</ html >