Skip to content

Commit 05f8f76

Browse files
committed
Revamp
1 parent 0854ebb commit 05f8f76

File tree

4 files changed

+118
-132
lines changed

4 files changed

+118
-132
lines changed

src/bootstrap.nim

Lines changed: 59 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,44 @@
66
# License, v. 2.0. If a copy of the MPL was not distributed with this
77
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
88

9-
import std/[os, strformat, strutils], packages, utils
9+
import std/[os, strformat, strutils]
10+
import packages, utils
1011

1112
proc cleanBootstrap*() =
12-
const dirs = ["../cross", "../log", "../tmp", "../toolchain"]
13+
const dirs = [
14+
"../../glaucus/cross",
15+
"../../glaucus/log",
16+
"../../glaucus/tmp",
17+
"../../glaucus/toolchain"]
1318

1419
for i in dirs:
1520
removeDir(i)
1621

1722
proc prepareToolchain() =
18-
const
19-
dirs = ["../cross", "../log", "../pkg", "../src", "../tmp", "../toolchain"]
20-
exes = [
21-
"autoconf", "automake", "autopoint", "awk", "bash", "booster", "bzip2", "curl",
22-
"diff", "find", "gcc", "git", "gperf", "grep", "gzip", "ld.bfd", "lex", "libtool",
23-
"limine", "m4", "make", "meson", "mkfs.erofs", "mkfs.fat", "ninja", "patch",
24-
"perl", "pkg-config", "sed", "tar", "xz", "yacc", "zstd",
25-
]
23+
const dirs = [
24+
"../../glaucus/cross",
25+
"../../glaucus/log",
26+
"../../glaucus/pkg",
27+
"../../glaucus/src",
28+
"../../glaucus/tmp",
29+
"../../glaucus/toolchain"]
30+
31+
const exes = [
32+
"autoconf", "automake", "autopoint", "awk",
33+
"bash", "booster", "bzip2",
34+
"curl",
35+
"diff",
36+
"find",
37+
"gcc", "git", "gperf", "grep", "gzip",
38+
"ld.bfd", "lex", "libtool", "limine",
39+
"m4", "make", "meson", "mkfs.erofs", "mkfs.fat",
40+
"ninja",
41+
"patch", "perl", "pkg-config",
42+
"sed",
43+
"tar",
44+
"xz",
45+
"yacc",
46+
"zstd"]
2647

2748
for i in exes:
2849
if findExe(i).isEmptyOrWhitespace():
@@ -34,17 +55,9 @@ proc prepareToolchain() =
3455
createDir(i)
3556

3657
proc configureToolchain() =
37-
const env = [
38-
("core", "../core"),
39-
("cross", "../cross"),
40-
("tmp", "../tmp"),
41-
("toolchain", "../toolchain"),
42-
]
43-
44-
for (i, j) in env:
45-
putEnv(i, absolutePath(j))
46-
47-
putEnv("PATH", getEnv("toolchain") / "usr/bin" & PathSep & getEnv("PATH"))
58+
putEnv("GLAUCUS_CROSS", absolutePath("../../glaucus/cross"))
59+
putEnv("GLAUCUS_TOOLCHAIN", absolutePath("../../glaucus/toolchain"))
60+
putEnv("PATH", absolutePath("../../glaucus/toolchain/usr/bin") & PathSep & getEnv("PATH"))
4861

4962
proc bootstrapToolchain*() =
5063
prepareToolchain()
@@ -58,33 +71,31 @@ proc prepareCross() =
5871
createDir(dir)
5972

6073
proc configureCross() =
61-
const
62-
env = [
63-
("AR", "x86_64-glaucus-linux-musl-gcc-ar"),
64-
("AS", "x86_64-glaucus-linux-musl-as"),
65-
("CC", "x86_64-glaucus-linux-musl-gcc"),
66-
("CPP", "x86_64-glaucus-linux-musl-gcc -E"),
67-
("CROSS_COMPILE", "x86_64-glaucus-linux-musl-"),
68-
("CXX", "x86_64-glaucus-linux-musl-g++"),
69-
("CXXCPP", "x86_64-glaucus-linux-musl-g++ -E"),
70-
("HOSTCC", "gcc"),
71-
("NM", "x86_64-glaucus-linux-musl-gcc-nm"),
72-
("OBJCOPY", "x86_64-glaucus-linux-musl-objcopy"),
73-
("OBJDUMP", "x86_64-glaucus-linux-musl-objdump"),
74-
("RANLIB", "x86_64-glaucus-linux-musl-gcc-ranlib"),
75-
("READELF", "x86_64-glaucus-linux-musl-readelf"),
76-
("SIZE", "x86_64-glaucus-linux-musl-size"),
77-
("STRIP", "x86_64-glaucus-linux-musl-strip"),
78-
]
79-
envPkgConfig = [
80-
("PKG_CONFIG_LIBDIR", "../cross/usr/lib/pkgconfig"),
81-
("PKG_CONFIG_PATH", "../cross/usr/lib/pkgconfig"),
82-
("PKG_CONFIG_SYSROOT_DIR", "../cross/"),
83-
("PKG_CONFIG_SYSTEM_INCLUDE_PATH", "../cross/usr/include"),
84-
("PKG_CONFIG_SYSTEM_LIBRARY_PATH", "../cross/usr/lib"),
85-
]
86-
87-
for (i, j) in env:
74+
const envExes = [
75+
("AR", "x86_64-glaucus-linux-musl-gcc-ar"),
76+
("AS", "x86_64-glaucus-linux-musl-as"),
77+
("CC", "x86_64-glaucus-linux-musl-gcc"),
78+
("CPP", "x86_64-glaucus-linux-musl-gcc -E"),
79+
("CROSS_COMPILE", "x86_64-glaucus-linux-musl-"),
80+
("CXX", "x86_64-glaucus-linux-musl-g++"),
81+
("CXXCPP", "x86_64-glaucus-linux-musl-g++ -E"),
82+
("HOSTCC", "gcc"),
83+
("NM", "x86_64-glaucus-linux-musl-gcc-nm"),
84+
("OBJCOPY", "x86_64-glaucus-linux-musl-objcopy"),
85+
("OBJDUMP", "x86_64-glaucus-linux-musl-objdump"),
86+
("RANLIB", "x86_64-glaucus-linux-musl-gcc-ranlib"),
87+
("READELF", "x86_64-glaucus-linux-musl-readelf"),
88+
("SIZE", "x86_64-glaucus-linux-musl-size"),
89+
("STRIP", "x86_64-glaucus-linux-musl-strip")]
90+
91+
const envPkgConfig = [
92+
("PKG_CONFIG_LIBDIR", "../../glaucus/cross/usr/lib/pkgconfig"),
93+
("PKG_CONFIG_PATH", "../../glaucus/cross/usr/lib/pkgconfig"),
94+
("PKG_CONFIG_SYSROOT_DIR", "../../glaucus/cross/"),
95+
("PKG_CONFIG_SYSTEM_INCLUDE_PATH", "../../glaucus/cross/usr/include"),
96+
("PKG_CONFIG_SYSTEM_LIBRARY_PATH", "../../glaucus/cross/usr/lib")]
97+
98+
for (i, j) in envExes:
8899
putEnv(i, j)
89100
for (i, j) in envPkgConfig:
90101
putEnv(i, absolutePath(j))

src/options.nim

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
# License, v. 2.0. If a copy of the MPL was not distributed with this
77
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
88

9-
import std/[os, parseopt, strutils], bootstrap, packages, utils
9+
import std/[os, parseopt, strutils]
10+
import bootstrap, packages, utils
1011

1112
proc options*() =
12-
const
13-
help =
14-
"""
13+
const help = """
1514
USAGE:
1615
rad [ COMMAND ]
1716
@@ -26,8 +25,8 @@ COMMANDS:
2625
search Search for packages
2726
update Update repositories
2827
version Show rad version"""
29-
helpBootstrap =
30-
"""
28+
29+
const helpBootstrap = """
3130
USAGE:
3231
rad bootstrap [ COMMAND ]
3332
@@ -37,8 +36,8 @@ COMMANDS:
3736
1, stage1 Bootstrap stage 1 (toolchain)
3837
2, stage2 Bootstrap stage 2 (cross)
3938
3, stage3 Bootstrap stage 3 (native)"""
40-
version =
41-
"""
39+
40+
const version = """
4241
rad version 0.1.0
4342
4443
Licensed under the Mozilla Public License Version 2.0 (MPL-2.0)

src/packages.nim

Lines changed: 51 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@
66
# License, v. 2.0. If a copy of the MPL was not distributed with this
77
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
88

9-
import std/[algorithm, os, osproc, sequtils, strformat, strutils, tables, times], utils
9+
import std/[algorithm, os, osproc, sequtils, strformat, strutils, tables, times]
10+
import utils
1011

11-
const
12-
pkgCache* = "/var/cache/rad/pkg"
13-
srcCache* = "/var/cache/rad/src"
14-
coreRepo* = "/var/lib/rad/repo/core"
15-
radLog* = "/var/log/rad"
16-
radTmp* = "/var/tmp/rad"
12+
const pkgCache = "/var/cache/rad/pkg"
13+
const srcCache = "/var/cache/rad/src"
14+
const coreRepo = "/var/lib/rad/repo/core"
15+
const radLog = "/var/log/rad"
16+
const radTmp = "/var/tmp/rad"
1717

