-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
VersionInfo: allow non-linkstamp rules to link in definitions #6803
Conversation
Signed-off-by: Jose Nino <[email protected]>
@@ -227,6 +227,11 @@ config_setting( | |||
values = {"cpu": "ios_arm64e"}, | |||
) | |||
|
|||
config_setting( | |||
name = "manual_stamp", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
open to better names
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have any bash in source. Open to moving this elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tools
is another option, but the current location is also good with me.
# By default the header file is empty. | ||
# This is done so that the definitions linked via the linkstamp rule don't cause collisions. | ||
"//conditions:default": [":generate_version_linkstamp_empty"], | ||
}), | ||
copts = envoy_select_boringssl( | ||
["-DENVOY_SSL_VERSION=\\\"BoringSSL-FIPS\\\""], | ||
["-DENVOY_SSL_VERSION=\\\"BoringSSL\\\""], | ||
), | ||
linkstamp = "version_linkstamp.cc", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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
linkstamp
attribute, so using--define manual_stamp=manual_stamp
would 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @dio
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally seems reasonable, but a bit queasy about relying on bazel-out
files directly.
@@ -262,11 +279,21 @@ envoy_cc_library( | |||
envoy_cc_library( | |||
name = "version_lib", | |||
srcs = ["version.cc"], | |||
hdrs = select({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in srcs
unless you are exporting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
Signed-off-by: Jose Nino <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @junr03. This is fine as an opt-in for the purposes you are after right now. I think over time we will learn more about the limitations of what's being done and hopefully Bazel improves its support for link stamping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
Signed-off-by: Jose Nino <[email protected]>
Signed-off-by: Jose Nino <[email protected]>
Signed-off-by: Jose Nino [email protected]
Description: currently envoy uses
linkstamp
to 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, thelinkstamp
attribute 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.