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 buildscript link flags only to parent crate #448

Merged
merged 2 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -724,15 +724,10 @@ def _create_extra_input_args(ctx, file, build_info, dep_info):
if build_info:
out_dir = build_info.out_dir.path
build_env_file = build_info.rustc_env.path

# out_dir will be added as input by the transitive_build_infos loop below.
build_flags_files.append(build_info.flags.path)

# This should probably only actually be exposed to actions which link.
for dep_build_info in dep_info.transitive_build_infos.to_list():
input_files.append(dep_build_info.out_dir)
build_flags_files.append(dep_build_info.link_flags.path)
input_files.append(dep_build_info.link_flags)
build_flags_files.append(build_info.link_flags.path)
input_files.append(build_info.out_dir)
input_files.append(build_info.link_flags)

return input_files, out_dir, build_env_file, build_flags_files

Expand Down
34 changes: 34 additions & 0 deletions test/transitive_lib/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load(
"@io_bazel_rules_rust//cargo:cargo_build_script.bzl",
"cargo_build_script",
)
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary", "rust_library")

# sets link alias
cargo_build_script(
name = "buildscript",
srcs = ["build.rs"],
crate_root = "build.rs",
edition = "2018",
)

# links to a symbol in shell32
rust_library(
name = "dll_user",
srcs = ["dll_user.rs"],
crate_type = "lib",
edition = "2018",
deps = [
":buildscript",
],
)

# does not link to any symbol in shell32
rust_binary(
name = "dll_user_user",
srcs = ["dll_user_user.rs"],
edition = "2018",
deps = [
":dll_user",
],
)
3 changes: 3 additions & 0 deletions test/transitive_lib/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("cargo:rustc-link-lib=alias:shell32");
}
5 changes: 5 additions & 0 deletions test/transitive_lib/dll_user.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[link(name = "alias")]
extern "C" {
// random symbol from shell32
pub fn LocalFree(ptr: *mut std::os::raw::c_void);
}
5 changes: 5 additions & 0 deletions test/transitive_lib/dll_user_user.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
// this file does not link to any shell32 symbols directly, and
// will thus cause a compile error if -lalias:shell32
// is present in the link flags
}