From 74e3b8a3206c3d7dbf1ae7ff7c327f72e37aa3cf Mon Sep 17 00:00:00 2001 From: RS Date: Sun, 27 Jun 2021 12:16:29 -0700 Subject: [PATCH 01/22] Expand locations in rustc_flags. --- rust/private/rustc.bzl | 10 +++++++++- rust/private/utils.bzl | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 367474d403..3528b38a71 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -21,6 +21,7 @@ load("//rust/private:common.bzl", "rust_common") load( "//rust/private:utils.bzl", "crate_name_from_attr", + "expand_arg_locations", "expand_locations", "find_cc_toolchain", "get_lib_name", @@ -440,7 +441,14 @@ def construct_arguments( args.add_all(rust_lib_paths, before_each = "-L", format_each = "%s") args.add_all(rust_flags) - args.add_all(getattr(attr, "rustc_flags", [])) + args.add_all( + expand_arg_locations( + ctx, + getattr(attr, "rustc_flags", []), + getattr(attr, "data", []) + + getattr(attr, "compile_data", []), + ), + ) add_edition_flags(args, crate_info) # Link! diff --git a/rust/private/utils.bzl b/rust/private/utils.bzl index ac455848a5..a62e331c3b 100644 --- a/rust/private/utils.bzl +++ b/rust/private/utils.bzl @@ -179,6 +179,23 @@ def expand_locations(ctx, env, data): """ return dict([(k, _expand_location(ctx, v, data)) for (k, v) in env.items()]) +def expand_arg_locations(ctx, args, data): + """Performs location-macro expansion on a list of string values. + + See `expand_locations` for detailed documentation. + + Args: + ctx (ctx): The rule's context object + args (list): A list we iterate over + data (sequence of Targets): The targets which may be referenced by + location macros. This is expected to be the `data` attribute of + the target, though may have other targets or attributes mixed in. + + Returns: + list: A list of arguments with expanded location macros + """ + return [_expand_location(ctx, arg, data) for arg in args] + def name_to_crate_name(name): """Converts a build target's name into the name of its associated crate. From 1625b23699fa2d260a8d71951c308dfef9dfd54f Mon Sep 17 00:00:00 2001 From: RS Date: Mon, 28 Jun 2021 08:48:57 -0700 Subject: [PATCH 02/22] Address comments. --- examples/env_locations/BUILD.bazel | 11 +++++++++++ examples/env_locations/main.rs | 4 ++++ rust/private/rustc.bzl | 10 +++++----- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/examples/env_locations/BUILD.bazel b/examples/env_locations/BUILD.bazel index fe313cf2d0..44e44641f1 100644 --- a/examples/env_locations/BUILD.bazel +++ b/examples/env_locations/BUILD.bazel @@ -11,11 +11,19 @@ genrule( cmd = "echo hello > $@", ) +# generate a file containing cfg flags +genrule( + name = "flag_generator", + outs = ["generated_flag.data"], + cmd = "echo --cfg=test_flag > $@", +) + _data = [ # we should be able to read non-generated source/data files "source.file", # and generated files as well "generated.data", + "generated_flag.data", # we should also be able to access external binaries # such as protoc. "@com_google_protobuf//:protoc", @@ -46,6 +54,9 @@ rust_test( "SOME_TOOL": "$(rootpath @com_google_protobuf//:protoc)", "SOURCE_FILE": "$(rootpath source.file)", }, + rustc_flags = [ + "@$(location generated_flag.data)", + ], deps = [ ":build", ], diff --git a/examples/env_locations/main.rs b/examples/env_locations/main.rs index 3b07b1dc9a..d3e3bedfd9 100644 --- a/examples/env_locations/main.rs +++ b/examples/env_locations/main.rs @@ -1,5 +1,9 @@ #[test] fn test() { + // we should able to read rustc args from a generated file + if !cfg!(test_flag) { + unreachable!(); + } // our source file should be readable let source_file = std::fs::read_to_string(env!("SOURCE_FILE")).unwrap(); assert_eq!(source_file, "source\n"); diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 3528b38a71..a85f7c2750 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -439,14 +439,15 @@ def construct_arguments( # Tell Rustc where to find the standard library args.add_all(rust_lib_paths, before_each = "-L", format_each = "%s") - args.add_all(rust_flags) + + # Data file paths for location expansion + data_paths = getattr(attr, "data", []) + getattr(attr, "compile_data", []) args.add_all( expand_arg_locations( ctx, getattr(attr, "rustc_flags", []), - getattr(attr, "data", []) + - getattr(attr, "compile_data", []), + data_paths ), ) add_edition_flags(args, crate_info) @@ -482,8 +483,7 @@ def construct_arguments( env.update(expand_locations( ctx, crate_info.rustc_env, - getattr(attr, "data", []) + - getattr(attr, "compile_data", []), + data_paths, )) # This empty value satisfies Clippy, which otherwise complains about the From 8993cb3fb34978a0d29257c85553e1dacb82ced1 Mon Sep 17 00:00:00 2001 From: RS Date: Mon, 28 Jun 2021 08:53:52 -0700 Subject: [PATCH 03/22] Fix buildifier. --- rust/private/rustc.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index a85f7c2750..3e5c0f8fc0 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -447,7 +447,7 @@ def construct_arguments( expand_arg_locations( ctx, getattr(attr, "rustc_flags", []), - data_paths + data_paths, ), ) add_edition_flags(args, crate_info) From cd0077ed0bb85241d49d1c0122aaaadc7f413f26 Mon Sep 17 00:00:00 2001 From: RS Date: Mon, 28 Jun 2021 09:07:58 -0700 Subject: [PATCH 04/22] Rename expand_location to expand_env_locations. --- cargo/cargo_build_script.bzl | 4 ++-- rust/private/rust.bzl | 4 ++-- rust/private/rustc.bzl | 4 ++-- rust/private/utils.bzl | 2 +- util/launcher/launcher_main.rs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cargo/cargo_build_script.bzl b/cargo/cargo_build_script.bzl index 1ac0f0dddd..91d2fe8e29 100644 --- a/cargo/cargo_build_script.bzl +++ b/cargo/cargo_build_script.bzl @@ -8,7 +8,7 @@ load("//rust:rust.bzl", "rust_binary") load("//rust/private:rustc.bzl", "BuildInfo", "get_compilation_mode_opts", "get_linker_and_args") # buildifier: disable=bzl-visibility -load("//rust/private:utils.bzl", "expand_locations", "find_cc_toolchain", "find_toolchain", "name_to_crate_name") +load("//rust/private:utils.bzl", "expand_env_locations", "find_cc_toolchain", "find_toolchain", "name_to_crate_name") def get_cc_compile_env(cc_toolchain, feature_configuration): """Gather cc environment variables from the given `cc_toolchain` @@ -117,7 +117,7 @@ def _build_script_impl(ctx): for f in ctx.attr.crate_features: env["CARGO_FEATURE_" + f.upper().replace("-", "_")] = "1" - env.update(expand_locations( + env.update(expand_env_locations( ctx, ctx.attr.build_script_env, getattr(ctx.attr, "data", []) + diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl index cf9b700f6e..51343eaa86 100644 --- a/rust/private/rust.bzl +++ b/rust/private/rust.bzl @@ -20,7 +20,7 @@ load( "crate_name_from_attr", "dedent", "determine_output_hash", - "expand_locations", + "expand_env_locations", "find_toolchain", ) @@ -340,7 +340,7 @@ def _create_test_launcher(ctx, toolchain, output, providers): # Expand the environment variables and write them to a file environ_file = ctx.actions.declare_file(launcher_filename + ".launchfiles/env") - environ = expand_locations( + environ = expand_env_locations( ctx, getattr(ctx.attr, "env", {}), data, diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 3e5c0f8fc0..fa582e886e 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -22,7 +22,7 @@ load( "//rust/private:utils.bzl", "crate_name_from_attr", "expand_arg_locations", - "expand_locations", + "expand_env_locations", "find_cc_toolchain", "get_lib_name", "get_preferred_artifact", @@ -480,7 +480,7 @@ def construct_arguments( env["CARGO_BIN_EXE_" + dep_crate_info.output.basename] = dep_crate_info.output.short_path # Update environment with user provided variables. - env.update(expand_locations( + env.update(expand_env_locations( ctx, crate_info.rustc_env, data_paths, diff --git a/rust/private/utils.bzl b/rust/private/utils.bzl index ce45f28a5a..952fcfd766 100644 --- a/rust/private/utils.bzl +++ b/rust/private/utils.bzl @@ -152,7 +152,7 @@ def _expand_location(ctx, env, data): env = env.replace(directive, "${pwd}/" + directive) return ctx.expand_location(env, data) -def expand_locations(ctx, env, data): +def expand_env_locations(ctx, env, data): """Performs location-macro expansion on string values. $(execroot ...) and $(location ...) are prefixed with ${pwd}, diff --git a/util/launcher/launcher_main.rs b/util/launcher/launcher_main.rs index 10a2a09ff8..af15d7762c 100644 --- a/util/launcher/launcher_main.rs +++ b/util/launcher/launcher_main.rs @@ -22,7 +22,7 @@ fn environ() -> BTreeMap { let file = File::open(env_path).expect("Failed to load the environment file"); // Variables will have the `${pwd}` variable replaced which is rendered by - // `@rules_rust//rust/private:util.bzl::expand_locations` + // `@rules_rust//rust/private:util.bzl::expand_env_locations` let pwd = std::env::current_dir().expect("Failed to get current working directory"); let pwd_str = pwd.to_string_lossy(); From bd00e6395b80f9806d85cdeaca2703e963a6ebc1 Mon Sep 17 00:00:00 2001 From: RS Date: Mon, 28 Jun 2021 09:28:19 -0700 Subject: [PATCH 05/22] Separate test. --- examples/env_locations/BUILD.bazel | 11 ----------- examples/env_locations/main.rs | 4 ---- examples/flag_locations/BUILD.bazel | 23 +++++++++++++++++++++++ examples/flag_locations/main.rs | 5 +++++ 4 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 examples/flag_locations/BUILD.bazel create mode 100644 examples/flag_locations/main.rs diff --git a/examples/env_locations/BUILD.bazel b/examples/env_locations/BUILD.bazel index 44e44641f1..fe313cf2d0 100644 --- a/examples/env_locations/BUILD.bazel +++ b/examples/env_locations/BUILD.bazel @@ -11,19 +11,11 @@ genrule( cmd = "echo hello > $@", ) -# generate a file containing cfg flags -genrule( - name = "flag_generator", - outs = ["generated_flag.data"], - cmd = "echo --cfg=test_flag > $@", -) - _data = [ # we should be able to read non-generated source/data files "source.file", # and generated files as well "generated.data", - "generated_flag.data", # we should also be able to access external binaries # such as protoc. "@com_google_protobuf//:protoc", @@ -54,9 +46,6 @@ rust_test( "SOME_TOOL": "$(rootpath @com_google_protobuf//:protoc)", "SOURCE_FILE": "$(rootpath source.file)", }, - rustc_flags = [ - "@$(location generated_flag.data)", - ], deps = [ ":build", ], diff --git a/examples/env_locations/main.rs b/examples/env_locations/main.rs index d3e3bedfd9..3b07b1dc9a 100644 --- a/examples/env_locations/main.rs +++ b/examples/env_locations/main.rs @@ -1,9 +1,5 @@ #[test] fn test() { - // we should able to read rustc args from a generated file - if !cfg!(test_flag) { - unreachable!(); - } // our source file should be readable let source_file = std::fs::read_to_string(env!("SOURCE_FILE")).unwrap(); assert_eq!(source_file, "source\n"); diff --git a/examples/flag_locations/BUILD.bazel b/examples/flag_locations/BUILD.bazel new file mode 100644 index 0000000000..ed54cdae4c --- /dev/null +++ b/examples/flag_locations/BUILD.bazel @@ -0,0 +1,23 @@ +load( + "@rules_rust//rust:rust.bzl", + "rust_test", +) + +# generate a file containing cfg flags +genrule( + name = "flag_generator", + outs = ["generated_flag.data"], + cmd = "echo --cfg=test_flag > $@", +) + +rust_test( + name = "test", + srcs = [ + "main.rs", + ], + data = [":flag_generator"], + edition = "2018", + rustc_flags = [ + "@$(location :flag_generator)", + ], +) diff --git a/examples/flag_locations/main.rs b/examples/flag_locations/main.rs new file mode 100644 index 0000000000..e4c79480d1 --- /dev/null +++ b/examples/flag_locations/main.rs @@ -0,0 +1,5 @@ +#[test] +fn test() { + // we should able to read rustc args from a generated file + assert!(cfg!(test_flag)); +} \ No newline at end of file From f34f71fc6ab16307fcce840edcc29f0ca441a3f7 Mon Sep 17 00:00:00 2001 From: RS Date: Mon, 28 Jun 2021 09:31:56 -0700 Subject: [PATCH 06/22] Whitespace. --- examples/flag_locations/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/flag_locations/main.rs b/examples/flag_locations/main.rs index e4c79480d1..493c76d2c3 100644 --- a/examples/flag_locations/main.rs +++ b/examples/flag_locations/main.rs @@ -2,4 +2,4 @@ fn test() { // we should able to read rustc args from a generated file assert!(cfg!(test_flag)); -} \ No newline at end of file +} From 16418c080a0f8ca5a72d539f1aee98323c1e7ff3 Mon Sep 17 00:00:00 2001 From: RS Date: Mon, 28 Jun 2021 09:37:35 -0700 Subject: [PATCH 07/22] Try to fix Clippy warning. --- examples/flag_locations/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/flag_locations/main.rs b/examples/flag_locations/main.rs index 493c76d2c3..cf3fec3f20 100644 --- a/examples/flag_locations/main.rs +++ b/examples/flag_locations/main.rs @@ -1,3 +1,4 @@ +#![deny(clippy::assertions_on_constants)] #[test] fn test() { // we should able to read rustc args from a generated file From c92bbb88a570923f0ecc67bf0d418ae65a632aca Mon Sep 17 00:00:00 2001 From: RS Date: Mon, 28 Jun 2021 09:45:02 -0700 Subject: [PATCH 08/22] Rewrite to satisfy clippy. --- examples/flag_locations/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/flag_locations/main.rs b/examples/flag_locations/main.rs index cf3fec3f20..7fd30c312a 100644 --- a/examples/flag_locations/main.rs +++ b/examples/flag_locations/main.rs @@ -2,5 +2,9 @@ #[test] fn test() { // we should able to read rustc args from a generated file - assert!(cfg!(test_flag)); + if cfg!(test_flag) { + return; + } + + unreachable!(); } From 0ce9dadf978d659a924b45b06de0a83baa98d259 Mon Sep 17 00:00:00 2001 From: RS Date: Mon, 28 Jun 2021 10:21:57 -0700 Subject: [PATCH 09/22] Remove clippy annotation. --- examples/flag_locations/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/flag_locations/main.rs b/examples/flag_locations/main.rs index 7fd30c312a..db9b0eea5e 100644 --- a/examples/flag_locations/main.rs +++ b/examples/flag_locations/main.rs @@ -1,4 +1,3 @@ -#![deny(clippy::assertions_on_constants)] #[test] fn test() { // we should able to read rustc args from a generated file From eddbd6f4db2c4b1ee8623d326d2eb4ceed7b12e8 Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Tue, 29 Jun 2021 16:42:57 -0700 Subject: [PATCH 10/22] Remove unnecessary comment. --- rust/private/rustc.bzl | 1 - 1 file changed, 1 deletion(-) diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index fa582e886e..1a76542d45 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -441,7 +441,6 @@ def construct_arguments( args.add_all(rust_lib_paths, before_each = "-L", format_each = "%s") args.add_all(rust_flags) - # Data file paths for location expansion data_paths = getattr(attr, "data", []) + getattr(attr, "compile_data", []) args.add_all( expand_arg_locations( From 7bf37a55514dcb5d3c2b401dd278ed02a91cd7ee Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Tue, 29 Jun 2021 16:54:00 -0700 Subject: [PATCH 11/22] Rename location expansion functions. --- cargo/cargo_build_script.bzl | 4 ++-- rust/private/rust.bzl | 4 ++-- rust/private/rustc.bzl | 8 ++++---- rust/private/utils.bzl | 4 ++-- util/launcher/launcher_main.rs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cargo/cargo_build_script.bzl b/cargo/cargo_build_script.bzl index 91d2fe8e29..7500920435 100644 --- a/cargo/cargo_build_script.bzl +++ b/cargo/cargo_build_script.bzl @@ -8,7 +8,7 @@ load("//rust:rust.bzl", "rust_binary") load("//rust/private:rustc.bzl", "BuildInfo", "get_compilation_mode_opts", "get_linker_and_args") # buildifier: disable=bzl-visibility -load("//rust/private:utils.bzl", "expand_env_locations", "find_cc_toolchain", "find_toolchain", "name_to_crate_name") +load("//rust/private:utils.bzl", "expand_dict_value_locations", "find_cc_toolchain", "find_toolchain", "name_to_crate_name") def get_cc_compile_env(cc_toolchain, feature_configuration): """Gather cc environment variables from the given `cc_toolchain` @@ -117,7 +117,7 @@ def _build_script_impl(ctx): for f in ctx.attr.crate_features: env["CARGO_FEATURE_" + f.upper().replace("-", "_")] = "1" - env.update(expand_env_locations( + env.update(expand_dict_value_locations( ctx, ctx.attr.build_script_env, getattr(ctx.attr, "data", []) + diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl index 51343eaa86..bb33646d9d 100644 --- a/rust/private/rust.bzl +++ b/rust/private/rust.bzl @@ -20,7 +20,7 @@ load( "crate_name_from_attr", "dedent", "determine_output_hash", - "expand_env_locations", + "expand_dict_value_locations", "find_toolchain", ) @@ -340,7 +340,7 @@ def _create_test_launcher(ctx, toolchain, output, providers): # Expand the environment variables and write them to a file environ_file = ctx.actions.declare_file(launcher_filename + ".launchfiles/env") - environ = expand_env_locations( + environ = expand_dict_value_locations( ctx, getattr(ctx.attr, "env", {}), data, diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 1a76542d45..faadcb3841 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -21,8 +21,8 @@ load("//rust/private:common.bzl", "rust_common") load( "//rust/private:utils.bzl", "crate_name_from_attr", - "expand_arg_locations", - "expand_env_locations", + "expand_list_element_locations", + "expand_dict_value_locations", "find_cc_toolchain", "get_lib_name", "get_preferred_artifact", @@ -443,7 +443,7 @@ def construct_arguments( data_paths = getattr(attr, "data", []) + getattr(attr, "compile_data", []) args.add_all( - expand_arg_locations( + expand_list_element_locations( ctx, getattr(attr, "rustc_flags", []), data_paths, @@ -479,7 +479,7 @@ def construct_arguments( env["CARGO_BIN_EXE_" + dep_crate_info.output.basename] = dep_crate_info.output.short_path # Update environment with user provided variables. - env.update(expand_env_locations( + env.update(expand_dict_value_locations( ctx, crate_info.rustc_env, data_paths, diff --git a/rust/private/utils.bzl b/rust/private/utils.bzl index 952fcfd766..94048d6c63 100644 --- a/rust/private/utils.bzl +++ b/rust/private/utils.bzl @@ -152,7 +152,7 @@ def _expand_location(ctx, env, data): env = env.replace(directive, "${pwd}/" + directive) return ctx.expand_location(env, data) -def expand_env_locations(ctx, env, data): +def expand_dict_value_locations(ctx, env, data): """Performs location-macro expansion on string values. $(execroot ...) and $(location ...) are prefixed with ${pwd}, @@ -179,7 +179,7 @@ def expand_env_locations(ctx, env, data): """ return dict([(k, _expand_location(ctx, v, data)) for (k, v) in env.items()]) -def expand_arg_locations(ctx, args, data): +def expand_list_element_locations(ctx, args, data): """Performs location-macro expansion on a list of string values. See `expand_locations` for detailed documentation. diff --git a/util/launcher/launcher_main.rs b/util/launcher/launcher_main.rs index af15d7762c..02ffbf2d7d 100644 --- a/util/launcher/launcher_main.rs +++ b/util/launcher/launcher_main.rs @@ -22,7 +22,7 @@ fn environ() -> BTreeMap { let file = File::open(env_path).expect("Failed to load the environment file"); // Variables will have the `${pwd}` variable replaced which is rendered by - // `@rules_rust//rust/private:util.bzl::expand_env_locations` + // `@rules_rust//rust/private:util.bzl::expand_dict_value_locations` let pwd = std::env::current_dir().expect("Failed to get current working directory"); let pwd_str = pwd.to_string_lossy(); From 14056201803c35b893f27e962970950d1aedd83a Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Tue, 29 Jun 2021 17:01:41 -0700 Subject: [PATCH 12/22] Add a brief note about expansions. --- rust/private/utils.bzl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rust/private/utils.bzl b/rust/private/utils.bzl index 94048d6c63..303a94b665 100644 --- a/rust/private/utils.bzl +++ b/rust/private/utils.bzl @@ -182,6 +182,10 @@ def expand_dict_value_locations(ctx, env, data): def expand_list_element_locations(ctx, args, data): """Performs location-macro expansion on a list of string values. + $(execroot ...) and $(location ...) are prefixed with ${pwd}, + which process_wrapper and build_script_runner will expand at run time + to the absolute path. + See `expand_locations` for detailed documentation. Args: From f0da18d1023677b542cf97a17c99e6335baec780 Mon Sep 17 00:00:00 2001 From: RS Date: Tue, 29 Jun 2021 17:03:37 -0700 Subject: [PATCH 13/22] Fix import order. --- rust/private/rustc.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index faadcb3841..55a07ab3c4 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -21,8 +21,8 @@ load("//rust/private:common.bzl", "rust_common") load( "//rust/private:utils.bzl", "crate_name_from_attr", - "expand_list_element_locations", "expand_dict_value_locations", + "expand_list_element_locations", "find_cc_toolchain", "get_lib_name", "get_preferred_artifact", From e3b17e85e05faedd2e34e7d5b780caff2dc2a6a5 Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Wed, 30 Jun 2021 11:31:42 -0700 Subject: [PATCH 14/22] Document location expansion. --- rust/private/rust.bzl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl index bb33646d9d..1f0e101e49 100644 --- a/rust/private/rust.bzl +++ b/rust/private/rust.bzl @@ -620,7 +620,14 @@ _common_attrs = { """), ), "rustc_flags": attr.string_list( - doc = "List of compiler flags passed to `rustc`.", + doc = dedent("""\ + 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)`. + """), ), # TODO(stardoc): How do we provide additional documentation to an inherited attribute? # "name": attr.string( From 5c1cd6121f0837c1af109dbfa1229dd021f9a8b5 Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Wed, 30 Jun 2021 11:37:29 -0700 Subject: [PATCH 15/22] Regenerate documentation --- docs/defs.md | 14 +++++++------- docs/flatten.md | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/defs.md b/docs/defs.md index e486b30605..2ac3659393 100644 --- a/docs/defs.md +++ b/docs/defs.md @@ -112,7 +112,7 @@ Run the benchmark test using: `bazel run //fibonacci:fibonacci_bench`. | 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. | List of strings | 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -230,7 +230,7 @@ Hello world | 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. | List of strings | 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -325,7 +325,7 @@ INFO: Elapsed time: 1.245s, Critical Path: 1.01s | 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. | List of strings | 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -359,7 +359,7 @@ Builds a Rust proc-macro crate. | 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. | List of strings | 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -401,7 +401,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | 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. | List of strings | 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -443,7 +443,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | 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. | List of strings | 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -605,7 +605,7 @@ Run the test with `bazel build //hello_lib:hello_lib_test`. | 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. | List of strings | 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" | diff --git a/docs/flatten.md b/docs/flatten.md index 2ac69dcbe0..05968b8158 100644 --- a/docs/flatten.md +++ b/docs/flatten.md @@ -197,7 +197,7 @@ Run the benchmark test using: `bazel run //fibonacci:fibonacci_bench`. | 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. | List of strings | 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -315,7 +315,7 @@ Hello world | 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. | List of strings | 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -665,7 +665,7 @@ INFO: Elapsed time: 1.245s, Critical Path: 1.01s | 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. | List of strings | 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -699,7 +699,7 @@ Builds a Rust proc-macro crate. | 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. | List of strings | 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -841,7 +841,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | 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. | List of strings | 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -883,7 +883,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | 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. | List of strings | 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -1045,7 +1045,7 @@ Run the test with `bazel build //hello_lib:hello_lib_test`. | 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. | List of strings | 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" | From cee8af9e6fe4aa13a69b22503edd2ac56a87360b Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Wed, 30 Jun 2021 12:21:36 -0700 Subject: [PATCH 16/22] Unit test for location expansion. --- test/unit/location_expansion/BUILD.bazel | 4 ++ .../location_expansion_test.bzl | 54 +++++++++++++++++++ test/unit/location_expansion/mylibrary.rs | 0 3 files changed, 58 insertions(+) create mode 100644 test/unit/location_expansion/BUILD.bazel create mode 100644 test/unit/location_expansion/location_expansion_test.bzl create mode 100644 test/unit/location_expansion/mylibrary.rs diff --git a/test/unit/location_expansion/BUILD.bazel b/test/unit/location_expansion/BUILD.bazel new file mode 100644 index 0000000000..83bf6c6ed1 --- /dev/null +++ b/test/unit/location_expansion/BUILD.bazel @@ -0,0 +1,4 @@ +load(":location_expansion_test.bzl", "location_expansion_test_suite") + +############################ UNIT TESTS ############################# +location_expansion_test_suite(name = "location_expansion_test_suite") diff --git a/test/unit/location_expansion/location_expansion_test.bzl b/test/unit/location_expansion/location_expansion_test.bzl new file mode 100644 index 0000000000..c2aa1940e6 --- /dev/null +++ b/test/unit/location_expansion/location_expansion_test.bzl @@ -0,0 +1,54 @@ +"""Unittest to verify location expansion in rustc flags""" + +load("@bazel_skylib//lib:unittest.bzl", "analysistest") +load("//rust:defs.bzl", "rust_library") +load("//test/unit:common.bzl", "assert_action_mnemonic", "assert_argv_contains") + +def _location_expansion_rustc_flags_test(ctx): + env = analysistest.begin(ctx) + tut = analysistest.target_under_test(env) + action = tut.actions[0] + argv = action.argv + assert_action_mnemonic(env, action, "Rustc") + assert_argv_contains(env, action, "test/unit/location_expansion/mylibrary.rs") + expected = "@${pwd}/" + ctx.bin_dir.path + "/test/unit/location_expansion/generated_flag.data" + assert_argv_contains(env, action, expected) + return analysistest.end(env) + +location_expansion_rustc_flags_test = analysistest.make(_location_expansion_rustc_flags_test) + +def _location_expansion_test(): + native.genrule( + name = "flag_generator", + outs = ["generated_flag.data"], + cmd = "echo --cfg=test_flag > $@", + ) + + rust_library( + name = "mylibrary", + srcs = ["mylibrary.rs"], + rustc_flags = [ + "@$(location :flag_generator)", + ], + compile_data = [":flag_generator"], + ) + + location_expansion_rustc_flags_test( + name = "location_expansion_rustc_flags_test", + target_under_test = ":mylibrary", + ) + +def location_expansion_test_suite(name): + """Entry-point macro called from the BUILD file. + + Args: + name: Name of the macro. + """ + _location_expansion_test() + + native.test_suite( + name = name, + tests = [ + ":location_expansion_rustc_flags_test", + ], + ) diff --git a/test/unit/location_expansion/mylibrary.rs b/test/unit/location_expansion/mylibrary.rs new file mode 100644 index 0000000000..e69de29bb2 From d9f2db325249b9717d131dd82ea3da8c8e5a8956 Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Wed, 30 Jun 2021 12:28:02 -0700 Subject: [PATCH 17/22] Make this file pass rustfmt. --- test/unit/location_expansion/mylibrary.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/unit/location_expansion/mylibrary.rs b/test/unit/location_expansion/mylibrary.rs index e69de29bb2..e04b1320a0 100644 --- a/test/unit/location_expansion/mylibrary.rs +++ b/test/unit/location_expansion/mylibrary.rs @@ -0,0 +1,3 @@ +pub fn hello_world() { + println!("Hello, world.") +} \ No newline at end of file From 609a8bca14bbac5a46f5de08c0f63e7e5501ae67 Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Wed, 30 Jun 2021 12:34:06 -0700 Subject: [PATCH 18/22] Whitespace. --- test/unit/location_expansion/mylibrary.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/location_expansion/mylibrary.rs b/test/unit/location_expansion/mylibrary.rs index e04b1320a0..4eaa24bfce 100644 --- a/test/unit/location_expansion/mylibrary.rs +++ b/test/unit/location_expansion/mylibrary.rs @@ -1,3 +1,3 @@ pub fn hello_world() { println!("Hello, world.") -} \ No newline at end of file +} From 9e6bb39c578fadb5f63ca66dbf421c7d4269ff9f Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Thu, 1 Jul 2021 09:30:25 -0700 Subject: [PATCH 19/22] Address review comments. --- examples/flag_locations/main.rs | 2 +- rust/private/rust.bzl | 2 +- rust/private/utils.bzl | 4 +++- test/unit/location_expansion/mylibrary.rs | 3 --- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/flag_locations/main.rs b/examples/flag_locations/main.rs index db9b0eea5e..cee1077015 100644 --- a/examples/flag_locations/main.rs +++ b/examples/flag_locations/main.rs @@ -1,6 +1,6 @@ #[test] fn test() { - // we should able to read rustc args from a generated file + // we should be able to read rustc args from a generated file if cfg!(test_flag) { return; } diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl index 1f0e101e49..7961d0e905 100644 --- a/rust/private/rust.bzl +++ b/rust/private/rust.bzl @@ -626,7 +626,7 @@ _common_attrs = { 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)`. + arguments to rustc: `@$(location //package:target)`. """), ), # TODO(stardoc): How do we provide additional documentation to an inherited attribute? diff --git a/rust/private/utils.bzl b/rust/private/utils.bzl index 303a94b665..30b8aee1c2 100644 --- a/rust/private/utils.bzl +++ b/rust/private/utils.bzl @@ -167,6 +167,8 @@ def expand_dict_value_locations(ctx, env, data): as compilation happens in a separate sandbox folder, so when it comes time to read the file at runtime, the path is no longer valid. + See [`expand_location`](https://docs.bazel.build/versions/main/skylark/lib/ctx.html#expand_location) for detailed documentation. + Args: ctx (ctx): The rule's context object env (dict): A dict whose values we iterate over @@ -186,7 +188,7 @@ def expand_list_element_locations(ctx, args, data): which process_wrapper and build_script_runner will expand at run time to the absolute path. - See `expand_locations` for detailed documentation. + See [`expand_location`](https://docs.bazel.build/versions/main/skylark/lib/ctx.html#expand_location) for detailed documentation. Args: ctx (ctx): The rule's context object diff --git a/test/unit/location_expansion/mylibrary.rs b/test/unit/location_expansion/mylibrary.rs index 4eaa24bfce..e69de29bb2 100644 --- a/test/unit/location_expansion/mylibrary.rs +++ b/test/unit/location_expansion/mylibrary.rs @@ -1,3 +0,0 @@ -pub fn hello_world() { - println!("Hello, world.") -} From 5ad52d330649445df5285c680812c0deaa21bbe6 Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Thu, 1 Jul 2021 09:34:40 -0700 Subject: [PATCH 20/22] Regenerate documentation --- docs/defs.md | 14 +++++++------- docs/flatten.md | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/defs.md b/docs/defs.md index 2ac3659393..6a846d27a1 100644 --- a/docs/defs.md +++ b/docs/defs.md @@ -112,7 +112,7 @@ Run the benchmark test using: `bazel run //fibonacci:fibonacci_bench`. | 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 | [] | +| 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -230,7 +230,7 @@ Hello world | 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 | [] | +| 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -325,7 +325,7 @@ INFO: Elapsed time: 1.245s, Critical Path: 1.01s | 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 | [] | +| 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -359,7 +359,7 @@ Builds a Rust proc-macro crate. | 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 | [] | +| 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -401,7 +401,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | 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 | [] | +| 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -443,7 +443,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | 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 | [] | +| 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -605,7 +605,7 @@ Run the test with `bazel build //hello_lib:hello_lib_test`. | 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 | [] | +| 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" | diff --git a/docs/flatten.md b/docs/flatten.md index 2d2ca3e460..b91b293e09 100644 --- a/docs/flatten.md +++ b/docs/flatten.md @@ -202,7 +202,7 @@ Run the benchmark test using: `bazel run //fibonacci:fibonacci_bench`. | 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 | [] | +| 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -320,7 +320,7 @@ Hello world | 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 | [] | +| 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -670,7 +670,7 @@ INFO: Elapsed time: 1.245s, Critical Path: 1.01s | 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 | [] | +| 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -704,7 +704,7 @@ Builds a Rust proc-macro crate. | 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 | [] | +| 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -846,7 +846,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | 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 | [] | +| 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -888,7 +888,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | 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 | [] | +| 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 | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -1050,7 +1050,7 @@ Run the test with `bazel build //hello_lib:hello_lib_test`. | 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 | [] | +| 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" | From 53b981c7f3c8e7e0591e56a801ec7aa480464aba Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Thu, 1 Jul 2021 09:41:52 -0700 Subject: [PATCH 21/22] Add two empty lines. --- test/unit/location_expansion/mylibrary.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unit/location_expansion/mylibrary.rs b/test/unit/location_expansion/mylibrary.rs index e69de29bb2..139597f9cb 100644 --- a/test/unit/location_expansion/mylibrary.rs +++ b/test/unit/location_expansion/mylibrary.rs @@ -0,0 +1,2 @@ + + From c9e4cd5eba1c2ab667b764ed662b925971de2f9c Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Thu, 1 Jul 2021 09:46:00 -0700 Subject: [PATCH 22/22] A single newline --- test/unit/location_expansion/mylibrary.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/location_expansion/mylibrary.rs b/test/unit/location_expansion/mylibrary.rs index 139597f9cb..8b13789179 100644 --- a/test/unit/location_expansion/mylibrary.rs +++ b/test/unit/location_expansion/mylibrary.rs @@ -1,2 +1 @@ -