-
Notifications
You must be signed in to change notification settings - Fork 483
Add support for passing a custom target specification. #836
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
Conversation
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.
Is there a way that this code path can be tested in CI? I think the rules should definitely be supportive to custom targets but I'd like to know when a change impacts support for custom code paths. Perhaps something can be added with the existing unit tests?
Also, to follow up on #770 (comment) I think this approach makes sense. I would probably add some protections against trying to set both |
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 for working on this!
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.
LGTM, thank you!
rust/toolchain.bzl
Outdated
@@ -193,6 +193,8 @@ def _rust_toolchain_impl(ctx): | |||
rustfmt = ctx.file.rustfmt, | |||
cargo = ctx.file.cargo, | |||
clippy_driver = ctx.file.clippy_driver, | |||
target_json = ctx.file.target_json, | |||
target_flag_value = ctx.file.target_json.path if ctx.file.target_json != None else ctx.attr.target_triple, |
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.
target_flag_value = ctx.file.target_json.path if ctx.file.target_json != None else ctx.attr.target_triple, | |
target_flag_value = ctx.file.target_json.path if ctx.file.target_json else ctx.attr.target_triple, |
Oh actually, +1 to @UebelAndre's comment, could you please add a check in the |
I'm a little out of my depth here, being pretty new to writing bazel build logic. Do you have any suggestions on where the new unit tests would go? |
We have unit tests located in test/unit. But this one might be pretty unique since the change is to the toolchain? I think a transition might be needed to build a target using a newly registered toolchain which exercises this code path. Maybe someone else might have a simpler path forward though? |
Sorry, but I don't really follow. I've tried throwing together a bare bones unit test: """Unit tests for rust toolchains."""
load("@bazel_skylib//lib:unittest.bzl", "analysistest")
load("//rust:toolchain.bzl", "rust_stdlib_filegroup", "rust_toolchain")
def _toolchain_specifies_target_triple_test_impl(ctx):
env = analysistest.begin(ctx)
target_under_test = analysistest.target_under_test(env)
# TODO: assert something
return analysistest.end(env)
toolchain_specifies_target_triple_test = analysistest.make(_toolchain_specifies_target_triple_test_impl)
def _toolchain_test():
rust_stdlib_filegroup(
name = "std_libs_none",
srcs = [],
)
rust_toolchain(
name = "rust_x86_64_none_impl",
binary_ext = "",
dylib_ext = ".so",
os = "linux",
rust_lib = ":std_libs_none",
staticlib_ext = ".a",
stdlib_linkflags = [],
)
toolchain_specifies_target_triple_test(
name = "toolchain_specifies_target_triple_test",
target_under_test = ":rust_toolchain",
)
def toolchain_test_suite(name):
_toolchain_test()
native.test_suite(
name = name,
tests = [":toolchain_specifies_target_triple_test"],
) But bazel isn't handling handle references to
|
Oh wow, you actually almost did make it work. In your So I guess you want to get the |
Thanks for the advice, that was it! I was quite able to get |
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.
Would it be possible to rename the x86_64-unknown-linux-gun.json
file to something like toolchain-test-triple.json
? I feel like it'd be better to set values here that would never match naturally to confirm we're not benefiting from any coincidental assumptions. I think the cross platform tests will probably catch this but I still feel it's worth going the extra step here? Could be convinced otherwise though. Let me know what you think 😅
Otherwise, I think this is looking awesome! Thanks for all the work you put into this 🙏
Also, docs can be fixed by running |
The target specifications are usually named after the target they're for, but I think it makes sense for the tests to use something more unique. |
I agree and would definitely maintain this behavior for any target I define, but yeah, tests should be able to afford the flexibility. |
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.
One final nit then otherwise looks good to me!
LGTM, I think this is good to go. |
I believe the nit was talked through and decided not to do anything more in this PR.
A label doesn't seem to express both a string (as in a triple like
x86_64-unkown-none
) and a path to a custom target specification (as in something like//path/to/target.json
), so this change is propose treatingtarget_json
as an override oftarget_triple
.