From 9bfa000cbd6c9386fea3fcfafe71f443de84b39c Mon Sep 17 00:00:00 2001 From: Rick Guo Date: Thu, 10 Sep 2026 11:28:29 +0800 Subject: [PATCH 1/2] formula: add anrieff/libcpuid --- .../libcpuid/v0.5.0/0.5.0-cmake-fixes.patch | 45 +++++++ anrieff/libcpuid/v0.5.0/libcpuid_llar.gox | 114 ++++++++++++++++++ anrieff/libcpuid/v0.6.0/libcpuid_llar.gox | 110 +++++++++++++++++ anrieff/libcpuid/v0.7.0/libcpuid_llar.gox | 111 +++++++++++++++++ anrieff/libcpuid/versions.json | 4 + 5 files changed, 384 insertions(+) create mode 100644 anrieff/libcpuid/v0.5.0/0.5.0-cmake-fixes.patch create mode 100644 anrieff/libcpuid/v0.5.0/libcpuid_llar.gox create mode 100644 anrieff/libcpuid/v0.6.0/libcpuid_llar.gox create mode 100644 anrieff/libcpuid/v0.7.0/libcpuid_llar.gox create mode 100644 anrieff/libcpuid/versions.json diff --git a/anrieff/libcpuid/v0.5.0/0.5.0-cmake-fixes.patch b/anrieff/libcpuid/v0.5.0/0.5.0-cmake-fixes.patch new file mode 100644 index 0000000..95f4252 --- /dev/null +++ b/anrieff/libcpuid/v0.5.0/0.5.0-cmake-fixes.patch @@ -0,0 +1,45 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -27,4 +27,3 @@ endif(UNIX) + # Include subdirectories + add_subdirectory(libcpuid) + add_subdirectory(cpuid_tool) +-add_subdirectory(tests) +--- a/cpuid_tool/CMakeLists.txt ++++ b/cpuid_tool/CMakeLists.txt +@@ -2,7 +2,7 @@ add_executable(cpuid_tool cpuid_tool.c) + + target_link_libraries(cpuid_tool cpuid) + +-if(WIN32) ++if(0) + install( + TARGETS cpuid_tool + CONFIGURATIONS Debug +@@ -12,5 +12,5 @@ if(WIN32) + CONFIGURATIONS Release + RUNTIME DESTINATION bin/Release) + else() +- install(TARGETS cpuid_tool RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) ++ install(TARGETS cpuid_tool DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() +--- a/libcpuid/CMakeLists.txt ++++ b/libcpuid/CMakeLists.txt +@@ -13,7 +13,7 @@ if("${MSVC_CXX_ARCHITECTURE_ID}" MATCHES "x64") + endif() + + if(UNIX) +- add_library(cpuid SHARED ${cpuid_sources}) ++ add_library(cpuid ${cpuid_sources}) + else() + add_library(cpuid ${cpuid_sources}) + endif() +@@ -67,7 +67,7 @@ include(CMakePackageConfigHelpers) + write_basic_package_version_file("${version_config}" COMPATIBILITY SameMajorVersion) + + # Configure 'Config.cmake' Use variables: * TARGETS_EXPORT_NAME * PROJECT_NAME +-configure_package_config_file("${CMAKE_MODULE_PATH}/Config.cmake.in" "${project_config}" ++configure_package_config_file("${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in" "${project_config}" + INSTALL_DESTINATION "${config_install_dir}") + + # Installation diff --git a/anrieff/libcpuid/v0.5.0/libcpuid_llar.gox b/anrieff/libcpuid/v0.5.0/libcpuid_llar.gox new file mode 100644 index 0000000..992c908 --- /dev/null +++ b/anrieff/libcpuid/v0.5.0/libcpuid_llar.gox @@ -0,0 +1,114 @@ +import ( + "os" + "path/filepath" + "slices" +) + +const consumerSource = `#include "libcpuid/libcpuid.h" + +#include + +int main(void) +{ + if (!cpuid_present()) { + return 1; + } + + struct cpu_raw_data_t raw; + struct cpu_id_t data; + if (cpuid_get_raw_data(&raw) < 0) { + return 2; + } + if (cpu_identify(&raw, &data) < 0) { + return 3; + } + + printf("%s %s\n", data.vendor_str, data.cpu_codename); + return 0; +} +` + +id "anrieff/libcpuid" + +fromVer "v0.5.0" + +defaults { + "shared": "OFF", + "fPIC": "ON", +} + +filter => { + for name, values in target.options { + if name != "shared" && name != "fPIC" { + return false + } + for value in values { + if value != "ON" && value != "OFF" { + return false + } + } + } + return slices.contains(target.require["arch"], "amd64") +} + +onBuild ctx => { + installDir := ctx.outputDir + + patch := ctx.Proj.readFile("v0.5.0/0.5.0-cmake-fixes.patch")! + patchPath := filepath.join(ctx.SourceDir, "_llar_cmake-fixes.patch") + os.writeFile(patchPath, patch, 0o644)! + git! "apply", "--unidiff-zero", patchPath + + shared := target.options["shared"][0] == "ON" + fPIC := target.options["fPIC"][0] == "ON" + c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) + c.defineBool "BUILD_SHARED_LIBS", shared + c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC + c.defineBool "CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS", shared + c.defineBool "ENABLE_DOCS", false + c.configure + c.build + c.install + + licenseDir := filepath.join(installDir, "licenses") + os.mkdirAll(licenseDir, 0o755)! + os.writeFile(filepath.join(licenseDir, "COPYING"), os.readFile(filepath.join(ctx.SourceDir, "COPYING"))!, 0o644)! + + pcDir := filepath.join(installDir, "lib", "pkgconfig") + os.mkdirAll(pcDir, 0o755)! + pc := pkgconfig.new( + name = "libcpuid", + description = "libcpuid provides CPU identification for x86", + version = "v0.5.0", + libs = ["-L$${libdir}", "-lcpuid"], + cflags = ["-I$${includedir}"], + )! + out := os.create(filepath.join(pcDir, "libcpuid.pc"))! + pc.writeTo(out)! + out.close()! + + pkgconfig.use installDir + ctx.setMetadata pkgconfig.lookup("libcpuid")! +} + +onTest ctx => { + installDir := ctx.outputDir + testDir := filepath.join(ctx.SourceDir, "_llar_consumer") + os.mkdirAll(testDir, 0o755)! + + consumer := filepath.join(testDir, "consumer.c") + os.writeFile(consumer, []byte(consumerSource), 0o644)! + + pkgconfig.use installDir + binary := filepath.join(testDir, "consumer") + flagsFile := filepath.join(testDir, "libcpuid.flags") + os.writeFile(flagsFile, []byte(pkgconfig.lookup("libcpuid")!), 0o644)! + cc! consumer, "-o", binary, "@"+flagsFile + + if target.options["shared"][0] == "ON" { + os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + } + exec! binary + exec! filepath.join(installDir, "bin", "cpuid_tool"), "--report" +} diff --git a/anrieff/libcpuid/v0.6.0/libcpuid_llar.gox b/anrieff/libcpuid/v0.6.0/libcpuid_llar.gox new file mode 100644 index 0000000..8fc9108 --- /dev/null +++ b/anrieff/libcpuid/v0.6.0/libcpuid_llar.gox @@ -0,0 +1,110 @@ +import ( + "os" + "path/filepath" + "slices" +) + +const consumerSource = `#include "libcpuid/libcpuid.h" + +#include + +int main(void) +{ + if (!cpuid_present()) { + return 1; + } + + struct cpu_raw_data_t raw; + struct cpu_id_t data; + if (cpuid_get_raw_data(&raw) < 0) { + return 2; + } + if (cpu_identify(&raw, &data) < 0) { + return 3; + } + + printf("%s %s\n", data.vendor_str, data.cpu_codename); + return 0; +} +` + +id "anrieff/libcpuid" + +fromVer "v0.6.0" + +defaults { + "shared": "OFF", + "fPIC": "ON", +} + +filter => { + for name, values in target.options { + if name != "shared" && name != "fPIC" { + return false + } + for value in values { + if value != "ON" && value != "OFF" { + return false + } + } + } + return slices.contains(target.require["arch"], "amd64") +} + +onBuild ctx => { + installDir := ctx.outputDir + shared := target.options["shared"][0] == "ON" + fPIC := target.options["fPIC"][0] == "ON" + + c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) + c.defineBool "BUILD_SHARED_LIBS", shared + c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC + c.defineBool "CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS", shared + c.defineBool "ENABLE_DOCS", false + c.defineBool "LIBCPUID_TESTS", false + c.configure + c.build + c.install + + licenseDir := filepath.join(installDir, "licenses") + os.mkdirAll(licenseDir, 0o755)! + os.writeFile(filepath.join(licenseDir, "COPYING"), os.readFile(filepath.join(ctx.SourceDir, "COPYING"))!, 0o644)! + + pcDir := filepath.join(installDir, "lib", "pkgconfig") + os.mkdirAll(pcDir, 0o755)! + pc := pkgconfig.new( + name = "libcpuid", + description = "libcpuid provides CPU identification for x86", + version = "v0.6.0", + libs = ["-L$${libdir}", "-lcpuid"], + cflags = ["-I$${includedir}"], + )! + out := os.create(filepath.join(pcDir, "libcpuid.pc"))! + pc.writeTo(out)! + out.close()! + + pkgconfig.use installDir + ctx.setMetadata pkgconfig.lookup("libcpuid")! +} + +onTest ctx => { + installDir := ctx.outputDir + testDir := filepath.join(ctx.SourceDir, "_llar_consumer") + os.mkdirAll(testDir, 0o755)! + + consumer := filepath.join(testDir, "consumer.c") + os.writeFile(consumer, []byte(consumerSource), 0o644)! + + pkgconfig.use installDir + binary := filepath.join(testDir, "consumer") + flagsFile := filepath.join(testDir, "libcpuid.flags") + os.writeFile(flagsFile, []byte(pkgconfig.lookup("libcpuid")!), 0o644)! + cc! consumer, "-o", binary, "@"+flagsFile + + if target.options["shared"][0] == "ON" { + os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + } + exec! binary + exec! filepath.join(installDir, "bin", "cpuid_tool"), "--report" +} diff --git a/anrieff/libcpuid/v0.7.0/libcpuid_llar.gox b/anrieff/libcpuid/v0.7.0/libcpuid_llar.gox new file mode 100644 index 0000000..9a69720 --- /dev/null +++ b/anrieff/libcpuid/v0.7.0/libcpuid_llar.gox @@ -0,0 +1,111 @@ +import ( + "os" + "path/filepath" + "slices" +) + +const consumerSource = `#include "libcpuid/libcpuid.h" + +#include + +int main(void) +{ + if (!cpuid_present()) { + return 1; + } + + struct cpu_raw_data_t raw; + struct cpu_id_t data; + if (cpuid_get_raw_data(&raw) < 0) { + return 2; + } + if (cpu_identify(&raw, &data) < 0) { + return 3; + } + + printf("%s %s\n", data.vendor_str, data.cpu_codename); + return 0; +} +` + +id "anrieff/libcpuid" + +fromVer "v0.7.0" + +defaults { + "shared": "OFF", + "fPIC": "ON", +} + +filter => { + for name, values in target.options { + if name != "shared" && name != "fPIC" { + return false + } + for value in values { + if value != "ON" && value != "OFF" { + return false + } + } + } + return slices.contains(target.require["arch"], "amd64") +} + +onBuild ctx => { + installDir := ctx.outputDir + shared := target.options["shared"][0] == "ON" + fPIC := target.options["fPIC"][0] == "ON" + + c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) + c.defineBool "BUILD_SHARED_LIBS", shared + c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC + c.defineBool "CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS", shared + c.defineBool "LIBCPUID_BUILD_DRIVERS", false + c.defineBool "LIBCPUID_ENABLE_TESTS", false + c.defineBool "LIBCPUID_ENABLE_DOCS", false + c.configure + c.build + c.install + + licenseDir := filepath.join(installDir, "licenses") + os.mkdirAll(licenseDir, 0o755)! + os.writeFile(filepath.join(licenseDir, "COPYING"), os.readFile(filepath.join(ctx.SourceDir, "COPYING"))!, 0o644)! + + pcDir := filepath.join(installDir, "lib", "pkgconfig") + os.mkdirAll(pcDir, 0o755)! + pc := pkgconfig.new( + name = "libcpuid", + description = "libcpuid provides CPU identification for x86", + version = "v0.7.0", + libs = ["-L$${libdir}", "-lcpuid"], + cflags = ["-I$${includedir}"], + )! + out := os.create(filepath.join(pcDir, "libcpuid.pc"))! + pc.writeTo(out)! + out.close()! + + pkgconfig.use installDir + ctx.setMetadata pkgconfig.lookup("libcpuid")! +} + +onTest ctx => { + installDir := ctx.outputDir + testDir := filepath.join(ctx.SourceDir, "_llar_consumer") + os.mkdirAll(testDir, 0o755)! + + consumer := filepath.join(testDir, "consumer.c") + os.writeFile(consumer, []byte(consumerSource), 0o644)! + + pkgconfig.use installDir + binary := filepath.join(testDir, "consumer") + flagsFile := filepath.join(testDir, "libcpuid.flags") + os.writeFile(flagsFile, []byte(pkgconfig.lookup("libcpuid")!), 0o644)! + cc! consumer, "-o", binary, "@"+flagsFile + + if target.options["shared"][0] == "ON" { + os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + } + exec! binary + exec! filepath.join(installDir, "bin", "cpuid_tool"), "--report" +} diff --git a/anrieff/libcpuid/versions.json b/anrieff/libcpuid/versions.json new file mode 100644 index 0000000..81d65a9 --- /dev/null +++ b/anrieff/libcpuid/versions.json @@ -0,0 +1,4 @@ +{ + "path": "anrieff/libcpuid", + "deps": {} +} From 05943d3141ce111c4acfbc6d7eccc2e1d5766dbf Mon Sep 17 00:00:00 2001 From: Rick Guo Date: Thu, 10 Sep 2026 13:42:27 +0800 Subject: [PATCH 2/2] fix(libcpuid): narrow legacy CMake adaptation --- .../libcpuid/v0.5.0/0.5.0-cmake-fixes.patch | 35 ++----------------- anrieff/libcpuid/v0.5.0/libcpuid_llar.gox | 2 +- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/anrieff/libcpuid/v0.5.0/0.5.0-cmake-fixes.patch b/anrieff/libcpuid/v0.5.0/0.5.0-cmake-fixes.patch index 95f4252..0d5c70d 100644 --- a/anrieff/libcpuid/v0.5.0/0.5.0-cmake-fixes.patch +++ b/anrieff/libcpuid/v0.5.0/0.5.0-cmake-fixes.patch @@ -1,45 +1,14 @@ ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -27,4 +27,3 @@ endif(UNIX) - # Include subdirectories - add_subdirectory(libcpuid) - add_subdirectory(cpuid_tool) --add_subdirectory(tests) --- a/cpuid_tool/CMakeLists.txt +++ b/cpuid_tool/CMakeLists.txt -@@ -2,7 +2,7 @@ add_executable(cpuid_tool cpuid_tool.c) - - target_link_libraries(cpuid_tool cpuid) - +@@ -5 +5 @@ -if(WIN32) +if(0) - install( - TARGETS cpuid_tool - CONFIGURATIONS Debug -@@ -12,5 +12,5 @@ if(WIN32) - CONFIGURATIONS Release - RUNTIME DESTINATION bin/Release) - else() -- install(TARGETS cpuid_tool RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -+ install(TARGETS cpuid_tool DESTINATION ${CMAKE_INSTALL_BINDIR}) - endif() --- a/libcpuid/CMakeLists.txt +++ b/libcpuid/CMakeLists.txt -@@ -13,7 +13,7 @@ if("${MSVC_CXX_ARCHITECTURE_ID}" MATCHES "x64") - endif() - +@@ -15,5 +15,5 @@ if(UNIX) - add_library(cpuid SHARED ${cpuid_sources}) + add_library(cpuid ${cpuid_sources}) else() add_library(cpuid ${cpuid_sources}) endif() -@@ -67,7 +67,7 @@ include(CMakePackageConfigHelpers) - write_basic_package_version_file("${version_config}" COMPATIBILITY SameMajorVersion) - - # Configure 'Config.cmake' Use variables: * TARGETS_EXPORT_NAME * PROJECT_NAME --configure_package_config_file("${CMAKE_MODULE_PATH}/Config.cmake.in" "${project_config}" -+configure_package_config_file("${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in" "${project_config}" - INSTALL_DESTINATION "${config_install_dir}") - - # Installation diff --git a/anrieff/libcpuid/v0.5.0/libcpuid_llar.gox b/anrieff/libcpuid/v0.5.0/libcpuid_llar.gox index 992c908..7e4e56a 100644 --- a/anrieff/libcpuid/v0.5.0/libcpuid_llar.gox +++ b/anrieff/libcpuid/v0.5.0/libcpuid_llar.gox @@ -67,7 +67,7 @@ onBuild ctx => { c.defineBool "CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS", shared c.defineBool "ENABLE_DOCS", false c.configure - c.build + c.build "--target", "cpuid_tool" c.install licenseDir := filepath.join(installDir, "licenses")