nandi/nimstaticpublic Fork 0
5feb05094be9eb20a8a0588b44117d22c7dc3cac
Commits
Clone
git clone https://git.rickub.com/nandi/nimstatic.git
git clone ssh://git@rickub.com/nandi/nimstatic.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

test_muslkit.nim · 187 lines · 5.6 KBNim Blame HistoryRaw
muslkit: musl static libraries from Alpine, without Alpine 5feb050 nandi 18h ago1import std/[os, strutils, tables, unittest]
2import ../src/muslkit
3
4const sampleIndex = """
5C:Q1aaa=
6P:openssl-libs-static
7V:3.3.7-r1
8A:x86_64
9S:13040623
10T:Toolkit for Transport Layer Security (TLS) (static library)
11L:Apache-2.0
12o:openssl
13
14C:Q1bbb=
15P:openssl-dev
16V:3.3.7-r1
17A:x86_64
18S:3000
19T:TLS toolkit (development files)
20D:libcrypto3=3.3.7-r1 pkgconfig
21p:openssl3-dev=3.3.7-r1 pc:libssl=3.3.7
22
23C:Q1ccc=
24P:libcrypto3
25V:3.3.7-r1
26A:x86_64
27S:2000
28T:crypto library
29D:so:libc.musl-x86_64.so.1
30p:so:libcrypto.so.3=3
31
32C:Q1ddd=
33P:musl
34V:1.2.5-r11
35A:x86_64
36S:400
37T:the musl c library
38p:so:libc.musl-x86_64.so.1=1
39
40C:Q1eee=
41P:pkgconf
42V:2.3.0-r0
43A:x86_64
44S:100
45T:pkg-config compatible
46p:pkgconfig=2.3.0-r0
47"""
48
49suite "index parsing":
50 let idx = parseIndex(sampleIndex, "main")
51
52 test "records and fields":
53 check idx.packages.len == 5
54 let p = idx.packages["openssl-libs-static"]
55 check p.version == "3.3.7-r1"
56 check p.size == 13040623
57 check p.repo == "main"
58 check p.description.endsWith("(static library)")
59
60 test "provides are indexed":
61 check idx.find("pkgconfig") == "pkgconf"
62 check idx.find("so:libcrypto.so.3") == "libcrypto3"
63 check idx.find("openssl3-dev") == "openssl-dev"
64 check idx.find("nope") == ""
65
66 test "version constraints are stripped":
67 check stripConstraint("musl=1.2.5-r11") == "musl"
68 check stripConstraint("so:libssl.so.3=3") == "so:libssl.so.3"
69 check stripConstraint("cmd>=2") == "cmd"
70 check stripConstraint("plain") == "plain"
71
72 test "conflicts are recognized":
73 check isConflict("!busybox")
74 check not isConflict("busybox")
75
76suite "resolution":
77 let idx = parseIndex(sampleIndex, "main")
78
79 test "dependencies come before dependents":
80 let order = idx.resolve(["openssl-dev"])
81 let names = block:
82 var s: seq[string]
83 for p in order: s.add p.name
84 s
85 check names[^1] == "openssl-dev"
86 check "libcrypto3" in names
87 check "musl" in names # reached through so:libc.musl-x86_64.so.1
88 check "pkgconf" in names # reached through the pkgconfig provide
89 check names.find("libcrypto3") < names.find("openssl-dev")
90
91 test "a package is visited once":
92 let order = idx.resolve(["openssl-dev", "libcrypto3", "openssl-dev"])
93 var seen: CountTable[string]
94 for p in order: seen.inc p.name
95 for name, n in seen: check n == 1
96
97 test "--no-deps stops at the request":
98 let order = idx.resolve(["openssl-dev"], withDeps = false)
99 check order.len == 1
100 check order[0].name == "openssl-dev"
101
102 test "an unsatisfiable request names its requester":
103 expect KeyError:
104 discard parseIndex("C:Q1\nP:lonely\nV:1\nD:ghost\n").resolve(["lonely"])
105
106 test "merge lets a later repo shadow an earlier one":
107 var a = parseIndex("C:Q1\nP:foo\nV:1\n", "main")
108 a.merge parseIndex("C:Q1\nP:foo\nV:2\n", "community")
109 check a.packages["foo"].version == "2"
110 check a.packages["foo"].repo == "community"
111
112suite "sysroot manifest":
113 let root = getTempDir() / "muslkit-test-root"
114 removeDir root
115
116 test "record then read back":
117 record(root, [Pkg(name: "zlib-static", version: "1.3.2-r0", repo: "main")])
118 record(root, [Pkg(name: "openssl-libs-static", version: "3.3.7-r1", repo: "main")])
119 let entries = readManifest(root)
120 check entries.len == 2
121 check installed(root, "zlib-static")
122 check not installed(root, "absent")
123
124 test "re-recording replaces rather than duplicates":
125 record(root, [Pkg(name: "zlib-static", version: "1.3.3-r0", repo: "main")])
126 let entries = readManifest(root)
127 check entries.len == 2
128 for e in entries:
129 if e.name == "zlib-static": check e.version == "1.3.3-r0"
130
131 test "static libs are found and sorted":
132 createDir root / "usr" / "lib"
133 for name in ["libz.a", "libcrypto.a"]:
134 writeFile(root / "usr" / "lib" / name, "")
135 let libs = staticLibs(root)
136 check libs.len == 2
137 check libs[0].extractFilename == "libcrypto.a"
138
139 removeDir root
140
141suite "flags":
142 let root = getTempDir() / "muslkit-test-flags"
143 removeDir root
144 createDir root / "usr" / "lib"
145
146 test "plain sysroot":
147 let f = nimFlags(root).join(" ")
148 check ("--passC:-I" & root & "/usr/include") in f
149 check "--passL:-static" in f
150 check "dynlibOverride" notin f
151
152 test "openssl archives switch on the static-TLS workarounds":
153 for name in ["libssl.a", "libcrypto.a"]:
154 writeFile(root / "usr" / "lib" / name, "")
155 let f = nimFlags(root, ["z"]).join(" ")
156 check "--dynlibOverride:ssl" in f
157 check "--dynlibOverride:crypto" in f
158 # OpenSSL 3 dropped the symbol Nim's wrapper still names
159 check "-DSSL_get_peer_certificate=SSL_get1_peer_certificate" in f
160 check "--passL:-lz" in f
161
162 test "cc flags and pkg-config env":
163 check ccFlags(root, ["ssl"]) == @["-I" & root & "/usr/include",
164 "-L" & root & "/usr/lib",
165 "-static", "-lssl"]
166 check pkgConfigEnv(root)[0] == "PKG_CONFIG_SYSROOT_DIR=" & root
167
168 test "nimcfg carries the compiler and the flags":
169 let cfg = nimCfg(root, "/tmp/zigcc")
170 check "--cc:clang" in cfg
171 check "--clang.exe:\"/tmp/zigcc\"" in cfg
172 check "--passL:-static" in cfg
173
174 test "zigcc script targets the right triple":
175 let s = zigccScript("aarch64-linux-musl")
176 check "zig cc -target aarch64-linux-musl" in s
177 check "\"$@\"" in s
178
179 removeDir root
180
181suite "remote":
182 test "urls are built from mirror, branch, repo and arch":
183 let r = initRemote(branch = "edge", arch = "aarch64")
184 check r.repoUrl("community") ==
185 "https://dl-cdn.alpinelinux.org/alpine/edge/community/aarch64"
186 check apkFile(Pkg(name: "zlib-static", version: "1.3.2-r0")) ==
187 "zlib-static-1.3.2-r0.apk"