Skip to content

Commit

Permalink
create symlinks to ambiguous native dependencies (#1148)
Browse files Browse the repository at this point in the history
Co-authored-by: cfredric <cfredric@chromium.org>
Co-authored-by: Chris Fredrickson <cfredric@users.noreply.github.com>
  • Loading branch information
3 people committed Feb 22, 2022
1 parent 4a4d217 commit 5591596
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 29 deletions.
40 changes: 40 additions & 0 deletions examples/ambiguous_deps/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_rust//rust:defs.bzl", "rust_binary")

# A rust_binary that depends on two native libs with the same name.
# See https://github.com/bazelbuild/rules_rust/issues/840.
rust_binary(
name = "bin_with_same_name_deps",
srcs = ["bin.rs"],
deps = [
"//ambiguous_deps/x:exc",
"//ambiguous_deps/y:exc",
],
)

# A rust_binary that depends on a native library with a name that doesn't
# match the `lib<name>.a` pattern on linux.
rust_binary(
name = "nonstandard_name_bin",
srcs = ["nonstandard_name_bin.rs"],
deps = [":nonstandard_name_intermediate"],
)

cc_library(
name = "nonstandard_name_cc_lib",
srcs = ["cc_library_with_func.cc"],
)

genrule(
name = "nonstandard_name_gen",
srcs = [":nonstandard_name_cc_lib"],
outs = ["nonstandard_name_gen.a"],
# Copy the first member (libnonstandard_name_cc_lib.a) from the srcs to the
# output nonstandard_name_gen.a.
cmd = "cp $$(awk '{print $$1}' <<< '$(SRCS)') $@",
)

cc_library(
name = "nonstandard_name_intermediate",
srcs = [":nonstandard_name_gen.a"],
)
10 changes: 10 additions & 0 deletions examples/ambiguous_deps/bin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use std::os::raw::c_int;

extern "C" {
pub fn cx() -> c_int;
pub fn cy() -> c_int;
}

fn main() {
println!("hi {} {}", unsafe { cx() }, unsafe { cy() });
}
3 changes: 3 additions & 0 deletions examples/ambiguous_deps/cc_library_with_func.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extern "C" int func() {
return 123;
}
9 changes: 9 additions & 0 deletions examples/ambiguous_deps/nonstandard_name_bin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::os::raw::c_int;

extern "C" {
pub fn func() -> c_int;
}

fn main() {
println!("hi {}", unsafe { func() });
}
7 changes: 7 additions & 0 deletions examples/ambiguous_deps/x/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("@rules_cc//cc:defs.bzl", "cc_library")

cc_library(
name = "exc",
srcs = ["exc.cc"],
visibility = ["//ambiguous_deps:__subpackages__"],
)
1 change: 1 addition & 0 deletions examples/ambiguous_deps/x/exc.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extern "C" int cx() { return 17; }
7 changes: 7 additions & 0 deletions examples/ambiguous_deps/y/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("@rules_cc//cc:defs.bzl", "cc_library")

cc_library(
name = "exc",
srcs = ["exc.cc"],
visibility = ["//ambiguous_deps:__subpackages__"],
)
1 change: 1 addition & 0 deletions examples/ambiguous_deps/y/exc.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extern "C" int cy() { return 113; }
3 changes: 2 additions & 1 deletion rust/private/clippy.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _clippy_aspect_impl(target, ctx):
are_linkstamps_supported = False,
)

compile_inputs, out_dir, build_env_files, build_flags_files, linkstamp_outs = collect_inputs(
compile_inputs, out_dir, build_env_files, build_flags_files, linkstamp_outs, ambiguous_libs = collect_inputs(
ctx,
ctx.rule.file,
ctx.rule.files,
Expand All @@ -94,6 +94,7 @@ def _clippy_aspect_impl(target, ctx):
crate_info = crate_info,
dep_info = dep_info,
linkstamp_outs = linkstamp_outs,
ambiguous_libs = ambiguous_libs,
output_hash = determine_output_hash(crate_info.root, ctx.label),
rust_flags = [],
out_dir = out_dir,
Expand Down
Loading

0 comments on commit 5591596

Please sign in to comment.