diff --git a/docs/defs.md b/docs/defs.md index 6d562010d6..f8c9895edb 100644 --- a/docs/defs.md +++ b/docs/defs.md @@ -72,8 +72,8 @@ Add additional rustc_flags from the command line with `--@rules_rust//:extra_rus
 rust_binary(name, aliases, compile_data, crate_features, crate_name, crate_root, crate_type, data,
-            deps, edition, linker_script, out_binary, proc_macro_deps, rustc_env, rustc_env_files,
-            rustc_flags, srcs, stamp, version)
+            deps, edition, experimental_use_whole_archive_for_native_deps, linker_script, out_binary,
+            proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp, version)
 
Builds a Rust binary crate. @@ -178,6 +178,7 @@ is available under the key `dsym_folder` in `OutputGroupInfo`. | 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 | "" | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | | linker_script | Link script to forward into linker via rustc options. | Label | optional | None | | out_binary | Force a target, regardless of it's crate_type, 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. | Boolean | optional | False | | proc_macro_deps | List of rust_library targets with kind proc-macro used to help build this library target. | List of labels | optional | [] | @@ -195,7 +196,8 @@ is available under the key `dsym_folder` in `OutputGroupInfo`.
 rust_library(name, aliases, compile_data, crate_features, crate_name, crate_root, data, deps,
-             edition, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp, version)
+             edition, experimental_use_whole_archive_for_native_deps, proc_macro_deps, rustc_env,
+             rustc_env_files, rustc_flags, srcs, stamp, version)
 
Builds a Rust library crate. @@ -276,6 +278,7 @@ INFO: Elapsed time: 1.245s, Critical Path: 1.01s | 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 | "" | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | | 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.

Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the stamp attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}. | List of labels | optional | [] | @@ -291,8 +294,8 @@ INFO: Elapsed time: 1.245s, Critical Path: 1.01s
 rust_proc_macro(name, aliases, compile_data, crate_features, crate_name, crate_root, data, deps,
-                edition, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp,
-                version)
+                edition, experimental_use_whole_archive_for_native_deps, proc_macro_deps, rustc_env,
+                rustc_env_files, rustc_flags, srcs, stamp, version)
 
Builds a Rust proc-macro crate. @@ -312,6 +315,7 @@ Builds a Rust proc-macro crate. | 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 | "" | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | | 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.

Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the stamp attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}. | List of labels | optional | [] | @@ -327,8 +331,8 @@ Builds a Rust proc-macro crate.
 rust_shared_library(name, aliases, compile_data, crate_features, crate_name, crate_root, data, deps,
-                    edition, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp,
-                    version)
+                    edition, experimental_use_whole_archive_for_native_deps, proc_macro_deps,
+                    rustc_env, rustc_env_files, rustc_flags, srcs, stamp, version)
 
Builds a Rust shared library. @@ -356,6 +360,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | 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 | "" | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | | 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.

Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the stamp attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}. | List of labels | optional | [] | @@ -371,8 +376,8 @@ When building the whole binary in Bazel, use `rust_library` instead.
 rust_static_library(name, aliases, compile_data, crate_features, crate_name, crate_root, data, deps,
-                    edition, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp,
-                    version)
+                    edition, experimental_use_whole_archive_for_native_deps, proc_macro_deps,
+                    rustc_env, rustc_env_files, rustc_flags, srcs, stamp, version)
 
Builds a Rust static library. @@ -400,6 +405,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | 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 | "" | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | | 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.

Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the stamp attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}. | List of labels | optional | [] | @@ -415,8 +421,8 @@ When building the whole binary in Bazel, use `rust_library` instead.
 rust_test(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, stamp,
-          use_libtest_harness, version)
+          edition, env, experimental_use_whole_archive_for_native_deps, proc_macro_deps, rustc_env,
+          rustc_env_files, rustc_flags, srcs, stamp, use_libtest_harness, version)
 
Builds a Rust test crate. @@ -559,6 +565,7 @@ Run the test with `bazel build //hello_lib:hello_lib_test`. | 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 $(rootpath), $(execpath), location, and ["Make variable"](https://docs.bazel.build/versions/master/be/make-variables.html) substitution.

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. | Dictionary: String -> String | optional | {} | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | | 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.

Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the stamp attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}. | List of labels | optional | [] | diff --git a/docs/flatten.md b/docs/flatten.md index f650bc92bb..4ccaacf620 100644 --- a/docs/flatten.md +++ b/docs/flatten.md @@ -182,8 +182,8 @@ Deprecated: gen_rust_project can now create a rust-project.json without a rust_a
 rust_binary(name, aliases, compile_data, crate_features, crate_name, crate_root, crate_type, data,
-            deps, edition, linker_script, out_binary, proc_macro_deps, rustc_env, rustc_env_files,
-            rustc_flags, srcs, stamp, version)
+            deps, edition, experimental_use_whole_archive_for_native_deps, linker_script, out_binary,
+            proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp, version)
 
