File emscripten-cflags.patch of Package nodejs-vscode-tree-sitter-wasm
--- emscripten-3.1.64/tools/system_libs.py.orig 2024-07-18 18:08:07.000000000 +0200
+++ emscripten-3.1.64/tools/system_libs.py 2025-03-08 11:11:46.697728664 +0100
@@ -56,7 +56,7 @@ def glob_in_path(path, glob_pattern, exc
def get_base_cflags(force_object_files=False, preprocess=True):
# Always build system libraries with debug information. Non-debug builds
# will ignore this at link time because we link with `-strip-debug`.
- flags = ['-g', '-sSTRICT', '-Werror']
+ flags = ['-sSTRICT']
if settings.LTO and not force_object_files:
flags += ['-flto=' + settings.LTO]
if settings.RELOCATABLE:
@@ -65,7 +65,7 @@ def get_base_cflags(force_object_files=F
flags += ['-DEMSCRIPTEN_DYNAMIC_LINKING']
if settings.MEMORY64:
flags += ['-Wno-experimental', '-sMEMORY64=' + str(settings.MEMORY64)]
- return flags
+ return flags + os.environ['CFLAGS'].split()
def clean_env():
@@ -74,7 +74,7 @@ def clean_env():
# At least one port also uses autoconf (harfbuzz) so we also need to clear
# CFLAGS/LDFLAGS which we don't want to effect the inner call to configure.
safe_env = os.environ.copy()
- for opt in ['CFLAGS', 'CXXFLAGS', 'LDFLAGS',
+ for opt in [
'EMCC_CFLAGS',
'EMCC_AUTODEBUG',
'EMCC_FORCE_STDLIBS',
@@ -354,7 +354,7 @@ class Library:
# extra code size. The -fno-unroll-loops flags was added here when loop
# unrolling landed upstream in LLVM to avoid changing behavior but was not
# specifically evaluated.
- cflags = ['-O2', '-Wall', '-fno-unroll-loops']
+ cflags = os.environ['CFLAGS'].split()
# A list of directories to put in the include path when building.
# This is a list of tuples of path components.
@@ -984,7 +984,7 @@ class libc(MuslInternalLibrary,
# We use -fno-inline-functions because it can produce slightly smaller
# (and slower) code in some cases. TODO(sbc): remove this and let llvm weight
# the cost/benefit of inlining.
- cflags = ['-Os', '-fno-inline-functions', '-fno-builtin']
+ cflags = ['-fno-builtin']
# Disable certain warnings for code patterns that are contained in upstream musl
cflags += ['-Wno-ignored-attributes',
@@ -1319,16 +1319,15 @@ class libc(MuslInternalLibrary,
return libc_files
def customize_build_cmd(self, cmd, filename):
- if filename in self.non_lto_files:
+ if filename.endswith('/sqrtl.c'):
# These files act more like the part of compiler-rt in that
# references to them can be generated at compile time.
# Treat them like compiler-rt in as much as never compile
# them as LTO and build them with -O2 rather then -Os (which
# use used for the rest of libc) because this set of files
# also contains performance sensitive math functions.
- cmd = [a for a in cmd if not a.startswith('-flto')]
- cmd = [a for a in cmd if not a.startswith('-O')]
- cmd += ['-O2']
+ # this file crashes the compiler otherwise
+ cmd = [a for a in cmd if not a.startswith('-fstack-protector')]
return cmd
@@ -1338,7 +1337,7 @@ class libc(MuslInternalLibrary,
class libc_optz(libc):
name = 'libc_optz'
- cflags = ['-Os', '-fno-inline-functions', '-fno-builtin', '-DEMSCRIPTEN_OPTIMIZE_FOR_OZ']
+ cflags = ['-fno-builtin', '-DEMSCRIPTEN_OPTIMIZE_FOR_OZ']
def __init__(self, **kwargs):
super().__init__(**kwargs)
@@ -1371,11 +1370,9 @@ class libc_optz(libc):
return libcall_files + mem_files
def customize_build_cmd(self, cmd, filename):
- if filename in self.non_lto_files:
+ if filename.endswith('/sqrtl.c'):
# see comments in libc.customize_build_cmd
- cmd = [a for a in cmd if not a.startswith('-flto')]
- cmd = [a for a in cmd if not a.startswith('-O')]
- cmd += ['-O2']
+ cmd = [a for a in cmd if not a.startswith('-fstack-protector')]
return cmd
def can_use(self):
@@ -1432,7 +1429,7 @@ class libwasm_workers(MTLibrary):
# https://github.com/emscripten-core/emscripten/issues/19331
cflags += ['-O0']
else:
- cflags += ['-DNDEBUG', '-Oz']
+ cflags += ['-DNDEBUG']
if settings.MAIN_MODULE:
cflags += ['-fPIC']
return cflags
@@ -1467,7 +1464,7 @@ class libwasm_workers(MTLibrary):
class libsockets(MuslInternalLibrary, MTLibrary):
name = 'libsockets'
- cflags = ['-Os', '-fno-inline-functions', '-fno-builtin', '-Wno-shift-op-parentheses']
+ cflags = ['-fno-builtin', '-Wno-shift-op-parentheses']
def get_files(self):
return files_in_path(
@@ -1481,7 +1478,7 @@ class libsockets(MuslInternalLibrary, MT
class libsockets_proxy(MTLibrary):
name = 'libsockets_proxy'
- cflags = ['-Os', '-fno-inline-functions']
+ cflags = []
def get_files(self):
return [utils.path_from_root('system/lib/websocket/websocket_to_posix_socket.c')]
@@ -1550,8 +1547,6 @@ class crtbegin(MuslInternalLibrary):
class libcxxabi(NoExceptLibrary, MTLibrary, DebugLibrary):
name = 'libc++abi'
cflags = [
- '-Oz',
- '-fno-inline-functions',
'-D_LIBCPP_BUILDING_LIBRARY',
'-D_LIBCXXABI_BUILDING_LIBRARY',
'-DLIBCXXABI_NON_DEMANGLING_TERMINATE',
@@ -1623,8 +1618,6 @@ class libcxx(NoExceptLibrary, MTLibrary)
name = 'libc++'
cflags = [
- '-Oz',
- '-fno-inline-functions',
'-DLIBCXX_BUILDING_LIBCXXABI=1',
'-D_LIBCPP_BUILDING_LIBRARY',
'-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS',
@@ -1668,7 +1661,7 @@ class libunwind(NoExceptLibrary, MTLibra
# See https://bugs.llvm.org/show_bug.cgi?id=44353
force_object_files = True
- cflags = ['-Oz', '-fno-inline-functions', '-D_LIBUNWIND_HIDE_SYMBOLS']
+ cflags = ['-D_LIBUNWIND_HIDE_SYMBOLS']
src_dir = 'system/lib/libunwind/src'
# Without this we can't build libunwind since it will pickup the unwind.h
# that is part of llvm (which is not compatible for some reason).
@@ -1820,7 +1813,7 @@ class libmimalloc(MTLibrary):
class libal(Library):
name = 'libal'
- cflags = ['-Os', '-fno-inline-functions']
+ cflags = []
src_dir = 'system/lib'
src_files = ['al.c']
@@ -1831,7 +1824,7 @@ class libGL(MTLibrary):
src_dir = 'system/lib/gl'
src_files = ['gl.c', 'webgl1.c', 'libprocaddr.c', 'webgl2.c']
- cflags = ['-Oz', '-fno-inline-functions']
+ cflags = []
def __init__(self, **kwargs):
self.is_legacy = kwargs.pop('is_legacy')
@@ -2040,7 +2033,7 @@ class libhtml5(Library):
name = 'libhtml5'
includes = ['system/lib/libc']
- cflags = ['-Oz', '-fno-inline-functions']
+ cflags = []
src_dir = 'system/lib/html5'
src_glob = '*.c'
@@ -2141,7 +2134,7 @@ class libstandalonewasm(MuslInternalLibr
# LTO defeats the weak linking trick used in __original_main.c
force_object_files = True
- cflags = ['-Os', '-fno-inline-functions', '-fno-builtin']
+ cflags = ['-fno-builtin']
src_dir = 'system/lib'
def __init__(self, **kwargs):
@@ -2218,7 +2211,7 @@ class libstandalonewasm(MuslInternalLibr
class libjsmath(Library):
name = 'libjsmath'
- cflags = ['-Os', '-fno-inline-functions']
+ cflags = []
src_dir = 'system/lib'
src_files = ['jsmath.c']