aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2024-04-13 15:21:59 +0200
committerAndre Weissflog <floooh@gmail.com>2024-04-13 15:21:59 +0200
commitbbed0798cbb4976d45ac82efe2e12c0f72c59b78 (patch)
treeb409e9db090a3e326f09ca7b881f38b22e2d055a
parente875a5b6ed4481c8f29ef62e853a0640d2da025b (diff)
parent4d7cc4b550c91cb98003b5209848e13c148d4846 (diff)
Merge branch 'jakubtomsu-odin-unitybuild-and-dll-support'
-rw-r--r--.github/workflows/gen_bindings.yml8
-rw-r--r--CHANGELOG.md8
-rw-r--r--bindgen/gen_odin.py68
3 files changed, 61 insertions, 23 deletions
diff --git a/.github/workflows/gen_bindings.yml b/.github/workflows/gen_bindings.yml
index 6d31a1e1..52a3bbe4 100644
--- a/.github/workflows/gen_bindings.yml
+++ b/.github/workflows/gen_bindings.yml
@@ -173,7 +173,10 @@ jobs:
rm -r ./dist/examples
mv ./dist/* ./
chmod a+x ./odin
+ cd sokol
+ chmod a+x ./build_clibs_linux.sh
./build_clibs_linux.sh
+ cd ..
- if: runner.os == 'macOS'
name: prepare-macos
run: |
@@ -184,14 +187,19 @@ jobs:
rm -r ./dist/examples
mv ./dist/* ./
chmod a+x ./odin
+ cd sokol
+ chmod a+x ./build_clibs_macos.sh
./build_clibs_macos.sh
+ cd ..
- if: runner.os == 'Windows'
name: prepare-windows
shell: cmd
run: |
curl -L https://github.com/odin-lang/Odin/releases/download/dev-2024-04/odin-windows-amd64-dev-2024-04.zip --output odin.zip
unzip odin.zip
+ cd sokol
build_clibs_windows.cmd
+ cd ..
- name: build
run: |
./odin build examples/clear -debug
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5018705f..e3b492c7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,13 @@
- sokol_gfx.h d3d11: resource label strings are now communicated to D3D11 resource objects,
making it easier to identify those resources in tools like the Visual Studio Graphics Debugger
- or RenderDoc. See PR https://github.com/floooh/sokol/pull/1025 for details. Many thanks to @jakubtomsu for the PR!
+ or RenderDoc. See PR https://github.com/floooh/sokol/pull/1025 for details. Many thanks to
+ @jakubtomsu for the PR!
+- Odin bindings: merged https://github.com/floooh/sokol/pull/1023 (and related PR
+ https://github.com/floooh/sokol-odin/pull/11) in the actual bindings repo. This changes
+ the directory structure of the bindings to make them a bit friendlier to integrate
+ with Odin projects, and also adds a couple of smaller improvements and fixes.
+ Many thanks to @jakubtomsu for the PRs!
### 21-Mar-2024:
diff --git a/bindgen/gen_odin.py b/bindgen/gen_odin.py
index a8901a04..dc1a2c37 100644
--- a/bindgen/gen_odin.py
+++ b/bindgen/gen_odin.py
@@ -8,7 +8,7 @@ import gen_util as util
import os, shutil, sys
bindings_root = 'sokol-odin'
-c_root = f'{bindings_root}/c'
+c_root = f'{bindings_root}/sokol/c'
module_root = f'{bindings_root}/sokol'
module_names = {
@@ -337,7 +337,8 @@ def get_system_libs(module, platform, backend):
return ''
def gen_c_imports(inp, c_prefix, prefix):
- clib_prefix = f'sokol_{inp["module"]}'
+ module_name = inp["module"]
+ clib_prefix = f'sokol_{module_name}'
clib_import = f'{clib_prefix}_clib'
windows_d3d11_libs = get_system_libs(prefix, 'windows', 'd3d11')
windows_gl_libs = get_system_libs(prefix, 'windows', 'gl')
@@ -345,37 +346,56 @@ def gen_c_imports(inp, c_prefix, prefix):
macos_gl_libs = get_system_libs(prefix, 'macos', 'gl')
linux_gl_libs = get_system_libs(prefix, 'linux', 'gl')
l( 'import "core:c"')
+ l( '')
+ l( 'SOKOL_DEBUG :: #config(SOKOL_DEBUG, ODIN_DEBUG)')
+ l( '')
+ l(f'DEBUG :: #config(SOKOL_{module_name.upper()}_DEBUG, SOKOL_DEBUG)')
+ l( 'USE_GL :: #config(SOKOL_USE_GL, false)')
+ l( 'USE_DLL :: #config(SOKOL_DLL, false)')
+ l( '')
l( 'when ODIN_OS == .Windows {')
- l( ' when #config(SOKOL_USE_GL,false) {')
- l(f' when ODIN_DEBUG == true {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_gl_debug.lib"{windows_gl_libs} }} }}')
- l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_gl_release.lib"{windows_gl_libs} }} }}')
+ l( ' when USE_DLL {')
+ l( ' when USE_GL {')
+ l(f' when DEBUG {{ foreign import {clib_import} {{ "../sokol_dll_windows_x64_gl_debug.lib"{windows_gl_libs} }} }}')
+ l(f' else {{ foreign import {clib_import} {{ "../sokol_dll_windows_x64_gl_release.lib"{windows_gl_libs} }} }}')
+ l( ' } else {')
+ l(f' when DEBUG {{ foreign import {clib_import} {{ "../sokol_dll_windows_x64_d3d11_debug.lib"{windows_d3d11_libs} }} }}')
+ l(f' else {{ foreign import {clib_import} {{ "../sokol_dll_windows_x64_d3d11_release.lib"{windows_d3d11_libs} }} }}')
+ l( ' }')
l( ' } else {')
- l(f' when ODIN_DEBUG == true {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_d3d11_debug.lib"{windows_d3d11_libs} }} }}')
- l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_d3d11_release.lib"{windows_d3d11_libs} }} }}')
+ l( ' when USE_GL {')
+ l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_gl_debug.lib"{windows_gl_libs} }} }}')
+ l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_gl_release.lib"{windows_gl_libs} }} }}')
+ l( ' } else {')
+ l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_d3d11_debug.lib"{windows_d3d11_libs} }} }}')
+ l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_d3d11_release.lib"{windows_d3d11_libs} }} }}')
+ l( ' }')
l( ' }')
l( '} else when ODIN_OS == .Darwin {')
- l( ' when #config(SOKOL_USE_GL,false) {')
+ l( ' when USE_GL {')
l( ' when ODIN_ARCH == .arm64 {')
- l(f' when ODIN_DEBUG == true {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_gl_debug.a"{macos_gl_libs} }} }}')
- l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_gl_release.a"{macos_gl_libs} }} }}')
+ l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_gl_debug.a"{macos_gl_libs} }} }}')
+ l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_gl_release.a"{macos_gl_libs} }} }}')
l( ' } else {')
- l(f' when ODIN_DEBUG == true {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_gl_debug.a"{macos_gl_libs} }} }}')
- l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_gl_release.a"{macos_gl_libs} }} }}')
+ l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_gl_debug.a"{macos_gl_libs} }} }}')
+ l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_gl_release.a"{macos_gl_libs} }} }}')
l( ' }')
l( ' } else {')
l( ' when ODIN_ARCH == .arm64 {')
- l(f' when ODIN_DEBUG == true {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_metal_debug.a"{macos_metal_libs} }} }}')
- l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_metal_release.a"{macos_metal_libs} }} }}')
+ l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_metal_debug.a"{macos_metal_libs} }} }}')
+ l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_metal_release.a"{macos_metal_libs} }} }}')
l( ' } else {')
- l(f' when ODIN_DEBUG == true {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_metal_debug.a"{macos_metal_libs} }} }}')
- l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_metal_release.a"{macos_metal_libs} }} }}')
+ l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_metal_debug.a"{macos_metal_libs} }} }}')
+ l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_metal_release.a"{macos_metal_libs} }} }}')
l( ' }')
l( ' }')
+ l( '} else when ODIN_OS == .Linux {')
+ l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_linux_x64_gl_debug.a"{linux_gl_libs} }} }}')
+ l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_linux_x64_gl_release.a"{linux_gl_libs} }} }}')
+ l( '} else {')
+ l( ' #panic("This OS is currently not supported")')
l( '}')
- l( 'else {')
- l(f' when ODIN_DEBUG == true {{ foreign import {clib_import} {{ "{clib_prefix}_linux_x64_gl_debug.a"{linux_gl_libs} }} }}')
- l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_linux_x64_gl_release.a"{linux_gl_libs} }} }}')
- l( '}')
+ l( '')
# Need to special case sapp_sg to avoid Odin's context keyword
if c_prefix == "sapp_sg":
@@ -396,11 +416,13 @@ def gen_c_imports(inp, c_prefix, prefix):
else:
l(f" {as_snake_case(decl['name'], c_prefix)} :: proc({args}) {res_str} ---")
l('}')
+ l('')
def gen_consts(decl, prefix):
for item in decl['items']:
item_name = check_override(item['name'])
l(f"{as_snake_case(item_name, prefix)} :: {item['value']}")
+ l('')
def gen_struct(decl, prefix):
c_struct_name = check_override(decl['name'])
@@ -415,6 +437,7 @@ def gen_struct(decl, prefix):
else:
l(f' {field_name} : {field_type},')
l('}')
+ l('')
def gen_enum(decl, prefix):
enum_name = check_override(decl['name'])
@@ -427,6 +450,7 @@ def gen_enum(decl, prefix):
else:
l(f" {item_name},")
l('}')
+ l('')
def gen_imports(dep_prefixes):
for dep_prefix in dep_prefixes:
@@ -479,10 +503,10 @@ def pre_parse(inp):
def prepare():
print('=== Generating Odin bindings:')
- if not os.path.isdir(c_root):
- os.makedirs(c_root)
if not os.path.isdir(module_root):
os.makedirs(module_root)
+ if not os.path.isdir(c_root):
+ os.makedirs(c_root)
def gen(c_header_path, c_prefix, dep_c_prefixes):
if not c_prefix in module_names: