Skip to content

Commit 05c46cc

Browse files
committed
fix odin
1 parent e8b5d8e commit 05c46cc

3 files changed

Lines changed: 121 additions & 31 deletions

File tree

vuruV2/src/common/index.odin

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import "core:sys/posix"
1111
// Package metadata from the index
1212
Package :: 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
2685
index_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

vuruV2/src/xbps/install.odin

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,22 @@ install_pkg :: proc(idx: ^common.Index, pkg_name: string, yes: bool) -> bool {
2020
return false
2121
}
2222

23-
if len(pkg.repo_url) == 0 || len(pkg.category) == 0 {
23+
if len(pkg.category) == 0 {
2424
common.log_error("Invalid package metadata for '%s'", pkg_name)
2525
return false
2626
}
2727

28-
common.log_info("Found %s in category '%s'", pkg_name, pkg.category)
28+
// Get system architecture and find matching repo URL
29+
system_arch := common.get_system_arch()
30+
repo_url, url_ok := common.get_repo_url_for_arch(&pkg, system_arch)
31+
32+
if !url_ok {
33+
common.log_error("Package '%s' is not available for architecture '%s'", pkg_name, system_arch)
34+
common.log_info("Available architectures: %v", pkg.archs[:])
35+
return false
36+
}
37+
38+
common.log_info("Found %s in category '%s' (arch: %s)", pkg_name, pkg.category, system_arch)
2939

3040
// Fetch template for review
3141
common.log_info("Fetching template for review...")
@@ -69,7 +79,7 @@ install_pkg :: proc(idx: ^common.Index, pkg_name: string, yes: bool) -> bool {
6979
defer delete(args)
7080

7181
append(&args, "xbps-install")
72-
append(&args, "-R", pkg.repo_url)
82+
append(&args, "-R", repo_url)
7383
append(&args, "-S")
7484
if yes {
7585
append(&args, "-y")

vuruV2/src/xbps/search.odin

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,53 @@ search :: proc(idx: ^common.Index, query: string) {
1313
}
1414

1515
query_lower := strings.to_lower(query, context.temp_allocator)
16+
system_arch := common.get_system_arch()
1617

1718
found_count := 0
1819

1920
// Print header
2021
fmt.println()
21-
fmt.printf("%s%-30s %-15s %-12s %s%s\n",
22+
fmt.printf("%s%-25s %-12s %-10s %-15s %s%s\n",
2223
common.color_code(.Bold),
2324
"Package",
2425
"Version",
2526
"Category",
26-
"Description",
27+
"Archs",
28+
"Available",
2729
common.color_code(.Reset))
28-
fmt.println(strings.repeat("-", 80))
30+
fmt.println(strings.repeat("-", 85))
2931

30-
for name, pkg in idx.packages {
32+
for name, &pkg in idx.packages {
3133
name_lower := strings.to_lower(name, context.temp_allocator)
3234
desc_lower := strings.to_lower(pkg.description, context.temp_allocator)
3335

3436
// Match against name or description
3537
if strings.contains(name_lower, query_lower) || strings.contains(desc_lower, query_lower) {
36-
// Truncate description if too long
37-
desc := pkg.description
38-
if len(desc) > 35 {
39-
desc = strings.concatenate({desc[:32], "..."}, context.temp_allocator)
38+
// Check if available for current arch
39+
_, available := common.get_repo_url_for_arch(&pkg, system_arch)
40+
avail_str := available ? "" : ""
41+
avail_color := available ? common.color_code(.Green) : common.color_code(.Red)
42+
43+
// Format archs list
44+
archs_str := strings.join(pkg.archs[:], ",", context.temp_allocator)
45+
if len(archs_str) > 15 {
46+
archs_str = strings.concatenate({archs_str[:12], "..."}, context.temp_allocator)
4047
}
4148

4249
// Highlight matching name
43-
if strings.contains(name_lower, query_lower) {
44-
fmt.printf("%s%-30s%s %-15s %-12s %s\n",
45-
common.color_code(.Green),
46-
name,
47-
common.color_code(.Reset),
48-
pkg.version,
49-
pkg.category,
50-
desc)
51-
} else {
52-
fmt.printf("%-30s %-15s %-12s %s\n",
53-
name,
54-
pkg.version,
55-
pkg.category,
56-
desc)
57-
}
50+
name_color := strings.contains(name_lower, query_lower) ? common.color_code(.Green) : ""
51+
name_reset := strings.contains(name_lower, query_lower) ? common.color_code(.Reset) : ""
52+
53+
fmt.printf("%s%-25s%s %-12s %-10s %-15s %s%s%s\n",
54+
name_color,
55+
name,
56+
name_reset,
57+
pkg.version,
58+
pkg.category,
59+
archs_str,
60+
avail_color,
61+
avail_str,
62+
common.color_code(.Reset))
5863

5964
found_count += 1
6065
}
@@ -64,6 +69,6 @@ search :: proc(idx: ^common.Index, query: string) {
6469
if found_count == 0 {
6570
common.log_info("No packages found matching '%s'", query)
6671
} else {
67-
common.log_info("Found %d package(s)", found_count)
72+
common.log_info("Found %d package(s) (your arch: %s)", found_count, system_arch)
6873
}
6974
}

0 commit comments

Comments
 (0)