diff --git a/tools/system_libs.py b/tools/system_libs.py index e6bbf1c3435b1..99e226cb9a8fc 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -42,6 +42,10 @@ # link time. USE_NINJA = int(os.environ.get('EMCC_USE_NINJA', '0')) +# A fake emscripten path to use in __FILE__ macro and debug info to produce +# reproducible builds across platforms. +FAKE_EMSCRIPTEN_PATH = '/emsdk/emscripten' + def files_in_path(path, filenames): srcdir = utils.path_from_root(path) @@ -472,9 +476,9 @@ def generate_ninja(self, build_dir, libname): if self.deterministic_paths: source_dir = utils.path_from_root() relative_source_dir = os.path.relpath(source_dir, build_dir) - cflags += [f'-ffile-prefix-map={source_dir}=/emsdk/emscripten', - f'-ffile-prefix-map={relative_source_dir}/=', - '-fdebug-compilation-dir=/emsdk/emscripten'] + cflags += [f'-ffile-prefix-map={source_dir}={FAKE_EMSCRIPTEN_PATH}', + f'-ffile-prefix-map={relative_source_dir}={FAKE_EMSCRIPTEN_PATH}', + '-fdebug-compilation-dir={FAKE_EMSCRIPTEN_PATH}'] asflags = get_base_cflags(preprocess=False) input_files = self.get_files() ninja_file = os.path.join(build_dir, 'build.ninja') @@ -496,9 +500,9 @@ def build_objects(self, build_dir): source_dir = utils.path_from_root() if batch_inputs: relative_source_dir = os.path.relpath(source_dir, build_dir) - cflags += [f'-ffile-prefix-map={relative_source_dir}/='] - cflags += [f'-ffile-prefix-map={source_dir}=/emsdk/emscripten', - '-fdebug-compilation-dir=/emsdk/emscripten'] + cflags += [f'-ffile-prefix-map={relative_source_dir}={FAKE_EMSCRIPTEN_PATH}'] + cflags += [f'-ffile-prefix-map={source_dir}={FAKE_EMSCRIPTEN_PATH}', + '-fdebug-compilation-dir={FAKE_EMSCRIPTEN_PATH}'] case_insensitive = is_case_insensitive(build_dir) for src in self.get_files(): ext = shared.suffix(src)