defun-games / claylib

A Common Lisp 2D/3D game toolkit built on top of Raylib 4.5.
zlib License
69 stars 4 forks source link

Building raylib and raygui with these patches #60

Closed simendsjo closed 1 year ago

simendsjo commented 1 year ago

I don't understand what the patches are, and I'm failing to build raylib with them. You don't have an automated build for these or instructions on how to build them? I want to build from scratch as I'm hacking the libraries to work otherwise (running Guix System). I checked out the 4.2.0 tag, copied over raylib.h and raymath.h, and tried building, but I then get errors during build. Building without these patches works, but I guess they're there for a reason.

I get lot's of these errors with the raymath changes

[  6%] Linking C shared library libraylib.so
ld: CMakeFiles/raylib.dir/rmodels.c.o: in function `Clamp':
/home/simendsjo/code/raylib/src/raymath.h:171: multiple definition of `Clamp'; CMakeFiles/raylib.dir/rcore.c.o:/home/simendsjo/code/raylib/src/raymath.h:171: first defined here
ld: CMakeFiles/raylib.dir/rmodels.c.o: in function `Lerp':
/home/simendsjo/code/raylib/src/raymath.h:181: multiple definition of `Lerp'; CMakeFiles/raylib.dir/rcore.c.o:/home/simendsjo/code/raylib/src/raymath.h:181: first defined here

The diff for my changes should be the same as in your repo:

diff --git a/src/raylib.h b/src/raylib.h
index 8a5d50c2..bd3446db 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -207,10 +207,10 @@ typedef struct Vector4 {
     float y;                // Vector y component
     float z;                // Vector z component
     float w;                // Vector w component
-} Vector4;
+} Quaternion;

 // Quaternion, 4 components (Vector4 alias)
-typedef Vector4 Quaternion;
+typedef Quaternion Vector4;

 // Matrix, 4x4 components, column major, OpenGL style, right handed
 typedef struct Matrix {
@@ -252,10 +252,10 @@ typedef struct Texture {
     int height;             // Texture base height
     int mipmaps;            // Mipmap levels, 1 by default
     int format;             // Data format (PixelFormat type)
-} Texture;
+} Texture2D;

 // Texture2D, same as Texture
-typedef Texture Texture2D;
+typedef Texture2D Texture;

 // TextureCubemap, same as Texture
 typedef Texture TextureCubemap;
@@ -265,10 +265,10 @@ typedef struct RenderTexture {
     unsigned int id;        // OpenGL framebuffer object id
     Texture texture;        // Color buffer attachment texture
     Texture depth;          // Depth buffer attachment texture
-} RenderTexture;
+} RenderTexture2D;

 // RenderTexture2D, same as RenderTexture
-typedef RenderTexture RenderTexture2D;
+typedef RenderTexture2D RenderTexture;

 // NPatchInfo, n-patch layout info
 typedef struct NPatchInfo {
@@ -400,6 +400,8 @@ typedef struct ModelAnimation {
     Transform **framePoses; // Poses array by frame
 } ModelAnimation;

+typedef Transform* TransformPtr;
+
 // Ray, ray for raycasting
 typedef struct Ray {
     Vector3 position;       // Ray position (origin)
diff --git a/src/raymath.h b/src/raymath.h
index fbe4cead..8e1012fd 100644
--- a/src/raymath.h
+++ b/src/raymath.h
@@ -47,6 +47,8 @@
 #ifndef RAYMATH_H
 #define RAYMATH_H

+#define RAYMATH_IMPLEMENTATION
+
 #if defined(RAYMATH_IMPLEMENTATION) && defined(RAYMATH_STATIC_INLINE)
     #error "Specifying both RAYMATH_IMPLEMENTATION and RAYMATH_STATIC_INLINE is contradictory"
 #endif
@@ -54,11 +56,11 @@
 // Function specifiers definition
 #if defined(RAYMATH_IMPLEMENTATION)
     #if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
-        #define RMAPI __declspec(dllexport) extern inline // We are building raylib as a Win32 shared library (.dll).
+        #define RMAPI __declspec(dllexport) extern // We are building raylib as a Win32 shared library (.dll).
     #elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
         #define RMAPI __declspec(dllimport)         // We are using raylib as a Win32 shared library (.dll)
     #else
-        #define RMAPI extern inline // Provide external definition
+        #define RMAPI extern // Provide external definition
     #endif
 #elif defined(RAYMATH_STATIC_INLINE)
     #define RMAPI static inline // Functions may be inlined, no external out-of-line definition
shelvick commented 1 year ago

Thanks for the report. I see the problem. RAYMATH_IMPLEMENTATION is defined in rcore.c after our definition in raymath.h. Not sure how it was working before; maybe I didn't have that line when I originally built Raylib. In any case, to get it built, you can either remove that line from raymath.h or use #ifndef in rcore.c. Unfortunately Autowrap still needs it to get all of the symbols, so the patch itself is right. We just need better docs on how it should be applied.

FWIW, here's how I configured Raylib on Gentoo:

cmake -DCUSTOMIZE_BUILD=ON -DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_SHARED_LIBS=ON -DUSE_EXTERNAL_GLFW=ON -DUSE_WAYLAND=ON -DWITH_PIC=ON -DOpenGL_GL_PREFERENCE=GLVND

And for Raygui, make an include dir and copy the raylib.h into it, then:

gcc -o libraygui.so src/raygui.c -shared -fpic -DRAYGUI_IMPLEMENTATION -lGL -lm -lpthread -ldl -lrt -I./include

If you do use EXTERNAL_GLFW and your GLFW is the latest stable (not dev), you'll run into an issue of Raylib expecting a bleeding-edge symbol that your GLFW doesn't have. The fix is to add this into rcore.c:

#if !defined(GLFW_MOUSE_PASSTHROUGH)
    #define GLFW_MOUSE_PASSTHROUGH      0x0002000D
#endif

We don't have reproducible build docs yet because this stuff has been tested by maybe two people. Let me know if you get anywhere with that though, would love to put some up.

@mjkalyan: You have a Guix machine, right?

simendsjo commented 1 year ago

Thanks, worked great! Would be great to support raylib without custom patches, but I guess that's not possible?

shelvick commented 1 year ago

The patches are minimal enough that I could see us getting to a point where they aren't needed. e.g. have a "wrapper" header for Raygui to #define RAYGUI_IMPLEMENTATION and #include "raygui.h". Lots more to do on build/distribution so this is by no means a permanent state.