Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion tools/ports/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def build_port(src_dir, output_path, port_name, includes=[], flags=[], cxxflags=
os.makedirs(build_dir, exist_ok=True)
ninja_file = os.path.join(build_dir, 'build.ninja')
system_libs.ensure_sysroot()
system_libs.create_ninja_file(srcs, ninja_file, output_path, cflags=cflags)
system_libs.create_ninja_file(srcs, ninja_file, output_path, cflags=cflags, cxxflags=cflags + cxxflags)
if not os.getenv('EMBUILDER_PORT_BUILD_DEFERRED'):
system_libs.run_ninja(build_dir)
else:
Expand Down
37 changes: 29 additions & 8 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def escape_ninja_path(path):
return re.sub(r'([ :$])', r'$\1', path)


def create_ninja_file(input_files, filename, libname, cflags, asflags=None, customize_build_flags=None):
def create_ninja_file(input_files, filename, libname, cflags, cxxflags, asflags=None, customize_build_flags=None):
if asflags is None:
asflags = []

Expand All @@ -193,6 +193,7 @@ def create_ninja_file(input_files, filename, libname, cflags, asflags=None, cust

ASFLAGS = {join_cmd(asflags)}
CFLAGS = {join_cmd(cflags)}
CXXFLAGS = {join_cmd(cxxflags)}
EMCC = {shared.EMCC}
EMXX = {shared.EMXX}
EMAR = {shared.EMAR}
Expand All @@ -204,7 +205,7 @@ def create_ninja_file(input_files, filename, libname, cflags, asflags=None, cust

rule cxx
depfile = $out.d
command = $EMXX -MD -MF $out.d $CFLAGS -c $in -o $out
command = $EMXX -MD -MF $out.d $CXXFLAGS -c $in -o $out
description = CXX $out

rule asm
Expand Down Expand Up @@ -266,12 +267,15 @@ def create_ninja_file(input_files, filename, libname, cflags, asflags=None, cust
flags = cflags
case _:
cmd = 'cxx'
flags = cflags
flags = cxxflags
out += f'build {escape_ninja_path(o)}: {cmd} {escape_ninja_path(src)}\n'
if customize_build_flags:
custom_flags = customize_build_flags(flags, src)
if custom_flags != flags:
out += f' CFLAGS = {join_cmd(custom_flags)}'
if flags == cflags:
out += f' CFLAGS = {join_cmd(custom_flags)}'
else:
out += f' CXXFLAGS = {join_cmd(custom_flags)}'
out += '\n'

objects = sorted(objects, key=objectfile_sort_key)
Expand Down Expand Up @@ -475,10 +479,12 @@ def generate_ninja(self, build_dir, libname):
self.build_dir = build_dir

cflags = self.get_cflags()
cxxflags = self.get_cxxflags()

asflags = get_base_cflags(self.build_dir, preprocess=False)
input_files = self.get_files()
ninja_file = os.path.join(build_dir, 'build.ninja')
create_ninja_file(input_files, ninja_file, libname, cflags, asflags=asflags, customize_build_flags=self.customize_build_cmd)
create_ninja_file(input_files, ninja_file, libname, cflags, cxxflags, asflags=asflags, customize_build_flags=self.customize_build_cmd)

def build_objects(self, build_dir):
"""
Expand All @@ -493,7 +499,6 @@ def build_objects(self, build_dir):
commands = []
objects = set()
objects_lowercase = set()
cflags = self.get_cflags()
for src in self.get_files():
ext = utils.suffix(src)
if ext in {'.s', '.S', '.c'}:
Expand All @@ -506,8 +511,10 @@ def build_objects(self, build_dir):
# pre-processor flags such as `-I` and `-D` but we still want core flags such as
# `-sMEMORY64`.
cmd += get_base_cflags(self.build_dir, preprocess=False)
elif ext in {'.c', '.S'}:
cmd += self.get_cflags()
else:
cmd += cflags
cmd += self.get_cxxflags()
cmd = self.customize_build_cmd(cmd, src)

object_basename = utils.unsuffixed_basename(src)
Expand Down Expand Up @@ -600,6 +607,13 @@ def get_cflags(self):
cflags += ['-I' + utils.path_from_root(i) for i in self._inherit_list('includes')]
return cflags

def get_cxxflags(self):
"""
Returns the list of flags to pass to em++ when building this variation
of the library.
"""
return self.get_cflags()

def get_base_name_prefix(self):
"""
Returns the base name of the library without any suffixes.
Expand Down Expand Up @@ -1744,7 +1758,7 @@ 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):
def _get_common_flags(self):
cflags = super().get_cflags()
cflags.append('-DNDEBUG')
if not self.is_mt and not self.is_ww:
Expand All @@ -1754,8 +1768,15 @@ def get_cflags(self):
cflags.append('-D_LIBUNWIND_HAS_NO_EXCEPTIONS')
case Exceptions.EMSCRIPTEN:
cflags.append('-D__EMSCRIPTEN_EXCEPTIONS__')

return cflags

def get_cflags(self):
return self._get_common_flags() + ['-std=c23']

def get_cxxflags(self):
return self._get_common_flags() + ['-std=c++23']
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was just looking at libunwin upstream and it seems they do not use c23/c++23, but C++17:

https://github.com/llvm/llvm-project/blob/3bf53844cfedf09f22d2786e57ef81d5d41fe249/libunwind/src/CMakeLists.txt#L139-L145

Do I don't think we want to do this maybe? Since we don't want to differ from upstream here.



class libmalloc(MTLibrary):
name = 'libmalloc'
Expand Down