Skip to content

Commit

Permalink
Make debug info in ports deterministic. NFC (#23777)
Browse files Browse the repository at this point in the history
See #23741
  • Loading branch information
sbc100 authored Feb 27, 2025
1 parent db261e8 commit 4b76531
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tools/ports/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def build_port(src_dir, output_path, port_name, includes=[], flags=[], cxxflags=
if ext in ('.c', '.cpp') and not any((excluded in f) for excluded in exclude_files):
srcs.append(os.path.join(root, f))

cflags = system_libs.get_base_cflags() + ['-O2', '-I' + src_dir] + flags
cflags = system_libs.get_base_cflags(build_dir) + ['-O2', '-I' + src_dir] + flags
for include in includes:
cflags.append('-I' + include)

Expand Down
22 changes: 11 additions & 11 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

# A (fake) deterministic emscripten path to use in __FILE__ macro and debug info
# to produce reproducible builds across platforms.
DETERMINISITIC_PREFIX = '/emsdk/emscripten'
DETERMINISTIC_PREFIX = '/emsdk/emscripten'


def files_in_path(path, filenames):
Expand All @@ -58,7 +58,7 @@ def glob_in_path(path, glob_pattern, excludes=()):
return sorted(f for f in files if os.path.basename(f) not in excludes)


def get_base_cflags(force_object_files=False, preprocess=True):
def get_base_cflags(build_dir, 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']
Expand All @@ -70,6 +70,12 @@ def get_base_cflags(force_object_files=False, preprocess=True):
flags += ['-DEMSCRIPTEN_DYNAMIC_LINKING']
if settings.MEMORY64:
flags += ['-Wno-experimental', '-sMEMORY64=' + str(settings.MEMORY64)]

source_dir = utils.path_from_root()
relative_source_dir = os.path.relpath(source_dir, build_dir)
flags += [f'-ffile-prefix-map={source_dir}={DETERMINISTIC_PREFIX}',
f'-ffile-prefix-map={relative_source_dir}={DETERMINISTIC_PREFIX}',
f'-fdebug-compilation-dir={DETERMINISTIC_PREFIX}']
return flags


Expand Down Expand Up @@ -462,7 +468,7 @@ def generate_ninja(self, build_dir, libname):
self.build_dir = build_dir

cflags = self.get_cflags()
asflags = get_base_cflags(preprocess=False)
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)
Expand Down Expand Up @@ -491,7 +497,7 @@ def build_objects(self, build_dir):
# .s files are processed directly by the assembler. In this case we can't pass
# pre-processor flags such as `-I` and `-D` but we still want core flags such as
# `-sMEMORY64`.
cmd += get_base_cflags(preprocess=False)
cmd += get_base_cflags(self.build_dir, preprocess=False)
else:
cmd += cflags
cmd = self.customize_build_cmd(cmd, src)
Expand Down Expand Up @@ -581,16 +587,10 @@ def get_cflags(self):
Override and add any flags as needed to handle new variations.
"""
cflags = self._inherit_list('cflags')
cflags += get_base_cflags(force_object_files=self.force_object_files)
cflags += get_base_cflags(self.build_dir, force_object_files=self.force_object_files)

if self.includes:
cflags += ['-I' + utils.path_from_root(i) for i in self._inherit_list('includes')]

source_dir = utils.path_from_root()
relative_source_dir = os.path.relpath(source_dir, self.build_dir)
cflags += [f'-ffile-prefix-map={source_dir}={DETERMINISITIC_PREFIX}',
f'-ffile-prefix-map={relative_source_dir}={DETERMINISITIC_PREFIX}',
f'-fdebug-compilation-dir={DETERMINISITIC_PREFIX}']
return cflags

def get_base_name_prefix(self):
Expand Down

0 comments on commit 4b76531

Please sign in to comment.