Skip to content

Commit

Permalink
Avoid hashing destination path for native deps
Browse files Browse the repository at this point in the history
  • Loading branch information
acmcarther committed May 31, 2017
1 parent 45b5d5f commit d42339c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions rust/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,21 @@ def _hashed_lib_path(lib):
split_basename = lib.basename.split('.', 2)
return split_basename[0] + '-' + hash_value + '.' + split_basename[1]

def _create_setup_cmd(lib, deps_dir, in_runfiles):
def _create_setup_cmd(lib, deps_dir, in_runfiles, hash_path=True):
"""
Helper function to construct a command for symlinking a library into the
deps directory.
It unique-ifies provided libs unless hash_path is set to false. This is
necessary for native libs.
"""
lib_path = lib.short_path if in_runfiles else lib.path
destination_path = lib.basename
if hash_path:
destination_path = _hashed_lib_path(lib)
return (
"ln -sf " + _relative(deps_dir, lib_path) + " " +
deps_dir + "/" + _hashed_lib_path(lib) + "\n"
deps_dir + "/" + destination_path + "\n"
)

def _setup_deps(deps, name, working_dir, allow_cc_deps=False,
Expand Down Expand Up @@ -153,6 +159,7 @@ def _setup_deps(deps, name, working_dir, allow_cc_deps=False,
libs = set()
transitive_libs = set()
symlinked_libs = set()
unique_symlinked_libs = set()
link_flags = []
for dep in deps:
if hasattr(dep, "rust_lib"):
Expand All @@ -175,17 +182,22 @@ def _setup_deps(deps, name, working_dir, allow_cc_deps=False,
native_libs = A_FILETYPE.filter(dep.cc.libs)
libs += native_libs
transitive_libs += native_libs
symlinked_libs += native_libs
unique_symlinked_libs += native_libs
link_flags += ["-l static=" + dep.label.name]
has_native = True

else:
fail("rust_library, rust_binary and rust_test targets can only depend " +
"on rust_library or cc_library targets.")

print(symlinked_libs)

for symlinked_lib in symlinked_libs:
setup_cmd += [_create_setup_cmd(symlinked_lib, deps_dir, in_runfiles)]

for unique_symlinked_lib in unique_symlinked_libs:
setup_cmd += [_create_setup_cmd(unique_symlinked_lib, deps_dir, in_runfiles, hash_path=False)]

search_flags = []
if has_rlib:
search_flags += ["-L dependency=%s" % deps_dir]
Expand Down

0 comments on commit d42339c

Please sign in to comment.