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>
87 lines
3.3 KiB
Python
Executable File
87 lines
3.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
#
|
|
# Opus get-version.py
|
|
#
|
|
# Extracts versions for build:
|
|
# - Opus package version based on 'git describe' or $srcroot/package_version
|
|
# - libtool version based on configure.ac
|
|
# - macos lib version based on configure.ac
|
|
#
|
|
# Usage:
|
|
# get-version.py [--package-version | --libtool-version | --darwin-version]
|
|
import argparse
|
|
import subprocess
|
|
import os
|
|
import sys
|
|
import shutil
|
|
|
|
if __name__ == '__main__':
|
|
arg_parser = argparse.ArgumentParser(description='Extract Opus package version or libtool version')
|
|
group = arg_parser.add_mutually_exclusive_group(required=True)
|
|
group.add_argument('--libtool-version', action='store_true')
|
|
group.add_argument('--package-version', action='store_true')
|
|
group.add_argument('--darwin-version', action='store_true')
|
|
args = arg_parser.parse_args()
|
|
|
|
srcroot = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
# package version
|
|
if args.package_version:
|
|
package_version = None
|
|
|
|
# check if git checkout
|
|
git_dir = os.path.join(srcroot, '.git')
|
|
is_git = os.path.isdir(git_dir)
|
|
have_git = shutil.which('git') is not None
|
|
|
|
if is_git and have_git:
|
|
git_cmd = subprocess.run(['git', '--git-dir=' + git_dir, 'describe', 'HEAD'], stdout=subprocess.PIPE)
|
|
if git_cmd.returncode:
|
|
print('ERROR: Could not extract package version via `git describe` in', srcroot, file=sys.stderr)
|
|
sys.exit(-1)
|
|
package_version = git_cmd.stdout.decode('ascii').strip().lstrip('v')
|
|
else:
|
|
with open(os.path.join(srcroot, 'package_version'), 'r') as f:
|
|
for line in f:
|
|
if line.startswith('PACKAGE_VERSION="'):
|
|
package_version = line[17:].strip().lstrip('v').rstrip('"')
|
|
if package_version:
|
|
break
|
|
|
|
if not package_version:
|
|
print('ERROR: Could not extract package version from package_version file in', srcroot, file=sys.stderr)
|
|
sys.exit(-1)
|
|
|
|
print(package_version)
|
|
sys.exit(0)
|
|
|
|
# libtool version + darwin version
|
|
elif args.libtool_version or args.darwin_version:
|
|
opus_lt_cur = None
|
|
opus_lt_rev = None
|
|
opus_lt_age = None
|
|
|
|
with open(os.path.join(srcroot, 'configure.ac'), 'r') as f:
|
|
for line in f:
|
|
if line.strip().startswith('OPUS_LT_CURRENT='):
|
|
opus_lt_cur = line[16:].strip()
|
|
elif line.strip().startswith('OPUS_LT_REVISION='):
|
|
opus_lt_rev = line[17:].strip()
|
|
elif line.strip().startswith('OPUS_LT_AGE='):
|
|
opus_lt_age = line[12:].strip()
|
|
|
|
if opus_lt_cur and opus_lt_rev and opus_lt_age:
|
|
opus_lt_cur = int(opus_lt_cur)
|
|
opus_lt_rev = int(opus_lt_rev)
|
|
opus_lt_age = int(opus_lt_age)
|
|
if args.libtool_version:
|
|
print('{}.{}.{}'.format(opus_lt_cur - opus_lt_age, opus_lt_age, opus_lt_rev))
|
|
elif args.darwin_version:
|
|
print('{}.{}.{}'.format(opus_lt_cur + 1, 0, 0))
|
|
sys.exit(0)
|
|
else:
|
|
print('ERROR: Could not extract libtool version from configure.ac file in', srcroot, file=sys.stderr)
|
|
sys.exit(-1)
|
|
else:
|
|
sys.exit(-1)
|