-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) Added Python 3.11 bindings + Added dummy Java tests + Added du…
…mmy Python tests
- Loading branch information
Showing
10 changed files
with
128 additions
and
23 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 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 @@ | ||
package spdr.client; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class TestSpdr { | ||
|
||
@Test | ||
public void testSample() { | ||
Spdr.Client instance = new Spdr.Client("localhost", 8080); | ||
|
||
assertEquals(0, instance.connect()); | ||
assertEquals(0, instance.disconnect()); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,19 +1,23 @@ | ||
CC=g++ | ||
|
||
all: webassembly | ||
all: webassembly java python | ||
|
||
clean: | ||
rm -f *.o *.so *.js *.wasm | ||
|
||
libspdr.so: spdr.o | ||
$(CC) -shared -o libspdr.so spdr.o | ||
|
||
spdr.o: spdr_client.cpp spdr_client.h | ||
$(CC) -c -fPIC spdr_client.cpp -o spdr.o | ||
|
||
webassembly: spdr_client.cpp spdr_client.h | ||
em++ spdr_client.cpp --bind -DUSE_EMSCRIPTEN -o spdr.js | ||
|
||
java: libspdr.so | ||
java: spdr_client.cpp spdr_client.h | ||
# Build library without support | ||
$(CC) -c -fPIC spdr_client.cpp -o spdr.o | ||
$(CC) -shared -o libspdr.so spdr.o | ||
|
||
# Copy libraries for Maven to use | ||
mkdir -p ../java/target/classes/spdr/client/linux-x86_64 | ||
cp libspdr.so ../java/target/classes/spdr/client/linux-x86_64 | ||
cp libspdr.so ../java/target/classes/spdr/client/linux-x86_64 | ||
|
||
python: spdr_client.cpp spdr_client.h | ||
# Build library with boost support | ||
$(CC) -c -fPIC spdr_client.cpp -o spdr.o -Iboost/ -I/usr/include/python3.11 -DUSE_PYTHON | ||
$(CC) -shared -Wl,-soname,libspdr.so -o libspdr.so spdr.o -lpython3.11 -lboost_python311 -Iboost -Lboost/stage/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,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
PYTHON_HEADERS_PATH="/usr/include/python3.11/" | ||
|
||
if [[ ! -d boost ]]; then | ||
echo "[*] Downloading boost 1.82.0..." | ||
wget https://boostorg.jfrog.io/artifactory/main/release/1.82.0/source/boost_1_82_0.tar.gz | ||
CHECKSUM=$(sha256sum boost_1_82_0.tar.gz | cut -d' ' -f1) | ||
|
||
if [[ ${CHECKSUM} != "66a469b6e608a51f8347236f4912e27dc5c60c60d7d53ae9bfe4683316c6f04c" ]]; then | ||
>&2 echo "[-] ERROR: Wrong checksum" | ||
exit 1 | ||
fi | ||
|
||
echo "[*] Decompressing archive..." | ||
tar xf boost_1_82_0.tar.gz && rm boost_1_82_0.tar.gz | ||
mv boost_* boost | ||
fi | ||
|
||
cd boost | ||
|
||
echo "[*] Building boost...." | ||
./bootstrap.sh --with-python=$(python --version | cut -d' ' -f2) | ||
mkdir -p ../boost_build | ||
CPLUS_INCLUDE_PATH="$CPLUS_INCLUDE_PATH:$PYTHON_HEADERS_PATH" ./b2 --build-dir=../boost_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
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,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
ORIGIN_DIR=$(pwd) | ||
|
||
build_library() { | ||
cd ../lib | ||
make clean | ||
make python | ||
cp libspdr.so ../python/ | ||
make clean | ||
|
||
cd ${ORIGIN_DIR} | ||
} | ||
|
||
run_test() { | ||
LIBRARY_LOCATION=$(pwd) | ||
cd test | ||
PYTHONPATH=${LIBRARY_LOCATION} python main.py | ||
rm ../libspdr.so | ||
} | ||
|
||
case "$1" in | ||
build) | ||
build_library | ||
;; | ||
|
||
test) | ||
build_library | ||
run_test | ||
;; | ||
esac |
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 @@ | ||
import libspdr | ||
|
||
def main(): | ||
instance = libspdr.Client("localhost", 8080) | ||
assert instance.connect() == 0 | ||
assert instance.disconnect() == 0 | ||
|
||
if __name__ == "__main__": | ||
main() |