Skip to content

Commit ac50580

Browse files
authored
Bump rules_rust to pick up working rust_doc_test (#115)
1 parent c9094a7 commit ac50580

5 files changed

Lines changed: 108 additions & 3 deletions

File tree

rs/rules_rust.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def _rules_rust_impl(mctx):
3131

3232
http_archive(
3333
name = "rules_rust",
34-
integrity = "sha256-cgcEczGYnZ2eievIbjKeHbx8IgadpgE+pqCP5T9KfpI=",
35-
strip_prefix = "rules_rust-f219b67063621df3478da66b45be30f67031254b",
36-
url = "https://github.com/hermeticbuild/rules_rust/archive/f219b67063621df3478da66b45be30f67031254b.tar.gz",
34+
integrity = "sha256-SylkBtg4Bb5Mz2Dr3EMw6wwV70eB4SzstsejNEAl+wE=",
35+
strip_prefix = "rules_rust-37c7e7461a10d6e244f67fc96657e639fe8e034f",
36+
url = "https://github.com/hermeticbuild/rules_rust/archive/37c7e7461a10d6e244f67fc96657e639fe8e034f.tar.gz",
3737
patches = patches,
3838
patch_strip = strip,
3939
)

rs/tests/BUILD.bazel

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
2+
load("@rules_rust//rust:defs.bzl", "rust_doc_test")
3+
load("//rs:rust_library.bzl", "rust_library")
4+
load(":rustdoc_musl_unwind_test.bzl", "rustdoc_musl_unwind_link_flags_test")
5+
6+
cc_library(
7+
name = "rustdoc_musl_unwind_cc",
8+
srcs = ["rustdoc_musl_unwind.cc"],
9+
)
10+
11+
rust_library(
12+
name = "rustdoc_musl_unwind",
13+
srcs = ["rustdoc_musl_unwind.rs"],
14+
crate_name = "rustdoc_musl_unwind",
15+
edition = "2021",
16+
deps = [":rustdoc_musl_unwind_cc"],
17+
)
18+
19+
rust_doc_test(
20+
name = "rustdoc_musl_unwind_doctest",
21+
crate = ":rustdoc_musl_unwind",
22+
)
23+
24+
rustdoc_musl_unwind_link_flags_test(
25+
name = "rustdoc_musl_unwind_link_flags_test",
26+
target_under_test = ":rustdoc_musl_unwind_doctest",
27+
)
28+
29+
test_suite(
30+
name = "tests",
31+
tests = [":rustdoc_musl_unwind_link_flags_test"],
32+
)

rs/tests/rustdoc_musl_unwind.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extern "C" int rustdoc_musl_unwind_value() {
2+
try {
3+
throw 430;
4+
} catch (int value) {
5+
return value;
6+
}
7+
}

rs/tests/rustdoc_musl_unwind.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! ```
2+
//! assert_eq!(rustdoc_musl_unwind::unwind_value(), 430);
3+
//! ```
4+
5+
extern "C" {
6+
fn rustdoc_musl_unwind_value() -> i32;
7+
}
8+
9+
pub fn unwind_value() -> i32 {
10+
unsafe { rustdoc_musl_unwind_value() }
11+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""Regression tests for musl rustdoc native linking."""
2+
3+
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
4+
5+
def _get_action_by_mnemonic(env, tut, mnemonic):
6+
actions = [action for action in tut.actions if action.mnemonic == mnemonic]
7+
asserts.equals(
8+
env,
9+
1,
10+
len(actions),
11+
"Expected exactly one {} action, got {}".format(mnemonic, [action.mnemonic for action in tut.actions]),
12+
)
13+
return actions[0]
14+
15+
def _assert_argv_contains(env, action, expected):
16+
asserts.true(
17+
env,
18+
expected in action.argv,
19+
"Expected argv to contain {}, got {}".format(expected, action.argv),
20+
)
21+
22+
def _assert_argv_contains_substrings(env, action, substrings, description):
23+
for arg in action.argv:
24+
if all([substring in arg for substring in substrings]):
25+
return
26+
27+
asserts.true(
28+
env,
29+
False,
30+
"Expected argv to contain {}, got {}".format(description, action.argv),
31+
)
32+
33+
def _rustdoc_musl_unwind_link_flags_test_impl(ctx):
34+
env = analysistest.begin(ctx)
35+
tut = analysistest.target_under_test(env)
36+
action = _get_action_by_mnemonic(env, tut, "RustdocTest")
37+
38+
_assert_argv_contains(env, action, "--test")
39+
_assert_argv_contains(env, action, "-Clink-arg=-lrustdoc_musl_unwind_cc")
40+
_assert_argv_contains_substrings(
41+
env,
42+
action,
43+
["-Clink-arg=-l", "unwind"],
44+
"a rustdoc-compatible libunwind link argument",
45+
)
46+
47+
return analysistest.end(env)
48+
49+
rustdoc_musl_unwind_link_flags_test = analysistest.make(
50+
_rustdoc_musl_unwind_link_flags_test_impl,
51+
config_settings = {
52+
"//command_line_option:extra_execution_platforms": str(Label("//rs/platforms:x86_64-unknown-linux-musl")),
53+
"//command_line_option:platforms": str(Label("//rs/platforms:x86_64-unknown-linux-musl")),
54+
},
55+
)

0 commit comments

Comments
 (0)