-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Advertise CcInfo provider on rules (#2126)
The aspect used in the `cc_shared_library` implementation in bazel 6.3 and 7 only traverses attributes that advertise the `CcInfo` provider via the `provides` attribute. This means in these versions of bazel, rust libraries are currently omitted from libraries built with `cc_shared_library`. Fixes #2101.
- Loading branch information
1 parent
0a4523e
commit 95e5d44
Showing
7 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") | ||
load("@rules_rust//rust:defs.bzl", "rust_static_library") | ||
|
||
rust_static_library( | ||
name = "rust_lib", | ||
srcs = ["lib.rs"], | ||
edition = "2021", | ||
) | ||
|
||
cc_library( | ||
name = "c_lib", | ||
srcs = ["lib.c"], | ||
hdrs = ["lib.h"], | ||
deps = [":rust_lib"], | ||
) | ||
|
||
# Tests that cc_shared_library correctly traverses into | ||
# `rust_static_library` when linking. | ||
cc_shared_library( | ||
name = "shared", | ||
deps = [":c_lib"], | ||
) | ||
|
||
cc_test( | ||
name = "test", | ||
srcs = ["main.c"], | ||
dynamic_deps = [":shared"], | ||
linkstatic = True, | ||
deps = [":c_lib"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "lib.h" | ||
|
||
extern int32_t bar(); | ||
|
||
int32_t foo() { return bar(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <stdint.h> | ||
|
||
#ifdef _WIN32 | ||
#define DllExport __declspec(dllexport) | ||
#else | ||
#define DllExport | ||
#endif | ||
|
||
DllExport int32_t foo(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#[no_mangle] | ||
pub extern "C" fn bar() -> i32 { | ||
4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <assert.h> | ||
#include <stdint.h> | ||
|
||
#include "lib.h" | ||
|
||
int main(int argc, char** argv) { | ||
assert(foo() == 4); | ||
return 0; | ||
} |