Skip to content

Commit

Permalink
build/emscripten: work around mesonbuild/meson#12638
Browse files Browse the repository at this point in the history
  • Loading branch information
Akaricchi committed Jan 24, 2024
1 parent 4d161b2 commit 42a7e49
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
3 changes: 3 additions & 0 deletions scripts/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,6 @@ res_index_install_command = [res_index_install_script, common_taiseilib_args]
macos_install_dylibs_script = find_program(files('macos-install-dylibs.py'))
# NOTE/FIXME: script doesn't use taiseilib
macos_install_dylibs_command = [macos_install_dylibs_script]

post_install_remove_script = find_program(files('post-install-remove.py'))
post_install_remove_command = [post_install_remove_script, common_taiseilib_args]
53 changes: 53 additions & 0 deletions scripts/post-install-remove.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3

import sys
import os
import shutil

from pathlib import Path

from taiseilib.common import (
add_common_args,
run_main,
)

def main(args):
import argparse
parser = argparse.ArgumentParser(description='Install resources from res-index', prog=args[0])

parser.add_argument('remove_items',
type=Path,
help='the files and/or directories to remove (relative to install destdir + prefix)',
nargs='*',
)

add_common_args(parser)

args = parser.parse_args(args[1:])

install_root = Path(os.environ['MESON_INSTALL_DESTDIR_PREFIX'])
quiet = bool(os.environ.get('MESON_INSTALL_QUIET', False))
dryrun = bool(os.environ.get('MESON_INSTALL_DRY_RUN', False))

def log(*s):
if not quiet:
print(*s)

for item in args.remove_items:
itempath = (install_root / item)

if dryrun:
log(f'Would remove {itempath}')
elif itempath.exists():
if itempath.is_dir():
log(f'Removing directory {itempath}')
itempath.rmdir()
else:
log(f'Removing file {itempath}')
itempath.unlink()
else:
log(f'Skipping non-existent file {itempath}')


if __name__ == '__main__':
run_main(main)
20 changes: 19 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,31 @@ if host_machine.system() == 'emscripten'
em_link_outputs += ['@0@.@1@'.format(taisei_basename, suffix)]
endforeach

meson_link_whole_is_broken = meson.version().version_compare('>1.1.0')

if meson_link_whole_is_broken
warning('Installing private static library to work around a Meson bug: https://github.com/mesonbuild/meson/issues/12638')
endif

libtaisei = static_library(taisei_basename, taisei_src, version_deps,
dependencies : taisei_deps,
c_pch : 'pch/taisei_pch.h',
c_args : [em_common_args, taisei_c_args],
install : false,
install : meson_link_whole_is_broken,
install_dir : '.',
install_tag : 'trash',
# Explicitly give it a predictable name, in case we have to remove it via install script
name_prefix : 'lib',
name_suffix : 'a',
)

if meson_link_whole_is_broken
meson.add_install_script(
post_install_remove_command, 'lib' + libtaisei.name() + '.a',
install_tag : 'trash',
)
endif

taisei = static_library(taisei_basename + '-full',
link_whole : libtaisei,
)
Expand Down

0 comments on commit 42a7e49

Please sign in to comment.