-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add example of c calling rust staticlib. * Remove trailing newlines. * Set visibility to private , run formatter.
- Loading branch information
1 parent
d20f528
commit cebb2a9
Showing
3 changed files
with
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package(default_visibility = ["//visibility:private"]) | ||
|
||
load("@//rust:rust.bzl", "rust_library", "rust_test", "rust_binary") | ||
|
||
rust_library( | ||
name = "rusty", | ||
srcs = ["lib.rs"], | ||
crate_type = "staticlib", | ||
) | ||
|
||
# cc_* rules expect cc_* deps, so we need to wrap our rust staticlib. | ||
cc_library( | ||
name = "wrapper", | ||
srcs = [":rusty"], | ||
) | ||
|
||
cc_test( | ||
name = "main", | ||
srcs = ["main.c"], | ||
deps = [":wrapper"], | ||
) |
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 fn my_favorite_number() -> 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> | ||
|
||
extern int32_t my_favorite_number(); | ||
|
||
int main(int argc, char** argv) { | ||
assert(my_favorite_number() == 4); | ||
return 0; | ||
} |