Files
wz-phone/vendor/audiopus_sys/opus/opus.m4
Siavash Sameni 0683dde5d3
Some checks failed
Mirror to GitHub / mirror (push) Failing after 35s
Build Release Binaries / build-amd64 (push) Has been cancelled
fix(windows): vendor audiopus_sys + patch libopus for clang-cl SIMD
cargo-xwin drives the Windows MSVC cross-compile via clang-cl, under
which CMake sets MSVC=1 — causing libopus 1.3.1's `if(NOT MSVC)` guards
to skip the per-file `-msse4.1` / `-mssse3` COMPILE_FLAGS that its x86
SIMD source files need. Clang-cl (unlike real cl.exe) still honors
Clang's target-feature system, so those files then fail to compile
with "always_inline function '_mm_cvtepi16_epi32' requires target
feature 'sse4.1'" errors across silk/NSQ_sse4_1.c, NSQ_del_dec_sse4_1.c,
and VQ_WMat_EC_sse4_1.c.

Earlier attempts to fix this downstream (cargo-xwin toolchain file,
override.cmake CMAKE_C_COMPILE_OBJECT <FLAGS> replace, CFLAGS env vars)
all failed because cargo-xwin rewrites override.cmake from scratch on
every `cargo xwin build` invocation and cmake-rs's -DCMAKE_C_FLAGS=
assembly happens before toolchain FORCE sets propagate.

Fixing it upstream at the source: vendor audiopus_sys 0.2.2 into
vendor/audiopus_sys, patch its bundled opus/CMakeLists.txt to introduce
an MSVC_CL var (true only when CMAKE_C_COMPILER_ID == "MSVC", i.e. real
cl.exe), and flip the eight `if(NOT MSVC)` SIMD guards to
`if(NOT MSVC_CL)`. Clang-cl then gets the GCC-style per-file flags and
the SSE4.1 sources build cleanly. Also flip the `if(MSVC)` global /arch
block at line 445 to `if(MSVC_CL)` so only cl.exe applies /arch:AVX and
clang-cl relies purely on per-file flags (no global/per-file mixing).

Wire via [patch.crates-io] in the workspace root Cargo.toml; the patch
is resolved relative to the workspace root as `vendor/audiopus_sys`.

Upstream context: xiph/opus#256, xiph/opus PR #257 (both stale).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 14:12:59 +04:00

118 lines
4.0 KiB
Plaintext

# Configure paths for libopus
# Gregory Maxwell <greg@xiph.org> 08-30-2012
# Shamelessly stolen from Jack Moffitt (libogg) who
# Shamelessly stole from Owen Taylor and Manish Singh
dnl XIPH_PATH_OPUS([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
dnl Test for libopus, and define OPUS_CFLAGS and OPUS_LIBS
dnl
AC_DEFUN([XIPH_PATH_OPUS],
[dnl
dnl Get the cflags and libraries
dnl
AC_ARG_WITH(opus,AC_HELP_STRING([--with-opus=PFX],[Prefix where opus is installed (optional)]), opus_prefix="$withval", opus_prefix="")
AC_ARG_WITH(opus-libraries,AC_HELP_STRING([--with-opus-libraries=DIR],[Directory where the opus library is installed (optional)]), opus_libraries="$withval", opus_libraries="")
AC_ARG_WITH(opus-includes,AC_HELP_STRING([--with-opus-includes=DIR],[Directory where the opus header files are installed (optional)]), opus_includes="$withval", opus_includes="")
AC_ARG_ENABLE(opustest,AC_HELP_STRING([--disable-opustest],[Do not try to compile and run a test opus program]),, enable_opustest=yes)
if test "x$opus_libraries" != "x" ; then
OPUS_LIBS="-L$opus_libraries"
elif test "x$opus_prefix" = "xno" || test "x$opus_prefix" = "xyes" ; then
OPUS_LIBS=""
elif test "x$opus_prefix" != "x" ; then
OPUS_LIBS="-L$opus_prefix/lib"
elif test "x$prefix" != "xNONE" ; then
OPUS_LIBS="-L$prefix/lib"
fi
if test "x$opus_prefix" != "xno" ; then
OPUS_LIBS="$OPUS_LIBS -lopus"
fi
if test "x$opus_includes" != "x" ; then
OPUS_CFLAGS="-I$opus_includes"
elif test "x$opus_prefix" = "xno" || test "x$opus_prefix" = "xyes" ; then
OPUS_CFLAGS=""
elif test "x$opus_prefix" != "x" ; then
OPUS_CFLAGS="-I$opus_prefix/include"
elif test "x$prefix" != "xNONE"; then
OPUS_CFLAGS="-I$prefix/include"
fi
AC_MSG_CHECKING(for Opus)
if test "x$opus_prefix" = "xno" ; then
no_opus="disabled"
enable_opustest="no"
else
no_opus=""
fi
if test "x$enable_opustest" = "xyes" ; then
ac_save_CFLAGS="$CFLAGS"
ac_save_LIBS="$LIBS"
CFLAGS="$CFLAGS $OPUS_CFLAGS"
LIBS="$LIBS $OPUS_LIBS"
dnl
dnl Now check if the installed Opus is sufficiently new.
dnl
rm -f conf.opustest
AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <opus.h>
int main ()
{
system("touch conf.opustest");
return 0;
}
],, no_opus=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
if test "x$no_opus" = "xdisabled" ; then
AC_MSG_RESULT(no)
ifelse([$2], , :, [$2])
elif test "x$no_opus" = "x" ; then
AC_MSG_RESULT(yes)
ifelse([$1], , :, [$1])
else
AC_MSG_RESULT(no)
if test -f conf.opustest ; then
:
else
echo "*** Could not run Opus test program, checking why..."
CFLAGS="$CFLAGS $OPUS_CFLAGS"
LIBS="$LIBS $OPUS_LIBS"
AC_TRY_LINK([
#include <stdio.h>
#include <opus.h>
], [ return 0; ],
[ echo "*** The test program compiled, but did not run. This usually means"
echo "*** that the run-time linker is not finding Opus or finding the wrong"
echo "*** version of Opus. If it is not finding Opus, you'll need to set your"
echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
echo "*** to the installed location Also, make sure you have run ldconfig if that"
echo "*** is required on your system"
echo "***"
echo "*** If you have an old version installed, it is best to remove it, although"
echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
[ echo "*** The test program failed to compile or link. See the file config.log for the"
echo "*** exact error that occurred. This usually means Opus was incorrectly installed"
echo "*** or that you have moved Opus since it was installed." ])
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
OPUS_CFLAGS=""
OPUS_LIBS=""
ifelse([$2], , :, [$2])
fi
AC_SUBST(OPUS_CFLAGS)
AC_SUBST(OPUS_LIBS)
rm -f conf.opustest
])