Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def generate_ninja(self, build_dir, libname):
utils.safe_ensure_dirs(build_dir)
self.build_dir = build_dir

cflags = self.get_cflags()
cflags = self.get_cflags(None)
asflags = get_base_cflags(self.build_dir, preprocess=False)
input_files = self.get_files()
ninja_file = os.path.join(build_dir, 'build.ninja')
Expand All @@ -492,7 +492,6 @@ def build_objects(self, build_dir):
batches = {}
commands = []
objects = set()
cflags = self.get_cflags()
for src in self.get_files():
ext = utils.suffix(src)
if ext in {'.s', '.S', '.c'}:
Expand All @@ -506,7 +505,7 @@ def build_objects(self, build_dir):
# `-sMEMORY64`.
cmd += get_base_cflags(self.build_dir, preprocess=False)
else:
cmd += cflags
cmd += self.get_cflags(src)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we already have the extension calculated here perhaps we can add self.cxxflags here when we have a cxx extension?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if I understand... We don't have self.cflags either. Do you want to add both? But then why would we have both self.cflags and self.get_cflags() then?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We do have self.cflags and the default self.get_cflags() will read from this field.

The idea is that for simple libraries where the cflags don't vary you can just do cflags = ['x', 'y', 'z'] at the class level.

See libunwind for example.

In this case we could just add support for cxxflags = ['x', 'y', 'z']?

cmd = self.customize_build_cmd(cmd, src)

object_basename = utils.unsuffixed_basename(src).lower()
Expand Down Expand Up @@ -586,7 +585,7 @@ def _inherit_list(cls, attr):
result += item.__dict__.get(attr, [])
return result

