aboutsummaryrefslogtreecommitdiff
path: root/bindgen
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2024-04-21 16:20:42 +0200
committerAndre Weissflog <floooh@gmail.com>2024-04-21 16:20:42 +0200
commit4fac1bb845c011ed91446f511d86c7ce50e15e42 (patch)
tree1d3d6fc599265add468ec3cbf135fef6bff30270 /bindgen
parent7e1035cb0dff181ca5ded241914ae128318e7d46 (diff)
parent4534e02d6c83e23fa212ac29c1fd90d8a22f5419 (diff)
Merge branch 'master' into storage-buffers
Diffstat (limited to 'bindgen')
-rw-r--r--bindgen/gen_odin.py70
-rw-r--r--bindgen/gen_rust.py12
2 files changed, 53 insertions, 29 deletions
diff --git a/bindgen/gen_odin.py b/bindgen/gen_odin.py
index 6ba84f3a..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,18 +437,20 @@ 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'])
l(f'{as_struct_or_enum_type(enum_name, prefix)} :: enum i32 {{')
for item in decl['items']:
item_name = as_enum_item_name(check_override(item['name']))
- if item_name != 'FORCE_U32':
+ if item_name != 'FORCE_U32' and item_name != 'NUM':
if 'value' in item:
l(f" {item_name} = {item['value']},")
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:
diff --git a/bindgen/gen_rust.py b/bindgen/gen_rust.py
index 0984d14a..59a2b672 100644
--- a/bindgen/gen_rust.py
+++ b/bindgen/gen_rust.py
@@ -1,7 +1,7 @@
# -------------------------------------------------------------------------------
-# Generate rust bindings.
+# Generate Rust bindings.
#
-# rust coding style:
+# Rust coding style:
# - types are PascalCase
# - otherwise snake_case
# -------------------------------------------------------------------------------
@@ -50,7 +50,7 @@ ignores = [
range_struct_name = "Range"
-# functions that need to be exposed as 'raw' C callbacks without a rust wrapper function
+# functions that need to be exposed as 'raw' C callbacks without a Rust wrapper function
c_callbacks = ["slog_func"]
# NOTE: syntax for function results: "func_name.RESULT"
@@ -753,7 +753,7 @@ def gen_imports(inp, dep_prefixes):
def gen_helpers(inp):
- l("/// Helper function to convert a C string to a rust string slice")
+ l("/// Helper function to convert a C string to a Rust string slice")
l("#[inline]")
l("fn c_char_ptr_to_rust_str(c_char_ptr: *const core::ffi::c_char) -> &'static str {")
l(" let c_str = unsafe { core::ffi::CStr::from_ptr(c_char_ptr) };")
@@ -762,11 +762,11 @@ def gen_helpers(inp):
l("")
if inp['prefix'] in ['sg_', 'sdtx_', 'sshape_', 'sapp_']:
- l("/// Helper function to cast a rust slice into a sokol Range")
+ l("/// Helper function to cast a Rust slice into a sokol Range")
l(f"pub fn slice_as_range<T>(data: &[T]) -> {range_struct_name} {{")
l(f" {range_struct_name} {{ size: std::mem::size_of_val(data), ptr: data.as_ptr() as *const _ }}")
l("}")
- l("/// Helper function to cast a rust reference into a sokol Range")
+ l("/// Helper function to cast a Rust reference into a sokol Range")
l(f"pub fn value_as_range<T>(value: &T) -> {range_struct_name} {{")
l(f" {range_struct_name} {{ size: std::mem::size_of::<T>(), ptr: value as *const T as *const _ }}")
l("}")