-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add nanobind extension for nob. * Add template to run nob command via Python and to CI. * Add basic robot framework test. * Start fixing memory leaks in nob (WIP, cf. TODO) * Update duplicate code action.
- Loading branch information
Showing
13 changed files
with
165 additions
and
24 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,39 @@ | ||
name: nanobind | ||
run-name: ${{ github.actor }} is building Python extensions with nanobind | ||
on: | ||
push: | ||
workflow_dispatch: | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: sh | ||
working-directory: . | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: 'recursive' | ||
#- name: Setup tmate session | ||
# uses: mxschmitt/action-tmate@v3 | ||
# with: | ||
# detached: true | ||
- name: Python setup | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11.9' | ||
- name: Install Python development dependency | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install python3.11-dev | ||
python -m pip install --upgrade pip | ||
pip install robotframework | ||
# pip install -r requirements.txt | ||
- name: Build | ||
run: ./build_nb.sh | ||
- name: Test | ||
working-directory: ${{github.workspace}} | ||
run: python3.11 nob.py | ||
- name: Robot | ||
run: PYTHONPATH=.:robot robot -d logs robot/NobTestSuite.robot |
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 |
---|---|---|
|
@@ -5,3 +5,5 @@ a.out | |
gcm.cache/ | ||
.ycm_extra_conf.py | ||
__pycache__/ | ||
nobuild/ | ||
venv/ |
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,3 @@ | ||
[submodule "ext/nanobind"] | ||
path = ext/nanobind | ||
url = https://github.com/wjakob/nanobind |
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,11 @@ | ||
#!/bin/sh -x | ||
|
||
mkdir nobuild | ||
|
||
PYTHON_INCLUDE=`pkg-config --cflags python3` | ||
|
||
g++ nobnb.cpp -std=c++20 -fvisibility=hidden -DNDEBUG -DNB_COMPACT_ASSERTIONS $PYTHON_INCLUDE -fPIC -Iext/nanobind/include -Iext/nanobind/ext/robin_map/include -Os -c -o nobuild/nobnb.o | ||
|
||
g++ ext/nanobind/src/nb_combined.cpp -std=c++20 -fvisibility=hidden -DNDEBUG -DNB_COMPACT_ASSERTIONS $PYTHON_INCLUDE -fPIC -Iext/nanobind/include -Iext/nanobind/ext/robin_map/include -O3 -fno-strict-aliasing -ffunction-sections -fdata-sections -c -o nobuild/libnanobind.o | ||
|
||
g++ -shared -Wl,-s -Wl,--gc-sections nobuild/nobnb.o nobuild/libnanobind.o -o nobuild/nob.cpython-311-x86_64-linux-gnu.so |
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,4 @@ | ||
import nobuild.nob as nob | ||
|
||
nob.make_and_run_cmd(["ls", "--color", "-l", "-t"]) | ||
nob.make_and_run_cmd(["pwd"]) |
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,18 @@ | ||
#include <utility> | ||
|
||
#include <nanobind/nanobind.h> | ||
#include <nanobind/stl/array.h> | ||
|
||
#include "nob.cpp" | ||
|
||
namespace nb = nanobind; | ||
|
||
NB_MODULE(nob, m) { | ||
nb::class_<Cmd>(m, "Cmd") | ||
.def(nb::init<>()) | ||
.def_rw("line", &Cmd::line); | ||
|
||
[&m]<std::size_t... Is>(std::index_sequence<Is...>) { | ||
(m.def("make_and_run_cmd", &make_and_run_cmd<Is + 1>), ...); | ||
}(std::make_index_sequence<19>{}); | ||
} |
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,16 @@ | ||
import nobuild.nob as nob | ||
import os | ||
import time | ||
|
||
class NobRobotLib: | ||
def __init__(self) -> None: | ||
pass | ||
|
||
def build_executable(self): | ||
nob.make_and_run_cmd(["g++", "template.cc"]) | ||
|
||
def get_executable_time(self): | ||
return os.path.getmtime('a.out') | ||
|
||
def get_current_time(self): | ||
return time.time() |
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,8 @@ | ||
*** Settings *** | ||
Documentation Basic nob test suite. | ||
Resource keywords.resource | ||
|
||
*** Test Cases *** | ||
Test Case 1 | ||
Build file | ||
Verify build |
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,12 @@ | ||
*** Settings *** | ||
Documentation | ||
Library NobRobotLib | ||
|
||
*** Keywords *** | ||
Build file | ||
Build executable | ||
|
||
Verify build | ||
${file_time}= Get Executable Time | ||
${time}= Get current time | ||
Should be true ${time}-${file_time} <= 1 |