瀏覽代碼

update cpuinfo (#2354)

* update cpuinfo

* fix missing syslink

* try fix cpuinfo on windows arm
Hoildkv 2 年之前
父節點
當前提交
8b5963de94
共有 1 個文件被更改,包括 19 次插入9 次删除
  1. 19 9
      packages/c/cpuinfo/xmake.lua

+ 19 - 9
packages/c/cpuinfo/xmake.lua

@@ -1,20 +1,20 @@
 package("cpuinfo")
     set_homepage("https://github.com/pytorch/cpuinfo")
     set_description("CPU INFOrmation library (x86/x86-64/ARM/ARM64, Linux/Windows/Android/macOS/iOS)")
-    set_license("BSD 2-Clause")
+    set_license("BSD-2-Clause")
 
     add_urls("https://github.com/pytorch/cpuinfo.git")
     add_versions("2022.09.15", "de2fa78ebb431db98489e78603e4f77c1f6c5c57")
-
-    add_deps("cmake")
+    add_versions("2023.07.21", "60480b7098c8ddc73d611285fc478dec66e4edf9")
 
     if is_plat("windows") then
-        add_configs("shared",     {description = "Build shared library.", default = false, type = "boolean", readonly = true})
-        add_configs("vs_runtime", {description = "Set vs compiler runtime.", default = "MT", readonly = true})
+        add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
     end
 
-    add_links("cpuinfo", "clog")
-    if is_plat("linux", "macosx", "bsd") then
+    add_deps("cmake")
+    if is_plat("windows") then
+        add_syslinks("advapi32")
+    elseif is_plat("linux", "macosx", "bsd") then
         add_syslinks("pthread")
     end
 
@@ -25,7 +25,17 @@ package("cpuinfo")
                          "-DCPUINFO_BUILD_BENCHMARKS=OFF",
                          "-DCPUINFO_BUILD_PKG_CONFIG=OFF"}
         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, "-DCPUINFO_LIBRARY_TYPE=" .. (package:config("shared") and "shared" or "static"))
+        if package:is_plat("windows") then
+            table.insert(configs, "-DCPUINFO_RUNTIME_TYPE=" .. (package:config("vs_runtime"):startswith("MT") and "static" or "shared"))
+            local vs_sdkver = import("core.tool.toolchain").load("msvc"):config("vs_sdkver")
+            if vs_sdkver then
+                local build_ver = string.match(vs_sdkver, "%d+%.%d+%.(%d+)%.?%d*")
+                assert(tonumber(build_ver) >= 18362, "cpuinfo requires Windows SDK to be at least 10.0.18362.0")
+                table.insert(configs, "-DCMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION=" .. vs_sdkver)
+                table.insert(configs, "-DCMAKE_SYSTEM_VERSION=" .. vs_sdkver)
+            end
+        end
         import("package.tools.cmake").install(package, configs)
     end)
 
@@ -34,7 +44,7 @@ package("cpuinfo")
             #include <iostream>
             void test(int args, char** argv) {
                 cpuinfo_initialize();
-                std::cout << "Running on %s CPU " << cpuinfo_get_package(0)->name;
+                std::cout << "Running on CPU " << cpuinfo_get_package(0)->name;
             }
         ]]}, {configs = {languages = "c++11"}, includes = "cpuinfo.h"}))
     end)