diff mbox series

[2/2] harfbuzz: build with -Os

Message ID 20250718135840.1969215-2-ross.burton@arm.com
State New
Headers show
Series [1/2] harfbuzz: disable building the tests | expand

Commit Message

Ross Burton July 18, 2025, 1:58 p.m. UTC
Upstream explicitly say in their CONFIG.md file to build with -Os:

  Make sure you build with your compiler's "optimize for size" option.
  On `gcc` this is `-Os` [ ... ] HarfBuzz heavily uses inline functions
  and the optimize-size flag can make the library smaller by 20% or
  more. Moreover, sometimes, based on the target CPU, the optimize-size
  builds perform *faster* as well, thanks to lower code footprint and
  caching effects

Drop the patch to build just hb-subset-plan-layout.cc with -Os (which
was a workaround for a GCC bug), and pass -Os globally.

This manages to reduce the duration to harfbuzz:do_compile on my machine
from 75s to 47s, and has a big impact on the library sizes:

  harfbuzz: PKGSIZE changed from 1769358 to 1237070 (-30%)
  harfbuzz-dbg: PKGSIZE changed from 84920168 to 71203208 (-16%)
  harfbuzz-subset: PKGSIZE changed from 1579247 to 940191 (-40%)

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 ...-to-compile-hb-subset-plan-layout.cc.patch | 72 -------------------
 .../harfbuzz/harfbuzz_11.2.1.bb               |  4 +-
 2 files changed, 3 insertions(+), 73 deletions(-)
 delete mode 100644 meta/recipes-graphics/harfbuzz/harfbuzz/0001-Use-Os-to-compile-hb-subset-plan-layout.cc.patch
diff mbox series

Patch

diff --git a/meta/recipes-graphics/harfbuzz/harfbuzz/0001-Use-Os-to-compile-hb-subset-plan-layout.cc.patch b/meta/recipes-graphics/harfbuzz/harfbuzz/0001-Use-Os-to-compile-hb-subset-plan-layout.cc.patch
deleted file mode 100644
index 38ff58fce5e..00000000000
--- a/meta/recipes-graphics/harfbuzz/harfbuzz/0001-Use-Os-to-compile-hb-subset-plan-layout.cc.patch
+++ /dev/null
@@ -1,72 +0,0 @@ 
-From a4325b6f6ddbebf3ecaee8f3825a2f03096adb6d Mon Sep 17 00:00:00 2001
-From: Khem Raj <raj.khem@gmail.com>
-Date: Sun, 27 Apr 2025 15:26:09 -0700
-Subject: [PATCH] Use -Os to compile hb-subset-plan-layout.cc
-
-This helps compiling with GCC 15
-
-Reported upstream with GH Issues [1]
-
-[1] https://github.com/harfbuzz/harfbuzz/issues/5306
-
-Upstream-Status: Inappropriate [GCC-15 workaround]
-
-Signed-off-by: Khem Raj <raj.khem@gmail.com>
----
- src/meson.build | 15 ++++++++++++---
- 1 file changed, 12 insertions(+), 3 deletions(-)
-
-diff --git a/src/meson.build b/src/meson.build
-index cbe5d9e..d7fc764 100644
---- a/src/meson.build
-+++ b/src/meson.build
-@@ -398,7 +398,6 @@ hb_subset_sources = files(
-   'hb-subset-instancer-solver.hh',
-   'hb-subset-instancer-solver.cc',
-   'hb-subset-plan.cc',
--  'hb-subset-plan-layout.cc',
-   'hb-subset-plan-var.cc',
-   'hb-subset-plan.hh',
-   'hb-subset-plan-member-list.hh',
-@@ -415,6 +414,10 @@ hb_subset_sources = files(
-   'hb-subset.hh',
- )
- 
-+hb_subset_sources_os = files(
-+  'hb-subset-plan-layout.cc',
-+)
-+
- hb_subset_headers = files(
-   'hb-subset.h',
-   'hb-subset-serialize.h'
-@@ -629,6 +632,12 @@ endif
- 
- darwin_versions = [hb_version_int, '@0@.0.0'.format(hb_version_int)]
- 
-+special_subset_layout_lib = static_library('special_subset_layout',
-+  'hb-subset-plan-layout.cc',
-+  include_directories: incconfig,
-+  cpp_args: cpp_args + extra_hb_cpp_args + ['-Os'], # <== compile this one with -Os
-+)
-+
- libharfbuzz = library('harfbuzz', hb_sources,
-   include_directories: incconfig,
-   dependencies: harfbuzz_deps,
-@@ -656,7 +665,7 @@ defs_list += [harfbuzz_subset_def]
- libharfbuzz_subset = library('harfbuzz-subset', hb_subset_sources,
-   include_directories: incconfig,
-   dependencies: [m_dep],
--  link_with: [libharfbuzz],
-+  link_with: [libharfbuzz] + [special_subset_layout_lib],
-   cpp_args: cpp_args + extra_hb_cpp_args,
-   soversion: hb_so_version,
-   version: version,
-@@ -668,7 +677,7 @@ libharfbuzz_subset = library('harfbuzz-subset', hb_subset_sources,
- custom_target('harfbuzz-subset.cc',
-   build_by_default: true,
-   output: 'harfbuzz-subset.cc',
--  input: hb_base_sources + hb_subset_sources,
-+  input: hb_base_sources + hb_subset_sources + hb_subset_sources_os,
-   command: [find_program('gen-harfbuzzcc.py'),
-             '@OUTPUT@', meson.current_source_dir(), '@INPUT@'],
- )
diff --git a/meta/recipes-graphics/harfbuzz/harfbuzz_11.2.1.bb b/meta/recipes-graphics/harfbuzz/harfbuzz_11.2.1.bb
index bc2c6acdaec..2c8a1363d0a 100644
--- a/meta/recipes-graphics/harfbuzz/harfbuzz_11.2.1.bb
+++ b/meta/recipes-graphics/harfbuzz/harfbuzz_11.2.1.bb
@@ -9,7 +9,6 @@  LIC_FILES_CHKSUM = "file://COPYING;md5=b98429b8e8e3c2a67cfef01e99e4893d \
                     "
 
 SRC_URI = "${GITHUB_BASE_URI}/download/${PV}/${BPN}-${PV}.tar.xz"
-SRC_URI += "file://0001-Use-Os-to-compile-hb-subset-plan-layout.cc.patch"
 SRC_URI[sha256sum] = "093714c8548a285094685f0bdc999e202d666b59eeb3df2ff921ab68b8336a49"
 
 DEPENDS += "glib-2.0-native"
@@ -21,6 +20,9 @@  GIR_MESON_DISABLE_FLAG = 'disabled'
 GTKDOC_MESON_ENABLE_FLAG = 'enabled'
 GTKDOC_MESON_DISABLE_FLAG = 'disabled'
 
+# As per upstream CONFIG.md, it is recommended to always build with -Os.
+FULL_OPTIMIZATION = "-Os ${DEBUG_LEVELFLAG}"
+
 EXTRA_OEMESON = "-Dtests=disabled"
 
 PACKAGECONFIG ??= "cairo freetype glib icu"