Builds a Rust binary crate. @@ -288,6 +288,7 @@ is available under the key `dsym_folder` in `OutputGroupInfo`. | 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 | "" | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | | linker_script | Link script to forward into linker via rustc options. | Label | optional | None | | out_binary | Force a target, regardless of it's crate_type, 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. | Boolean | optional | False | | proc_macro_deps | List of rust_library targets with kind proc-macro used to help build this library target. | List of labels | optional | [] | @@ -404,7 +405,8 @@ rust_clippy( ## rust_doc
-rust_doc(name, crate, html_after_content, html_before_content, html_in_header, markdown_css)
+rust_doc(name, crate, experimental_use_whole_archive_for_native_deps, html_after_content,
+         html_before_content, html_in_header, markdown_css)
 
Generates code documentation. @@ -451,6 +453,7 @@ Running `bazel build //hello_lib:hello_lib_doc` will build a zip file containing | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | crate | The label of the target to generate code documentation for.

rust_doc can generate HTML code documentation for the source files of rust_library or rust_binary targets. | Label | required | | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | | html_after_content | File to add in <body>, after content. | Label | optional | None | | html_before_content | File to add in <body>, before content. | Label | optional | None | | html_in_header | File to add to <head>. | Label | optional | None | @@ -462,7 +465,7 @@ Running `bazel build //hello_lib:hello_lib_doc` will build a zip file containing ## rust_doc_test
-rust_doc_test(name, crate)
+rust_doc_test(name, crate, experimental_use_whole_archive_for_native_deps)
 
Runs Rust documentation tests. @@ -510,6 +513,7 @@ Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation t | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | crate | The label of the target to generate code documentation for. rust_doc_test can generate HTML code documentation for the source files of rust_library or rust_binary targets. | Label | required | | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | @@ -561,7 +565,8 @@ rust_binary(
 rust_library(name, aliases, compile_data, crate_features, crate_name, crate_root, data, deps,
-             edition, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp, version)
+             edition, experimental_use_whole_archive_for_native_deps, proc_macro_deps, rustc_env,
+             rustc_env_files, rustc_flags, srcs, stamp, version)
 
Builds a Rust library crate. @@ -642,6 +647,7 @@ INFO: Elapsed time: 1.245s, Critical Path: 1.01s | 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 | "" | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | | 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.

Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the stamp attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}. | List of labels | optional | [] | @@ -657,8 +663,8 @@ INFO: Elapsed time: 1.245s, Critical Path: 1.01s
 rust_proc_macro(name, aliases, compile_data, crate_features, crate_name, crate_root, data, deps,
-                edition, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp,
-                version)
+                edition, experimental_use_whole_archive_for_native_deps, proc_macro_deps, rustc_env,
+                rustc_env_files, rustc_flags, srcs, stamp, version)
 
Builds a Rust proc-macro crate. @@ -678,6 +684,7 @@ Builds a Rust proc-macro crate. | 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 | "" | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | | 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.

Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the stamp attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}. | List of labels | optional | [] | @@ -793,8 +800,8 @@ See @rules_rust//proto:BUILD for examples of defining the toolchain.
 rust_shared_library(name, aliases, compile_data, crate_features, crate_name, crate_root, data, deps,
-                    edition, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp,
-                    version)
+                    edition, experimental_use_whole_archive_for_native_deps, proc_macro_deps,
+                    rustc_env, rustc_env_files, rustc_flags, srcs, stamp, version)
 
Builds a Rust shared library. @@ -822,6 +829,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | 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 | "" | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | | 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.

Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the stamp attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}. | List of labels | optional | [] | @@ -837,8 +845,8 @@ When building the whole binary in Bazel, use `rust_library` instead.
 rust_static_library(name, aliases, compile_data, crate_features, crate_name, crate_root, data, deps,
-                    edition, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp,
-                    version)
+                    edition, experimental_use_whole_archive_for_native_deps, proc_macro_deps,
+                    rustc_env, rustc_env_files, rustc_flags, srcs, stamp, version)
 
