Merge pull request #5120 from harfbuzz/fontations-shrink

Fontations shrink
This commit is contained in:
Behdad Esfahbod 2025-03-07 22:01:23 -07:00 committed by GitHub
commit 27fa1c4229
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 78 additions and 36 deletions

View file

@ -21,11 +21,14 @@ jobs:
uses: hendrikmuhs/ccache-action@a1209f81afb8c005c13b4296c32e363431bffea5 # v1.2.17
with:
key: ${{ github.job }}-${{ runner.os }}-${{ runner.arch }}
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
- uses: dtolnay/rust-toolchain@nightly
- name: Install Dependencies
run: |
rustup component add \
rust-src \
rustfmt \
clippy \
--toolchain nightly-x86_64-unknown-linux-gnu
sudo apt-get update
sudo apt-get install \
gcc \

View file

@ -462,10 +462,6 @@ configure_file(output: 'config.h', configuration: conf)
alias_target('lib', libharfbuzz)
alias_target('libs', libharfbuzz, libharfbuzz_subset)
if get_option('fontations').enabled()
alias_target('clippy', clippy)
alias_target('fmt', fmt)
endif
if meson.version().version_compare('>=0.57.0')
# Re glib, see https://github.com/harfbuzz/harfbuzz/issues/4153#issuecomment-2646347531

View file

@ -7,18 +7,26 @@ os.environ['LC_ALL'] = 'C' # otherwise 'nm' prints in wrong order
builddir = os.getenv ('builddir', os.path.dirname (__file__))
libs = os.getenv ('libs', '.libs')
IGNORED_SYMBOLS = '|'.join(['_fini', '_init', '_fdata', '_ftext', '_fbss',
IGNORED_SYMBOLS = ['_fini', '_init', '_fdata', '_ftext', '_fbss',
'__bss_start', '__bss_start__', '__bss_end__', '_edata', '_end', '_bss_end__',
'__end__', '__gcov_.*', 'llvm_.*', 'flush_fn_list', 'writeout_fn_list', 'mangle_path',
'lprofDirMode', 'reset_fn_list'])
'lprofDirMode', 'reset_fn_list']
# Rust
IGNORED_SYMBOLS += [
'rust_eh_personality',
'_ZN3std9panicking11EMPTY_PANIC.*', # 'std::panicking::EMPTY_PANIC::.*'
'_ZN3std3sys3pal4unix4args3imp15ARGV_INIT_ARRAY.*', # 'std::sys::pal::unix::args::imp::ARGV_INIT_ARRAY::.*'
'_ZN17compiler_builtins4math4libm7generic4sqrt9RSQRT_TAB.*', # 'compiler_builtins::math::libm::generic::sqrt::RSQRT_TAB::.*'
]
IGNORED_SYMBOLS = '|'.join (IGNORED_SYMBOLS)
nm = os.getenv ('NM', shutil.which ('nm'))
if not nm:
print ('check-symbols.py: \'nm\' not found; skipping test')
sys.exit (77)
cxxfilt = shutil.which ('c++filt')
tested = False
stat = 0
@ -34,12 +42,6 @@ for soname in ['harfbuzz', 'harfbuzz-subset', 'harfbuzz-icu', 'harfbuzz-gobject'
for s in re.findall (r'^.+ [BCDGIRSTu] .+$', subprocess.check_output (nm.split() + [so]).decode ('utf-8'), re.MULTILINE)
if not re.match (r'.* %s(%s)\b' % (symprefix, IGNORED_SYMBOLS), s)]
# run again c++filt also if is available
if cxxfilt:
EXPORTED_SYMBOLS = subprocess.check_output (
[cxxfilt], input='\n'.join (EXPORTED_SYMBOLS).encode ()
).decode ('utf-8').splitlines ()
prefix = (symprefix + os.path.basename (so)).replace ('libharfbuzz', 'hb').replace ('-', '_').split ('.')[0]
print ('Checking that %s does not expose internal symbols' % so)

View file

@ -11,6 +11,15 @@ name = "harfbuzz_fontations"
path = "lib.rs"
crate-type = ["staticlib"]
[profile.release]
strip = true
lto = true
panic = "abort"
overflow-checks = false
codegen-units = 1
[profile.debugoptimized]
inherits = "release"
debug = true
codegen-units = 16
strip = false

View file

