separate static and dynamic libraries completely

This commit is contained in:
electronstudio 2021-10-03 21:21:59 +01:00
parent d9ae6515a5
commit 81819a133a
39 changed files with 1601 additions and 86 deletions

13
dynamic/MANIFEST.in Normal file
View file

@ -0,0 +1,13 @@
include raylib/*.pyi
include raylib/*.pyd
exclude raylib/*.a
include raylib/*.h
include raylib/*.pyi
exclude raylib/*.c
exclude raylib/*.o
include raylib/*.dylib
include raylib/*.dll
include raylib/*.so
include raylib/32bit/*.dylib
include raylib/32bit/*.dll
include raylib/32bit/*.so

1
dynamic/README.md Normal file
View file

@ -0,0 +1 @@
Dynamically linked version of Raylib Python CFFI

Binary file not shown.

View file

@ -0,0 +1,57 @@
"""
This is an attempt at a CFFI dynamic (ABI) binding. It was failing in the exactly same place the ctypes binding fails, accessing
materials of a model. But now it __seems__ to work
"""
# Copyright (c) 2021 Richard Smith and others
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# This Source Code may also be made available under the following Secondary
# licenses when the conditions for such availability set forth in the Eclipse
# Public License, v. 2.0 are satisfied: GNU General Public License, version 2
# with the GNU Classpath Exception which is
# available at https://www.gnu.org/software/classpath/license.html.
#
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
from cffi import FFI
import itertools
import os
import pathlib
import platform
MODULE = pathlib.Path(__file__).parent
def raylib_library_path():
'''Return the full path of the raylib shared library
If the environment variable "USE_EXTERNAL_RAYLIB" is set (no value required)
then the library will be loaded from the system library paths.
'''
def so_path():
return str(MODULE) if not 'USE_EXTERNAL_RAYLIB' in os.environ else ''
def so_name():
'''Returns the appropriate for the library on the current platform.'''
lib_filenames = {
'Windows': 'libraylib.dll',
'Linux': 'libraylib.so',
'Darwin': 'libraylib.dylib',
}
if platform.system() not in lib_filenames:
raise ValueError('Unrecognised system "{}"'.format(platform.system()))
return lib_filenames.get(platform.system())
return os.path.join(so_path(), so_name())
ffi = FFI()
ffi.cdef(open(MODULE / "raylib_modified.h").read().replace('RLAPI ', ''))
try:
raylib_fname = raylib_library_path()
raylib = ffi.dlopen(raylib_fname)
print('LOADED DYNAMICALLY SHARED LIB "{}"'.format(raylib_fname))
except Exception as e:
print(e)

40
dynamic/raylib/colors.py Normal file
View file

@ -0,0 +1,40 @@
# Copyright (c) 2021 Richard Smith and others
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# This Source Code may also be made available under the following Secondary
# licenses when the conditions for such availability set forth in the Eclipse
# Public License, v. 2.0 are satisfied: GNU General Public License, version 2
# with the GNU Classpath Exception which is
# available at https://www.gnu.org/software/classpath/license.html.
#
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
LIGHTGRAY =( 200, 200, 200, 255 )
GRAY =( 130, 130, 130, 255 )
DARKGRAY =( 80, 80, 80, 255 )
YELLOW =( 253, 249, 0, 255 )
GOLD =( 255, 203, 0, 255 )
ORANGE =( 255, 161, 0, 255 )
PINK =( 255, 109, 194, 255 )
RED =( 230, 41, 55, 255 )
MAROON =( 190, 33, 55, 255 )
GREEN =( 0, 228, 48, 255 )
LIME =( 0, 158, 47, 255 )
DARKGREEN =( 0, 117, 44, 255 )
SKYBLUE =( 102, 191, 255, 255 )
BLUE =( 0, 121, 241, 255 )
DARKBLUE =( 0, 82, 172, 255 )
PURPLE =( 200, 122, 255, 255 )
VIOLET =( 135, 60, 190, 255 )
DARKPURPLE =( 112, 31, 126, 255 )
BEIGE =( 211, 176, 131, 255 )
BROWN =( 127, 106, 79, 255 )
DARKBROWN =( 76, 63, 47, 255 )
WHITE =( 255, 255, 255, 255 )
BLACK =( 0, 0, 0, 255 )
BLANK =( 0, 0, 0, 0 )
MAGENTA =( 255, 0, 255, 255 )
RAYWHITE =( 245, 245, 245, 255 )

BIN
dynamic/raylib/libraylib.dylib Executable file

Binary file not shown.

BIN
dynamic/raylib/libraylib.so Normal file

Binary file not shown.

BIN
dynamic/raylib/raylib.dll Normal file

Binary file not shown.

File diff suppressed because it is too large Load diff

37
dynamic/setup.py Normal file
View file

@ -0,0 +1,37 @@
import pathlib
from setuptools import setup
from setuptools.dist import Distribution
# The directory containing this file
HERE = pathlib.Path(__file__).parent
# The text of the README file
README = (HERE / "README.md").read_text()
# This call to setup() does all the work
setup(
name="raylib-dynamic",
version="3.7.0.post6",
description="Python CFFI bindings for Raylib DLL version",
long_description=README,
long_description_content_type="text/markdown",
url="https://github.com/electronstudio/raylib-python-cffi",
author="Electron Studio",
author_email="github@electronstudio.co.uk",
license="EPL-2.0",
classifiers=[
"License :: OSI Approved :: Eclipse Public License 2.0 (EPL-2.0)",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
packages=["raylib"],
include_package_data=True,
install_requires=["cffi>=1.14.5","inflection"],
)

37
dynamic/test_dynamic.py Normal file
View file

@ -0,0 +1,37 @@
"""
This shows how to use the CFFI dynamic (ABI) binding. Note that is slower and more likely to run into silent errors and segfaults.
But it doesnt require any C compiler to build.
"""
from raylib import ffi, raylib as rl
from raylib.colors import *
rl.InitWindow(800, 450, b"Raylib dynamic binding test")
rl.SetTargetFPS(60)
camera = ffi.new("struct Camera3D *", [[18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0])
image = rl.LoadImage(b"examples/models/resources/heightmap.png")
texture = rl.LoadTextureFromImage(image)
mesh = rl.GenMeshHeightmap(image, [16, 8, 16])
model = rl.LoadModelFromMesh(mesh)
print(model.materials) # SHOULD BE A pointer to a 'struct Material' but some is NULL pointer to 'Material' ?
model.materials.maps[rl.MATERIAL_MAP_DIFFUSE].texture = texture
rl.UnloadImage(image)
rl.SetCameraMode(camera[0], rl.CAMERA_ORBITAL)
while not rl.WindowShouldClose():
rl.UpdateCamera(camera)
rl.BeginDrawing()
rl.ClearBackground(RAYWHITE)
rl.BeginMode3D(camera[0])
rl.DrawModel(model, (-8.0, 0.0, -8.0), 1.0, RED)
rl.DrawGrid(20, 1.0)
rl.EndMode3D()
rl.DrawText(b"This mesh should be textured", 190, 200, 20, VIOLET)
rl.EndDrawing()
rl.CloseWindow()
"""
Previously this failed to work in the same place the ctypes binding fails, accessing
materials of a model. I though it was because Python can't dynamically tell the difference between a pointer and an array.
"""