Răsfoiți Sursa

cpu_features: add v0.9.0 version (#5691)

* cpu_features: add v0.9.0 version

* add alias

* fix cross-compilation

* fix android

* Revert "add alias"

This reverts commit 5a33f249f0e2e6f1ab6fdc13b796eaa9560707d3.
star9029 9 luni în urmă
părinte
comite
5409cad70d
1 a modificat fișierele cu 57 adăugiri și 9 ștergeri
  1. 57 9
      packages/c/cpu-features/xmake.lua

+ 57 - 9
packages/c/cpu-features/xmake.lua

@@ -1,31 +1,79 @@
 package("cpu-features")
 package("cpu-features")
-
     set_homepage("https://github.com/google/cpu_features")
     set_homepage("https://github.com/google/cpu_features")
     set_description("A cross platform C99 library to get cpu features at runtime.")
     set_description("A cross platform C99 library to get cpu features at runtime.")
     set_license("Apache-2.0")
     set_license("Apache-2.0")
 
 
-    add_urls("https://github.com/google/cpu_features/archive/$(version).tar.gz",
+    add_urls("https://github.com/google/cpu_features/archive/refs/tags/$(version).tar.gz",
              "https://github.com/google/cpu_features.git")
              "https://github.com/google/cpu_features.git")
+
     add_versions("v0.6.0", "95a1cf6f24948031df114798a97eea2a71143bd38a4d07d9a758dda3924c1932")
     add_versions("v0.6.0", "95a1cf6f24948031df114798a97eea2a71143bd38a4d07d9a758dda3924c1932")
     add_versions("v0.7.0", "df80d9439abf741c7d2fdcdfd2d26528b136e6c52976be8bd0cd5e45a27262c0")
     add_versions("v0.7.0", "df80d9439abf741c7d2fdcdfd2d26528b136e6c52976be8bd0cd5e45a27262c0")
+    add_versions("v0.9.0", "bdb3484de8297c49b59955c3b22dba834401bc2df984ef5cfc17acbe69c5018e")
 
 
-    add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
+    if is_plat("macosx") then
+        add_extsources("brew::cpu_features")
+    end
 
 
     add_deps("cmake")
     add_deps("cmake")
 
 
-    on_install("windows|x64", "windows|x86", "linux", "macosx", "android", function (package)
-        local configs = {"-DBUILD_TESTING=OFF"}
-        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
-        if package:is_plat("linux") then
-            table.insert(configs, "-DBUILD_PIC=ON")
+    on_install("!wasm", function (package)
+        if package:is_cross() then
+            local arch
+            if package:is_arch("arm.*") then
+                arch = (package:is_arch64() and "set(PROCESSOR_IS_AARCH64 TRUE)" or "set(PROCESSOR_IS_ARM TRUE)")
+                io.replace("CMakeLists.txt", "set(PROCESSOR_IS_X86 TRUE)", arch, {plain = true})
+            end
+        end
+
+        local configs = {"-DBUILD_TESTING=OFF", "-DENABLE_INSTALL=ON", "-DBUILD_EXECUTABLE=ON"}
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+        table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+        table.insert(configs, "-DCMAKE_POSITION_INDEPENDENT_CODE=" .. (package:config("pic") and "ON" or "OFF"))
+        table.insert(configs, "-DBUILD_PIC=" .. (package:config("pic") and "ON" or "OFF"))
+        if package:is_plat("cross", "iphoneos") then
+            table.insert(configs, "-DCMAKE_SYSTEM_PROCESSOR=" .. package:arch())
+        end
+        if package:config("shared") and package:is_plat("windows") then
+            table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
         end
         end
         import("package.tools.cmake").install(package, configs)
         import("package.tools.cmake").install(package, configs)
         package:addenv("PATH", "bin")
         package:addenv("PATH", "bin")
+
+        if package:is_plat("windows") and package:is_debug() then
+            local dir = package:installdir(package:config("shared") and "bin" or "lib")
+            os.vcp(path.join(package:buildir(), "*.pdb"), dir)
+        end
     end)
     end)
 
 
     on_test(function (package)
     on_test(function (package)
         if not package:is_cross() then
         if not package:is_cross() then
             os.vrun("list_cpu_features")
             os.vrun("list_cpu_features")
         end
         end
-        assert(package:has_ctypes("CacheLevelInfo", {includes = "cpu_features/cpu_features_cache_info.h"}))
+        assert(package:check_csnippets({test = [[
+            #include <cpu_features/cpu_features_macros.h>
+            #if defined(CPU_FEATURES_ARCH_X86)
+            #include <cpu_features/cpuinfo_x86.h>
+            #elif defined(CPU_FEATURES_ARCH_ARM)
+            #include <cpu_features/cpuinfo_arm.h>
+            #elif defined(CPU_FEATURES_ARCH_AARCH64)
+            #include <cpu_features/cpuinfo_aarch64.h>
+            #elif defined(CPU_FEATURES_ARCH_MIPS)
+            #include <cpu_features/cpuinfo_mips.h>
+            #elif defined(CPU_FEATURES_ARCH_PPC)
+            #include <cpu_features/ccpuinfo_ppc.h>
+            #endif
+            void test() {
+                #if defined(CPU_FEATURES_ARCH_X86)
+                    X86Features features = GetX86Info().features;
+                #elif defined(CPU_FEATURES_ARCH_ARM)
+                    ArmFeatures features = GetArmInfo().features;
+                #elif defined(CPU_FEATURES_ARCH_AARCH64)
+                    Aarch64Features features = GetAarch64Info().features;
+                #elif defined(CPU_FEATURES_ARCH_MIPS)
+                    MipsFeatures features = GetMipsInfo().features;
+                #elif defined(CPU_FEATURES_ARCH_PPC)
+                    PPCFeatures features = GetPPCInfo().features;
+                #endif
+            }
+        ]]}))
     end)
     end)