Builds a Rust static library. @@ -866,6 +874,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | 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 | "" | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | | 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.

Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the stamp attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}. | List of labels | optional | [] | @@ -900,8 +909,8 @@ A dedicated filegroup-like rule for Rust stdlib artifacts.
 rust_test(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, stamp,
-          use_libtest_harness, version)
+          edition, env, experimental_use_whole_archive_for_native_deps, proc_macro_deps, rustc_env,
+          rustc_env_files, rustc_flags, srcs, stamp, use_libtest_harness, version)
 
Builds a Rust test crate. @@ -1044,6 +1053,7 @@ Run the test with `bazel build //hello_lib:hello_lib_test`. | 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 $(rootpath), $(execpath), location, and ["Make variable"](https://docs.bazel.build/versions/master/be/make-variables.html) substitution.

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. | Dictionary: String -> String | optional | {} | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | | 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.

Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the stamp attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}. | List of labels | optional | [] | diff --git a/docs/rust_doc.md b/docs/rust_doc.md index cf5bf017bd..b8b5e71a9a 100644 --- a/docs/rust_doc.md +++ b/docs/rust_doc.md @@ -9,7 +9,8 @@ ## rust_doc
-rust_doc(name, crate, html_after_content, html_before_content, html_in_header, markdown_css)
+rust_doc(name, crate, experimental_use_whole_archive_for_native_deps, html_after_content,
+         html_before_content, html_in_header, markdown_css)
 
Generates code documentation. @@ -56,6 +57,7 @@ Running `bazel build //hello_lib:hello_lib_doc` will build a zip file containing | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | crate | The label of the target to generate code documentation for.

rust_doc can generate HTML code documentation for the source files of rust_library or rust_binary targets. | Label | required | | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | | html_after_content | File to add in <body>, after content. | Label | optional | None | | html_before_content | File to add in <body>, before content. | Label | optional | None | | html_in_header | File to add to <head>. | Label | optional | None | @@ -67,7 +69,7 @@ Running `bazel build //hello_lib:hello_lib_doc` will build a zip file containing ## rust_doc_test
-rust_doc_test(name, crate)
+rust_doc_test(name, crate, experimental_use_whole_archive_for_native_deps)
 
Runs Rust documentation tests. @@ -115,5 +117,6 @@ Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation t | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | crate | The label of the target to generate code documentation for. rust_doc_test can generate HTML code documentation for the source files of rust_library or rust_binary targets. | Label | required | | +| experimental_use_whole_archive_for_native_deps | Whether to use +whole-archive linking modifier for native dependencies.

