pw_build: Configurable Python and proto toolchains
- Rename pw_toolchain/dummy to pw_toolchain/default to make its intended
purpose clear. Keep pw_toolchain/dummy around for compatibility.
- Create a template that generates non-C++ toolchains. This is used for
non-C++ tasks like Python and proto. GN parses build files differently
in the default toolchain (all targets are instantiated), so the
these toolchains can be used when that is not desired.
- Make pw_python_package's toolchain configurable with the
pw_build_PYTHON_TOOLCHAIN arg.
- Make pw_proto_library's toolchain configurable with the
pw_protobuf_compiler_TOOLCHAIN arg.
Requires: pigweed-internal:11680
Change-Id: I0aad049c605906b77c58b93a08efc63a648947ee
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/40763
Reviewed-by: Armando Montanez <amontanez@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
diff --git a/pw_protobuf_compiler/proto.gni b/pw_protobuf_compiler/proto.gni
index a6ec15e..c6348c9 100644
--- a/pw_protobuf_compiler/proto.gni
+++ b/pw_protobuf_compiler/proto.gni
@@ -21,6 +21,7 @@
import("$dir_pw_build/python_action.gni")
import("$dir_pw_build/target_types.gni")
import("$dir_pw_third_party/nanopb/nanopb.gni")
+import("toolchain.gni")
# Variables forwarded from the public pw_proto_library template to the final
# pw_source_set.
@@ -35,7 +36,7 @@
# This creates the internal GN target $target_name.$language._gen that compiles
# proto files with protoc.
template("_pw_invoke_protoc") {
- if (current_toolchain == default_toolchain) {
+ if (current_toolchain == pw_protobuf_compiler_TOOLCHAIN) {
if (defined(invoker.out_dir)) {
_out_dir = invoker.out_dir
} else {
@@ -101,7 +102,7 @@
}
}
} else {
- # protoc is only ever invoked from the default toolchain.
+ # protoc is only ever invoked from pw_protobuf_compiler_TOOLCHAIN.
not_needed([ "target_name" ])
not_needed(invoker, "*")
}
@@ -127,7 +128,7 @@
pw_source_set(target_name) {
forward_variables_from(invoker, _forwarded_vars)
public_configs = [ ":$target_name._include_path" ]
- deps = [ ":$target_name._gen($default_toolchain)" ]
+ deps = [ ":$target_name._gen($pw_protobuf_compiler_TOOLCHAIN)" ]
public_deps = [ dir_pw_protobuf ] + invoker.deps
sources = invoker.outputs
public = filter_include(sources, [ "*.pwpb.h" ])
@@ -156,7 +157,7 @@
pw_source_set(target_name) {
forward_variables_from(invoker, _forwarded_vars)
public_configs = [ ":$target_name._include_path" ]
- deps = [ ":$target_name._gen($default_toolchain)" ]
+ deps = [ ":$target_name._gen($pw_protobuf_compiler_TOOLCHAIN)" ]
public_deps = [
":${invoker.base_target}.nanopb",
"$dir_pw_rpc:server",
@@ -175,11 +176,14 @@
# compiled internally, so skip recompiling it with protoc.
if (rebase_path(invoker.sources, invoker.compile_dir) == [ "nanopb.proto" ]) {
group("$target_name._gen") {
- deps = [ ":${invoker.base_target}._sources" ]
+ deps = [
+ ":${invoker.base_target}._sources($pw_protobuf_compiler_TOOLCHAIN)",
+ ]
}
group("$target_name") {
- deps = invoker.deps + [ ":$target_name._gen($default_toolchain)" ]
+ deps = invoker.deps +
+ [ ":$target_name._gen($pw_protobuf_compiler_TOOLCHAIN)" ]
}
} else {
# Create a target which runs protoc configured with the nanopb plugin to
@@ -199,7 +203,7 @@
pw_source_set(target_name) {
forward_variables_from(invoker, _forwarded_vars)
public_configs = [ ":$target_name._include_path" ]
- deps = [ ":$target_name._gen($default_toolchain)" ]
+ deps = [ ":$target_name._gen($pw_protobuf_compiler_TOOLCHAIN)" ]
public_deps = [ "$dir_pw_third_party/nanopb" ] + invoker.deps
sources = invoker.outputs
public = filter_include(sources, [ "*.pb.h" ])
@@ -229,7 +233,7 @@
pw_source_set(target_name) {
forward_variables_from(invoker, _forwarded_vars)
public_configs = [ ":$target_name._include_path" ]
- deps = [ ":$target_name._gen($default_toolchain)" ]
+ deps = [ ":$target_name._gen($pw_protobuf_compiler_TOOLCHAIN)" ]
public_deps = [
"$dir_pw_rpc:server",
"$dir_pw_rpc/raw:method_union",
@@ -259,7 +263,8 @@
}
group(target_name) {
- deps = invoker.deps + [ ":$target_name._gen($default_toolchain)" ]
+ deps =
+ invoker.deps + [ ":$target_name._gen($pw_protobuf_compiler_TOOLCHAIN)" ]
}
}
@@ -305,7 +310,7 @@
sources = invoker.outputs
strip_prefix = "${invoker.base_out_dir}/python"
python_deps = invoker.deps
- other_deps = [ ":$target_name._gen($default_toolchain)" ]
+ other_deps = [ ":$target_name._gen($pw_protobuf_compiler_TOOLCHAIN)" ]
static_analysis = []
_pw_module_as_package = invoker.module_as_package != ""
@@ -380,8 +385,8 @@
# Sources are mirrored to "$base_out_dir/sources" and protoc puts outputs in
# "$base_out_dir/$language" by default.
base_out_dir =
- get_label_info(":$target_name($default_toolchain)", "target_gen_dir") +
- "/$target_name.proto_library"
+ get_label_info(":$target_name($pw_protobuf_compiler_TOOLCHAIN)",
+ "target_gen_dir") + "/$target_name.proto_library"
compile_dir = "$base_out_dir/sources"
@@ -468,15 +473,19 @@
}
# Mirror the proto sources to the output directory with the prefix added.
- pw_mirror_tree("$target_name._sources") {
- source_root = _source_root
- sources = invoker.sources
+ if (current_toolchain == pw_protobuf_compiler_TOOLCHAIN) {
+ pw_mirror_tree("$target_name._sources") {
+ source_root = _source_root
+ sources = invoker.sources
- if (defined(invoker.inputs)) {
- sources += invoker.inputs
+ if (defined(invoker.inputs)) {
+ sources += invoker.inputs
+ }
+
+ directory = "${_common.compile_dir}/$_prefix"
}
-
- directory = "${_common.compile_dir}/$_prefix"
+ } else {
+ not_needed(invoker, [ "inputs" ])
}
# Enumerate all of the protobuf generator targets.