From 0b2cd94cf43cfcdda40e74841eb36b901210a82a Mon Sep 17 00:00:00 2001 From: Yauhen Pahrabniak Date: Mon, 8 May 2023 23:05:14 +0200 Subject: [PATCH] Disabled AVX instructions to support ghetto PCs --- .../l/libopus/patches/1.3.1/cmake.patch | 13 ++++++++ localpkg/packages/l/libopus/xmake.lua | 32 +++++++++++++++++++ xmake.lua | 4 ++- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 localpkg/packages/l/libopus/patches/1.3.1/cmake.patch create mode 100644 localpkg/packages/l/libopus/xmake.lua diff --git a/localpkg/packages/l/libopus/patches/1.3.1/cmake.patch b/localpkg/packages/l/libopus/patches/1.3.1/cmake.patch new file mode 100644 index 0000000..79271ea --- /dev/null +++ b/localpkg/packages/l/libopus/patches/1.3.1/cmake.patch @@ -0,0 +1,13 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 17ee3fc2..9027d073 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -16,7 +16,6 @@ string(REGEX + message(STATUS "Opus project version: ${PROJECT_VERSION}") + + project(Opus LANGUAGES C VERSION ${PROJECT_VERSION}) +-include(opus_buildtype.cmake) + + option(OPUS_STACK_PROTECTOR "Use stack protection" ON) + option(OPUS_USE_ALLOCA "Use alloca for stack arrays (on non-C99 compilers)" OFF) + \ No newline at end of file diff --git a/localpkg/packages/l/libopus/xmake.lua b/localpkg/packages/l/libopus/xmake.lua new file mode 100644 index 0000000..1ad4a01 --- /dev/null +++ b/localpkg/packages/l/libopus/xmake.lua @@ -0,0 +1,32 @@ +package("libopus") + + set_homepage("https://opus-codec.org") + set_description("Modern audio compression for the internet.") + + set_urls("https://archive.mozilla.org/pub/opus/opus-$(version).tar.gz", + "https://gitlab.xiph.org/xiph/opus.git") + + add_versions("1.3.1", "65b58e1e25b2a114157014736a3d9dfeaad8d41be1c8179866f144a2fb44ff9d") + add_patches("1.3.1", path.join(os.scriptdir(), "patches", "1.3.1", "cmake.patch"), "603c746006d3f1f44700bc55fd46c2b466c5002b3612055af0216463a115c42f") + add_configs("avxSupported", { description = "AVX_SUPPORTED", default = true, type = "boolean" }) + add_configs("opusx86MayHaveAvx", { description = "OPUS_X86_MAY_HAVE_AVX", default = true, type = "boolean" }) + + add_deps("cmake") + + on_install("windows", "linux", "macosx", "iphoneos", "mingw", "android", function (package) + local configs = {} + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release")) + table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) + table.insert(configs, "-DAVX_SUPPORTED=" .. (package:config("avxSupported") and "ON" or "OFF")) + table.insert(configs, "-DOPUS_X86_MAY_HAVE_AVX=" .. (package:config("opusx86MayHaveAvx") and "ON" or "OFF")) + table.insert(configs, "-DCMAKE_POSITION_INDEPENDENT_CODE=ON") + if package:is_plat("mingw") then + -- Disable stack protection on MinGW since it causes link errors + table.insert(configs, "-DOPUS_STACK_PROTECTOR=OFF") + end + import("package.tools.cmake").install(package, configs) + end) + + on_test(function (package) + assert(package:has_cfuncs("opus_encoder_create", {includes = "opus/opus.h"})) + end) \ No newline at end of file diff --git a/xmake.lua b/xmake.lua index 5899c85..f4797a4 100644 --- a/xmake.lua +++ b/xmake.lua @@ -8,10 +8,11 @@ set_languages("cxx20", "cxx2a") set_runtimes(is_mode("debug") and "MDd" or "MD") set_symbols("debug") +add_repositories("local-repo localpkg") add_requires("bass", {verify = false}) add_requires("bass-fx", {verify = false}) -add_requires("libopus", {verify = false}) +add_requires("libopus", {verify = false, configs = { avxSupported = false, opusx86MayHaveAvx = false }}) add_requires("rnnoise f75e7dd", {verify = false}) target("alt-voice") @@ -22,6 +23,7 @@ target("alt-voice") add_headerfiles("src/**.h", "include/**.h") add_includedirs("src/", "include/", { public = true }) add_packages("bass", "bass-fx", "libopus", "rnnoise") + after_build(function (target) for pkg, pkg_details in pairs(target:pkgs()) do if os.isdir(pkg_details._INFO.installdir) then