diff --git a/Minecraft.Client/Platform/Emscripten/gl4es/libGL4ES.a b/Minecraft.Client/Platform/Emscripten/gl4es/libGL4ES.a new file mode 100644 index 000000000..c11b27989 Binary files /dev/null and b/Minecraft.Client/Platform/Emscripten/gl4es/libGL4ES.a differ diff --git a/Minecraft.Client/meson.build b/Minecraft.Client/meson.build index f81dddddd..fe9945e4a 100644 --- a/Minecraft.Client/meson.build +++ b/Minecraft.Client/meson.build @@ -46,7 +46,7 @@ platform_sources += run_command( ).stdout().strip().split('\n') # linux-specific files (everything in Platform/Linux) -if host_machine.system() == 'linux' +if host_machine.system() == 'linux' or host_machine.system() == 'emscripten' platform_sources += run_command( 'sh', '-c', 'find "' @@ -56,6 +56,13 @@ if host_machine.system() == 'linux' ).stdout().strip().split('\n') endif +is_emscripten = host_machine.system() == 'emscripten' +emcc_link_args = [] + +if is_emscripten + emcc_link_args += ['--preload-file', meson.global_source_root() + '/build/Minecraft.Client/Common@Common'] +endif + client_dependencies = [ render_dep, input_dep, @@ -67,7 +74,7 @@ client_dependencies = [ glu_dep, thread_dep, thread_dep, - dependency('zlib'), + zlib_dep, miniaudio_dep ] @@ -101,6 +108,7 @@ client = executable('Minecraft.Client', '-DUNICODE', '-D_UNICODE', '-include', meson.current_source_dir() / 'Platform/stdafx.h', ], + link_args: emcc_link_args, c_args : global_cpp_defs + ['-DUNICODE', '-D_UNICODE'], install : true, install_dir : '' diff --git a/Minecraft.World/Emscripten/md5 b/Minecraft.World/Emscripten/md5 new file mode 160000 index 000000000..d8e299482 --- /dev/null +++ b/Minecraft.World/Emscripten/md5 @@ -0,0 +1 @@ +Subproject commit d8e299482a9f7f08151c893a25274c7beb1735aa diff --git a/Minecraft.World/meson.build b/Minecraft.World/meson.build index d1aabfb9a..ffa83115c 100644 --- a/Minecraft.World/meson.build +++ b/Minecraft.World/meson.build @@ -46,8 +46,12 @@ lib_world = static_library('Minecraft.World', ], ) -zlib_dep = dependency('zlib') -crypto_dep = dependency('libcrypto') # for MD5 in Hasher.cpp on Linux +is_emscripten = host_machine.system() == 'emscripten' +if is_emscripten + crypto_dep = declare_dependency() +else + crypto_dep = dependency('libcrypto') # for MD5 in Hasher.cpp on Linux +endif world_dep = declare_dependency( link_with : lib_world, diff --git a/meson.build b/meson.build index cd2b7daa8..d5ed0d66c 100644 --- a/meson.build +++ b/meson.build @@ -17,13 +17,26 @@ python = pymod.find_installation('python3', required: true) cc = meson.get_compiler('cpp') # system deps -gl_dep = dependency('gl') -glu_dep = dependency('glu') -sdl2_dep = dependency('sdl2') # Yes.. i know sdl3 is out, but there's not point upgrading right now except when +if host_machine.system() == 'emscripten' + # These are handled in Emscripten via -sUSE_ + gl_dep = declare_dependency() + glu_dep = declare_dependency() + sdl2_dep = declare_dependency() + thread_dep = declare_dependency() + zlib_dep = declare_dependency() + miniaudio_dep = declare_dependency() +else + gl_dep = dependency('gl') + glu_dep = dependency('glu') + sdl2_dep = dependency('sdl2') # Yes.. i know sdl3 is out, but there's not point upgrading right now except when # someone is gonna ask me "Hey juicey can you make it SDL3?" and i'd be like fuck you and still do it. -thread_dep = dependency('threads') -miniaudio_dep = dependency('miniaudio') + thread_dep = dependency('threads') + zlib_dep = dependency('zlib') + miniaudio_dep = dependency('miniaudio') +endif + stb = subproject('stb').get_variable('stb_inc') + # compile flags (chagne ts juicey) global_cpp_args = [ '-fpermissive', @@ -31,6 +44,25 @@ global_cpp_args = [ '-pipe', # use pipes instead of temp files between compiler stages ] +if host_machine.system() == 'emscripten' + add_project_arguments( + '-pthread', + language: 'cpp' + ) + + add_project_link_arguments( + '-sUSE_WEBGL2=1', + '-sLEGACY_GL_EMULATION=1', + '-sALLOW_MEMORY_GROWTH=1', + '-sPTHREAD_POOL_SIZE=4', + '-sERROR_ON_UNDEFINED_SYMBOLS=0', + '-sASSERTIONS=0', + '--use-port=zlib', + '--use-port=sdl2', + language: 'cpp' + ) +endif + # global ccp defs type shi global_cpp_defs = [ '-DSPLIT_SAVES', @@ -41,7 +73,8 @@ global_cpp_defs = [ '-DDEBUG', ] -if host_machine.system() == 'linux' +# DecalOverdose: yes i know it's bad to do this but I don't know a better way to do this. +if host_machine.system() == 'linux' or host_machine.system() == 'emscripten' global_cpp_defs += [ '-Dlinux', '-D__linux', diff --git a/scripts/emscripten_native.txt b/scripts/emscripten_native.txt new file mode 100644 index 000000000..5b62c62c6 --- /dev/null +++ b/scripts/emscripten_native.txt @@ -0,0 +1,15 @@ +[binaries] +c = 'emcc' +cpp = 'em++' +ar = 'emar' +strip = 'emstrip' + +[built-in options] +c_args = [] +c_link_args = [] + +[host_machine] +system = 'emscripten' +cpu_family = 'wasm32' +cpu = 'wasm32' +endian = 'little'