From 304192c10c43a0fc105085a4b99b8c2dd985b095 Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Tue, 13 Aug 2024 21:25:00 +0800 Subject: [PATCH] fix(bypy/macos/__main__): Use -Os The launchers were getting compiled with no optimization at all. If one runs `objdump --disassemble calibre-launcher.dylib --no-show-raw-insn`, the result is a lot of loads and stores from the stack. Probably not critical at all for performance, but ugly and silly nevertheless. --- bypy/macos/__main__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bypy/macos/__main__.py b/bypy/macos/__main__.py index 99fee29194..7591043158 100644 --- a/bypy/macos/__main__.py +++ b/bypy/macos/__main__.py @@ -59,7 +59,7 @@ def compile_launcher_lib(contents_dir, gcc, base, pyver, inc_dir): dest = join(contents_dir, 'Frameworks', 'calibre-launcher.dylib') src = join(base, 'util.c') - cmd = [gcc] + ARCH_FLAGS + '-Wall -dynamiclib -std=gnu99'.split() + [src] + \ + cmd = [gcc] + ARCH_FLAGS + CFLAGS + '-Wall -dynamiclib -std=gnu99'.split() + [src] + \ ['-I' + base] + '-DPY_VERSION_MAJOR={} -DPY_VERSION_MINOR={}'.format(*pyver.split('.')).split() + \ [f'-I{path_to_freeze_dir()}', f'-I{inc_dir}'] + \ [f'-DENV_VARS={env}', f'-DENV_VAR_VALS={env_vals}'] + \ @@ -82,6 +82,7 @@ def compile_launcher_lib(contents_dir, gcc, base, pyver, inc_dir): gcc = os.environ.get('CC', 'clang') +CFLAGS = os.environ.get('CFLAGS', '-Os') def compile_launchers(contents_dir, inc_dir, xprograms, pyver): @@ -95,7 +96,7 @@ def compile_launchers(contents_dir, inc_dir, xprograms, pyver): out = join(contents_dir, 'MacOS', program) programs.append(out) is_gui = 'true' if ptype == 'gui' else 'false' - cmd = [gcc] + ARCH_FLAGS + [ + cmd = [gcc] + ARCH_FLAGS + CFLAGS + [ '-Wall', f'-DPROGRAM=L"{program}"', f'-DMODULE=L"{module}"', f'-DFUNCTION=L"{func}"', f'-DIS_GUI={is_gui}', '-I' + base, src, lib, '-o', out, '-headerpad_max_install_names', ] @@ -707,7 +708,7 @@ class Freeze: plist['CFBundleExecutable'] = exe + '-placeholder-for-codesigning' nexe = join(exe_dir, plist['CFBundleExecutable']) base = os.path.dirname(abspath(__file__)) - cmd = [gcc] + ARCH_FLAGS + [ + cmd = [gcc] + ARCH_FLAGS + CFLAGS + [ '-Wall', '-Werror', '-DEXE_NAME="%s"' % exe, '-DREL_PATH="%s"' % rel_path, join(base, 'placeholder.c'), '-o', nexe, '-headerpad_max_install_names' ]