Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB] Makefile: building with RAYLIB_LIBTYPE=SHARED silently creates STATIC library #4717

Closed
sleeptightAnsiC opened this issue Jan 21, 2025 · 7 comments · Fixed by #4718
Closed

Comments

@sleeptightAnsiC
Copy link
Contributor

sleeptightAnsiC commented Jan 21, 2025

If you build raylib with src/Makefile, with PLATFORM_WEB and RAYLIB_LIBTYPE=SHARED, it will silently create STATIC library, instead of creating shared library or throwing an error.

If I understand right, shared libraries are not really a thing with Emscripten (it's just a fake static lib imitating .so for portability reasons): https://emscripten.org/docs/compiling/Building-Projects.html#faux-dynamic-linking
However, Makefile should not silently create STATIC lib when explicitly asked for SHARED.
It should EITHER: throw an error and exit OR create fake .so as asked.

I can easily patch it and propose PR, just tell me which behavior do you want (probably error would be better).

The code that dictates current behavior is here (it ignores $(RAYLIB_LIBTYPE) entirely):

raylib/src/Makefile

Lines 664 to 670 in d48b8af

raylib: $(OBJS)
ifeq ($(TARGET_PLATFORM),$(filter $(TARGET_PLATFORM),PLATFORM_WEB PLATFORM_WEB_RGFW))
# Compile raylib libray for web
#$(CC) $(OBJS) -r -o $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).bc
$(AR) rcs $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).web.a $(OBJS)
@echo "raylib library generated (lib$(RAYLIB_LIB_NAME).web.a)!"
else

Environment

~ $ uname -a
Linux MAL200424 6.12.9-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 10 Jan 2025 00:39:41 +0000 x86_64 GNU/Linux
~ $ emcc --version
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.72-git (437140d149d9c977ffc8b09dbaf9b0f5a02db190)

Code Example

~ $ git clone https://github.com/raysan5/raylib
~ $ cd raylib/src
~/raylib/src $ make TARGET_PLATFORM=PLATFORM_WEB RAYLIB_LIBTYPE=SHARED
[...]
emar rcs ../src/libraylib.web.a rcore.o rshapes.o rtextures.o rtext.o utils.o  rmodels.o raudio.o
raylib library generated (libraylib.web.a)!
@Peter0x44
Copy link
Contributor

Emscripten does not really support shared libs anyway.

https://emscripten.org/docs/compiling/Building-Projects.html

See "Faux shared libraries" on this page.

I'm wondering, what exactly is your use case?

@sleeptightAnsiC
Copy link
Contributor Author

Din't you read the whole issue @Peter0x44 ?

I linked to the same page as you did, and mentioned the same information:

shared libraries are not really a thing with Emscripten (it's just a fake static lib imitating .so for portability reasons): https://emscripten.org/docs/compiling/Building-Projects.html#faux-dynamic-linking

I explained why current behavior is not right:

Makefile should not silently create STATIC lib when explicitly asked for SHARED.
It should EITHER: throw an error and exit OR create fake .so as asked.

Analogy: If you ask a waitress for a specific dish in a restaurant and the restaurant does not serve it at the moment, shouldn't waitress tell you about it instead of silently bringing you an entirely different dish?

I'm wondering, what exactly is your use case?

I have my own Makefile building the project. It queries raylib's Makefile in order to build raylib. I tested multiple raylib's configuration and noticed that this one does not work as expected.

This is not a severe issue though.

@Peter0x44
Copy link
Contributor

My bad, I missed that, not sure how.

I am of the opinion "don't do this" as anyone relying on this probably has some fundamental misunderstanding of linking, but on the other hand I don't think an error is necessary either.
I will check what CMake does for this case.

@sleeptightAnsiC
Copy link
Contributor Author

anyone relying on this probably has some fundamental misunderstanding of linking

That's why I want to have an error in said case.
Currently it just silently gives wrong library format and people may struggle with figuring what's going on.
And in the other hand, emcc can create .so files, they just aren't true shared libraries.

@Peter0x44
Copy link
Contributor

CMake Warning (dev) at src/CMakeLists.txt:58 (add_library):
  ADD_LIBRARY called with SHARED option but the target platform does not
  support dynamic linking.  Building a STATIC library instead.  This may lead
  to problems.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake emits this warning, and then proceeds to create a static library. So I think for the best consistency, the makefile should do the same, that is emit a warning and proceed to create a static library anyway.

@sleeptightAnsiC
Copy link
Contributor Author

sleeptightAnsiC commented Jan 21, 2025

To be fair I would also patch it in Cmake since this is not exactly what you want either and This may lead to problems BUT I do understand the problem of supporting multiple build systems and that it may not be suitable (e.g. some old Cmake recipes could break).

sleeptightAnsiC added a commit to sleeptightAnsiC/raylib that referenced this issue Jan 21, 2025
When asking Makefile to create SHARED library for WEB
	$ make TARGET_PLATFORM=PLATFORM_WEB RAYLIB_LIBTYPE=SHARED
it would instead silently create STATIC library
thus not fulfilling the request as expected

This commit adds an error in this case and stops further execution.

This is not consistent with Cmake, because Cmake throws the warning and
does not stop, but Cmake can easily recover from this case and people
probably does not even notice it. However, Makefile is something that
you have to handle yourself and you have to recover from any issues so
having an error and aborting with exit code 1 is more expected.
Otherwise people may spend a lot of time debugging Makefile in order to
understand what's even going on.

Fixes: raysan5#4717
sleeptightAnsiC added a commit to sleeptightAnsiC/raylib that referenced this issue Jan 21, 2025
When asking Makefile to create SHARED library for WEB
	$ make TARGET_PLATFORM=PLATFORM_WEB RAYLIB_LIBTYPE=SHARED
it would instead silently create STATIC library
thus not fulfilling the request as expected

This commit adds an error in this case and stops further execution.

This is not consistent with Cmake, because Cmake throws the warning and
does not stop, but Cmake can easily recover from this case and people
probably does not even notice it. However, Makefile is something that
you have to handle yourself and you have to recover from any issues so
having an error and aborting with exit code 1 is more expected.
Otherwise people may spend a lot of time debugging Makefile in order to
understand what's even going on.

Fixes: raysan5#4717
@sleeptightAnsiC
Copy link
Contributor Author

I proposed PR and went with the error: #4718 (this is only touching Makefile, not Cmake)

I think it is fine for Cmake to report warning and keep execution because Cmake can recover from this. However, with Makefile you have to recover yourself so error and exit code 1 is more expected. Otherwise people may spend time debuging Makefile. With Cmake they may not even notice any problem.

raysan5 pushed a commit that referenced this issue Jan 21, 2025
#4718)

When asking Makefile to create SHARED library for WEB
	$ make TARGET_PLATFORM=PLATFORM_WEB RAYLIB_LIBTYPE=SHARED
it would instead silently create STATIC library
thus not fulfilling the request as expected

This commit adds an error in this case and stops further execution.

This is not consistent with Cmake, because Cmake throws the warning and
does not stop, but Cmake can easily recover from this case and people
probably does not even notice it. However, Makefile is something that
you have to handle yourself and you have to recover from any issues so
having an error and aborting with exit code 1 is more expected.
Otherwise people may spend a lot of time debugging Makefile in order to
understand what's even going on.

Fixes: #4717
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants