@@ -11,9 +11,10 @@ import "core:sys/posix"
1111// Package metadata from the index
1212Package :: struct {
1313 category: string ,
14- repo_url: string ,
1514 version: string ,
1615 description: string ,
16+ archs: [dynamic ]string ,
17+ repo_urls: map [string ]string , // arch -> url
1718}
1819
1920// The package index
@@ -22,6 +23,64 @@ Index :: struct {
2223 raw_json: json.Value,
2324}
2425
26+ // Get current system architecture
27+ get_system_arch :: proc () -> string {
28+ // Use uname to get machine type
29+ pipe_fds: [2 ]posix.FD
30+ if posix.pipe (&pipe_fds) != .OK {
31+ return " x86_64" // fallback
32+ }
33+
34+ pid := posix.fork ()
35+
36+ if pid < 0 {
37+ posix.close (pipe_fds[0 ])
38+ posix.close (pipe_fds[1 ])
39+ return " x86_64"
40+ }
41+
42+ if pid == 0 {
43+ posix.close (pipe_fds[0 ])
44+ posix.dup2 (pipe_fds[1 ], posix.STDOUT_FILENO)
45+ posix.close (pipe_fds[1 ])
46+
47+ args: []cstring = {" uname" , " -m" , nil }
48+ posix.execvp (" uname" , raw_data (args))
49+ posix._exit (127 )
50+ }
51+
52+ posix.close (pipe_fds[1 ])
53+
54+ buf: [64 ]byte
55+ n := posix.read (pipe_fds[0 ], raw_data (buf[:]), len (buf))
56+ posix.close (pipe_fds[0 ])
57+
58+ status: c.int
59+ posix.waitpid (pid, &status, {})
60+
61+ if n > 0 {
62+ arch := strings.trim_space (string (buf[:n]))
63+ // Map uname output to xbps arch names
64+ if arch == " x86_64" { return " x86_64" }
65+ if arch == " aarch64" { return " aarch64" }
66+ if arch == " armv7l" { return " armv7l" }
67+ if arch == " armv6l" { return " armv6l" }
68+ if arch == " i686" || arch == " i386" { return " i686" }
69+ return arch
70+ }
71+
72+ return " x86_64"
73+ }
74+
75+ // Get repo URL for current architecture
76+ get_repo_url_for_arch :: proc (pkg: ^Package, arch: string ) -> (url: string , ok: bool ) {
77+ if pkg == nil {
78+ return " " , false
79+ }
80+ url, ok = pkg.repo_urls[arch]
81+ return url, ok
82+ }
83+
2584// Free index resources
2685index_free :: proc (idx: ^Index) {
2786 if idx == nil {
@@ -146,16 +205,32 @@ parse_index :: proc(json_str: string) -> (idx: Index, ok: bool) {
146205 if cat, cat_ok := pkg_obj[" category" ].(json.String); cat_ok {
147206 pkg.category = cat
148207 }
149- if url, url_ok := pkg_obj[" repo_url" ].(json.String); url_ok {
150- pkg.repo_url = url
151- }
152208 if ver, ver_ok := pkg_obj[" version" ].(json.String); ver_ok {
153209 pkg.version = ver
154210 }
155211 if desc, desc_ok := pkg_obj[" description" ].(json.String); desc_ok {
156212 pkg.description = desc
157213 }
158214
215+ // Parse archs array
216+ if archs_arr, archs_ok := pkg_obj[" archs" ].(json.Array); archs_ok {
217+ for arch_val in archs_arr {
218+ if arch_str, str_ok := arch_val.(json.String); str_ok {
219+ append (&pkg.archs, arch_str)
220+ }
221+ }
222+ }
223+
224+ // Parse repo_urls map
225+ if urls_obj, urls_ok := pkg_obj[" repo_urls" ].(json.Object); urls_ok {
226+ pkg.repo_urls = make (map [string ]string )
227+ for arch, url_val in urls_obj {
228+ if url_str, str_ok := url_val.(json.String); str_ok {
229+ pkg.repo_urls[arch] = url_str
230+ }
231+ }
232+ }
233+
159234 idx.packages[name] = pkg
160235 }
161236
0 commit comments