Skip to content

Commit

Permalink
Avoid compiling stb_image at link time (emscripten-core#13658)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sbc100 authored Mar 16, 2021
1 parent 0c1b421 commit 5db55ae
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
9 changes: 3 additions & 6 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1524,21 +1524,18 @@ def default_setting(name, new_default):
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

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
Expand Down
9 changes: 9 additions & 0 deletions system/lib/stb_image.c
Original file line number Diff line number Diff line change
@@ -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>
File renamed without changes.
9 changes: 9 additions & 0 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,15 @@ def get_files(self):
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
Expand Down

0 comments on commit 5db55ae

Please sign in to comment.