Skip to content

Commit

Permalink
Merge branch 'main' into auth-for-downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion committed Oct 19, 2021
2 parents c921f8c + cdca6ed commit 1fcaa2d
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 21 deletions.
6 changes: 5 additions & 1 deletion cargo/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,18 @@ def cargo_build_script(
if "CARGO_CRATE_NAME" not in rustc_env:
rustc_env["CARGO_CRATE_NAME"] = name_to_crate_name(_name_to_pkg_name(name))

binary_tags = [tag for tag in tags or []]
if "manual" not in binary_tags:
binary_tags.append("manual")

rust_binary(
name = name + "_script_",
crate_features = crate_features,
version = version,
deps = deps,
data = data,
rustc_env = rustc_env,
tags = ["manual"],
tags = binary_tags,
**kwargs
)
_build_script_run(
Expand Down
2 changes: 1 addition & 1 deletion cargo/cargo_build_script_runner/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn run_buildrs() -> Result<(), String> {
}

if let Some(cc_path) = env::var_os("CC") {
let mut cc_path = exec_root.join(cc_path);
let mut cc_path = exec_root.join(cc_path).into_os_string();
if let Some(sysroot_path) = env::var_os("SYSROOT") {
cc_path.push(" --sysroot=");
cc_path.push(&exec_root.join(sysroot_path));
Expand Down
5 changes: 3 additions & 2 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def collect_deps(label, deps, proc_macro_deps, aliases, are_linkstamps_supported
cc_info = _get_cc_info(dep)
dep_build_info = _get_build_info(dep)

if cc_info and are_linkstamps_supported:
linkstamps.append(cc_info.linking_context.linkstamps())

if crate_info:
# This dependency is a rust_library

Expand Down Expand Up @@ -174,8 +177,6 @@ def collect_deps(label, deps, proc_macro_deps, aliases, are_linkstamps_supported
libs = [get_preferred_artifact(lib) for li in linker_inputs for lib in li.libraries]
transitive_noncrate_libs.append(depset(libs))
transitive_noncrates.append(cc_info.linking_context.linker_inputs)
if are_linkstamps_supported:
linkstamps.append(cc_info.linking_context.linkstamps())
elif dep_build_info:
if build_info:
fail("Several deps are providing build information, " +
Expand Down
34 changes: 34 additions & 0 deletions test/out_dir_in_tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("//cargo:cargo_build_script.bzl", "cargo_build_script")
load("//rust:defs.bzl", "rust_test_suite")
load(
"//rust:rust.bzl",
"rust_library",
"rust_test",
)

cargo_build_script(
name = "build_script",
srcs = ["build.rs"],
)

rust_library(
name = "demo_lib",
srcs = [
"src/lib.rs",
],
deps = [":build_script"],
)

rust_test(
name = "demo_lib_test",
crate = ":demo_lib",
)

rust_test_suite(
name = "suite",
srcs = glob(["tests/**"]),
# Add the 'crate' argument, which will be passed as a kwarg
# to the underlying rust_test rules. This will make OUT_DIR
# available when compiling integration tests.
crate = ":demo_lib",
)
11 changes: 11 additions & 0 deletions test/out_dir_in_tests/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;

fn main() -> std::io::Result<()> {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let mut file = File::create(out_path.join("test_content.txt"))?;
file.write_all(b"Test content")?;
Ok(())
}
18 changes: 18 additions & 0 deletions test/out_dir_in_tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#[cfg(test)]
mod tests {
use std::env;

#[test]
fn can_find_the_out_dir_file() {
// The file contents must be included via a macro.
let contents = include_str!(concat!(env!("OUT_DIR"), "/test_content.txt"));
assert_eq!("Test content", contents);
}

#[test]
fn no_out_dir_at_runtime() {
// Cargo seems to set this at runtime as well, although the documentation
// says it's only available at compile time.
assert!(env::var("OUT_DIR").is_err());
}
}
15 changes: 15 additions & 0 deletions test/out_dir_in_tests/tests/out_dir_reader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::env;

#[test]
fn can_find_the_out_dir_file() {
// The file contents must be included via a macro.
let contents = include_str!(concat!(env!("OUT_DIR"), "/test_content.txt"));
assert_eq!("Test content", contents);
}

#[test]
fn no_out_dir_at_runtime() {
// Cargo seems to set this at runtime as well, although the documentation
// says it's only available at compile time.
assert!(env::var("OUT_DIR").is_err());
}
51 changes: 34 additions & 17 deletions test/unit/linkstamps/linkstamps_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//rust:defs.bzl", "rust_binary", "rust_test")
load("//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
load("//test/unit:common.bzl", "assert_action_mnemonic")

def _is_running_on_linux(ctx):
Expand Down Expand Up @@ -64,50 +64,67 @@ def _linkstamps_test():
}),
)

cc_library(
name = "cc_lib_with_linkstamp_transitively",
deps = [":cc_lib_with_linkstamp"],
)

rust_binary(
name = "some_rust_binary",
srcs = ["foo.rs"],
deps = [":cc_lib_with_linkstamp"],
)

rust_binary(
name = "some_rust_binary_with_multiple_paths_to_a_linkstamp",
srcs = ["foo.rs"],
deps = [":cc_lib_with_linkstamp", ":cc_lib_with_linkstamp_transitively"],
supports_linkstamps_test(
name = "rust_binary_supports_linkstamps_test",
target_under_test = ":some_rust_binary",
)

rust_test(
name = "some_rust_test1",
rust_library(
name = "some_rust_library_with_linkstamp_transitively",
srcs = ["foo.rs"],
deps = [":cc_lib_with_linkstamp"],
)

rust_test(
name = "some_rust_test2",
rust_binary(
name = "some_rust_binary_with_linkstamp_transitively",
srcs = ["foo.rs"],
deps = [":cc_lib_with_linkstamp"],
deps = [":some_rust_library_with_linkstamp_transitively"],
)

supports_linkstamps_test(
name = "rust_binary_supports_linkstamps_test",
target_under_test = ":some_rust_binary",
name = "rust_binary_with_linkstamp_transitively",
target_under_test = ":some_rust_binary_with_linkstamp_transitively",
)

cc_library(
name = "cc_lib_with_linkstamp_transitively",
deps = [":cc_lib_with_linkstamp"],
)

rust_binary(
name = "some_rust_binary_with_multiple_paths_to_a_linkstamp",
srcs = ["foo.rs"],
deps = [":cc_lib_with_linkstamp", ":cc_lib_with_linkstamp_transitively"],
)

supports_linkstamps_test(
name = "rust_binary_supports_duplicated_linkstamps",
target_under_test = ":some_rust_binary_with_multiple_paths_to_a_linkstamp",
)

rust_test(
name = "some_rust_test1",
srcs = ["foo.rs"],
deps = [":cc_lib_with_linkstamp"],
)

supports_linkstamps_test(
name = "rust_test_supports_linkstamps_test1",
target_under_test = ":some_rust_test1",
)

rust_test(
name = "some_rust_test2",
srcs = ["foo.rs"],
deps = [":cc_lib_with_linkstamp"],
)

supports_linkstamps_test(
name = "rust_test_supports_linkstamps_test2",
target_under_test = ":some_rust_test2",
Expand Down

0 comments on commit 1fcaa2d

Please sign in to comment.