@ -704,14 +704,14 @@ extern "C" fn _hb_fontations_paint_glyph(
unsafe { std::slice::from_raw_parts(std::ptr::NonNull::dangling().as_ptr(), 0) }
} else {
let cpal = cpal.unwrap();
let num_entries: usize = cpal.num_palette_entries().into();
let num_entries = cpal.num_palette_entries().into();
let color_records = cpal.color_records_array();
let start_index = cpal.color_record_indices().get(palette_index as usize);
let start_index = if start_index.is_some() {
start_index
} else {
// https://github.com/harfbuzz/harfbuzz/issues/5116
cpal.color_record_indices().get(0 as usize)
cpal.color_record_indices().first()
};
if let (Some(Ok(color_records)), Some(start_index)) = (color_records, start_index) {

View file

@ -8,25 +8,33 @@ hb_rs = rust.bindgen(
'--allowlist-type=hb_.*',
'--no-copy=hb_.*',
],
#args : ['--no-rustfmt-bindings'],
)
cargo = find_program('cargo')
rustfmt = find_program('rustfmt')
rust_flags = ''
cargo_args = []
buildtype = get_option('buildtype')
if buildtype == 'release' or buildtype == 'debugoptimized'
cargo_args = ['--profile', buildtype]
else
cargo_args = []
cargo_args += ['--profile', buildtype]
endif
opt_level = get_option('optimization')
rust_flags += ' -C opt-level=' + opt_level
cargo_args += ['-Z', 'build-std=std,panic_abort',
'-Z', 'build-std-features=panic_immediate_abort']
harfbuzz_fontations = custom_target(
'harfbuzz_fontations',
input: ['lib.rs', 'Cargo.toml', 'Cargo.lock'],
output: ['libharfbuzz_fontations.a'],
depends: [hb_rs],
env: ['OUT_DIR=' + meson.current_build_dir()],
env: ['OUT_DIR=' + meson.current_build_dir(),
'RUSTFLAGS=' + rust_flags,
],
command: [
cargo, 'build',
] + cargo_args + [
@ -44,25 +52,36 @@ harfbuzz_fontations_dep = declare_dependency(
link_whole: harfbuzz_fontations,
)
clippy = custom_target(
'clippy',
input: 'lib.rs',
output: 'clippy',
depends: [hb_rs],
clippy_fix = run_target(
'clippy-fix',
env: ['OUT_DIR=' + meson.current_build_dir()],
command: [
cargo, 'clippy',
'--allow-dirty', '--fix',
] + cargo_args + [
'--lib', '-p', 'harfbuzz_fontations',
'--target-dir', meson.current_build_dir(),
'--manifest-path', meson.current_source_dir() / 'Cargo.toml'
'--manifest-path', meson.current_source_dir() / 'Cargo.toml',
],
)
if get_option('tests').enabled() and cargo.found()
test(
'clippy',
cargo,
env: ['OUT_DIR=' + meson.current_build_dir()],
args: [
'clippy',
] + cargo_args + [
'--lib', '-p', 'harfbuzz_fontations',
'--target-dir', meson.current_build_dir(),
'--manifest-path', meson.current_source_dir() / 'Cargo.toml',
'--', '-D', 'warnings',
],
)
endif
fmt = custom_target(
'fmt',
input: 'lib.rs',
output: 'fmt',
depends: [hb_rs],
rustfmt_fix = run_target(
'rustfmt-fix',
env: ['OUT_DIR=' + meson.current_build_dir()],
command: [
rustfmt,
@ -71,3 +90,16 @@ fmt = custom_target(
meson.current_source_dir() / 'lib.rs',
],
)
if get_option('tests').enabled() and rustfmt.found()
test(
'rustfmt',
rustfmt,
env: ['OUT_DIR=' + meson.current_build_dir()],
args: [
'--check',
'--edition', '2021',
'--',
meson.current_source_dir() / 'lib.rs',
],
)
endif

View file

@ -1044,7 +1044,7 @@ if get_option('tests').enabled()
endforeach
env.set('HBHEADERS', ' '.join(HBHEADERS))
if conf.get('HAVE_FONTATIONS', 0) == 0 and cpp.get_argument_syntax() != 'msvc' and not meson.is_cross_build() # ensure the local tools are usable
if cpp.get_argument_syntax() != 'msvc' and not meson.is_cross_build() # ensure the local tools are usable
dist_check_script += ['check-static-inits', 'check-symbols']
if get_option('wasm').disabled() and not get_option('with_libstdcxx')
dist_check_script += ['check-libstdc++']