diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index c0b54777c6..797b7908d1 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -62,6 +62,7 @@ PAGES = dict([ "rust_proc_macro", "rust_benchmark", "rust_test", + "rust_test_binary", "rust_test_suite", ], ), diff --git a/docs/defs.md b/docs/defs.md index 60ecff4c9f..2eb51d1b40 100644 --- a/docs/defs.md +++ b/docs/defs.md @@ -8,6 +8,7 @@ * [rust_proc_macro](#rust_proc_macro) * [rust_benchmark](#rust_benchmark) * [rust_test](#rust_test) +* [rust_test_binary](#rust_test_binary) * [rust_test_suite](#rust_test_suite) @@ -611,6 +612,52 @@ Run the test with `bazel build //hello_lib:hello_lib_test`. | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | + + +## rust_test_binary + +
+rust_test_binary(name, aliases, compile_data, crate, crate_features, crate_name, crate_root, data,
+                 deps, edition, env, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs,
+                 use_libtest_harness, version)
+
+ +Builds a Rust test binary, without marking this rule as a Bazel test. + +**Warning**: This rule is currently experimental. + +This should be used when you want to run the test binary from a different test +rule (such as [`sh_test`](https://docs.bazel.build/versions/master/be/shell.html#sh_test)), +and know that running the test binary directly will fail. + +See `rust_test` for example usage. + + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| aliases | Remap crates to a new name or moniker for linkage to this target

These are other rust_library targets and will be presented as the new name given. | Dictionary: Label -> String | optional | {} | +| compile_data | List of files used by this rule at compile time.

This attribute can be used to specify any data files that are embedded into the library, such as via the [include_str!](https://doc.rust-lang.org/std/macro.include_str!.html) macro. | List of labels | optional | [] | +| crate | Target inline tests declared in the given crate

These tests are typically those that would be held out under #[cfg(test)] declarations. | Label | optional | None | +| crate_features | List of features to enable for this crate.

Features are defined in the code using the #[cfg(feature = "foo")] configuration option. The features listed here will be passed to rustc with --cfg feature="${feature_name}" flags. | List of strings | optional | [] | +| crate_name | Crate name to use for this target.

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. | String | optional | "" | +| crate_root | The file that will be passed to rustc to be used for building this crate.

If crate_root is not set, then this rule will look for a lib.rs file (or main.rs for rust_binary) or the single file in srcs if srcs contains only one file. | Label | optional | None | +| data | List of files used by this rule at compile time and runtime.

If including data at compile time with include_str!() and similar, prefer compile_data over data, to prevent the data also being included in the runfiles. | List of labels | optional | [] | +| deps | List of other libraries to be linked to this library target.

These can be either other rust_library targets or cc_library targets if linking a native library. | List of labels | optional | [] | +| edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | "" | +| env | Specifies additional environment variables to set when the test is executed by bazel test. Values are subject to $(execpath) and ["Make variable"](https://docs.bazel.build/versions/master/be/make-variables.html) substitution. | Dictionary: String -> String | optional | {} | +| proc_macro_deps | List of rust_library targets with kind proc-macro used to help build this library target. | List of labels | optional | [] | +| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc.

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. | Dictionary: String -> String | optional | {} | +| rustc_env_files | Files containing additional environment variables to set for rustc.

These files should contain a single variable per line, of format NAME=value, and newlines may be included in a value by ending a line with a trailing back-slash (\).

The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged. | List of labels | optional | [] | +| rustc_flags | List of compiler flags passed to rustc.

These strings are subject to Make variable expansion for predefined source/output path variables like $location, $execpath, and $rootpath. This expansion is useful if you wish to pass a generated file of arguments to rustc: @$(location //package:target). | List of strings | optional | [] | +| srcs | List of Rust .rs source files used to build the library.

If srcs contains more than one file, then there must be a file either named lib.rs. Otherwise, crate_root must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | List of labels | optional | [] | +| use_libtest_harness | Whether to use libtest. | Boolean | optional | True | +| version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | + + ## rust_test_suite diff --git a/docs/flatten.md b/docs/flatten.md index f9b301ec1e..7da3f0028b 100644 --- a/docs/flatten.md +++ b/docs/flatten.md @@ -29,6 +29,7 @@ * [rust_static_library](#rust_static_library) * [rust_stdlib_filegroup](#rust_stdlib_filegroup) * [rust_test](#rust_test) +* [rust_test_binary](#rust_test_binary) * [rust_test_suite](#rust_test_suite) * [rust_toolchain](#rust_toolchain) * [rust_toolchain_repository](#rust_toolchain_repository) @@ -1118,6 +1119,52 @@ Run the test with `bazel build //hello_lib:hello_lib_test`. | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | + + +## rust_test_binary + +
+rust_test_binary(name, aliases, compile_data, crate, crate_features, crate_name, crate_root, data,
+                 deps, edition, env, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs,
+                 use_libtest_harness, version)
+
+ +Builds a Rust test binary, without marking this rule as a Bazel test. + +**Warning**: This rule is currently experimental. + +This should be used when you want to run the test binary from a different test +rule (such as [`sh_test`](https://docs.bazel.build/versions/master/be/shell.html#sh_test)), +and know that running the test binary directly will fail. + +See `rust_test` for example usage. + + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| aliases | Remap crates to a new name or moniker for linkage to this target

These are other rust_library targets and will be presented as the new name given. | Dictionary: Label -> String | optional | {} | +| compile_data | List of files used by this rule at compile time.

This attribute can be used to specify any data files that are embedded into the library, such as via the [include_str!](https://doc.rust-lang.org/std/macro.include_str!.html) macro. | List of labels | optional | [] | +| crate | Target inline tests declared in the given crate

These tests are typically those that would be held out under #[cfg(test)] declarations. | Label | optional | None | +| crate_features | List of features to enable for this crate.

Features are defined in the code using the #[cfg(feature = "foo")] configuration option. The features listed here will be passed to rustc with --cfg feature="${feature_name}" flags. | List of strings | optional | [] | +| crate_name | Crate name to use for this target.

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. | String | optional | "" | +| crate_root | The file that will be passed to rustc to be used for building this crate.

If crate_root is not set, then this rule will look for a lib.rs file (or main.rs for rust_binary) or the single file in srcs if srcs contains only one file. | Label | optional | None | +| data | List of files used by this rule at compile time and runtime.

If including data at compile time with include_str!() and similar, prefer compile_data over data, to prevent the data also being included in the runfiles. | List of labels | optional | [] | +| deps | List of other libraries to be linked to this library target.

These can be either other rust_library targets or cc_library targets if linking a native library. | List of labels | optional | [] | +| edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | "" | +| env | Specifies additional environment variables to set when the test is executed by bazel test. Values are subject to $(execpath) and ["Make variable"](https://docs.bazel.build/versions/master/be/make-variables.html) substitution. | Dictionary: String -> String | optional | {} | +| proc_macro_deps | List of rust_library targets with kind proc-macro used to help build this library target. | List of labels | optional | [] | +| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc.

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. | Dictionary: String -> String | optional | {} | +| rustc_env_files | Files containing additional environment variables to set for rustc.

These files should contain a single variable per line, of format NAME=value, and newlines may be included in a value by ending a line with a trailing back-slash (\).

The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged. | List of labels | optional | [] | +| rustc_flags | List of compiler flags passed to rustc.

These strings are subject to Make variable expansion for predefined source/output path variables like $location, $execpath, and $rootpath. This expansion is useful if you wish to pass a generated file of arguments to rustc: @$(location //package:target). | List of strings | optional | [] | +| srcs | List of Rust .rs source files used to build the library.

If srcs contains more than one file, then there must be a file either named lib.rs. Otherwise, crate_root must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | List of labels | optional | [] | +| use_libtest_harness | Whether to use libtest. | Boolean | optional | True | +| version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | + + ## rust_toolchain diff --git a/docs/symbols.bzl b/docs/symbols.bzl index 626aa0616a..86218f280c 100644 --- a/docs/symbols.bzl +++ b/docs/symbols.bzl @@ -49,6 +49,7 @@ load( _rust_shared_library = "rust_shared_library", _rust_static_library = "rust_static_library", _rust_test = "rust_test", + _rust_test_binary = "rust_test_binary", _rust_test_suite = "rust_test_suite", _rustfmt_aspect = "rustfmt_aspect", _rustfmt_test = "rustfmt_test", @@ -86,6 +87,7 @@ rust_static_library = _rust_static_library rust_shared_library = _rust_shared_library rust_proc_macro = _rust_proc_macro rust_test = _rust_test +rust_test_binary = _rust_test_binary rust_test_suite = _rust_test_suite rust_doc = _rust_doc rust_doc_test = _rust_doc_test