18-
type
19-
Package = object
20-
ver, url, sum, bld, run*, opt = "nil"
18+
type Package = object
19+
ver, url, sum, bld, run*, opt = "nil"
2120

22-
Stages* = enum
23-
cross
24-
native
25-
toolchain
21+
type Stages* = enum
22+
cross, native, toolchain
2623

2724
proc cleanCache*() =
2825
removeDir(radTmp)
@@ -43,9 +40,8 @@ proc parseInfo*(nom: string): Package =
4340
if line.contains("= \"") or line.contains(" =\"") or '=' notin line:
4441
abort(&"""{"nom":8}{"whitespace found":48}""")
4542

46-
let
47-
pair = line.split('=', 1)
48-
key = pair[0]
43+
let pair = line.split('=', 1)
44+
let key = pair[0]
4945
var val = pair[1]
5046

5147
if not (val.startsWith('"') and val.endsWith('"')):
@@ -113,9 +109,8 @@ proc fetchPackages(packages: openArray[string]) =
113109
if package.url == "nil":
114110
continue
115111

116-
let
117-
src = srcCache / nom
118-
tmp = radTmp / nom
112+
let src = srcCache / nom
113+
let tmp = radTmp / nom
119114

120115
if package.sum == "nil":
121116
if not dirExists(src):
@@ -145,9 +140,8 @@ proc resolveDeps(
145140
if nom in packages:
146141
return
147142

148-
let
149-
package = parseInfo(nom)
150-
dep = package.bld
143+
let package = parseInfo(nom)
144+
let dep = package.bld
151145

152146
deps[nom] =
153147
if dep == "nil":
@@ -161,9 +155,8 @@ proc resolveDeps(
161155
packages &= nom
162156

163157
proc sortPackages(packages: openArray[string]): seq[string] =
164-
var
165-
deps: Table[string, seq[string]]
166-
sorted: seq[string]
158+
var deps: Table[string, seq[string]]
159+
var sorted: seq[string]
167160

168161
for nom in packages.deduplicate():
169162
resolveDeps(nom, sorted, deps)
@@ -181,13 +174,12 @@ proc installPackage(nom: string, fs = "/", pkgCache = pkgCache) =
181174
)
182175

183176
proc buildPackages*(packages: openArray[string], bootstrap = false, stage = native) =
184-
let
185-
sorted = sortPackages(packages)
186-
queue =
187-
if bootstrap:
188-
packages.toSeq()
189-
else:
190-
sorted
177+
let sorted = sortPackages(packages)
178+
let queue =
179+
if bootstrap:
180+
packages.toSeq()
181+
else:
182+
sorted
191183

192184
fetchPackages(sorted)
193185

@@ -196,13 +188,12 @@ proc buildPackages*(packages: openArray[string], bootstrap = false, stage = nati
196188
printHeader()
197189

198190
for idx, nom in queue:
199-
let
200-
package = parseInfo(nom)
201-
archive =
202-
if package.url == "nil":
203-
pkgCache / nom / nom & ".tar.zst"
204-
else:
205-
pkgCache / nom / nom & '-' & package.ver & ".tar.zst"
191+
let package = parseInfo(nom)
192+
let archive =
193+
if package.url == "nil":
194+
pkgCache / nom / nom & ".tar.zst"
195+
else:
196+
pkgCache / nom / nom & '-' & package.ver & ".tar.zst"
206197

207198
printContent(idx, nom, package.ver, "build")
208199

@@ -226,15 +217,11 @@ proc buildPackages*(packages: openArray[string], bootstrap = false, stage = nati
226217
("NM", "gcc-nm"),
227218
("PKG_CONFIG", "u-config"),
228219
("RANLIB", "gcc-ranlib"),
229-
("YACC", "byacc"),
230-
]
220+
("YACC", "byacc")]
231221

232222
for (i, j) in env:
233223
putEnv(i, j)
234224

235-
if bootstrap:
236-
putEnv("PATH", absolutePath("../toolchain/usr/bin") & PathSep & getEnv("PATH"))
237-
238225
if dirExists(radTmp / nom):
239226
setCurrentDir(radTmp / nom)
240227
if dirExists(radTmp / nom / nom & '-' & package.ver):
@@ -245,31 +232,27 @@ proc buildPackages*(packages: openArray[string], bootstrap = false, stage = nati
245232
("BUILD", execCmdEx(coreRepo / "slibtool/files/config.guess").output.strip()),
246233
("CTARGET", "x86_64-glaucus-linux-musl"),
247234
("PRETTY_NAME", "glaucus s6 x86-64-v3 " & now().format("YYYYMMdd")),
248-
("TARGET", "x86_64-pc-linux-musl"),
249-
]
235+
("TARGET", "x86_64-pc-linux-musl")]
250236

