Skip to content
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
7 changes: 7 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,10 @@ http_archive(
#
# load("@bazelci_rules//:rbe_repo.bzl", "rbe_preconfig")
# rbe_preconfig(name = "buildkite_config", toolchain = "ubuntu2004-bazel-java11")

http_archive(
name = "rules_testing",
sha256 = "b84ed8546f1969d700ead4546de9f7637e0f058d835e47e865dcbb13c4210aed",
strip_prefix = "rules_testing-0.5.0",
url = "https://github.com/bazelbuild/rules_testing/releases/download/v0.5.0/rules_testing-v0.5.0.tar.gz",
)
3 changes: 3 additions & 0 deletions test/bindgen/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
load(":bindgen_test.bzl", "bindgen_test_suite")

bindgen_test_suite(name = "cc_bindgen_test_suite")
53 changes: 53 additions & 0 deletions test/bindgen/bindgen_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""Analysis test for for rust_bindgen_library rule."""

load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_rust//bindgen:defs.bzl", "rust_bindgen_library")
load("@rules_rust//rust:defs.bzl", "rust_binary")
load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")

def _test_cc_linkopt_impl(env, target):
# Assert
env.expect.that_action(target.actions[0]) \
.contains_at_least_args(["--codegen=link-arg=-shared"])

def _test_cc_linkopt(name):
# Arrange
cc_library(
name = name + "_cc",
srcs = ["simple.cc"],
hdrs = ["simple.h"],
linkopts = ["-shared"],
tags = ["manual"],
)
rust_bindgen_library(
name = name + "_rust_bindgen",
cc_lib = name + "_cc",
header = "simple.h",
tags = ["manual"],
edition = "2021",
)
rust_binary(
name = name + "_rust_binary",
srcs = ["main.rs"],
deps = [name + "_rust_bindgen"],
tags = ["manual"],
edition = "2021",
)

# Act
# TODO: Use targets attr to also verify `rust_bindgen_library` not having
# the linkopt after https://github.com/bazelbuild/rules_testing/issues/67
# is released
analysis_test(
name = name,
target = name + "_rust_binary",
impl = _test_cc_linkopt_impl,
)

def bindgen_test_suite(name):
test_suite(
name = name,
tests = [
_test_cc_linkopt,
],
)
7 changes: 7 additions & 0 deletions test/bindgen/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Analysis test shouldn't need this file.
// This is a workaround until
// https://github.com/bazelbuild/rules_rust/issues/2499
// is fixed
fn main() {
println!("Hello world");
}
4 changes: 4 additions & 0 deletions test/bindgen/simple.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Analysis test shouldn't need this file.
// This is a workaround until
// https://github.com/bazelbuild/rules_rust/issues/2499
// is fixed
4 changes: 4 additions & 0 deletions test/bindgen/simple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Analysis test shouldn't need this file.
// This is a workaround until
// https://github.com/bazelbuild/rules_rust/issues/2499
// is fixed