-
Notifications
You must be signed in to change notification settings - Fork 426
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
Deduplicate rule impls, fix rust_doc_test (#117) #122
Deduplicate rule impls, fix rust_doc_test (#117) #122
Conversation
rust/rustc.bzl
Outdated
for dep in deps: | ||
if hasattr(dep, "crate_info"): | ||
# This dependency is a rust_library | ||
rlib = dep.crate_info.output |
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 chunk is just a move, except for these crate_info usages
|
||
compile_inputs = ( | ||
crate_info.srcs + | ||
ctx.files.data + |
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.
it feels a little weird for this to be in both compile_inputs and runfiles, but oh well
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'll need to come up with a real solution to runfiles -- probably related to including a crate in rules_rust for loading them.
I've said as much before (in different terms) but I suspect we need a crisper boundary between compile-time data and run-time data. The cc_embed_data approach described here: #79 (comment) makes sense to me for that purpose, and we could package a crate in rules_rust for accessing data packaged into an rlib in that manner.
Longer term thinking, of course....
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.
Does the default 'data' attr imply runtime data? If so we can add compile_data in short order to differentiate, without dealing w/ embedding the data more directly
Test failures in test/BUILD, forgot about that.. |
working_dir = "." | ||
depinfo = _setup_deps( | ||
target.deps, | ||
target.name, | ||
[ctx.attr.dep], |
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 bit was pretty off, setup was wrong and none of it was being exercised because rustdoc wasn't being called with --test
else: | ||
fail("rust targets can only depend on rust_library or cc_library targets.") | ||
|
||
transitive_libs = depset([c.output for c in transitive_crates]) + transitive_staticlibs + transitive_dylibs |
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.
split up collecting deps / creating flags, hard to separate more though
Looks like doc_test is missing some runfiles (at best), won't have time to fix this for a little bit. Other than that this should be good to go, @acmcarther. |
@buchgr should I be able to see the failed test logs in the source.cloud.google.com ui? If not, and they are visible on the buildkite page, can I get access to that? |
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.
Some really light initial comments.
The refactoring here at least superficially looks kinda involved, so I want to give it a better look when I can find some time to sit down and do a review. Maybe 12 or 24 hours from now.
rust/rustc.bzl
Outdated
|
||
_setup_deps = setup_deps | ||
|
||
CrateInfo = provider( |
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.
- Should this be hoisted out on top of the other functions? I don't feel strongly about this but it does feel hidden.
- Is per-field documentation appropriate? I'm thinking specifically the "type" and "output" fields could use some extra detail
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.
-
Sure, it sees enough usage; at some point it felt attached to the rustc_compile_action and I was just shy of splitting out rustc.bzl / rustdoc.bzl
-
Yeah, when this settles down I will add more documentation (though I miss static typing here too).
will be symlinked into the .deps dir from the runfiles tree. | ||
|
||
Returns: | ||
Returns a struct containing the following fields: |
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.
Are all of these fields supposed to have an explanation?
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.
I didn't touch any documentation since I consider this still in flux; In general I think some of these docs are boilerplatey though.
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.
Oh my bad, ack.
@@ -7,6 +7,6 @@ load( | |||
|
|||
rust_library( | |||
name = "example_name_conflict", | |||
srcs = ["src/lib.rs"], | |||
srcs = ["lib.rs"], |
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.
Side question: What are your personal feelings on ditching "src/" here? I've been thinking on how source files in rust sort of automatically "require" other local files to exist if they have module declarations, and I've been wondering if maybe we should take a more serious look at this at some point.
Initially, I was in a camp of "abandoning crate organization conventions", but I know repeatedly disregarding language conventions isn't really a convincing attitude, so I wanted to run through the thought exercise of what "embracing" those conventions might look like.
I'm interested to hear your thoughts, and we can move this into a proper issue if you'd like.
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.
I have mostly been writing BUILD per dir, and avoiding the extra noise of src/ and main/ dirs.
I don't think src and main dirs work as well for company-sized or polyglot projects, but maven has precipitated a similar structure in enterprise java land. I have also seen enough crates set explicit values for lib / main paths that I don't feel guilty doing this.
) | ||
depinfo = _rust_test_common(ctx, test_binary) | ||
info = _rust_test_common(ctx, bench_binary) |
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.
Nit: Only this "info" changed names? The others stayed as "depinfo"?
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 is the rustc_compile_action struct output, not depinfo; I agree it is not particularly clear either way
rust/rustc.bzl
Outdated
@@ -8,9 +8,9 @@ ZIP_PATH = "/usr/bin/zip" | |||
|
|||
def _get_rustc_env(ctx): | |||
version = ctx.attr.version if hasattr(ctx.attr, "version") else "0.0.0" | |||
v1, v2, v3 = version.split(".") | |||
v1, v2, v3 = version.split(".", 2) |
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.
Nit: v1, v2, v3 : major_ver, minor_ver, patch_ver?
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.
will change to major, minor, patch =
will be symlinked into the .deps dir from the runfiles tree. | ||
|
||
Returns: | ||
Returns a struct containing the following fields: |
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.
Oh my bad, ack.
rust/rustc.bzl
Outdated
deps_dir = working_dir + "/" + name + ".deps" | ||
setup_cmd = ["rm -rf " + deps_dir + "; mkdir " + deps_dir + "\n"] | ||
for lib in transitive_libs: | ||
setup_cmd += [_create_setup_cmd(lib, deps_dir, in_runfiles)] |
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.
Nit: I know you didn't directly touch this here, but I think this is a good opportunity to rename this function. It only does one specific setup thing, and it might get called more than once which doesn't match the intuition derived from the function name.
Candidate: _(create_)?dep_symlink_cmd
|
||
compile_inputs = ( | ||
crate_info.srcs + | ||
ctx.files.data + |
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'll need to come up with a real solution to runfiles -- probably related to including a crate in rules_rust for loading them.
I've said as much before (in different terms) but I suspect we need a crisper boundary between compile-time data and run-time data. The cc_embed_data approach described here: #79 (comment) makes sense to me for that purpose, and we could package a crate in rules_rust for accessing data packaged into an rlib in that manner.
Longer term thinking, of course....
rust/rust.bzl
Outdated
crate_root = dep.crate_root, | ||
crate_type = crate_type, | ||
deps = dep.rust_deps, | ||
crate = ctx.attr.deps[0].crate_info |
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.
Nit: crate -> parent_crate
Just to better describe the relationship between this rust_test rule and the rust_library that it wraps.
|
||
# nb. Crates are linked via --extern regardless of their crate_type | ||
link_flags += ["--extern " + crate.name + "=" + deps_dir + "/" + crate.output.basename for crate in direct_crates] | ||
link_flags += ["-l dylib=" + _get_lib_name(lib) for lib in transitive_dylibs.to_list()] |
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.
Seems kind of a shame that we can't get rid of the _get_lib_name function and just use CrateInfo, but it makes sense that we might still need it for non-rust deps.
# TODO(katre): Remove the fork of test_rules when the fixed version is released. | ||
#"@bazel_tools//tools/build_rules:test_rules.bzl", | ||
":test_rules.bzl", | ||
"@bazel_tools//tools/build_rules:test_rules.bzl", |
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 fixing this!
I'll go ahead and skip the tests failing REB, pending being able to see the logs at all, and tidy the rest. |
_out_dir_setup_cmd(ctx.file.out_dir_tar) + | ||
_get_rustc_env(ctx) + [ | ||
"LD_LIBRARY_PATH=%s" % _get_path_str(_get_dir_names(toolchain.rustc_lib)), |
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.
@acmcarther fyi I believe these became removable because of the newer rustup-style arrangement of the toolchain
This test fails with: error[E0463]: can't find crate for --> test/chained_direct_deps/mod3.rs:4:1 | 4 | extern crate mod1; | ^^^^^^^^^^^^^^^^^^ can't find crate A git bisect indicate that bazelbuild#122 is the culprit change.
Before bazelbuild#122 the test was wrongly passing.
…155) * Test for failure to import crate in rust_doc_test. This test fails with: error[E0463]: can't find crate for --> test/chained_direct_deps/mod3.rs:4:1 | 4 | extern crate mod1; | ^^^^^^^^^^^^^^^^^^ can't find crate A git bisect indicate that #122 is the culprit change. * fix: doc_test Before #122 the test was wrongly passing. * Fix rustdoc_test by using the dependency's providers Instead of trying to recreate the DepInfo provider, use directly the dep's DepInfo. It allows to correctly add all the direct deps to the command line. * Exclude rust_doc_test from RBE All other rust_doc_test are already excluded.
This is reasonable as is, but I will work through the doc rules as well.
Open to any and all nits, comments on naming, etc, as this is pretty subjective refactoring stuff.
Functional Changes: