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

create symlinks to ambiguous native dependencies #1148

Merged
merged 13 commits into from
Feb 22, 2022
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