-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
genrule "outs" is not configurable via select() #281
Comments
Greg, could you take a look please? |
Rule outputs are "special" in that they have to be defined unambiguously based purely on the rule definition. So we can't have the same genrule produce different outputs depending on what config parameters are passed at the command line (which is what fitting them into a select would mean). We might be able to lift this restriction in the future, but I don't think it would be quick or easy. Instead, can you define platform-specific genrules then have whoever depends on them use a select to choose the appropriate dependency? |
That's not an optimal solution, but it could do in a pinch. It looks like static |
Pardon my ignorance. Are you saying the boost header files are all automatically generated? |
Sorry, let me be clearer. If I were to wrap Boost's build system from Bazel, I imagine it would look something like this:
The In practice, however, it turns out that none of the generated headers produced to |
As it happens, This strategy will work in practice: BOOST_SOURCE_HEADERS = glob(["boost/**/*.hpp", "boost/**/*.ipp", "boost/**/*.h"])
BOOST_INSTALLED_HEADERS = ["install/include/%s" % header for header in BOOST_SOURCE_HEADERS]
genrule(
name = "build-boost",
srcs = [":boost-srcs"],
tools = [":bootstrap-boost"],
outs = [ ...
] + BOOST_INSTALLED_HEADERS, ... however, it is only safe if the |
Are the header files modified as part of the bootstrap? Are they copied into the output tree? What isn't safe? |
They are not modified as part of the bootstrap, as near as I can tell. They are indeed copied into the output tree. My concern is the context in which the following expression is evaluated:
It's created outside of a rule, so I imagine there is a small chance that it is evaluated outside of (before) a rule as well. If so, I could create a new If glob() is evaluated on every up-to-date check of the genrule(), where it is used in |
Globs are evaluated over the source tree, and Bazel ensures that new or removed files get picked up on incremental builds. We don't re-evaluate the glob unless it has changed. We either use inotify (if enabled, except on MacOS) or we do a bulk stat+readdir operation over the source tree. |
I guess that sounds a little bit weird, so let me try to clarify: We have a Skyframe node (in memory) corresponding to the glob evaluation, and that depends on nodes corresponding to readdir and stat calls. On incremental builds, we go through all readdir and stat nodes, and rerun the corresponding operations (if inotify is enabled, we get the list of such nodes by listening to inotify events). If they return the same result, we never look at the node corresponding to the glob, and (transitively) don't redo any of the work that depends on the glob. |
It sounds like it's safe to use, then. Great work! It sounds like |
This is still an issue for me. I want to create a .tar.gz with a filename that contains fragments of build info. Please consider re-opening. Ex. someoutput-dbg-k8.tar.gz or someoutput-opt-arm.tar.gz .. It would be nice to be able to select the suffix strings and use in outputs of the genrule that creates the tar archive. Another option would be to expand make variables in the outs so that I can do $(TARGET_CPU) etc and include in filename. |
for me it is important too. |
I don't think that the claim "There are no ways to configure name of libs depending of platform" is correct. genrule.outs is not configurable via select by design. The string passed to outs becomes a target in the package, i.e., a named thing that can be referenced from other BUILD files. If the value depended on the configuration (via select), then it would no longer be possible to reference it from other BUILD files. Example:
You can reference the rule
Then you could no longer reliably reference
However, it is possible to write something like a genrule that does not add outs to the package, and this is possible today with a simple Starlark rule. This is an incomplete and untested example of how that would look like:
Another alternative is to declare different names using multiple rules, but I take it that's not what you want to do.
|
To support select() properly, the argument "outs" in kernel_build macro cannot be parsed, and it needs to be passed to _kernel_build directly. Hence, outs (and for consistency, module_outs and implicit_outs) of _kernel_build are changed to a string_list. Then inside _kernel_build_impl, declare_file() of the proper output file. Because _kernel_build_impl already explicitly return DefaultInfo(), this is okay. To continue to support e.g. "kernel_aarch64/vmlinux", filegroups with output groups are created to point to the correct file: kernel_build(name = "kernel_aarch64", out = ["vmlinux"]) becomes _kernel_build(name = "kernel_aarch64", ...) filegroup(name = "kernel_aarch64/vmlinux", srcs = ["kernel_aarch64"], output_group = "vmlinux") See discussion thread: bazelbuild/bazel#281 Bug: 202075567 Bug: 202075499 Test: builds Change-Id: I92d5c7f357d2d69c40039ef35b3e0a25cdb7214f
To support select() properly, the argument "outs" in kernel_build macro cannot be parsed, and it needs to be passed to _kernel_build directly. Hence, outs (and for consistency, module_outs and implicit_outs) of _kernel_build are changed to a string_list. Then inside _kernel_build_impl, declare_file() of the proper output file. Because _kernel_build_impl already explicitly return DefaultInfo(), this is okay. To continue to support e.g. "kernel_aarch64/vmlinux", filegroups with output groups are created to point to the correct file: kernel_build(name = "kernel_aarch64", out = ["vmlinux"]) becomes _kernel_build(name = "kernel_aarch64", ...) filegroup(name = "kernel_aarch64/vmlinux", srcs = ["kernel_aarch64"], output_group = "vmlinux") See discussion thread: bazelbuild/bazel#281 Bug: 202075567 Bug: 202075499 Test: builds Change-Id: I92d5c7f357d2d69c40039ef35b3e0a25cdb7214f
To support select() properly, the argument "outs" in kernel_build macro cannot be parsed, and it needs to be passed to _kernel_build directly. Hence, outs (and for consistency, module_outs and implicit_outs) of _kernel_build are changed to a string_list. Then inside _kernel_build_impl, declare_file() of the proper output file. Because _kernel_build_impl already explicitly return DefaultInfo(), this is okay. The downside is that the following becomes invalid: kernel_build(name = "kernel", out = ["vmlinux"]) filegroup(name = "foo", srcs = ["kernel/vmlinux"]) This is because `kernel/vmlinux` is no longer in the explicit output list. See discussion thread: bazelbuild/bazel#281 Bug: 202075567 Bug: 202075499 Test: builds Change-Id: I92d5c7f357d2d69c40039ef35b3e0a25cdb7214f
To support select() properly, the argument "outs" in kernel_build macro cannot be parsed, and it needs to be passed to _kernel_build directly. Hence, outs (and for consistency, module_outs and implicit_outs) of _kernel_build are changed to a string_list. Then inside _kernel_build_impl, declare_file() of the proper output file. Because _kernel_build_impl already explicitly return DefaultInfo(), this is okay. The downside is that the following becomes invalid: kernel_build(name = "kernel", out = ["vmlinux"]) filegroup(name = "foo", srcs = ["kernel/vmlinux"]) This is because `kernel/vmlinux` is no longer in the explicit output list. See discussion thread: bazelbuild/bazel#281 Change-Id: I92d5c7f357d2d69c40039ef35b3e0a25cdb7214f
To support select() properly, the argument "outs" in kernel_build macro cannot be parsed, and it needs to be passed to _kernel_build directly. Hence, outs (and for consistency, module_outs and implicit_outs) of _kernel_build are changed to a string_list. Then inside _kernel_build_impl, declare_file() of the proper output file. Because _kernel_build_impl already explicitly return DefaultInfo(), this is okay. The downside is that the following becomes invalid: kernel_build(name = "kernel", out = ["vmlinux"]) filegroup(name = "foo", srcs = ["kernel/vmlinux"]) This is because `kernel/vmlinux` is no longer in the explicit output list. See discussion thread: bazelbuild/bazel#281 Bug: 202075567 Bug: 202075499 Test: builds Change-Id: I92d5c7f357d2d69c40039ef35b3e0a25cdb7214f
To support select() properly, the argument "outs" in kernel_build macro cannot be parsed, and it needs to be passed to _kernel_build directly. Hence, outs (and for consistency, module_outs and implicit_outs) of _kernel_build are changed to a string_list. Then inside _kernel_build_impl, declare_file() of the proper output file. Because _kernel_build_impl already explicitly return DefaultInfo(), this is okay. The downside is that the following becomes invalid: kernel_build(name = "kernel", out = ["vmlinux"]) filegroup(name = "foo", srcs = ["kernel/vmlinux"]) This is because `kernel/vmlinux` is no longer in the explicit output list. See discussion thread: bazelbuild/bazel#281 Bug: 202075567 Bug: 202075499 Test: builds Change-Id: I92d5c7f357d2d69c40039ef35b3e0a25cdb7214f
To support select() properly, the argument "outs" in kernel_build macro cannot be parsed, and it needs to be passed to _kernel_build directly. Hence, outs (and for consistency, module_outs and implicit_outs) of _kernel_build are changed to a string_list. Then inside _kernel_build_impl, declare_file() of the proper output file. Because _kernel_build_impl already explicitly return DefaultInfo(), this is okay. The downside is that the following becomes invalid: kernel_build(name = "kernel", out = ["vmlinux"]) filegroup(name = "foo", srcs = ["kernel/vmlinux"]) This is because `kernel/vmlinux` is no longer in the explicit output list. See discussion thread: bazelbuild/bazel#281 Bug: 202075567 Bug: 202075499 Test: builds Change-Id: I92d5c7f357d2d69c40039ef35b3e0a25cdb7214f
To support select() properly, the argument "outs" in kernel_build macro cannot be parsed, and it needs to be passed to _kernel_build directly. Hence, outs (and for consistency, module_outs and implicit_outs) of _kernel_build are changed to a string_list. Then inside _kernel_build_impl, declare_file() of the proper output file. Because _kernel_build_impl already explicitly return DefaultInfo(), this is okay. The downside is that the following becomes invalid: kernel_build(name = "kernel", out = ["vmlinux"]) filegroup(name = "foo", srcs = ["kernel/vmlinux"]) This is because `kernel/vmlinux` is no longer in the explicit output list. See discussion thread: bazelbuild/bazel#281 Change-Id: I92d5c7f357d2d69c40039ef35b3e0a25cdb7214f
This makes it a bit difficult to use a single genrule which produces different files on different platforms (i.e. foo.so, foo.dylib). It's not ideal to use a genrule to create libraries, but is very convenient for wrapping libraries built by autotools or CMake.
The text was updated successfully, but these errors were encountered: