fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
482a21cf
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 > prost - rules_rust</ title > 7 8 9<!-- Custom HTML head --> 10 11< meta name ="description "content =""> 12< meta name ="viewport "content ="width=device-width, initial-scale=1 "> 13< meta name ="theme-color "content ="#ffffff "> 14 15< link rel ="icon "href ="favicon.svg "> 16< link rel ="shortcut icon "href ="favicon.png "> 17< link rel ="stylesheet "href ="css/variables.css "> 18< link rel ="stylesheet "href ="css/general.css "> 19< link rel ="stylesheet "href ="css/chrome.css "> 20< link rel ="stylesheet "href ="css/print.css "media ="> 21 22<!-- Fonts --> 23< link rel ="stylesheet "href ="FontAwesome/css/font-awesome.css "> 24< link rel ="stylesheet "href ="fonts/fonts.css "> 25 26<!-- Highlight.js Stylesheets --> 27< link rel ="stylesheet "href ="highlight.css "> 28< link rel ="stylesheet "href ="tomorrow-night.css "> 29< link rel ="stylesheet "href ="ayu-highlight.css "> 30 31<!-- Custom theme stylesheets --> 32 33 34<!-- Provide site root to javascript --> 35< script > 36var path_to_root = "" ; 37var default_theme = window . matchMedia ( "(prefers-color-scheme: dark)" ). matches ?"navy" :"light" ; 38</ script > 39<!-- Start loading toc.js asap --> 40< script src ="toc.js "></ script > 41</ head > 42< body > 43< div id ="body-container "> 44<!-- Work around some values being stored in localStorage wrapped in quotes --> 45< script > 46try { 47var theme = localStorage . getItem ( 'mdbook-theme' ); 48var sidebar = localStorage . getItem ( 'mdbook-sidebar' ); 49 50if ( theme . startsWith ( '"' ) && theme . endsWith ( '"' )) { 51localStorage . setItem ( 'mdbook-theme' , theme . slice ( 1 , theme . length - 1 )); 52} 53 54if ( sidebar . startsWith ( '"' ) && sidebar . endsWith ( '"' )) { 55localStorage . setItem ( 'mdbook-sidebar' , sidebar . slice ( 1 , sidebar . length - 1 )); 56} 57} catch ( e ) { } 58</ script > 59 60<!-- Set the theme before any content is loaded, prevents flash --> 61< script > 62var theme ; 63try { theme = localStorage . getItem ( 'mdbook-theme' ); } catch ( e ) { } 64if ( theme === null || theme === undefined ) { theme = default_theme ; } 65const html = document . documentElement ; 66html . classList . remove ( 'light' ) 67html . classList . add ( theme ); 68html . classList . add ( "js" ); 69</ script > 70 71< input type ="checkbox "id ="sidebar-toggle-anchor "class ="hidden "> 72 73<!-- Hide / unhide sidebar before it is displayed --> 74< script > 75var sidebar = null ; 76var sidebar_toggle = document . getElementById ( "sidebar-toggle-anchor" ); 77if ( document . body . clientWidth >= 1080 ) { 78try { sidebar = localStorage . getItem ( 'mdbook-sidebar' ); } catch ( e ) { } 79sidebar = sidebar || 'visible' ; 80} else { 81sidebar = 'hidden' ; 82} 83sidebar_toggle . checked = sidebar === 'visible' ; 84html . classList . remove ( 'sidebar-visible' ); 85html . classList . add ( "sidebar-" + sidebar ); 86</ script > 87 88< nav id ="sidebar "class ="sidebar "aria-label ="Table of contents "> 89<!-- populated by js --> 90< mdbook-sidebar-scrollbox class ="sidebar-scrollbox "></ mdbook-sidebar-scrollbox > 91< noscript > 92< iframe class ="sidebar-iframe-outer "src ="toc.html "></ iframe > 93</ noscript > 94< div id ="sidebar-resize-handle "class ="sidebar-resize-handle "> 95< div class ="sidebar-resize-indicator "></ div > 96</ div > 97</ nav > 98 99< div id ="page-wrapper "class ="page-wrapper "> 100 101< div class ="page "> 102< div id ="menu-bar-hover-placeholder "></ div > 103< div id ="menu-bar "class ="menu-bar sticky "> 104< div class ="left-buttons "> 105< label id ="sidebar-toggle "class ="icon-button "for ="sidebar-toggle-anchor "title ="Toggle Table of Contents "aria-label ="Toggle Table of Contents "aria-controls ="sidebar "> 106< i class ="fa fa-bars "></ i > 107</ label > 108< button id ="theme-toggle "class ="icon-button "type ="button "title ="Change theme "aria-label ="Change theme "aria-haspopup ="true "aria-expanded ="false "aria-controls ="theme-list "> 109< i class ="fa fa-paint-brush "></ i > 110</ button > 111< ul id ="theme-list "class ="theme-popup "aria-label ="Themes "role ="menu "> 112< li role ="none ">< button role ="menuitem "class ="theme "id ="light "> Light</ button ></ li > 113< li role ="none ">< button role ="menuitem "class ="theme "id ="rust "> Rust</ button ></ li > 114< li role ="none ">< button role ="menuitem "class ="theme "id ="coal "> Coal</ button ></ li > 115< li role ="none ">< button role ="menuitem "class ="theme "id ="navy "> Navy</ button ></ li > 116< li role ="none ">< button role ="menuitem "class ="theme "id ="ayu "> Ayu</ button ></ li > 117</ ul > 118< button id ="search-toggle "class ="icon-button "type ="button "title ="Search. (Shortkey: s) "aria-label ="Toggle Searchbar "aria-expanded ="false "aria-keyshortcuts ="S "aria-controls ="searchbar "> 119< i class ="fa fa-search "></ i > 120</ button > 121</ div > 122 123< h1 class ="menu-title "> rules_rust</ h1 > 124 125< div class ="right-buttons "> 126< a href ="print.html "title ="Print this book "aria-label ="Print this book "> 127< i id ="print-button "class ="fa fa-print "></ i > 128</ a > 129< a href ="https://github.com/bazelbuild/rules_rust "title ="Git repository "aria-label ="Git repository "> 130< i id ="git-repository-button "class ="fa fa-github "></ i > 131</ a > 132 133</ div > 134</ div > 135 136< div id ="search-wrapper "class ="hidden "> 137< form id ="searchbar-outer "class ="searchbar-outer "> 138< input type ="search "id ="searchbar "name ="searchbar "placeholder ="Search this book ... "aria-controls ="searchresults-outer "aria-describedby ="searchresults-header "> 139</ form > 140< div id ="searchresults-outer "class ="searchresults-outer hidden "> 141< div id ="searchresults-header "class ="searchresults-header "></ div > 142< ul id ="searchresults "> 143</ ul > 144</ div > 145</ div > 146 147<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM --> 148< script > 149document . getElementById ( 'sidebar-toggle' ). setAttribute ( 'aria-expanded' , sidebar === 'visible' ); 150document . getElementById ( 'sidebar' ). setAttribute ( 'aria-hidden' , sidebar !== 'visible' ); 151Array . from ( document . querySelectorAll ( '#sidebar a' )). forEach ( function ( link ) { 152link . setAttribute ( 'tabIndex' , sidebar === 'visible' ?0 :- 1 ); 153}); 154</ script > 155 156< div id ="content "class ="content "> 157< main > 158<!-- Generated with Stardoc: http://skydoc.bazel.build --> 159< h1 id ="rules_rust_prost ">< a class ="header "href ="#rules_rust_prost "> rules_rust_prost</ a ></ h1 > 160< 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 161using< a href ="https://github.com/tokio-rs/prost "> Prost</ a > and< a href ="https://github.com/tokio-rs/tonic "> Tonic</ a ></ p > 162< h2 id ="rules ">< a class ="header "href ="#rules "> Rules</ a ></ h2 > 163< ul > 164< li >< a href ="#rust_prost_library "> rust_prost_library</ a ></ li > 165< li >< a href ="#rust_prost_toolchain "> rust_prost_toolchain</ a ></ li > 166</ ul > 167< h2 id ="setup ">< a class ="header "href ="#setup "> Setup</ a ></ h2 > 168< pre >< code class ="language-python "> load("@rules_rust//proto/prost:repositories.bzl", "rust_prost_dependencies") 169 170rust_prost_dependencies() 171 172load("@rules_rust//proto/prost:transitive_repositories.bzl", "rust_prost_transitive_repositories") 173 174rust_prost_transitive_repositories() 175</ code ></ pre > 176< p > The< code > prost</ code > and< code > tonic</ code > rules do not specify a default toolchain in order to avoid mismatched 177dependency issues. To setup the< code > prost</ code > and< code > tonic</ code > toolchain, please see the section 178< a href ="#custom-prost-deps "> Customizing< code > prost</ code > and< code > tonic</ code > Dependencies</ a > .</ p > 179< p > For additional information about Bazel toolchains, see< a href ="https://docs.bazel.build/versions/master/toolchains.html "> here</ a > .</ p > 180< 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 > 181< 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 182for 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 > 183< p > To get access to these crates, you can use the< a href ="./crate_universe.html "> crate_universe</ a > repository 184rules. For example:</ p > 185< pre >< code class ="language-python "> load("//crate_universe:defs.bzl", "crate", "crates_repository") 186 187crates_repository( 188 name = "crates_io", 189 annotations = { 190 "protoc-gen-prost": [crate.annotation( 191 gen_binaries = ["protoc-gen-prost"], 192 patch_args = [ 193 "-p1", 194 ], 195 patches = [ 196 # Note: You will need to use this patch until a version greater than `0.2.2` of 197 # `protoc-gen-prost` is released. 198 "@rules_rust//proto/prost/private/3rdparty/patches:protoc-gen-prost.patch", 199 ], 200 )], 201 "protoc-gen-tonic": [crate.annotation( 202 gen_binaries = ["protoc-gen-tonic"], 203 )], 204 }, 205 cargo_lockfile = "Cargo.Bazel.lock", 206 mode = "remote", 207 packages = { 208 "prost": crate.spec( 209 version = "0", 210 ), 211 "prost-types": crate.spec( 212 version = "0", 213 ), 214 "protoc-gen-prost": crate.spec( 215 version = "0", 216 ), 217 "protoc-gen-tonic": crate.spec( 218 version = "0", 219 ), 220 "tonic": crate.spec( 221 version = "0", 222 ), 223 }, 224 repository_name = "rules_rust_prost", 225 tags = ["manual"], 226) 227</ code ></ pre > 228< p > You can then define a toolchain with the< code > rust_prost_toolchain</ code > rule which uses the crates 229defined above. For example:</ p > 230< pre >< code class ="language-python "> load("@rules_rust//proto/prost:defs.bzl", "rust_prost_toolchain") 231load("@rules_rust//rust:defs.bzl", "rust_library_group") 232 233rust_library_group( 234 name = "prost_runtime", 235 deps = [ 236 "@crates_io//:prost", 237 ], 238) 239 240rust_library_group( 241 name = "tonic_runtime", 242 deps = [ 243 ":prost_runtime", 244 "@crates_io//:tonic", 245 ], 246) 247 248rust_prost_toolchain( 249 name = "prost_toolchain_impl", 250 prost_plugin = "@crates_io//:protoc-gen-prost__protoc-gen-prost", 251 prost_runtime = ":prost_runtime", 252 prost_types = "@crates_io//:prost-types", 253 proto_compiler = "@com_google_protobuf//:protoc", 254 tonic_plugin = "@crates_io//:protoc-gen-tonic__protoc-gen-tonic", 255 tonic_runtime = ":tonic_runtime", 256) 257 258toolchain( 259 name = "prost_toolchain", 260 toolchain = "prost_toolchain_impl", 261 toolchain_type = "@rules_rust//proto/prost:toolchain_type", 262) 263</ code ></ pre > 264< p > Lastly, you must register the toolchain in your< code > WORKSPACE</ code > file. For example:</ p > 265< pre >< code class ="language-python "> register_toolchains("//toolchains:prost_toolchain") 266</ code ></ pre > 267< hr /> 268< hr /> 269< p >< a id ="rust_prost_toolchain "></ a ></ p > 270< h2 id ="rust_prost_toolchain ">< a class ="header "href ="#rust_prost_toolchain "> rust_prost_toolchain</ a ></ h2 > 271< pre > 272rust_prost_toolchain(< a href ="#rust_prost_toolchain-name "> name</ a > ,< a href ="#rust_prost_toolchain-include_transitive_deps "> include_transitive_deps</ a > ,< a href ="#rust_prost_toolchain-prost_opts "> prost_opts</ a > ,< a href ="#rust_prost_toolchain-prost_plugin "> prost_plugin</ a > ,< a href ="#rust_prost_toolchain-prost_plugin_flag "> prost_plugin_flag</ a > , 273< a href ="#rust_prost_toolchain-prost_runtime "> prost_runtime</ a > ,< a href ="#rust_prost_toolchain-prost_types "> prost_types</ a > ,< a href ="#rust_prost_toolchain-proto_compiler "> proto_compiler</ a > ,< a href ="#rust_prost_toolchain-tonic_opts "> tonic_opts</ a > ,< a href ="#rust_prost_toolchain-tonic_plugin "> tonic_plugin</ a > , 274< a href ="#rust_prost_toolchain-tonic_plugin_flag "> tonic_plugin_flag</ a > ,< a href ="#rust_prost_toolchain-tonic_runtime "> tonic_runtime</ a > ) 275</ pre > 276< p > Rust Prost toolchain rule.</ p > 277< p >< strong > ATTRIBUTES</ strong ></ p > 278< 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 > 279< 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 > 280< 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 > 281< 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 > 282< 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 > 283< 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 > 284< 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 > 285< 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 > 286< 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 > 287< 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 > 288< 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 > 289< 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 > 290< 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 > 291</ tbody ></ table > 292</ div > 293< p >< a id ="rust_prost_library "></ a ></ p > 294< h2 id ="rust_prost_library ">< a class ="header "href ="#rust_prost_library "> rust_prost_library</ a ></ h2 > 295< pre > 296rust_prost_library(< a href ="#rust_prost_library-name "> name</ a > ,< a href ="#rust_prost_library-kwargs "> kwargs</ a > ) 297</ pre > 298< p > A rule for generating a Rust library using Prost.</ p > 299< p >< strong > PARAMETERS</ strong ></ p > 300< 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 > 301< 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 > 302< 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 > 303</ tbody ></ table > 304</ div > 305</ main > 306 307< nav class ="nav-wrapper "aria-label ="Page navigation "> 308<!-- Mobile navigation buttons --> 309< a rel ="prev "href ="rust_bindgen.html "class ="mobile-nav-chapters previous "title ="Previous chapter "aria-label ="Previous chapter "aria-keyshortcuts ="Left "> 310< i class ="fa fa-angle-left "></ i > 311</ a > 312 313< a rel ="next prefetch "href ="rust_protobuf.html "class ="mobile-nav-chapters next "title ="Next chapter "aria-label ="Next chapter "aria-keyshortcuts ="Right "> 314< i class ="fa fa-angle-right "></ i > 315</ a > 316 317< div style ="clear: both "></ div > 318</ nav > 319</ div > 320</ div > 321 322< nav class ="nav-wide-wrapper "aria-label ="Page navigation "> 323< a rel ="prev "href ="rust_bindgen.html "class ="nav-chapters previous "title ="Previous chapter "aria-label ="Previous chapter "aria-keyshortcuts ="Left "> 324< i class ="fa fa-angle-left "></ i > 325</ a > 326 327< a rel ="next prefetch "href ="rust_protobuf.html "class ="nav-chapters next "title ="Next chapter "aria-label ="Next chapter "aria-keyshortcuts ="Right "> 328< i class ="fa fa-angle-right "></ i > 329</ a > 330</ nav > 331 332</ div > 333 334 335 336 337< script > 338window . playground_copyable = true ; 339</ script > 340 341 342< script src ="elasticlunr.min.js "></ script > 343< script src ="mark.min.js "></ script > 344< script src ="searcher.js "></ script > 345 346< script src ="clipboard.min.js "></ script > 347< script src ="highlight.js "></ script > 348< script src ="book.js "></ script > 349 350<!-- Custom JS scripts --> 351 352 353</ div > 354</ body > 355</ html >