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.

muslkit: musl static libraries from Alpine, without Alpine 5feb050 · on 5feb05094be9eb20a8a0588b44117d22c7dc3cac · nandi · 20h ago
sysroot.nim · 48 lines · 1.7 KBNim Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
## The sysroot: a plain directory tree of unpacked Alpine packages, plus a
## manifest of what was installed so `list` and re-runs are cheap.

import std/[algorithm, os, sequtils, strutils]
import ./index

const manifestPath* = ".muslkit/installed.tsv"

type Installed* = object
  name*, version*, repo*: string

proc manifestFile*(sysroot: string): string = sysroot / manifestPath

proc readManifest*(sysroot: string): seq[Installed] =
  let path = manifestFile(sysroot)
  if not fileExists(path): return
  for line in readFile(path).splitLines:
    if line.len == 0 or line.startsWith("#"): continue
    let f = line.split('\t')
    if f.len >= 3:
      result.add Installed(name: f[0], version: f[1], repo: f[2])

proc writeManifest*(sysroot: string, entries: seq[Installed]) =
  createDir manifestFile(sysroot).parentDir
  var lines = @["# name\tversion\trepo — written by muslkit"]
  for e in entries.sortedByIt(it.name):
    lines.add e.name & "\t" & e.version & "\t" & e.repo
  writeFile(manifestFile(sysroot), lines.join("\n") & "\n")

proc record*(sysroot: string, pkgs: openArray[Pkg]) =
  ## Merge freshly installed packages into the manifest, newest version winning.
  var entries = readManifest(sysroot)
  for pkg in pkgs:
    entries.keepItIf(it.name != pkg.name)
    entries.add Installed(name: pkg.name, version: pkg.version, repo: pkg.repo)
  writeManifest(sysroot, entries)

proc installed*(sysroot, name: string): bool =
  readManifest(sysroot).anyIt(it.name == name)

proc staticLibs*(sysroot: string): seq[string] =
  ## Every .a in the sysroot, as absolute paths.
  for dir in ["usr/lib", "lib", "usr/lib64"]:
    let d = sysroot / dir
    if dirExists(d):
      for path in walkFiles(d / "*.a"):
        result.add path
  result.sort()