Skip to content

[libsoundio] Update to 2.0.1-7#13336

Merged
ViralBShah merged 1 commit intoJuliaPackaging:masterfrom
mj2984:master
Mar 29, 2026
Merged

[libsoundio] Update to 2.0.1-7#13336
ViralBShah merged 1 commit intoJuliaPackaging:masterfrom
mj2984:master

Conversation

@mj2984
Copy link
Copy Markdown
Contributor

@mj2984 mj2984 commented Mar 19, 2026

Added optimizations
export CFLAGS="-O3 -funroll-loops -fno-plt -flto"
export CXXFLAGS="${CFLAGS}"
export LDFLAGS="-Wl,-O1 -flto"

@ViralBShah ViralBShah marked this pull request as draft March 29, 2026 14:22
@ViralBShah
Copy link
Copy Markdown
Member

@mj2984 Just curious - Can you share why these optimizations are needed over and above the regular build process? Does this solve a performance issue you have run into?

@mj2984
Copy link
Copy Markdown
Contributor Author

mj2984 commented Mar 29, 2026

The library runs frequent callbacks (based on latency set) and the intention is to use it with https://github.com/mj2984/SoundIO.jl. This can be used not just with audio but also with any device that mimics an audio device and can leverage OS level optimizations for audio transport (eg closed loop motor control).

I do not have benchmarks to confirm, and the experiments are random (I'm one person working on this), but I feel that the reliability was better with these optimizations (though it could be from other parts of the code I changed later).

@ViralBShah ViralBShah marked this pull request as ready for review March 29, 2026 22:19
@ViralBShah
Copy link
Copy Markdown
Member

@mj2984 I have updated this to be less aggressive on GCC version, but added the performance flags. This should do everything you want - and we can bump things further if necessary - but it would be good to try this out and see how it performs.

@ViralBShah ViralBShah changed the title Create build_tarballs.jl for libsoundio_jll (version bump to 2.0.0+1) [libsoundio] Update to 2.0.1-7 Mar 29, 2026
Bump libsoundio from v2.0.0 to v2.0.1 (upstream tag 2.0.1-7).
Add -funroll-loops, -fno-plt, and LTO via CMake flags for
real-time audio callback performance. Patch MinGW GUID
redefinition errors (upstream PR JuliaPackaging#283).

Co-Authored-By: mj2984 <92405693+mj2984@users.noreply.github.com>
Co-Authored-By: Viral B. Shah <ViralBShah@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ViralBShah ViralBShah merged commit 00d4cf0 into JuliaPackaging:master Mar 29, 2026
20 checks passed
@mj2984
Copy link
Copy Markdown
Contributor Author

mj2984 commented Mar 30, 2026

Thanks for merging the update. I feel the worst-case scenario (callback returning to julia and back) seems to stutter more with the gcc8 version, but the best-case scenario works equally well. I'm unsure how to arrange a benchmark for this particular case. (for personal experiments with extreme scenarios, it looks safer using the custom jll built using the original script). I would personally prefer prioritizing performance and trade off compatibility with older systems, as the task is latency sensitive anyway.

@ViralBShah
Copy link
Copy Markdown
Member

ViralBShah commented Mar 30, 2026

Can you try to build a local JLL with this script and share what diff helps fix the stutter? The only difference here is that I am using GCC 8 instead of GCC 13. The rest of the build options should be the same.

If there is an observable improvement from your perspective, we can have a build with GCC 13. Since this is a C codebase, presumably there won't be issues with comptability with the dependencies and such.

@mj2984
Copy link
Copy Markdown
Contributor Author

mj2984 commented Mar 30, 2026

GCC = 13.2 (13.2 is the version I was originally suggested through binarybuilder) is more stable. I tried using the latest version of yggdrasil with the suggested changes and patchfixes, and just changing gcc version = 13.2 and it is better for the worst-case scenario (similar to the original commit).

# Build the tarballs
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; julia_compat="1.6", preferred_gcc_version = v"13.2.0")

Optional: I also ran a second test, by explicitly setting some optimizations (on windows, libsoundio connects to wasapi which is written in C++) just to be safe which also performs fine. This script change would be nice to have if it does not cause any other issues but is fine to skip otherwise.

Updated script is:

script = raw"""
cd $WORKSPACE/srcdir/libsoundio

# Fix MinGW GUID redefinition errors (upstream PR #283)
atomic_patch -p1 $WORKSPACE/srcdir/patches/fix-mingw-guid-redefinition.patch

# Initialize flags
CMAKE_FLAGS=("-DCMAKE_INSTALL_PREFIX=$prefix"
             "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN}"
             "-DCMAKE_BUILD_TYPE=Release"
             "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON"
             "-DCMAKE_C_FLAGS_RELEASE=-O3 -DNDEBUG -funroll-loops -fno-plt"
             "-DCMAKE_CXX_FLAGS_RELEASE=-O3 -DNDEBUG -funroll-loops -fno-plt"
             "-DBUILD_STATIC_LIBS=OFF"
             "-DBUILD_EXAMPLE_PROGRAMS=OFF"
             "-DBUILD_TESTS=OFF"
             "-DENABLE_JACK=OFF")

# Platform-specific backend configuration
case "${target}" in
    *linux*)
        CMAKE_FLAGS+=("-DENABLE_ALSA=ON" "-DENABLE_PULSEAUDIO=ON" "-DENABLE_COREAUDIO=OFF" "-DENABLE_WASAPI=OFF")
        ;;
    *apple*)
        CMAKE_FLAGS+=("-DENABLE_ALSA=OFF" "-DENABLE_PULSEAUDIO=OFF" "-DENABLE_COREAUDIO=ON" "-DENABLE_WASAPI=OFF")
        ;;
    *w64*)
        CMAKE_FLAGS+=("-DENABLE_ALSA=OFF" "-DENABLE_PULSEAUDIO=OFF" "-DENABLE_COREAUDIO=OFF" "-DENABLE_WASAPI=ON")
        ;;
    *)
        CMAKE_FLAGS+=("-DENABLE_ALSA=OFF" "-DENABLE_PULSEAUDIO=OFF" "-DENABLE_COREAUDIO=OFF" "-DENABLE_WASAPI=OFF")
        ;;
esac

# Explicit linker optimization
export LDFLAGS="-Wl,-O1"
cmake -B build "${CMAKE_FLAGS[@]}"
cmake --build build --parallel ${nproc}
cmake --install build

install_license ./LICENSE
"""

@ViralBShah
Copy link
Copy Markdown
Member

Is there a way to provide the linker flags through cmake. If you use claude, it may be able to help you find that. If not, then we'll do it this way.

May I request you to create a new PR on top of this one with these changes and the new gcc? The version number doesn't need to change.

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

Successfully merging this pull request may close these issues.

2 participants