Skip to content
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

Merged
merged 14 commits into from
Aug 25, 2018

Conversation

mfarrugi
Copy link
Collaborator

@mfarrugi mfarrugi commented Aug 21, 2018

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:

  • runfiles is now populated for libraries, which should be meaningless
  • progress messages are a little different
  • rust_doc_test is no longer a noop :)

rust/rustc.bzl Outdated
for dep in deps:
if hasattr(dep, "crate_info"):
# This dependency is a rust_library
rlib = dep.crate_info.output
Copy link
Collaborator Author

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 +
Copy link
Collaborator Author

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

Copy link
Collaborator

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....

Copy link
Collaborator Author

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

@mfarrugi
Copy link
Collaborator Author

Test failures in test/BUILD, forgot about that..

@mfarrugi mfarrugi changed the title (wip) Deduplicate rule impls (#117) Deduplicate rule impls, fix rust_doc_test (#117) Aug 21, 2018
working_dir = "."
depinfo = _setup_deps(
target.deps,
target.name,
[ctx.attr.dep],
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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

@mfarrugi
Copy link
Collaborator Author

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.

@mfarrugi
Copy link
Collaborator Author

@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?

Copy link
Collaborator

@acmcarther acmcarther left a 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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Should this be hoisted out on top of the other functions? I don't feel strongly about this but it does feel hidden.
  2. Is per-field documentation appropriate? I'm thinking specifically the "type" and "output" fields could use some extra detail

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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

  2. 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:
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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"],
Copy link
Collaborator

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.

Copy link
Collaborator Author

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)
Copy link
Collaborator

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"?

Copy link
Collaborator Author

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)
Copy link
Collaborator

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?

Copy link
Collaborator Author

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:
Copy link
Collaborator

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)]
Copy link
Collaborator

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 +
Copy link
Collaborator

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
Copy link
Collaborator

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()]
Copy link
Collaborator

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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

@mfarrugi
Copy link
Collaborator Author

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)),
Copy link
Collaborator Author

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

@mfarrugi mfarrugi merged commit eb46819 into bazelbuild:master Aug 25, 2018
damienmg added a commit to damienmg/rules_rust that referenced this pull request Nov 11, 2018
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.
damienmg added a commit to damienmg/rules_rust that referenced this pull request Nov 11, 2018
Before bazelbuild#122 the test was wrongly passing.
acmcarther pushed a commit that referenced this pull request Nov 13, 2018
…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.
@mfarrugi mfarrugi deleted the marco-consolidate-compile branch October 19, 2020 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants