generated from bazel-contrib/rules-template
-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example: Add example for pybind11 (#375)
Add an example for pybind11 with rules_py which is a modified version of https://github.com/pybind/pybind11_bazel/tree/master/examples/basic. --- ### Changes are visible to end-users: no ### Test plan <!-- Delete any which do not apply --> - New test cases added
- Loading branch information
Showing
4 changed files
with
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
load("@aspect_rules_py//py:defs.bzl", "py_library", "py_test") | ||
load("@pybind11_bazel//:build_defs.bzl", "pybind_extension") | ||
|
||
pybind_extension( | ||
name = "basic", | ||
srcs = ["basic.cpp"], | ||
) | ||
|
||
py_library( | ||
name = "basic_lib", | ||
data = [":basic"], | ||
imports = ["."], | ||
) | ||
|
||
py_test( | ||
name = "basic_test", | ||
srcs = ["basic_test.py"], | ||
deps = [":basic_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,10 @@ | ||
#include <pybind11/pybind11.h> | ||
|
||
int add(int i, int j) { | ||
return i + j; | ||
} | ||
|
||
PYBIND11_MODULE(basic, module) { | ||
module.doc() = "A basic pybind11 extension"; | ||
module.def("add", &add, "A function that adds two numbers"); | ||
} |
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,14 @@ | ||
import unittest | ||
|
||
import basic | ||
|
||
|
||
class TestBasic(unittest.TestCase): | ||
|
||
def test_add(self): | ||
self.assertEqual(basic.add(1, 2), 3) | ||
self.assertEqual(basic.add(2, 2), 4) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |