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

Emscripten wasm side module library #548

Open
wants to merge 1 commit into
base: libpng16
Choose a base branch
from

Conversation

danoli3
Copy link
Contributor

@danoli3 danoli3 commented Feb 19, 2024

As Emscripten libraries require executable code rather than static this fixes issues for WASM using side module.
.wasm extension target

Can be interpreted as .a with this executable byte code

This can be used for patching your own libpng frameworks.
Emscripten comes with a em port however versions are not always up to date with latest changes so this is convenient for cmake / developers / frameworks.

I think also we can assume libpng is being compiled by Emscripten via emmake

Example Cmake commands:

mkdir -p build_$TYPE
	    cd build_$TYPE
	    rm -f CMakeCache.txt *.a *.o *.wasm

	    ZLIB_ROOT="$LIBS_ROOT/zlib/"
	    ZLIB_INCLUDE_DIR="$LIBS_ROOT/zlib/include"
	    ZLIB_LIBRARY="$LIBS_ROOT/zlib/lib/$TYPE/zlib.wasm"

	    $EMSDK/upstream/emscripten/emcmake cmake .. \
	    	${DEFS} \
	    	-DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake \
	    	-DCMAKE_C_STANDARD=17 \
	    	-DEMSCRIPTEN=ON \
			-DCMAKE_CXX_STANDARD=17 \
			-DCMAKE_CXX_STANDARD_REQUIRED=ON \
			-DCMAKE_CXX_FLAGS="-DUSE_PTHREADS=1 -std=c++17 -Wno-implicit-function-declaration -frtti -fPIC ${FLAG_RELEASE}" \
			-DCMAKE_C_FLAGS="-DUSE_PTHREADS=1 -std=c17 -Wno-implicit-function-declaration -frtti -fPIC ${FLAG_RELEASE}" \
			-DCMAKE_CXX_EXTENSIONS=OFF \
			-DCMAKE_INSTALL_PREFIX=Release \
			-DZLIB_ROOT=${ZLIB_ROOT} \
			-DZLIB_LIBRARY=${ZLIB_LIBRARY} \
			-DZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIR} \
			-DZLIB_INCLUDE_DIRS=${ZLIB_INCLUDE_DIR} \
			-DCMAKE_BUILD_TYPE=Release \
			-DBUILD_SHARED_LIBS=ON \
			-DPNG_EXECUTABLES=OFF \
			-DPNG_BUILD_ZLIB=OFF
	    cmake --build . --target install --config Release
	    cd ..

@@ -949,6 +949,24 @@ if(PNG_SHARED AND PNG_TOOLS)
list(APPEND PNG_BIN_TARGETS png-fix-itxt)
endif()

if(EMSCRIPTEN)
set(LIBPNG_WASM_SOURCES
${pngfix_sources}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an actual review comment, but rather, a question:

Is pngfix needed for the Emscripten build?

I just pushed a new commit, see aa95dee. I'm still building the third-party contributed tools for now, if only not to break the downstream package maintainers' workflows. However, I want to decouple those tools from the main library build, including pngfix, eventually. They should be built independently from libpng, in a manner that allows us to verify the correctness of a libpng installation.

One thing that you may or may not want to consider is adding EMSCRIPTEN besides ANDROID and IOS at line 72:

if (ANDROID OR IOS)

@jbowler
Copy link
Contributor

jbowler commented Oct 4, 2024

@ctruta: won't fix. No reply from OP

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 this pull request may close these issues.

3 participants