-
Notifications
You must be signed in to change notification settings - Fork 646
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup the flaxlib in C++, using Meson and Nanobind.
Not enabling GitHub auto-build of flaxlib yet - gonna do that later. PiperOrigin-RevId: 696623140
- Loading branch information
Showing
16 changed files
with
77 additions
and
29 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,34 @@ | ||
# flaxlib | ||
|
||
## Build flaxlib from source | ||
|
||
Install necessary dependencies to build the C++ based package. | ||
|
||
```shell | ||
pip install meson-python ninja build | ||
``` | ||
|
||
Clone the Flax repository, navigate to the flaxlib source directory. | ||
|
||
```shell | ||
git clone [email protected]:google/flax.git | ||
cd flax/flaxlib_src | ||
``` | ||
|
||
Configure the build. | ||
|
||
```shell | ||
mkdir -p subprojects | ||
meson wrap install robin-map | ||
meson wrap install nanobind | ||
meson setup builddir | ||
``` | ||
|
||
Compile the code. You'll need to run this repeatedly if you modify the source | ||
code. Note that the actual wheel name will differ depending on your system. | ||
|
||
```shell | ||
meson compile -C builddir | ||
python -m build . -w | ||
pip install dist/flaxlib-0.0.1-cp311-cp311-macosx_14_0_arm64.whl --force-reinstall | ||
``` |
File renamed without changes.
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 @@ | ||
project( | ||
'flaxlib', | ||
'cpp', | ||
version: '0.0.1', | ||
default_options: ['cpp_std=c++17'], | ||
) | ||
py = import('python').find_installation() | ||
nanobind_dep = dependency('nanobind', static: true) | ||
py.extension_module( | ||
'flaxlib', | ||
sources: ['src/lib.cc'], | ||
dependencies: [nanobind_dep], | ||
install: true, | ||
) |
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,14 @@ | ||
#include <string> | ||
|
||
#include "nanobind/nanobind.h" | ||
#include "nanobind/stl/string.h" | ||
|
||
namespace flaxlib { | ||
std::string sum_as_string(int a, int b) { | ||
return std::to_string(a + b); | ||
} | ||
|
||
NB_MODULE(flaxlib, m) { | ||
m.def("sum_as_string", &sum_as_string); | ||
} | ||
} // namespace flaxlib |
File renamed without changes.
File renamed without changes.
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