VersionInfo: allow non-linkstamp rules to link in definitions#6803
VersionInfo: allow non-linkstamp rules to link in definitions#6803
Conversation
Signed-off-by: Jose Nino <jnino@lyft.com>
| ) | ||
|
|
||
| config_setting( | ||
| name = "manual_stamp", |
| hdrs = select({ | ||
| "//bazel:manual_stamp": [":generate_version_linkstamp"], | ||
| # By default the header file is empty. | ||
| # This is done so that the definitions linked via the linkstamp rule don't cause collisions. |
There was a problem hiding this comment.
Note that nothing prevents someone from running a rule that respects linkstamp and uses the manual_stamp define. I'll document this in the docs if this is the approach we congeal on.
| @@ -0,0 +1,13 @@ | |||
| #!/bin/bash | |||
There was a problem hiding this comment.
We don't have any bash in source. Open to moving this elsewhere.
There was a problem hiding this comment.
tools is another option, but the current location is also good with me.
| ["-DENVOY_SSL_VERSION=\\\"BoringSSL-FIPS\\\""], | ||
| ["-DENVOY_SSL_VERSION=\\\"BoringSSL\\\""], | ||
| ), | ||
| linkstamp = "version_linkstamp.cc", |
There was a problem hiding this comment.
@mattklein123 as I have implemented here, this PR does not solve for #2181 for two reasons:
- The generated header still takes the value from the workspace status.
- The bazel rule does not conditionally add the
linkstampattribute, so using--define manual_stamp=manual_stampwould actually cause duplicated definitions.
I am starting to think that the best way to resolve #2181 is to include a SOURCE_VERSION file and make that documented per the issue, or include it in the tarball somehow.
However, I am open to fixing by more bazel work here.
|
This is an MVP. I have left a few comments in places where there might be better options available, would love any feedback you all have. In general my bazel is pretty rudimentary, so this might not be the most elegant way to accomplish what I want. I am open to alternatives. Mostly I felt that in the absence of truly custom flags or full support for custom build flags bazelbuild/bazel#5577 the |
htuch
left a comment
There was a problem hiding this comment.
Generally seems reasonable, but a bit queasy about relying on bazel-out files directly.
| envoy_cc_library( | ||
| name = "version_lib", | ||
| srcs = ["version.cc"], | ||
| hdrs = select({ |
There was a problem hiding this comment.
This should be in srcs unless you are exporting.
There was a problem hiding this comment.
The reason I had to put them in hdrs is because as far as I could tell (empirically and from docs) is that strip_include_prefix only words on hrds and not on header files in srcs. And I needed to do that in order to be able to have the same filename for the header file in version.cc
| # However, linkstamp is not available to non-binary bazel targets. | ||
| # This means that if the topmost target being used to compile version_lib is a envoy_cc_library or related, linkstamp will not be in effect. | ||
| # In turn this means that version_linkstamp.cc is not linked, and the build_scm_revision and build_scm_status are unknown symbols to the linker. | ||
| build_scm_revision=$(grep BUILD_SCM_REVISION bazel-out/volatile-status.txt | sed 's/^BUILD_SCM_REVISION //' | tr -d '\\n') |
There was a problem hiding this comment.
How does this work when Envoy is included transitively in a project? I'm thinking something like envoy-filter-example, or whatever is being done for Envoy Mobile.
There was a problem hiding this comment.
As long as the outer project is a git repo or it has a SOURCE_VERSION file it works the same as the current flow via linkstamp, i.e it uses the outer project's get_workspace_status command. In Envoy mobile this is set to Envoy's script -- envoy/bazel/get_workspace_status.
| @@ -0,0 +1,13 @@ | |||
| #!/bin/bash | |||
There was a problem hiding this comment.
tools is another option, but the current location is also good with me.
Yep, makes me a bit queasy as well. Although the We could take the route of solving #6803 (comment) and have the value be user defined (not sure how to plumb this quite yet, but I'll figure it out). That way we could close #2181 with this as well. |
|
@htuch I left some comments. lmk what you think. |
lizan
left a comment
There was a problem hiding this comment.
Generally LGTM, is in the long term we would like to switch to use genrule for both binary and library?
|
@lizan @junr03 can you file an issue to track this as a feature (rather than just as something weird in the documented behavior)? I can share this internally with Bazel folks as well once that is done. |
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino jnino@lyft.com
Description: currently envoy uses
linkstampto get access to workspace defined revision and status info for the VersionInfo class. However, if version_lib is depended on by a non-binary top level bazel target, thelinkstampattribute is not used and the linker fails to get definitions for:envoy/source/common/common/version.cc
Lines 8 to 9 in 1bbf271
This PR adds a genrule generated header in order to include definitions for the necessary names.
Risk Level: Medium. This PR changes dependencies on VersionLib which is used on the server.
Testing: I have compiled a static binary, and ran it as a smoke test to verify that the previous path still works as intended.
Docs Changes: added under bazel/README.md.
Release Notes: added.