Avoid compiling stb_image at link time (#13658)

Instead make it into a system library like libfetch or libembind.
This was the final example of a place where emcc was inject extra
source files into the build at link time.
This commit is contained in:
Sam Clegg 2021-03-15 17:34:36 -07:00 коммит произвёл GitHub
Родитель 0c1b42130d
Коммит 5db55ae5ad
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 21 добавлений и 6 удалений

Просмотреть файл

@ -1524,12 +1524,11 @@ There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR P
shared.Settings.WORKAROUND_IOS_9_RIGHT_SHIFT_BUG = 0
shared.Settings.WORKAROUND_OLD_WEBGL_UNIFORM_UPLOAD_IGNORED_OFFSET_BUG = 0
forced_stdlibs = []
if shared.Settings.STB_IMAGE and final_suffix in EXECUTABLE_ENDINGS:
input_files.append((len(newargs), shared.path_from_root('third_party', 'stb_image.c')))
forced_stdlibs.append('libstb_image')
shared.Settings.EXPORTED_FUNCTIONS += ['_stbi_load', '_stbi_load_from_memory', '_stbi_image_free']
# stb_image 2.x need to have STB_IMAGE_IMPLEMENTATION defined to include the implementation
# when compiling
newargs.append('-DSTB_IMAGE_IMPLEMENTATION')
if shared.Settings.USE_WEBGL2:
shared.Settings.MAX_WEBGL_VERSION = 2
@ -1537,8 +1536,6 @@ There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR P
if not shared.Settings.GL_SUPPORT_SIMPLE_ENABLE_EXTENSIONS and shared.Settings.GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS:
exit_with_error('-s GL_SUPPORT_SIMPLE_ENABLE_EXTENSIONS=0 only makes sense with -s GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS=0!')
forced_stdlibs = []
if shared.Settings.ASMFS and final_suffix in EXECUTABLE_ENDINGS:
forced_stdlibs.append('libasmfs')
shared.Settings.FILESYSTEM = 0

9
system/lib/stb_image.c Normal file
Просмотреть файл

@ -0,0 +1,9 @@
// Copyright 2021 The Emscripten Authors. All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.
// stb_image 2.x need to have STB_IMAGE_IMPLEMENTATION defined to include
// the implementation when compiling
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>

Просмотреть файл

Просмотреть файл

@ -1159,6 +1159,15 @@ class libfetch(MTLibrary):
return [shared.path_from_root('system', 'lib', 'fetch', 'emscripten_fetch.cpp')]
class libstb_image(Library):
name = 'libstb_image'
never_force = True
includes = [['third_party']]
def get_files(self):
return [shared.path_from_root('system', 'lib', 'stb_image.c')]
class libasmfs(MTLibrary):
name = 'libasmfs'
never_force = True