|
15 | 15 | * [rust_doc_test](#rust_doc_test)
|
16 | 16 | * [rust_grpc_library](#rust_grpc_library)
|
17 | 17 | * [rust_library](#rust_library)
|
| 18 | +* [rust_proc_macro](#rust_proc_macro) |
18 | 19 | * [rust_proto_library](#rust_proto_library)
|
19 | 20 | * [rust_proto_repositories](#rust_proto_repositories)
|
20 | 21 | * [rust_proto_toolchain](#rust_proto_toolchain)
|
21 | 22 | * [rust_repositories](#rust_repositories)
|
22 | 23 | * [rust_repository_set](#rust_repository_set)
|
| 24 | +* [rust_shared_library](#rust_shared_library) |
| 25 | +* [rust_static_library](#rust_static_library) |
23 | 26 | * [rust_test](#rust_test)
|
24 | 27 | * [rust_toolchain](#rust_toolchain)
|
25 | 28 | * [rust_toolchain_repository](#rust_toolchain_repository)
|
@@ -116,7 +119,7 @@ To build the benchmark test, add a `rust_benchmark` target:
|
116 | 119 | ```python
|
117 | 120 | package(default_visibility = ["//visibility:public"])
|
118 | 121 |
|
119 |
| -load("@rules_rust//rust:rust.bzl", "rust_library", "rust_benchmark") |
| 122 | +load("@rules_rust//rust:defs.bzl", "rust_library", "rust_benchmark") |
120 | 123 |
|
121 | 124 | rust_library(
|
122 | 125 | name = "fibonacci",
|
@@ -159,9 +162,9 @@ Run the benchmark test using: `bazel run //fibonacci:fibonacci_bench`.
|
159 | 162 | ## rust_binary
|
160 | 163 |
|
161 | 164 | <pre>
|
162 |
| -rust_binary(<a href="#rust_binary-name">name</a>, <a href="#rust_binary-aliases">aliases</a>, <a href="#rust_binary-compile_data">compile_data</a>, <a href="#rust_binary-crate_features">crate_features</a>, <a href="#rust_binary-crate_root">crate_root</a>, <a href="#rust_binary-crate_type">crate_type</a>, <a href="#rust_binary-data">data</a>, <a href="#rust_binary-deps">deps</a>, |
163 |
| - <a href="#rust_binary-edition">edition</a>, <a href="#rust_binary-linker_script">linker_script</a>, <a href="#rust_binary-out_binary">out_binary</a>, <a href="#rust_binary-out_dir_tar">out_dir_tar</a>, <a href="#rust_binary-proc_macro_deps">proc_macro_deps</a>, <a href="#rust_binary-rustc_env">rustc_env</a>, <a href="#rust_binary-rustc_flags">rustc_flags</a>, |
164 |
| - <a href="#rust_binary-srcs">srcs</a>, <a href="#rust_binary-version">version</a>) |
| 165 | +rust_binary(<a href="#rust_binary-name">name</a>, <a href="#rust_binary-aliases">aliases</a>, <a href="#rust_binary-compile_data">compile_data</a>, <a href="#rust_binary-crate_features">crate_features</a>, <a href="#rust_binary-crate_root">crate_root</a>, <a href="#rust_binary-data">data</a>, <a href="#rust_binary-deps">deps</a>, <a href="#rust_binary-edition">edition</a>, |
| 166 | + <a href="#rust_binary-linker_script">linker_script</a>, <a href="#rust_binary-out_binary">out_binary</a>, <a href="#rust_binary-out_dir_tar">out_dir_tar</a>, <a href="#rust_binary-proc_macro_deps">proc_macro_deps</a>, <a href="#rust_binary-rustc_env">rustc_env</a>, <a href="#rust_binary-rustc_flags">rustc_flags</a>, <a href="#rust_binary-srcs">srcs</a>, |
| 167 | + <a href="#rust_binary-version">version</a>) |
165 | 168 | </pre>
|
166 | 169 |
|
167 | 170 | Builds a Rust binary crate.
|
@@ -258,7 +261,6 @@ Hello world
|
258 | 261 | | <a id="rust_binary-compile_data"></a>compile_data | 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 [<code>include_str!</code>](https://doc.rust-lang.org/std/macro.include_str!.html) macro. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
259 | 262 | | <a id="rust_binary-crate_features"></a>crate_features | 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. | List of strings | optional | [] |
|
260 | 263 | | <a id="rust_binary-crate_root"></a>crate_root | 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. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
|
261 |
| -| <a id="rust_binary-crate_type"></a>crate_type | - | String | optional | "bin" | |
262 | 264 | | <a id="rust_binary-data"></a>data | 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. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
263 | 265 | | <a id="rust_binary-deps"></a>deps | 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. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
264 | 266 | | <a id="rust_binary-edition"></a>edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | "" |
|
@@ -528,101 +530,6 @@ rust_binary(
|
528 | 530 | | <a id="rust_grpc_library-rust_deps"></a>rust_deps | The crates the generated library depends on. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [Label("//proto/raze:protobuf"), Label("//proto/raze:grpc"), Label("//proto/raze:tls_api"), Label("//proto/raze:tls_api_stub")] |
|
529 | 531 |
|
530 | 532 |
|
531 |
| -<a id="#rust_library"></a> |
532 |
| - |
533 |
| -## rust_library |
534 |
| - |
535 |
| -<pre> |
536 |
| -rust_library(<a href="#rust_library-name">name</a>, <a href="#rust_library-aliases">aliases</a>, <a href="#rust_library-compile_data">compile_data</a>, <a href="#rust_library-crate_features">crate_features</a>, <a href="#rust_library-crate_root">crate_root</a>, <a href="#rust_library-crate_type">crate_type</a>, <a href="#rust_library-data">data</a>, <a href="#rust_library-deps">deps</a>, |
537 |
| - <a href="#rust_library-edition">edition</a>, <a href="#rust_library-out_dir_tar">out_dir_tar</a>, <a href="#rust_library-proc_macro_deps">proc_macro_deps</a>, <a href="#rust_library-rustc_env">rustc_env</a>, <a href="#rust_library-rustc_flags">rustc_flags</a>, <a href="#rust_library-srcs">srcs</a>, <a href="#rust_library-version">version</a>) |
538 |
| -</pre> |
539 |
| - |
540 |
| -Builds a Rust library crate. |
541 |
| - |
542 |
| -Example: |
543 |
| - |
544 |
| -Suppose you have the following directory structure for a simple Rust library crate: |
545 |
| - |
546 |
| -```output |
547 |
| -[workspace]/ |
548 |
| - WORKSPACE |
549 |
| - hello_lib/ |
550 |
| - BUILD |
551 |
| - src/ |
552 |
| - greeter.rs |
553 |
| - lib.rs |
554 |
| -``` |
555 |
| - |
556 |
| -`hello_lib/src/greeter.rs`: |
557 |
| -```rust |
558 |
| -pub struct Greeter { |
559 |
| - greeting: String, |
560 |
| -} |
561 |
| - |
562 |
| -impl Greeter { |
563 |
| - pub fn new(greeting: &str) -> Greeter { |
564 |
| - Greeter { greeting: greeting.to_string(), } |
565 |
| - } |
566 |
| - |
567 |
| - pub fn greet(&self, thing: &str) { |
568 |
| - println!("{} {}", &self.greeting, thing); |
569 |
| - } |
570 |
| -} |
571 |
| -``` |
572 |
| - |
573 |
| -`hello_lib/src/lib.rs`: |
574 |
| - |
575 |
| -```rust |
576 |
| -pub mod greeter; |
577 |
| -``` |
578 |
| - |
579 |
| -`hello_lib/BUILD`: |
580 |
| -```python |
581 |
| -package(default_visibility = ["//visibility:public"]) |
582 |
| - |
583 |
| -load("@rules_rust//rust:rust.bzl", "rust_library") |
584 |
| - |
585 |
| -rust_library( |
586 |
| - name = "hello_lib", |
587 |
| - srcs = [ |
588 |
| - "src/greeter.rs", |
589 |
| - "src/lib.rs", |
590 |
| - ], |
591 |
| -) |
592 |
| -``` |
593 |
| - |
594 |
| -Build the library: |
595 |
| -```output |
596 |
| -$ bazel build //hello_lib |
597 |
| -INFO: Found 1 target... |
598 |
| -Target //examples/rust/hello_lib:hello_lib up-to-date: |
599 |
| - bazel-bin/examples/rust/hello_lib/libhello_lib.rlib |
600 |
| -INFO: Elapsed time: 1.245s, Critical Path: 1.01s |
601 |
| -``` |
602 |
| - |
603 |
| - |
604 |
| -**ATTRIBUTES** |
605 |
| - |
606 |
| - |
607 |
| -| Name | Description | Type | Mandatory | Default | |
608 |
| -| :------------- | :------------- | :------------- | :------------- | :------------- | |
609 |
| -| <a id="rust_library-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | | |
610 |
| -| <a id="rust_library-aliases"></a>aliases | 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. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: Label -> String</a> | optional | {} | |
611 |
| -| <a id="rust_library-compile_data"></a>compile_data | 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 [<code>include_str!</code>](https://doc.rust-lang.org/std/macro.include_str!.html) macro. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] | |
612 |
| -| <a id="rust_library-crate_features"></a>crate_features | 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. | List of strings | optional | [] | |
613 |
| -| <a id="rust_library-crate_root"></a>crate_root | 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. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None | |
614 |
| -| <a id="rust_library-crate_type"></a>crate_type | The type of linkage to use for building this library. Options include <code>"lib"</code>, <code>"rlib"</code>, <code>"dylib"</code>, <code>"cdylib"</code>, <code>"staticlib"</code>, and <code>"proc-macro"</code>.<br><br>The exact output file will depend on the toolchain used. | String | optional | "rlib" | |
615 |
| -| <a id="rust_library-data"></a>data | 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. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] | |
616 |
| -| <a id="rust_library-deps"></a>deps | 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. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] | |
617 |
| -| <a id="rust_library-edition"></a>edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | "" | |
618 |
| -| <a id="rust_library-out_dir_tar"></a>out_dir_tar | __Deprecated__, do not use, see [#cargo_build_script] instead. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None | |
619 |
| -| <a id="rust_library-proc_macro_deps"></a>proc_macro_deps | List of <code>rust_library</code> targets with kind <code>proc-macro</code> used to help build this library target. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] | |
620 |
| -| <a id="rust_library-rustc_env"></a>rustc_env | 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. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} | |
621 |
| -| <a id="rust_library-rustc_flags"></a>rustc_flags | List of compiler flags passed to <code>rustc</code>. | List of strings | optional | [] | |
622 |
| -| <a id="rust_library-srcs"></a>srcs | 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. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] | |
623 |
| -| <a id="rust_library-version"></a>version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | |
624 |
| - |
625 |
| - |
626 | 533 | <a id="#rust_proto_library"></a>
|
627 | 534 |
|
628 | 535 | ## rust_proto_library
|
@@ -779,7 +686,7 @@ To build and run the tests, simply add a `rust_test` rule with no `srcs` and onl
|
779 | 686 | ```python
|
780 | 687 | package(default_visibility = ["//visibility:public"])
|
781 | 688 |
|
782 |
| -load("@rules_rust//rust:rust.bzl", "rust_library", "rust_test") |
| 689 | +load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") |
783 | 690 |
|
784 | 691 | rust_library(
|
785 | 692 | name = "hello_lib",
|
@@ -842,7 +749,7 @@ with `greeting.rs` in `srcs` and a dependency on the `hello_lib` target:
|
842 | 749 | ```python
|
843 | 750 | package(default_visibility = ["//visibility:public"])
|
844 | 751 |
|
845 |
| -load("@rules_rust//rust:rust.bzl", "rust_library", "rust_test") |
| 752 | +load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") |
846 | 753 |
|
847 | 754 | rust_library(
|
848 | 755 | name = "hello_lib",
|
@@ -1214,6 +1121,24 @@ Declare dependencies needed for bindgen.
|
1214 | 1121 |
|
1215 | 1122 |
|
1216 | 1123 |
|
| 1124 | +<a id="#rust_library"></a> |
| 1125 | + |
| 1126 | +## rust_library |
| 1127 | + |
| 1128 | +<pre> |
| 1129 | +rust_library(<a href="#rust_library-args">args</a>) |
| 1130 | +</pre> |
| 1131 | + |
| 1132 | +Deprecated. Use the version from "@rules_rust//rust:defs.bzl" instead. |
| 1133 | + |
| 1134 | +**PARAMETERS** |
| 1135 | + |
| 1136 | + |
| 1137 | +| Name | Description | Default Value | |
| 1138 | +| :------------- | :------------- | :------------- | |
| 1139 | +| <a id="rust_library-args"></a>args | args to pass to the relevant rule. | none | |
| 1140 | + |
| 1141 | + |
1217 | 1142 | <a id="#rust_proto_repositories"></a>
|
1218 | 1143 |
|
1219 | 1144 | ## rust_proto_repositories
|
|
0 commit comments