aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


tools/client/build_wasm_dependencies.py (2891B)


      1 """Build the audio/font dependencies with the repository's Emscripten SDK."""
      2 import hashlib
      3 import pathlib
      4 import subprocess
      5 import tarfile
      6 import urllib.request
      7 
      8 
      9 root = pathlib.Path(__file__).resolve().parents[2]
     10 work = root / 'local/wasm'
     11 sdk = root / 'toolchains/emsdk/upstream/emscripten'
     12 work.mkdir(parents=True, exist_ok=True)
     13 
     14 # Pin the same libsndfile release used on Debian and its required MPEG encoder.
     15 for name, url, digest in [
     16     ('libsndfile-1.2.2.tar.xz',
     17      'https://github.com/libsndfile/libsndfile/releases/download/1.2.2/libsndfile-1.2.2.tar.xz',
     18      '3799ca9924d3125038880367bf1468e53a1b7e3686a934f098b7e1d286cdb80e'),
     19     ('lame-3.100.tar.gz',
     20      'https://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz',
     21      'ddfe36cab873794038ae2c1210557ad34857a4b6bdc515785d1da9e175b1da1e'),
     22 ]:
     23     archive = work / name
     24     if not archive.exists():
     25         urllib.request.urlretrieve(url, archive)
     26     assert hashlib.sha256(archive.read_bytes()).hexdigest() == digest, archive
     27     directory = work / name.split('.tar.')[0]
     28     if not directory.exists():
     29         with tarfile.open(archive) as package:
     30             package.extractall(work, filter='data')
     31 
     32 # Emscripten supplies its supported FreeType and mpg123 ports.
     33 probe = work / 'dependency-probe.c'
     34 probe.write_text('int main(void) { return 0; }\n')
     35 subprocess.run([str(sdk / 'emcc'), str(probe), '-pthread', '-sUSE_SDL=2',
     36                 '-sUSE_FREETYPE=1', '-sUSE_MPG123=1', '-o', str(work / 'dependency-probe.js')], check=True)
     37 prefix = work / 'deps'
     38 subprocess.run([str(sdk / 'emconfigure'), './configure', '--prefix=' + str(prefix),
     39                 '--disable-shared', '--disable-frontend', '--disable-decoder', 'CFLAGS=-O2 -pthread'],
     40                cwd=work / 'lame-3.100', check=True)
     41 subprocess.run(['make', '-j4'], cwd=work / 'lame-3.100', check=True)
     42 subprocess.run(['make', 'install'], cwd=work / 'lame-3.100', check=True)
     43 
     44 # Keep decoding in C so Linux and browser audio use the same mixer and formats.
     45 subprocess.run([str(sdk / 'emcmake'), 'cmake', '-S', str(work / 'libsndfile-1.2.2'),
     46                 '-B', str(work / 'sndfile-build'), '-DCMAKE_BUILD_TYPE=Release',
     47                 '-DCMAKE_C_FLAGS=-pthread', '-DCMAKE_INSTALL_PREFIX=' + str(prefix),
     48                 '-DENABLE_EXTERNAL_LIBS=OFF', '-DBUILD_PROGRAMS=OFF',
     49                 '-DBUILD_EXAMPLES=OFF', '-DBUILD_TESTING=OFF',
     50                 '-Dmpg123_INCLUDE_DIR=' + str(sdk / 'cache/sysroot/include'),
     51                 '-Dmpg123_LIBRARY=' + str(sdk / 'cache/sysroot/lib/wasm32-emscripten/libmpg123.a'),
     52                 '-DMP3LAME_INCLUDE_DIR=' + str(prefix / 'include'),
     53                 '-DMP3LAME_LIBRARY=' + str(prefix / 'lib/libmp3lame.a')], check=True)
     54 subprocess.run(['cmake', '--build', str(work / 'sndfile-build'), '-j4'], check=True)
     55 subprocess.run(['cmake', '--install', str(work / 'sndfile-build')], check=True)