From 4db73990af0b64b50d0329f52d7982481bba1f97 Mon Sep 17 00:00:00 2001 From: DreamOfIce Date: Mon, 18 Sep 2023 00:10:04 +0800 Subject: [PATCH] fix(libvpx): fix wasm build --- packages/l/libvpx/port/xmake.lua | 65 ++++++++++--------- packages/l/libvpx/port/xmake/scripts/rtcd.lua | 14 ++++ .../l/libvpx/port/xmake/scripts/utils.lua | 11 ++-- 3 files changed, 53 insertions(+), 37 deletions(-) diff --git a/packages/l/libvpx/port/xmake.lua b/packages/l/libvpx/port/xmake.lua index cfd64398eac..508e250a1cb 100644 --- a/packages/l/libvpx/port/xmake.lua +++ b/packages/l/libvpx/port/xmake.lua @@ -5,8 +5,36 @@ includes("check_csnippets.lua") add_moduledirs("xmake/scripts") add_imports("core.project.project", "lib.detect.find_tool", "rtcd", "utils") add_rules("asm", "mode.debug", "mode.release") +set_languages("gnu89") set_config("buildir", "xmake_build") +local arch, fullarch +if is_arch("x86") then + arch = "x86" + fullarch = "x86" +elseif is_arch("x64", "x86_64") then + arch = "x86" + fullarch = "x86_64" +elseif is_arch("aarch64.*", "armv8.*") then + arch = "arm" + fullarch = "aarch64" +elseif is_arch("arm.*") then + arch = "arm" + fullarch = "arm" +elseif is_arch("loongarch.*") then + arch = "loongarch" + fullarch = "loongarch" +elseif is_arch("mips.*") then + arch = "mips" + fullarch = "mips" +elseif is_arch("ppc.*", "powerpc.*") then + arch = "ppc" + fullarch = "ppc" +else + arch = "unknown" + fullarch = "" +end + option("vp8", function() add_deps("vp8-encoder", "vp8-decoder") set_description("VP8 codec support") @@ -151,6 +179,11 @@ end) option("runtime-cpu-detect", function() set_description("runtime cpu detection") set_default(true) + after_check(function(opt) + if arch == "unknown" then + opt:enable(false) + end + end) end) option("multi-res-encoding", function() @@ -179,34 +212,6 @@ option("libyuv", function() set_default(false) end) --- platform extendtions -local arch, fullarch - -if is_arch("x86") then - arch = "x86" - fullarch = "x86" -elseif is_arch("x64", "x86_64") then - arch = "x86" - fullarch = "x86_64" -elseif is_arch("aarch64.*", "armv8.*") then - arch = "arm" - fullarch = "aarch64" -elseif is_arch("arm.*") then - arch = "arm" - fullarch = "arm" -elseif is_arch("loongarch.*") then - arch = "loongarch" - fullarch = "loongarch" -elseif is_arch("mips.*") then - arch = "mips" - fullarch = "mips" -elseif is_arch("ppc.*", "powerpc.*") then - arch = "ppc" - fullarch = "ppc" -else - arch = "unknown" -end - local exts = { x86 = {{ name = "mmx", @@ -309,10 +314,6 @@ on_load(function(target) target:add("cxflags", "-mfloat-abi=soft") end end - - if project.option("pic") or vformat("$(kind)") == "shared" then - -- target:add("cxflags", "-fPIC") - end end end) diff --git a/packages/l/libvpx/port/xmake/scripts/rtcd.lua b/packages/l/libvpx/port/xmake/scripts/rtcd.lua index 32bfd10a492..050598aee25 100644 --- a/packages/l/libvpx/port/xmake/scripts/rtcd.lua +++ b/packages/l/libvpx/port/xmake/scripts/rtcd.lua @@ -116,6 +116,19 @@ static void setup_rtcd_internal(void) suffix = [[ } #endif +]] + }, + unknown = { + prefix = [[ +#include "vpx_config.h" + +#ifdef RTCD_C +static void setup_rtcd_internal(void) +{ +]], + suffix = [[ +} +#endif ]] } } @@ -275,6 +288,7 @@ function _write_header(output, arch, all_exts, functions, aliases, decls) file:write(setup[arch].prefix) file:write(rtcd_content) file:write(setup[arch].suffix) + file:write("void " .. path.basename(output):gsub("%-", "_") .. "();\n") -- avoid emscripten/emscripten-core#2175 file:write(common_buttom) file:close() end diff --git a/packages/l/libvpx/port/xmake/scripts/utils.lua b/packages/l/libvpx/port/xmake/scripts/utils.lua index c01cc18a06c..fa2ed937243 100644 --- a/packages/l/libvpx/port/xmake/scripts/utils.lua +++ b/packages/l/libvpx/port/xmake/scripts/utils.lua @@ -42,11 +42,12 @@ function add_arch_files(target, prefix, arch, fullarch, all_exts) end end for _, ext in ipairs(exts) do - for _, file in ipairs(table.join(os.files(path.join(prefix, arch, "**_" .. ext .. ".*|*.h")), - os.files(path.join(prefix, arch, "**_" .. arch .. ".*|*.h")), - os.files(path.join(prefix, arch, "**_" .. fullarch .. ".*|*.h")), - os.files(path.join(prefix, "generic", "*.*|*.h")))) do - target:add("files", file) + for _, file in ipairs(table.join(os.files(path.join(prefix, arch, "**_" .. ext .. ".*")), + os.files(path.join(prefix, arch, "**_" .. arch .. ".*")), + os.files(path.join(prefix, arch, "**_" .. fullarch .. ".*")), os.files(path.join(prefix, "generic", "*")))) do + if path.extension(file) ~= ".h" then + target:add("files", file) + end end end end