Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building a WASM #356

Open
bernardbaker opened this issue Feb 27, 2023 · 5 comments
Open

Building a WASM #356

bernardbaker opened this issue Feb 27, 2023 · 5 comments

Comments

@bernardbaker
Copy link

Expected behavior:
The WASM is generated with the exported functions.

Actual behavior:
No functions appear to be exported.

Steps to reproduce the problem:
There are two make files. One for compiling the source. And the second for emscripten.

Compile source:

# Compiler and linker flags
CXXFLAGS = -I./include -O3 -D WITH_NULL=1

# Source files
SRCS = $(wildcard ./src/**/*.cpp)

# Object files
OBJS = $(SRCS:.cpp=.o)

# Build rules
.PHONY: all clean

all: libs

libs: $(OBJS)
	ar rcs lib/libsoloud.a $^

%.o: %.cpp
	$(CXX) $(CXXFLAGS) -c -o $@ $<

clean:
	rm -f $(OBJS) lib/libsoloud.a

Compile WASM:

# Compiler and linker flags
CXXFLAGS = -03 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s LLD_REPORT_UNDEFINED -s EXPORTED_FUNCTIONS="@exports.txt"
LDFLAGS = -L./lib -lsoloud


# Object files
OBJS = $(wildcard ./src/*.o)


# Exported functions
EXPORTS = $(shell nm -gC --extern-only --format=posix ./lib/libsoloud.a | grep -E '^_[[:alnum:]]+_' | awk '{ print $$1 }')

# Build rules
.PHONY: all clean

all: exports.txt soloud.js

# soloud.js: $(OBJS)
soloud.js:
	emcc $(CXXFLAGS) $(LDFLAGS) -o $@ $^

exports.txt:
	echo $(EXPORTS) | tr ' ' '\n' > exports.txt

clean:
	rm -f $(OBJS) soloud.js exports.txt

The command expands to:

emcc -03 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s LLD_REPORT_UNDEFINED -s EXPORTED_FUNCTIONS="@exports.txt" -L./lib -lsoloud -o soloud.js 

The error:

emcc: error: undefined exported symbol: "_BassboostFilter_create" [-Wundefined] [-Werror]
make: *** [soloud.js] Error 1

The file with the exported functions:

_BassboostFilter_create
_BassboostFilter_destroy
_BassboostFilter_getParamCount
_BassboostFilter_getParamMax
_BassboostFilter_getParamMin
_BassboostFilter_getParamName
_BassboostFilter_getParamType
_BassboostFilter_setParams
_BiquadResonantFilter_create
_BiquadResonantFilter_destroy
_BiquadResonantFilter_getParamCount
_BiquadResonantFilter_getParamMax
_BiquadResonantFilter_getParamMin
_BiquadResonantFilter_getParamName
_BiquadResonantFilter_getParamType
_BiquadResonantFilter_setParams
_Bus_annexSound
_Bus_calcFFT
_Bus_create
_Bus_destroy
_Bus_getActiveVoiceCount
_Bus_getApproximateVolume
_Bus_getLoopPoint
_Bus_getWave
_Bus_play
_Bus_play3d
_Bus_play3dClocked
_Bus_play3dClockedEx
_Bus_play3dEx
_Bus_playClocked
_Bus_playClockedEx
_Bus_playEx
_Bus_set3dAttenuation
_Bus_set3dAttenuator
_Bus_set3dCollider
_Bus_set3dColliderEx
_Bus_set3dDistanceDelay
_Bus_set3dDopplerFactor
_Bus_set3dListenerRelative
_Bus_set3dMinMaxDistance
_Bus_setChannels
_Bus_setFilter
_Bus_setInaudibleBehavior
_Bus_setLoopPoint
_Bus_setLooping
_Bus_setVisualizationEnable
_Bus_setVolume
_Bus_stop
_DCRemovalFilter_create
_DCRemovalFilter_destroy
_DCRemovalFilter_getParamCount
_DCRemovalFilter_getParamMax
_DCRemovalFilter_getParamMin
_DCRemovalFilter_getParamName
_DCRemovalFilter_getParamType
_DCRemovalFilter_setParams
_DCRemovalFilter_setParamsEx
_EchoFilter_create
_EchoFilter_destroy
_EchoFilter_getParamCount
_EchoFilter_getParamMax
_EchoFilter_getParamMin
_EchoFilter_getParamName
_EchoFilter_getParamType
_EchoFilter_setParams
_EchoFilter_setParamsEx
_FFTFilter_create
_FFTFilter_destroy
_FFTFilter_getParamCount
_FFTFilter_getParamMax
_FFTFilter_getParamMin
_FFTFilter_getParamName
_FFTFilter_getParamType
_FlangerFilter_create
_FlangerFilter_destroy
_FlangerFilter_getParamCount
_FlangerFilter_getParamMax
_FlangerFilter_getParamMin
_FlangerFilter_getParamName
_FlangerFilter_getParamType
_FlangerFilter_setParams
_FreeverbFilter_create
_FreeverbFilter_destroy
_FreeverbFilter_getParamCount
_FreeverbFilter_getParamMax
_FreeverbFilter_getParamMin
_FreeverbFilter_getParamName
_FreeverbFilter_getParamType
_FreeverbFilter_setParams
_LofiFilter_create
_LofiFilter_destroy
_LofiFilter_getParamCount
_LofiFilter_getParamMax
_LofiFilter_getParamMin
_LofiFilter_getParamName
_LofiFilter_getParamType
_LofiFilter_setParams
_Monotone_create
_Monotone_destroy
_Monotone_getLoopPoint
_Monotone_load
_Monotone_loadFile
_Monotone_loadMem
_Monotone_loadMemEx
_Monotone_set3dAttenuation
_Monotone_set3dAttenuator
_Monotone_set3dCollider
_Monotone_set3dColliderEx
_Monotone_set3dDistanceDelay
_Monotone_set3dDopplerFactor
_Monotone_set3dListenerRelative
_Monotone_set3dMinMaxDistance
_Monotone_setFilter
_Monotone_setInaudibleBehavior
_Monotone_setLoopPoint
_Monotone_setLooping
_Monotone_setParams
_Monotone_setParamsEx
_Monotone_setVolume
_Monotone_stop
_Noise_create
_Noise_destroy
_Noise_getLoopPoint
_Noise_set3dAttenuation
_Noise_set3dAttenuator
_Noise_set3dCollider
_Noise_set3dColliderEx
_Noise_set3dDistanceDelay
_Noise_set3dDopplerFactor
_Noise_set3dListenerRelative
_Noise_set3dMinMaxDistance
_Noise_setFilter
_Noise_setInaudibleBehavior
_Noise_setLoopPoint
_Noise_setLooping
_Noise_setOctaveScale
_Noise_setType
_Noise_setVolume
_Noise_stop
_Openmpt_create
_Openmpt_destroy
_Openmpt_getLoopPoint
_Openmpt_load
_Openmpt_loadFile
_Openmpt_loadMem
_Openmpt_loadMemEx
_Openmpt_set3dAttenuation
_Openmpt_set3dAttenuator
_Openmpt_set3dCollider
_Openmpt_set3dColliderEx
_Openmpt_set3dDistanceDelay
_Openmpt_set3dDopplerFactor
_Openmpt_set3dListenerRelative
_Openmpt_set3dMinMaxDistance
_Openmpt_setFilter
_Openmpt_setInaudibleBehavior
_Openmpt_setLoopPoint
_Openmpt_setLooping
_Openmpt_setVolume
_Openmpt_stop
_Queue_create
_Queue_destroy
_Queue_getLoopPoint
_Queue_getQueueCount
_Queue_isCurrentlyPlaying
_Queue_play
_Queue_set3dAttenuation
_Queue_set3dAttenuator
_Queue_set3dCollider
_Queue_set3dColliderEx
_Queue_set3dDistanceDelay
_Queue_set3dDopplerFactor
_Queue_set3dListenerRelative
_Queue_set3dMinMaxDistance
_Queue_setFilter
_Queue_setInaudibleBehavior
_Queue_setLoopPoint
_Queue_setLooping
_Queue_setParams
_Queue_setParamsEx
_Queue_setParamsFromAudioSource
_Queue_setVolume
_Queue_stop
_RobotizeFilter_create
_RobotizeFilter_destroy
_RobotizeFilter_getParamCount
_RobotizeFilter_getParamMax
_RobotizeFilter_getParamMin
_RobotizeFilter_getParamName
_RobotizeFilter_getParamType
_RobotizeFilter_setParams
_Sfxr_create
_Sfxr_destroy
_Sfxr_getLoopPoint
_Sfxr_loadParams
_Sfxr_loadParamsFile
_Sfxr_loadParamsMem
_Sfxr_loadParamsMemEx
_Sfxr_loadPreset
_Sfxr_resetParams
_Sfxr_set3dAttenuation
_Sfxr_set3dAttenuator
_Sfxr_set3dCollider
_Sfxr_set3dColliderEx
_Sfxr_set3dDistanceDelay
_Sfxr_set3dDopplerFactor
_Sfxr_set3dListenerRelative
_Sfxr_set3dMinMaxDistance
_Sfxr_setFilter
_Sfxr_setInaudibleBehavior
_Sfxr_setLoopPoint
_Sfxr_setLooping
_Sfxr_setVolume
_Sfxr_stop
_Soloud_addVoiceToGroup
_Soloud_calcFFT
_Soloud_countAudioSource
_Soloud_create
_Soloud_createVoiceGroup
_Soloud_deinit
_Soloud_destroy
_Soloud_destroyVoiceGroup
_Soloud_fadeFilterParameter
_Soloud_fadeGlobalVolume
_Soloud_fadePan
_Soloud_fadeRelativePlaySpeed
_Soloud_fadeVolume
_Soloud_get3dSoundSpeed
_Soloud_getActiveVoiceCount
_Soloud_getApproximateVolume
_Soloud_getBackendBufferSize
_Soloud_getBackendChannels
_Soloud_getBackendId
_Soloud_getBackendSamplerate
_Soloud_getBackendString
_Soloud_getErrorString
_Soloud_getFilterParameter
_Soloud_getGlobalVolume
_Soloud_getInfo
_Soloud_getLoopCount
_Soloud_getLoopPoint
_Soloud_getLooping
_Soloud_getMaxActiveVoiceCount
_Soloud_getOverallVolume
_Soloud_getPan
_Soloud_getPause
_Soloud_getPostClipScaler
_Soloud_getProtectVoice
_Soloud_getRelativePlaySpeed
_Soloud_getSamplerate
_Soloud_getSpeakerPosition
_Soloud_getStreamPosition
_Soloud_getStreamTime
_Soloud_getVersion
_Soloud_getVoiceCount
_Soloud_getVolume
_Soloud_getWave
_Soloud_init
_Soloud_initEx
_Soloud_isValidVoiceHandle
_Soloud_isVoiceGroup
_Soloud_isVoiceGroupEmpty
_Soloud_mix
_Soloud_mixSigned16
_Soloud_oscillateFilterParameter
_Soloud_oscillateGlobalVolume
_Soloud_oscillatePan
_Soloud_oscillateRelativePlaySpeed
_Soloud_oscillateVolume
_Soloud_play
_Soloud_play3d
_Soloud_play3dClocked
_Soloud_play3dClockedEx
_Soloud_play3dEx
_Soloud_playBackground
_Soloud_playBackgroundEx
_Soloud_playClocked
_Soloud_playClockedEx
_Soloud_playEx
_Soloud_schedulePause
_Soloud_scheduleStop
_Soloud_seek
_Soloud_set3dListenerAt
_Soloud_set3dListenerParameters
_Soloud_set3dListenerParametersEx
_Soloud_set3dListenerPosition
_Soloud_set3dListenerUp
_Soloud_set3dListenerVelocity
_Soloud_set3dSoundSpeed
_Soloud_set3dSourceAttenuation
_Soloud_set3dSourceDopplerFactor
_Soloud_set3dSourceMinMaxDistance
_Soloud_set3dSourceParameters
_Soloud_set3dSourceParametersEx
_Soloud_set3dSourcePosition
_Soloud_set3dSourceVelocity
_Soloud_setDelaySamples
_Soloud_setFilterParameter
_Soloud_setGlobalFilter
_Soloud_setGlobalVolume
_Soloud_setInaudibleBehavior
_Soloud_setLoopPoint
_Soloud_setLooping
_Soloud_setMaxActiveVoiceCount
_Soloud_setPan
_Soloud_setPanAbsolute
_Soloud_setPanAbsoluteEx
_Soloud_setPause
_Soloud_setPauseAll
_Soloud_setPostClipScaler
_Soloud_setProtectVoice
_Soloud_setRelativePlaySpeed
_Soloud_setSamplerate
_Soloud_setSpeakerPosition
_Soloud_setVisualizationEnable
_Soloud_setVolume
_Soloud_stop
_Soloud_stopAll
_Soloud_stopAudioSource
_Soloud_update3dAudio
_Speech_create
_Speech_destroy
_Speech_getLoopPoint
_Speech_set3dAttenuation
_Speech_set3dAttenuator
_Speech_set3dCollider
_Speech_set3dColliderEx
_Speech_set3dDistanceDelay
_Speech_set3dDopplerFactor
_Speech_set3dListenerRelative
_Speech_set3dMinMaxDistance
_Speech_setFilter
_Speech_setInaudibleBehavior
_Speech_setLoopPoint
_Speech_setLooping
_Speech_setParams
_Speech_setParamsEx
_Speech_setText
_Speech_setVolume
_Speech_stop
_TedSid_create
_TedSid_destroy
_TedSid_getLoopPoint
_TedSid_load
_TedSid_loadFile
_TedSid_loadFileToMem
_TedSid_loadMem
_TedSid_loadMemEx
_TedSid_loadToMem
_TedSid_set3dAttenuation
_TedSid_set3dAttenuator
_TedSid_set3dCollider
_TedSid_set3dColliderEx
_TedSid_set3dDistanceDelay
_TedSid_set3dDopplerFactor
_TedSid_set3dListenerRelative
_TedSid_set3dMinMaxDistance
_TedSid_setFilter
_TedSid_setInaudibleBehavior
_TedSid_setLoopPoint
_TedSid_setLooping
_TedSid_setVolume
_TedSid_stop
_Vic_create
_Vic_destroy
_Vic_getLoopPoint
_Vic_getModel
_Vic_getRegister
_Vic_set3dAttenuation
_Vic_set3dAttenuator
_Vic_set3dCollider
_Vic_set3dColliderEx
_Vic_set3dDistanceDelay
_Vic_set3dDopplerFactor
_Vic_set3dListenerRelative
_Vic_set3dMinMaxDistance
_Vic_setFilter
_Vic_setInaudibleBehavior
_Vic_setLoopPoint
_Vic_setLooping
_Vic_setModel
_Vic_setRegister
_Vic_setVolume
_Vic_stop
_Vizsn_create
_Vizsn_destroy
_Vizsn_getLoopPoint
_Vizsn_set3dAttenuation
_Vizsn_set3dAttenuator
_Vizsn_set3dCollider
_Vizsn_set3dColliderEx
_Vizsn_set3dDistanceDelay
_Vizsn_set3dDopplerFactor
_Vizsn_set3dListenerRelative
_Vizsn_set3dMinMaxDistance
_Vizsn_setFilter
_Vizsn_setInaudibleBehavior
_Vizsn_setLoopPoint
_Vizsn_setLooping
_Vizsn_setText
_Vizsn_setVolume
_Vizsn_stop
_WavStream_create
_WavStream_destroy
_WavStream_getLength
_WavStream_getLoopPoint
_WavStream_load
_WavStream_loadFile
_WavStream_loadFileToMem
_WavStream_loadMem
_WavStream_loadMemEx
_WavStream_loadToMem
_WavStream_set3dAttenuation
_WavStream_set3dAttenuator
_WavStream_set3dCollider
_WavStream_set3dColliderEx
_WavStream_set3dDistanceDelay
_WavStream_set3dDopplerFactor
_WavStream_set3dListenerRelative
_WavStream_set3dMinMaxDistance
_WavStream_setFilter
_WavStream_setInaudibleBehavior
_WavStream_setLoopPoint
_WavStream_setLooping
_WavStream_setVolume
_WavStream_stop
_Wav_create
_Wav_destroy
_Wav_getLength
_Wav_getLoopPoint
_Wav_load
_Wav_loadFile
_Wav_loadMem
_Wav_loadMemEx
_Wav_loadRawWave
_Wav_loadRawWave16
_Wav_loadRawWave16Ex
_Wav_loadRawWave8
_Wav_loadRawWave8Ex
_Wav_loadRawWaveEx
_Wav_set3dAttenuation
_Wav_set3dAttenuator
_Wav_set3dCollider
_Wav_set3dColliderEx
_Wav_set3dDistanceDelay
_Wav_set3dDopplerFactor
_Wav_set3dListenerRelative
_Wav_set3dMinMaxDistance
_Wav_setFilter
_Wav_setInaudibleBehavior
_Wav_setLoopPoint
_Wav_setLooping
_Wav_setVolume
_Wav_stop
_WaveShaperFilter_create
_WaveShaperFilter_destroy
_WaveShaperFilter_getParamCount
_WaveShaperFilter_getParamMax
_WaveShaperFilter_getParamMin
_WaveShaperFilter_getParamName
_WaveShaperFilter_getParamType
_WaveShaperFilter_setParams
_memset_pattern16
_Soloud_fft_bitrev_10
_Soloud_fft_bitrev_8
_Soloud_fft_trig_10
_Soloud_fft_trig_8
_Soloud_Filehack_fclose
_Soloud_Filehack_fgetc
_Soloud_Filehack_fopen
_Soloud_Filehack_fopen_s
_Soloud_Filehack_fread
_Soloud_Filehack_fseek
_Soloud_Filehack_ftell
_clock_gettime
_pthread_create
_pthread_join
_pthread_mutex_destroy
_pthread_mutex_init
_pthread_mutex_lock
_pthread_mutex_unlock
_pthread_mutexattr_init

SoLoud version, operating system, backend used, any other potentially useful information:
Version: soloud_20200207.zip <

Operating system: OSX

@bernardbaker
Copy link
Author

@jarikomppa hello... Do you have time to look at this?

@konsumer
Copy link

konsumer commented Apr 1, 2023

I did this on OSX to get wasm (using cmake, which you can install with brew install cmake):

git clone https://github.com/jarikomppa/soloud.git
cd soloud/build
emcmake cmake -DSOLOUD_BACKEND_SDL2=OFF -DSOLOUD_C_API=ON -DSOLOUD_BACKEND_NULL=ON -DSOLOUD_BUILD_DEMOS=ON ../contrib
make

This gives me libsoloud.a, which is a static lib for emscripten. It also builds the demos as wasm.

SoLoud_enumerate.js
SoLoud_enumerate.wasm
SoLoud_null.js
SoLoud_null.wasm
SoLoud_simplest.js
SoLoud_simplest.wasm
SoLoud_welcome.js
SoLoud_welcome.wasm
libsoloud.a

If you want to turn the .a file into a big wasm/js library:

emcc -s LINKABLE=1 -s EXPORT_ALL=1 libsoloud.a -o soloud.js

This exports a ton of random things, so is probably not exactly the right way (would be better to surgically export what you are actually using, from a C file with EMSCRIPTEN_KEEPALIVE instead of EXPORT_ALL.)

@konsumer
Copy link

konsumer commented Apr 1, 2023

You can also see some 1-off emscripten-builds in demos/emscripten, but it looks like the file-paths are messed up for preloaded assets.

@konsumer
Copy link

konsumer commented Apr 1, 2023

@ChaseCarlson why 😕 ?

If you have a look here you can see it references ../../bin/graphics/ which should be bin/, but that dir does not exist. It's not in the repo:

find . -name soloud_bg.png

Is it somewhere else?

@konsumer
Copy link

konsumer commented Apr 2, 2023

Played with it a bunch on my fork and I still can't get the right combo of engine/flags/js to be able to reach into the wasm and play things, but I think it's a start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants