From 11799cbdf28e63e3782b4ab7c7fc7070ac366285 Mon Sep 17 00:00:00 2001 From: G4Vi Date: Wed, 13 Aug 2025 13:53:13 -0400 Subject: [PATCH 1/2] fix(music player decoder): emscripten 4.0.7 compat 1. switch over to WASM_BIGINT, explicitly add flag so pre 4.0.0 works 2. explicitly export HEAPU8 HEAPU16 HEAPU32 on 4.0.7+ 3. fix warning starting 3.1.35, use stringToNewUTF8 instead of allocateUTF8 --- .../music_worklet_inprogress/decoder/Makefile | 2 +- .../decoder/exported_runtime_methods.pl | 37 ++++++++++++++----- .../decoder/mhfscl.js | 9 ++--- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/App-MHFS/share/public_html/static/music_worklet_inprogress/decoder/Makefile b/App-MHFS/share/public_html/static/music_worklet_inprogress/decoder/Makefile index a49ecd0..cd7a6e3 100644 --- a/App-MHFS/share/public_html/static/music_worklet_inprogress/decoder/Makefile +++ b/App-MHFS/share/public_html/static/music_worklet_inprogress/decoder/Makefile @@ -8,7 +8,7 @@ TARGET:=$(OUTDIR)/_mhfscl.js EXPORTED_RUNTIME_METHODS := $(shell perl exported_runtime_methods.pl) STACK_SIZE_NAME := $(shell perl stack_size_name.pl) -CFLAGS:=-Wall -Wextra -I$(DRFLACDIR) -I$(MINIAUDIODIR) -DMA_NO_DEVICE_IO -DMA_NO_THREADING -DMA_NO_ENCODING -DDR_FLAC_BUFFER_SIZE=65536 -DDR_FLAC_NO_OGG $(EXPORTED_RUNTIME_METHODS) -s'EXPORTED_FUNCTIONS=["_malloc", "_realloc", "_free"]' -sEXPORT_ES6=1 -s$(STACK_SIZE_NAME)=128KB -sALLOW_MEMORY_GROWTH=1 -sMODULARIZE=1 -sALLOW_TABLE_GROWTH=1 +CFLAGS:=-Wall -Wextra -I$(DRFLACDIR) -I$(MINIAUDIODIR) -DMA_NO_DEVICE_IO -DMA_NO_THREADING -DMA_NO_ENCODING -DDR_FLAC_BUFFER_SIZE=65536 -DDR_FLAC_NO_OGG $(EXPORTED_RUNTIME_METHODS) -s'EXPORTED_FUNCTIONS=["_malloc", "_realloc", "_free"]' -sEXPORT_ES6=1 -s$(STACK_SIZE_NAME)=128KB -sALLOW_MEMORY_GROWTH=1 -sMODULARIZE=1 -sALLOW_TABLE_GROWTH=1 -sWASM_BIGINT=1 # a non zero value turns on Werrror MHFS_CL_DEC_Werror?=0 diff --git a/App-MHFS/share/public_html/static/music_worklet_inprogress/decoder/exported_runtime_methods.pl b/App-MHFS/share/public_html/static/music_worklet_inprogress/decoder/exported_runtime_methods.pl index c1a344a..eb56e41 100644 --- a/App-MHFS/share/public_html/static/music_worklet_inprogress/decoder/exported_runtime_methods.pl +++ b/App-MHFS/share/public_html/static/music_worklet_inprogress/decoder/exported_runtime_methods.pl @@ -1,20 +1,27 @@ #!/usr/bin/perl -# EXTRA_EXPORTED_RUNTIME_METHODS was deprecated in emsdk 2.0.18 use strict; use warnings; my @exported_runtime_methods = ("cwrap", "ccall"); -my @extra_exported_runtime_methods = ("UTF8ToString", "addFunction", "removeFunction", "allocateUTF8"); +my @extra_exported_runtime_methods = ("UTF8ToString", "addFunction", "removeFunction"); # determine configuration open(my $emcc, "-|", 'emcc', '--version') or die("Failed to open emcc"); -my $combine_extra; my $line = <$emcc>; -if($line =~ /\s+(\d+)\.(\d+)\.(\d+)/) { - my ($maj, $min, $patch) = ($1, $2, $3); - $combine_extra = ($maj > 2) || (($maj == 2) && (($min > 0) || ($patch >= 18))); +my @version = $line =~ /\s+(\d+)\.(\d+)\.(\d+)/; +if (!@version) { + @version = (4, 0, 12); + warn "version parsing failed, assuming " . join('.', @version); } -if(!defined($combine_extra)) { - warn "warn: Failed to find version, assuming combine_extra"; - $combine_extra = 1; +# EXTRA_EXPORTED_RUNTIME_METHODS was deprecated +my $combine_extra = version_greater_than_or_equal(\@version, [2, 0, 18]); +# allocateUTF8 was deprecated in favor of stringToNewUTF8 +if (version_greater_than_or_equal(\@version, [3, 1, 35])) { + push @exported_runtime_methods, 'stringToNewUTF8'; +} else { + push @extra_exported_runtime_methods, 'allocateUTF8'; +} +# HEAP* is no longer exported by default in emsdk 4.0.7 +if (version_greater_than_or_equal(\@version, [4, 0, 7])) { + push @exported_runtime_methods, qw(HEAPU8 HEAPU16 HEAPU32); } # build the arrays @@ -40,3 +47,15 @@ } print $opts; + +sub version_greater_than_or_equal { + my ($version, $expected) = @_; + @$version >= @$expected or die "expected has more version components"; + my $i = 0; + foreach my $component (@$expected) { + return 0 if($version->[$i] < $component); + return 1 if($version->[$i] > $component); + $i++; + } + return 1; +} diff --git a/App-MHFS/share/public_html/static/music_worklet_inprogress/decoder/mhfscl.js b/App-MHFS/share/public_html/static/music_worklet_inprogress/decoder/mhfscl.js index 9ee21e0..608e1d5 100644 --- a/App-MHFS/share/public_html/static/music_worklet_inprogress/decoder/mhfscl.js +++ b/App-MHFS/share/public_html/static/music_worklet_inprogress/decoder/mhfscl.js @@ -402,17 +402,15 @@ const MHFSCLTrack = async function(gsignal, theURL, DLMGR) { if(!that.ptr) throw("failed malloc"); const rd = MHFSCL.mhfs_cl_track_return_data.from(that.ptr + alignedTrackSize); const thatid = MHFSCLObjectMap.addData(that); - const pFullFilename = MHFSCL.Module.allocateUTF8(theURL); + const pFullFilename = MHFSCL.Module.stringToNewUTF8(theURL); let pMime; try { // initialize the track let start = 0; const firstreq = await that._downloadChunk(start, gsignal); const mime = firstreq.headers['Content-Type'] || ''; - pMime = MHFSCL.Module.allocateUTF8(mime); + pMime = MHFSCL.Module.stringToNewUTF8(mime); const totalPCMFrames = BigInt(firstreq.headers['X-MHFS-totalPCMFrameCount'] || 0); - const totalPCMFramesLo = Number(totalPCMFrames & BigInt(0xFFFFFFFF)); - const totalPCMFramesHi = Number((totalPCMFrames >> BigInt(32)) & BigInt(0xFFFFFFFF)); MHFSCL.Module._mhfs_cl_track_init(that.ptr, that.CHUNKSIZE); that.initialized = true; that._storeChunk(firstreq, start); @@ -420,7 +418,7 @@ const MHFSCLTrack = async function(gsignal, theURL, DLMGR) { // load enough of the track that the metadata loads for(;;) { that.picture = null; - const code = MHFSCL.Module._mhfs_cl_track_load_metadata(that.ptr, rd.ptr, pMime, pFullFilename, totalPCMFramesLo, totalPCMFramesHi, MHFSCL.pMHFSCLTrackOnMeta, thatid); + const code = MHFSCL.Module._mhfs_cl_track_load_metadata(that.ptr, rd.ptr, pMime, pFullFilename, totalPCMFrames, MHFSCL.pMHFSCLTrackOnMeta, thatid); if(code === MHFSCL.MHFS_CL_SUCCESS) { break; } @@ -732,6 +730,7 @@ const ExposeType_LoadTypes = function(BINDTO, wasmMod, loadType) { Module().then(function(MHFSCLMod){ MHFSCL.Module = MHFSCLMod; + MHFSCL.Module.stringToNewUTF8 ||= MHFSCL.Module.allocateUTF8; // < 3.1.35 emcc compat // Load types ExposeType_LoadTypes(MHFSCL, MHFSCL.Module, MHFSCL.Module._mhfs_cl_et_load_type); From a1158a79d86b175e8091e9ea429cc5e115a6b483 Mon Sep 17 00:00:00 2001 From: G4Vi Date: Wed, 13 Aug 2025 14:21:34 -0400 Subject: [PATCH 2/2] ci: hardcode release emsdk version, bump emsdk and perl versions used to test --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a247ec5..525458f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,14 +22,14 @@ jobs: - name: Install Perl and MHFS Perl dependencies uses: shogo82148/actions-setup-perl@v1 with: - perl-version: '5.38' + perl-version: '5.40' working-directory: MHFS install-modules-with: cpanm install-modules-args: --with-develop --with-configure --with-recommends - name: Setup emscripten uses: mymindstorm/setup-emsdk@v14 with: - version: latest + version: '4.0.12' actions-cache-folder: 'emsdk-cache' - name: Build and package MHFS run: | @@ -60,7 +60,7 @@ jobs: - name: Install Perl and MHFS Perl dependencies uses: shogo82148/actions-setup-perl@v1 with: - perl-version: '5.38' + perl-version: '5.40' working-directory: MHFS install-modules-with: cpanm install-modules: LWP::UserAgent LWP::Protocol::https Perl::Dist::APPerl @@ -98,7 +98,7 @@ jobs: strategy: matrix: os: ['ubuntu-latest'] - emcc: ['1.40.1', '2.0.0', '2.0.34', '3.0.0', '3.1.17' ] + emcc: ['1.40.1', '2.0.34', '3.1.74', '4.0.0', 'latest'] runs-on: ${{ matrix.os }} steps: - name: Fetch repo and submodules