Skip to content

Commit 2fd52c7

Browse files
Nazarevskycdecker
authored andcommitted
sdk: Fix gl-sdk bindings generation for multiple OS
1 parent c068614 commit 2fd52c7

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

libs/gl-client-py/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pygrpc: ${PROTOSRC}
3939
cd ${PYDIR}; uv run python -m grpc_tools.protoc ${PYPROTOC_OPTS} glclient/greenlight.proto
4040

4141
check-py:
42-
#uv run --all-packages mypy ${PYDIR}/glclient
43-
uv run --all-packages pytest tests -n $(shell nproc) ${PYDIR}/tests
42+
#uv run --reinstall-package='gl-sdk' --all-packages mypy ${PYDIR}/glclient
43+
uv run --reinstall-package='gl-sdk' --all-packages pytest tests -n $(shell nproc) ${PYDIR}/tests
4444

4545
clean-py:
4646
rm -f ${PYPROTOS} ${PYDIR}/build ${PYDIR}/dist

libs/gl-sdk/.tasks.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
version: "3"
22

3+
vars:
4+
LIB_EXT:
5+
sh: |
6+
case "$(uname -s)" in
7+
Darwin*)
8+
echo "dylib"
9+
;;
10+
MINGW*|MSYS*|CYGWIN*)
11+
echo "dll"
12+
;;
13+
*)
14+
echo "so"
15+
;;
16+
esac
17+
318
tasks:
419
build:
520
desc: "Build the gl-sdk library"
@@ -20,8 +35,9 @@ tasks:
2035
- build-release
2136
cmds:
2237
- |
38+
cp ${CARGO_TARGET_DIR:-target}/release/libglsdk.{{.LIB_EXT}} ./libs/gl-sdk/glsdk/libglsdk.{{.LIB_EXT}};
2339
cargo run --bin uniffi-bindgen -- generate \
24-
--library ${CARGO_TARGET_DIR:-target}/release/libglsdk.so \
40+
--library ${CARGO_TARGET_DIR:-target}/release/libglsdk.{{.LIB_EXT}} \
2541
--language python \
2642
--out-dir ./libs/gl-sdk/bindings
2743
@@ -32,8 +48,9 @@ tasks:
3248
- build-release
3349
cmds:
3450
- |
51+
cp ${CARGO_TARGET_DIR:-target}/release/libglsdk.{{.LIB_EXT}} ./libs/gl-sdk/glsdk/libglsdk.{{.LIB_EXT}};
3552
cargo run --bin uniffi-bindgen -- generate \
36-
--library ${CARGO_TARGET_DIR:-target}/release/libglsdk.so \
53+
--library ${CARGO_TARGET_DIR:-target}/release/libglsdk.{{.LIB_EXT}} \
3754
--language kotlin \
3855
--out-dir ./libs/gl-sdk/bindings
3956
@@ -44,8 +61,9 @@ tasks:
4461
- build-release
4562
cmds:
4663
- |
64+
cp ${CARGO_TARGET_DIR:-target}/release/libglsdk.{{.LIB_EXT}} ./libs/gl-sdk/glsdk/libglsdk.{{.LIB_EXT}};
4765
cargo run --bin uniffi-bindgen -- generate \
48-
--library ${CARGO_TARGET_DIR:-target}/release/libglsdk.so \
66+
--library ${CARGO_TARGET_DIR:-target}/release/libglsdk.{{.LIB_EXT}} \
4967
--language swift \
5068
--out-dir ./libs/gl-sdk/bindings
5169
@@ -56,8 +74,9 @@ tasks:
5674
- build-release
5775
cmds:
5876
- |
77+
cp ${CARGO_TARGET_DIR:-target}/release/libglsdk.{{.LIB_EXT}} ./libs/gl-sdk/glsdk/libglsdk.{{.LIB_EXT}};
5978
cargo run --bin uniffi-bindgen -- generate \
60-
--library ${CARGO_TARGET_DIR:-target}/release/libglsdk.so \
79+
--library ${CARGO_TARGET_DIR:-target}/release/libglsdk.{{.LIB_EXT}} \
6180
--language ruby \
6281
--out-dir ./libs/gl-sdk/bindings
6382
@@ -106,6 +125,6 @@ tasks:
106125
cmds:
107126
- rm -rf ./bindings
108127
- rm -rf dist/ build/ *.egg-info
109-
- rm -f glsdk/*.so glsdk/glsdk.py
128+
- rm -f glsdk/*.{{.LIB_EXT}} glsdk/glsdk.py
110129
- find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
111130
- find . -type f -name "*.pyc" -delete
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
2+
import platform
3+
4+
class CustomBuildHook(BuildHookInterface):
5+
def initialize(self, version, build_data):
6+
"""
7+
Sets force-include option for glsdk/libglsdk shared lib.
8+
9+
Does the same as [tool.hatch.build.targets.wheel.force-include], however
10+
assumes system OS and based on that sets the correct extension.
11+
"""
12+
system = platform.system()
13+
14+
match system:
15+
case "Darwin":
16+
lib_ext = ".dylib"
17+
case "Windows":
18+
lib_ext = ".dll"
19+
case _:
20+
lib_ext = ".so"
21+
22+
shared_file = f"glsdk/libglsdk{lib_ext}"
23+
build_data['force_include'][shared_file] = shared_file

libs/gl-sdk/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ build-backend = "hatchling.build"
1717
packages = ["glsdk"]
1818

1919
# Include the shared library as package data
20-
[tool.hatch.build.targets.wheel.force-include]
21-
"glsdk/libglsdk.so" = "glsdk/libglsdk.so"
20+
[tool.hatch.build.hooks.custom]
21+
path = "hooks/libglsdk_force_include.py"
2222

2323
[dependency-groups]
2424
dev = [

0 commit comments

Comments
 (0)