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

Add cc toolchain files to rustc dependencies (for linker) #217

Merged
merged 4 commits into from
May 9, 2019

Conversation

m3rcuriel
Copy link
Contributor

Currently if you're using an artifacted compiler the Rust rules will complain that they can't find the linker script. This is because it is not a dependency.

I'm pretty sure there's a correct way to do this with the new toolchain system but I was looking around and saw that people mostly stuck with this with some TODOs to find a better way.

I tried to get it using ctx.toolchains but that doesn't actually have files, it seems.

@mfarrugi
Copy link
Collaborator

mfarrugi commented Apr 23, 2019 via email

Copy link
Collaborator

@damienmg damienmg left a comment

Choose a reason for hiding this comment

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

This is fine to me, please add a TODO about finding a canonical way to include C++ toolchains files (indeed that should comes with cc_toolchain, @hlopko any idea?).

The only downside of doing that I can see is that we may have way to much files in the input of the action.

rust/private/rustc.bzl Outdated Show resolved Hide resolved
@hlopko
Copy link
Member

hlopko commented Apr 24, 2019

Hi all,

to make sure I understand the issue correctly, you want to do this so the linker is present for the linking action, not the linker script (one is tool that does linking, another one is a script that ld can consume to tweak the linking process, used e.g. to specify symbol visibility etc), correct?

The best way to access C++ toolchain files is to use all_files , which is only in 0.25 (bazelbuild/bazel@f59038d) :). Until then, ctx.attr._cc_toolchain.files is good enough.

The best way to access the C++ toolchain is to use find_cpp_toolchain which is forward compatible with bazelbuild/bazel#6516. But this makes the full sense only in 0.25 with all_files.

@m3rcuriel
Copy link
Contributor Author

@hlopko correct, this is in order to ensure that the linker itself (and its dependencies!) are available in the sandbox during linking.

I was going to use all_files as I am a nerd and run whatever most recent Bazel I can but stuck with cxt.attr._cc_toolchain.files because I realized all_files is extremely new.

Currently we get the toolchain out of find_cpp_toolchain. When we want to migrate to all_files we just have to move the depset down about 50 lines below where we get the linker to pass into rustc anyways.

@m3rcuriel m3rcuriel force-pushed the fix_cc_toolchain_deps branch 3 times, most recently from a7c506a to dd8eb35 Compare April 24, 2019 18:14
@@ -198,7 +198,8 @@ def rustc_compile_action(
transitive = [
toolchain.rustc_lib.files,
toolchain.rust_lib.files,
],
# TODO wait for CcToolchainInfo.all_files to be available
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# TODO wait for CcToolchainInfo.all_files to be available
# C++ library linked in rust libraries need the linker to be available at compile-time.
# TODO: Switch to CcToolchainInfo.all_files once available.

@m3rcuriel
Copy link
Contributor Author

@mfarrugi I have no idea why this failed CI on one OS, and I don't have OS X to test on.

@mfarrugi
Copy link
Collaborator

mfarrugi commented May 6, 2019 via email

@m3rcuriel m3rcuriel force-pushed the fix_cc_toolchain_deps branch from dd8eb35 to f617724 Compare May 6, 2019 16:35
rust/private/rustc.bzl Outdated Show resolved Hide resolved
@m3rcuriel
Copy link
Contributor Author

So we should probably add an artifacted compiler/linker set up to test now that I've gotten it working.

The reason it was failing is because ctx.files._cc_toolchain is an empty list on Linux, but contains File(s) on OS X. It needed to be wrapped in a depset. That it didn't fail / that no one but me has encountered the problem this PR should fix means that I should probably take my setup, strip it down, and make it part of the test suite.

@m3rcuriel
Copy link
Contributor Author

m3rcuriel commented May 9, 2019

Now featuring the required fixes to get this to work with --incompatible_enable_cc_toolchain_resolution.

CcToolchainInfo.all_files is introduced in 0.25.0, thus invalidating my TODO.

I'm fairly sure that flipping --incompatible_enable_cc_toolchain_resolution will just break this completely but I haven't downloaded an older Bazel version to check.

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.

5 participants