def get_cflags(self):
def get_cflags(self, _filename=None):
"""
Returns the list of flags to pass to emcc when building this variation
of the library.
Expand Down Expand Up @@ -710,8 +709,8 @@ def __init__(self, **kwargs):
self.is_ww = kwargs.pop('is_ww') and not self.is_mt
super().__init__(**kwargs)

def get_cflags(self):
cflags = super().get_cflags()
def get_cflags(self, _filename=None):
cflags = super().get_cflags(_filename)
if self.is_mt:
cflags += ['-pthread', '-sWASM_WORKERS']
if self.is_ww:
Expand Down Expand Up @@ -751,8 +750,8 @@ def __init__(self, **kwargs):
self.is_debug = kwargs.pop('is_debug')
super().__init__(**kwargs)

def get_cflags(self):
cflags = super().get_cflags()
def get_cflags(self, _filename=None):
cflags = super().get_cflags(_filename)
if not self.is_debug:
cflags += ['-DNDEBUG']
return cflags
Expand Down Expand Up @@ -795,8 +794,8 @@ def __init__(self, **kwargs):
self.eh_mode = kwargs.pop('eh_mode')
super().__init__(**kwargs)

def get_cflags(self):
cflags = super().get_cflags()
def get_cflags(self, _filename=None):
cflags = super().get_cflags(_filename)
match self.eh_mode:
case Exceptions.NONE:
cflags += ['-fno-exceptions']
Expand Down Expand Up @@ -850,8 +849,8 @@ def __init__(self, **kwargs):
self.eh_mode = kwargs.pop('eh_mode')
super().__init__(**kwargs)

def get_cflags(self):
cflags = super().get_cflags()
def get_cflags(self, _filename=None):
cflags = super().get_cflags(_filename)
match self.eh_mode:
case Exceptions.EMSCRIPTEN:
cflags += ['-sSUPPORT_LONGJMP=emscripten',
Expand Down Expand Up @@ -919,8 +918,8 @@ def __init__(self, **kwargs):
self.is_asan = kwargs.pop('is_asan', False)
super().__init__(**kwargs)

def get_cflags(self):
cflags = super().get_cflags()
def get_cflags(self, _filename=None):
cflags = super().get_cflags(_filename)
if self.is_asan:
cflags += ['-fsanitize=address']
return cflags
Expand Down Expand Up @@ -1478,8 +1477,8 @@ def __init__(self, **kwargs):
self.is_stub = kwargs.pop('stub')
super().__init__(**kwargs)

def get_cflags(self):
cflags = super().get_cflags()
def get_cflags(self, _filename=None):
cflags = super().get_cflags(_filename)
if self.is_debug:
cflags += ['-D_DEBUG']
# library_wasm_worker.c contains an assert that a nonnull parameter
Expand Down Expand Up @@ -1635,8 +1634,8 @@ def __init__(self, **kwargs):
# the non-debug version of libc++abi.
self.is_debug |= settings.EXCEPTION_STACK_TRACES

def get_cflags(self):
cflags = super().get_cflags()
def get_cflags(self, _filename=None):
cflags = super().get_cflags(_filename)
if not self.is_mt and not self.is_ww:
cflags.append('-D_LIBCXXABI_HAS_NO_THREADS')
match self.eh_mode:
Expand Down Expand Up @@ -1747,8 +1746,8 @@ def __init__(self, **kwargs):
def can_use(self):
return super().can_use() and self.eh_mode in (Exceptions.WASM_LEGACY, Exceptions.WASM)

def get_cflags(self):
cflags = super().get_cflags()
def get_cflags(self, _filename=None):
cflags = super().get_cflags(_filename)
cflags.append('-DNDEBUG')
if not self.is_mt and not self.is_ww:
cflags.append('-D_LIBUNWIND_HAS_NO_THREADS')
Expand All @@ -1757,6 +1756,7 @@ def get_cflags(self):
cflags.append('-D_LIBUNWIND_HAS_NO_EXCEPTIONS')
case Exceptions.EMSCRIPTEN:
cflags.append('-D__EMSCRIPTEN_EXCEPTIONS__')

return cflags


Expand Down Expand Up @@ -1789,8 +1789,8 @@ def get_files(self):
sbrk = utils.path_from_root('system/lib/libc/sbrk.c')
return [malloc, sbrk]

def get_cflags(self):
cflags = super().get_cflags()
def get_cflags(self, _filename=None):
cflags = super().get_cflags(_filename)
if self.memvalidate:
cflags += ['-DEMMALLOC_MEMVALIDATE']
if self.verbose:
Expand Down Expand Up @@ -1926,8 +1926,8 @@ def get_base_name(self):
name += '-getprocaddr'
return name

def get_cflags(self):
cflags = super().get_cflags()
def get_cflags(self, _filename=None):
cflags = super().get_cflags(_filename)
if self.is_legacy:
cflags += ['-DLEGACY_GL_EMULATION=1']
cflags += [f'-DMAX_WEBGL_VERSION={2 if self.is_webgl2 else 1}']
Expand Down Expand Up @@ -1963,8 +1963,8 @@ def __init__(self, **kwargs):
self.with_rtti = kwargs.pop('with_rtti', False)
super().__init__(**kwargs)

def get_cflags(self):
cflags = super().get_cflags()
def get_cflags(self, _filename=None):
cflags = super().get_cflags(_filename)
cflags.append('-std=c++20')
if not self.with_rtti:
cflags += ['-fno-rtti', '-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0']
Expand Down Expand Up @@ -2017,8 +2017,8 @@ def __init__(self, **kwargs):
self.ignore_case = kwargs.pop('ignore_case')
super().__init__(**kwargs)

def get_cflags(self):
cflags = super().get_cflags()
def get_cflags(self, _filename=None):
cflags = super().get_cflags(_filename)
if self.ignore_case:
cflags += ['-DWASMFS_CASE_INSENSITIVE']
return cflags
Expand Down Expand Up @@ -2204,8 +2204,8 @@ def get_base_name(self):
name += '-pure'
return name

def get_cflags(self):
cflags = super().get_cflags()
def get_cflags(self, _filename=None):
cflags = super().get_cflags(_filename)
cflags += ['-DNDEBUG', '-DEMSCRIPTEN_STANDALONE_WASM']
if self.is_mem_grow:
cflags += ['-DEMSCRIPTEN_MEMORY_GROWTH']
Expand Down