251237
for (i, j) in env:
252238
putEnv(i, j)
253239

254-
let
255-
cflags =
240+
let cflags =
241+
if "no-lto" notin package.opt:
242+
"-pipe -O2 -fgraphite-identity -floop-nest-optimize -flto=auto -flto-compression-level=3 -fuse-linker-plugin -fstack-protector-strong -fstack-clash-protection -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-plt -march=x86-64-v3 -mfpmath=sse -mabi=sysv -malign-data=cacheline -mtls-dialect=gnu2"
243+
else:
244+
"-pipe -O2 -fgraphite-identity -floop-nest-optimize -fstack-protector-strong -fstack-clash-protection -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-plt -march=x86-64-v3 -mfpmath=sse -mabi=sysv -malign-data=cacheline -mtls-dialect=gnu2"
245+
246+
let envFlags = [
247+
("CFLAGS", cflags),
248+
("CXXFLAGS", cflags),
249+
("LDFLAGS",
256250
if "no-lto" notin package.opt:
257-
"-pipe -O2 -fgraphite-identity -floop-nest-optimize -flto=auto -flto-compression-level=3 -fuse-linker-plugin -fstack-protector-strong -fstack-clash-protection -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-plt -march=x86-64-v3 -mfpmath=sse -mabi=sysv -malign-data=cacheline -mtls-dialect=gnu2"
251+
"-Wl,-O1,-s,-z,noexecstack,-z,now,-z,pack-relative-relocs,-z,relro,-z,x86-64-v3,--as-needed,--gc-sections,--sort-common,--hash-style=gnu " &
252+
cflags
258253
else:
259-
"-pipe -O2 -fgraphite-identity -floop-nest-optimize -fstack-protector-strong -fstack-clash-protection -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-plt -march=x86-64-v3 -mfpmath=sse -mabi=sysv -malign-data=cacheline -mtls-dialect=gnu2"
260-
envFlags = [
261-
("CFLAGS", cflags),
262-
("CXXFLAGS", cflags),
263-
(
264-
"LDFLAGS",
265-
if "no-lto" notin package.opt:
266-
"-Wl,-O1,-s,-z,noexecstack,-z,now,-z,pack-relative-relocs,-z,relro,-z,x86-64-v3,--as-needed,--gc-sections,--sort-common,--hash-style=gnu " &
267-
cflags
268-
else:
269-
"-Wl,-O1,-s,-z,noexecstack,-z,now,-z,pack-relative-relocs,-z,relro,-z,x86-64-v3,--as-needed,--gc-sections,--sort-common,--hash-style=gnu",
270-
),
271-
("MAKEFLAGS", if "no-parallel" notin package.opt: "-j 5 -O" else: "-j 1"),
272-
]
254+
"-Wl,-O1,-s,-z,noexecstack,-z,now,-z,pack-relative-relocs,-z,relro,-z,x86-64-v3,--as-needed,--gc-sections,--sort-common,--hash-style=gnu"),
255+
("MAKEFLAGS", if "no-parallel" notin package.opt: "-j 5 -O" else: "-j 1")]
273256

274257
for (i, j) in envFlags:
275258
putEnv(i, j)
@@ -284,21 +267,16 @@ proc buildPackages*(packages: openArray[string], bootstrap = false, stage = nati
284267
fi
285268
done
286269
287-
package
288-
'"""
289-
)
270+
package'""")
290271

291-
writeFile(
292-
radLog / nom & (if stage == native: "" else: '.' & $stage), shell.output.strip()
293-
)
272+
writeFile(radLog / nom & (if stage == native: "" else: '.' & $stage), shell.output.strip())
294273

295274
if shell.exitCode != QuitSuccess:
296275
abort(&"{shell.exitCode:<8}{nom:24}{package.ver:24}")
297276

298277
if stage == native:
299-
let
300-
dst = getEnv("DSTD")
301-
status = createTarZst(archive, dst)
278+
let dst = getEnv("DSTD")
279+
let status = createTarZst(archive, dst)
302280

303281
# Purge
304282
# if "empty" notin package.opt:

src/utils.nim

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ proc interrupt() {.noconv.} =
4141

4242
proc lock*(lock = "/var/tmp/rad.lock") =
4343
if fileExists(lock):
44-
styledEcho fgRed,
45-
styleBright,
46-
&"""{QuitFailure:<8}{"lock exists":48}{"abort":8}""" & now().format("hh:mm tt")
44+
styledEcho fgRed, styleBright, &"""{QuitFailure:<8}{"lock exists":48}{"abort":8}""" & now().format("hh:mm tt")
4745

4846
quit(QuitFailure)
4947

0 commit comments

Comments
 (0)