generated from bazel-contrib/rules-template
-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "example: Add example for pybind11" (#444)"
This reverts commit aae7c24.
- 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() |