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

Propagate linkopts from native deps #264

Closed
wants to merge 1 commit into from

Conversation

hlopko
Copy link
Member

@hlopko hlopko commented Nov 3, 2019

This PR ensures that linkopts attributes from dependencies such as cc_library make it to the rust_binary linker invocation.

Not-so-great but still motivating example is that with this PR we can make openssl-sys crate work with system installed openssl just by pushing additional_deps cc_libraries:

cc_library(
  name = "crypto",
  linkopts = ["-lcrypto"],
)

cc_library(
  name = "ssl",
  linkopts = ["-lssl"],
  deps = [":crypt"],
)

I updated skylib and made use of its unittest.bzl framework for adding the unittest.

And since I was there, I added one TODO regarding libraries to link ordering.

WORKSPACE Show resolved Hide resolved
@@ -114,10 +116,20 @@ def collect_deps(deps, toolchain):

# TODO: We could let the user choose how to link, instead of always preferring to link static libraries.
libs = get_libs_for_static_executable(dep)
# TODO: This is changing the order of linker inputs, it shouldn't.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The fix is to iterate through libs once, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. I didn't want to do that in this PR, but it should be fairly straightforward.

dylibs = [l for l in libs.to_list() if l.basename.endswith(toolchain.dylib_ext)]
staticlibs = [l for l in libs.to_list() if l.basename.endswith(toolchain.staticlib_ext)]
transitive_dylibs = depset(transitive = [transitive_dylibs, depset(dylibs)])
transitive_staticlibs = depset(transitive = [transitive_staticlibs, depset(staticlibs)])
linkopts.extend(dep[CcInfo].linking_context.user_link_flags)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't this also need to be building up transitive_linkopts when rust -> rust -> c?

@@ -397,6 +410,7 @@ def add_native_link_flags(args, dep_info):
args.add_all(native_libs, map_each = _get_dirname, uniquify = True, format_each = "-Lnative=%s")
args.add_all(dep_info.transitive_dylibs, map_each = get_lib_name, format_each = "-ldylib=%s")
args.add_all(dep_info.transitive_staticlibs, map_each = get_lib_name, format_each = "-lstatic=%s")
args.add_all(dep_info.linkopts, uniquify = False)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is uniquify false? Because it already came from a depset?

@hlopko hlopko force-pushed the propagate_linkopts branch from 11b0249 to 1eae40f Compare November 6, 2019 20:59
@damienmg
Copy link
Collaborator

Marcel left the Bazel team. closing.

@damienmg damienmg closed this May 18, 2020
@hlopko
Copy link
Member Author

hlopko commented May 19, 2020

Ouch :) FTR, it's the newborn that is the reason, not the team transfer :) I still plan to work on the rules when the time allows.

@damienmg
Copy link
Collaborator

damienmg commented May 19, 2020 via email

@ali5h
Copy link

ali5h commented Jul 22, 2020

i was wondering if this will be worked on in the near future?

@ali5h
Copy link

ali5h commented Jul 23, 2020

also, is there any workaround for this issue for now?

@ali5h
Copy link

ali5h commented Aug 1, 2020

can we reopen this issue? this is not resolved, right?

@damienmg
Copy link
Collaborator

damienmg commented Aug 3, 2020

This is not an issue, this is PR and @hlopko had no time to work on it so far (in addition to having moved out the Bazel team).

@hlopko hlopko deleted the propagate_linkopts branch April 1, 2021 07:48
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