TODO: This is a stopgap feature and will be removed, see https://github.com/bazelbuild/rules_rust/issues/1268. | Boolean | optional | False | diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl index 3c2c6b5189..4687e638a3 100644 --- a/rust/private/rust.bzl +++ b/rust/private/rust.bzl @@ -493,6 +493,15 @@ _common_attrs = { "edition": attr.string( doc = "The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.", ), + "experimental_use_whole_archive_for_native_deps": attr.bool( + doc = dedent("""\ + Whether to use +whole-archive linking modifier for native dependencies. + + TODO: This is a stopgap feature and will be removed, + see https://github.com/bazelbuild/rules_rust/issues/1268. + """), + default = False, + ), # Previously `proc_macro_deps` were a part of `deps`, and then proc_macro_host_transition was # used into cfg="host" using `@local_config_platform//:host`. # This fails for remote execution, which needs cfg="exec", and there isn't anything like diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 2c33bb4fe3..3f1084a2b2 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -762,7 +762,7 @@ def construct_arguments( rustc_flags.add("--codegen=linker=" + ld) rustc_flags.add_joined("--codegen", link_args, join_with = " ", format_joined = "link-args=%s") - _add_native_link_flags(rustc_flags, dep_info, linkstamp_outs, ambiguous_libs, crate_info.type, toolchain, cc_toolchain, feature_configuration) + _add_native_link_flags(rustc_flags, dep_info, linkstamp_outs, ambiguous_libs, crate_info.type, toolchain, cc_toolchain, feature_configuration, attr.experimental_use_whole_archive_for_native_deps) # These always need to be added, even if not linking this crate. extra_link_inputs = add_crate_link_flags(ctx, toolchain, rustc_flags, crate_info, dep_info, force_all_deps_direct) @@ -1306,13 +1306,16 @@ def _get_crate_dirname(crate): """ return crate.output.dirname -def _portable_link_flags(lib, use_pic, ambiguous_libs): +def _portable_link_flags(lib, use_pic, ambiguous_libs, experimental_use_whole_archive_for_native_deps): artifact = get_preferred_artifact(lib, use_pic) if ambiguous_libs and artifact.path in ambiguous_libs: artifact = ambiguous_libs[artifact.path] if lib.static_library or lib.pic_static_library: + modifiers = "" + if experimental_use_whole_archive_for_native_deps: + modifiers = ":+whole-archive" return [ - "-lstatic=%s" % get_lib_name(artifact), + "-lstatic%s=%s" % (modifiers, get_lib_name(artifact)), ] elif _is_dylib(lib): return [ @@ -1321,18 +1324,18 @@ def _portable_link_flags(lib, use_pic, ambiguous_libs): return [] -def _make_link_flags_windows(linker_input_and_use_pic_and_ambiguous_libs): - linker_input, use_pic, ambiguous_libs = linker_input_and_use_pic_and_ambiguous_libs +def _make_link_flags_windows(linker_input_and_use_pic_and_ambiguous_libs_and_experimental_use_whole_archive_for_native_deps): + linker_input, use_pic, ambiguous_libs, experimental_use_whole_archive_for_native_deps = linker_input_and_use_pic_and_ambiguous_libs_and_experimental_use_whole_archive_for_native_deps ret = [] for lib in linker_input.libraries: if lib.alwayslink: ret.extend(["-C", "link-arg=/WHOLEARCHIVE:%s" % get_preferred_artifact(lib, use_pic).path]) else: - ret.extend(_portable_link_flags(lib, use_pic, ambiguous_libs)) + ret.extend(_portable_link_flags(lib, use_pic, ambiguous_libs, experimental_use_whole_archive_for_native_deps)) return ret -def _make_link_flags_darwin(linker_input_and_use_pic_and_ambiguous_libs): - linker_input, use_pic, ambiguous_libs = linker_input_and_use_pic_and_ambiguous_libs +def _make_link_flags_darwin(linker_input_and_use_pic_and_ambiguous_libs_and_experimental_use_whole_archive_for_native_deps): + linker_input, use_pic, ambiguous_libs, experimental_use_whole_archive_for_native_deps = linker_input_and_use_pic_and_ambiguous_libs_and_experimental_use_whole_archive_for_native_deps ret = [] for lib in linker_input.libraries: if lib.alwayslink: @@ -1341,11 +1344,11 @@ def _make_link_flags_darwin(linker_input_and_use_pic_and_ambiguous_libs): ("link-arg=-Wl,-force_load,%s" % get_preferred_artifact(lib, use_pic).path), ]) else: - ret.extend(_portable_link_flags(lib, use_pic, ambiguous_libs)) + ret.extend(_portable_link_flags(lib, use_pic, ambiguous_libs, experimental_use_whole_archive_for_native_deps)) return ret -def _make_link_flags_default(linker_input_and_use_pic_and_ambiguous_libs): - linker_input, use_pic, ambiguous_libs = linker_input_and_use_pic_and_ambiguous_libs +def _make_link_flags_default(linker_input_and_use_pic_and_ambiguous_libs_and_experimental_use_whole_archive_for_native_deps): + linker_input, use_pic, ambiguous_libs, experimental_use_whole_archive_for_native_deps = linker_input_and_use_pic_and_ambiguous_libs_and_experimental_use_whole_archive_for_native_deps ret = [] for lib in linker_input.libraries: if lib.alwayslink: @@ -1358,16 +1361,16 @@ def _make_link_flags_default(linker_input_and_use_pic_and_ambiguous_libs): "link-arg=-Wl,--no-whole-archive", ]) else: - ret.extend(_portable_link_flags(lib, use_pic, ambiguous_libs)) + ret.extend(_portable_link_flags(lib, use_pic, ambiguous_libs, experimental_use_whole_archive_for_native_deps)) return ret -def _libraries_dirnames(linker_input_and_use_pic_and_ambiguous_libs): - link_input, use_pic, _ = linker_input_and_use_pic_and_ambiguous_libs +def _libraries_dirnames(linker_input_and_use_pic_and_ambiguous_libs_and_experimental_use_whole_archive_for_native_deps): + link_input, use_pic, _, _ = linker_input_and_use_pic_and_ambiguous_libs_and_experimental_use_whole_archive_for_native_deps # De-duplicate names. return depset([get_preferred_artifact(lib, use_pic).dirname for lib in link_input.libraries]).to_list() -def _add_native_link_flags(args, dep_info, linkstamp_outs, ambiguous_libs, crate_type, toolchain, cc_toolchain, feature_configuration): +def _add_native_link_flags(args, dep_info, linkstamp_outs, ambiguous_libs, crate_type, toolchain, cc_toolchain, feature_configuration, experimental_use_whole_archive_for_native_deps): """Adds linker flags for all dependencies of the current target. Args: @@ -1379,7 +1382,7 @@ def _add_native_link_flags(args, dep_info, linkstamp_outs, ambiguous_libs, crate toolchain (rust_toolchain): The current `rust_toolchain` cc_toolchain (CcToolchainInfo): The current `cc_toolchain` feature_configuration (FeatureConfiguration): feature configuration to use with cc_toolchain - + experimental_use_whole_archive_for_native_deps (bool): Whether to use the whole-archive link modifier for native deps, see https://github.com/bazelbuild/rules_rust/issues/1268 """ if crate_type in ["lib", "rlib"]: return @@ -1394,15 +1397,15 @@ def _add_native_link_flags(args, dep_info, linkstamp_outs, ambiguous_libs, crate make_link_flags = _make_link_flags_default # TODO(hlopko): Remove depset flattening by using lambdas once we are on >=Bazel 5.0 - args_and_pic_and_ambiguous_libs = [(arg, use_pic, ambiguous_libs) for arg in dep_info.transitive_noncrates.to_list()] - args.add_all(args_and_pic_and_ambiguous_libs, map_each = _libraries_dirnames, uniquify = True, format_each = "-Lnative=%s") + args_and_pic_and_ambiguous_libs_and_use_whole_archive_for_native_deps = [(arg, use_pic, ambiguous_libs, experimental_use_whole_archive_for_native_deps) for arg in dep_info.transitive_noncrates.to_list()] + args.add_all(args_and_pic_and_ambiguous_libs_and_use_whole_archive_for_native_deps, map_each = _libraries_dirnames, uniquify = True, format_each = "-Lnative=%s") if ambiguous_libs: # If there are ambiguous libs, the disambiguation symlinks to them are # all created in the same directory. Add it to the library search path. ambiguous_libs_dirname = ambiguous_libs.values()[0].dirname args.add("-Lnative={}".format(ambiguous_libs_dirname)) - args.add_all(args_and_pic_and_ambiguous_libs, map_each = make_link_flags) + args.add_all(args_and_pic_and_ambiguous_libs_and_use_whole_archive_for_native_deps, map_each = make_link_flags) for linkstamp_out in linkstamp_outs: args.add_all(["-C", "link-arg=%s" % linkstamp_out.path]) diff --git a/rust/private/rustdoc.bzl b/rust/private/rustdoc.bzl index a2825a6b8f..b9b59dc5bb 100644 --- a/rust/private/rustdoc.bzl +++ b/rust/private/rustdoc.bzl @@ -266,6 +266,15 @@ rust_doc = rule( providers = [rust_common.crate_info], mandatory = True, ), + "experimental_use_whole_archive_for_native_deps": attr.bool( + doc = dedent("""\ + Whether to use +whole-archive linking modifier for native dependencies. + + TODO: This is a stopgap feature and will be removed, + see https://github.com/bazelbuild/rules_rust/issues/1268. + """), + default = False, + ), "html_after_content": attr.label( doc = "File to add in ``, after content.", allow_single_file = [".html", ".md"], diff --git a/rust/private/rustdoc_test.bzl b/rust/private/rustdoc_test.bzl index 663c65f12b..148e8eab06 100644 --- a/rust/private/rustdoc_test.bzl +++ b/rust/private/rustdoc_test.bzl @@ -154,6 +154,15 @@ rust_doc_test = rule( providers = [rust_common.crate_info], mandatory = True, ), + "experimental_use_whole_archive_for_native_deps": attr.bool( + doc = dedent("""\ + Whether to use +whole-archive linking modifier for native dependencies. + + TODO: This is a stopgap feature and will be removed, + see https://github.com/bazelbuild/rules_rust/issues/1268. + """), + default = False, + ), "_cc_toolchain": attr.label( doc = ( "In order to use find_cc_toolchain, your rule has to depend " +