Skip to content

Commit 304192c

Browse files
authored
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.
1 parent 66f8ae2 commit 304192c

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

bypy/macos/__main__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def compile_launcher_lib(contents_dir, gcc, base, pyver, inc_dir):
5959

6060
dest = join(contents_dir, 'Frameworks', 'calibre-launcher.dylib')
6161
src = join(base, 'util.c')
62-
cmd = [gcc] + ARCH_FLAGS + '-Wall -dynamiclib -std=gnu99'.split() + [src] + \
62+
cmd = [gcc] + ARCH_FLAGS + CFLAGS + '-Wall -dynamiclib -std=gnu99'.split() + [src] + \
6363
['-I' + base] + '-DPY_VERSION_MAJOR={} -DPY_VERSION_MINOR={}'.format(*pyver.split('.')).split() + \
6464
[f'-I{path_to_freeze_dir()}', f'-I{inc_dir}'] + \
6565
[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):
8282

8383

8484
gcc = os.environ.get('CC', 'clang')
85+
CFLAGS = os.environ.get('CFLAGS', '-Os')
8586

8687

8788
def compile_launchers(contents_dir, inc_dir, xprograms, pyver):
@@ -95,7 +96,7 @@ def compile_launchers(contents_dir, inc_dir, xprograms, pyver):
9596
out = join(contents_dir, 'MacOS', program)
9697
programs.append(out)
9798
is_gui = 'true' if ptype == 'gui' else 'false'
98-
cmd = [gcc] + ARCH_FLAGS + [
99+
cmd = [gcc] + ARCH_FLAGS + CFLAGS + [
99100
'-Wall', f'-DPROGRAM=L"{program}"', f'-DMODULE=L"{module}"', f'-DFUNCTION=L"{func}"', f'-DIS_GUI={is_gui}',
100101
'-I' + base, src, lib, '-o', out, '-headerpad_max_install_names',
101102
]
@@ -707,7 +708,7 @@ def create_app_clone(self, name, specialise_plist, remove_doc_types=False, base_
707708
plist['CFBundleExecutable'] = exe + '-placeholder-for-codesigning'
708709
nexe = join(exe_dir, plist['CFBundleExecutable'])
709710
base = os.path.dirname(abspath(__file__))
710-
cmd = [gcc] + ARCH_FLAGS + [
711+
cmd = [gcc] + ARCH_FLAGS + CFLAGS + [
711712
'-Wall', '-Werror', '-DEXE_NAME="%s"' % exe, '-DREL_PATH="%s"' % rel_path,
712713
join(base, 'placeholder.c'), '-o', nexe, '-headerpad_max_install_names'
713714
]

0 commit comments

Comments
 (0)