Skip to content

Commit bd65893

Browse files
committed
Improvements
1 parent 43b9966 commit bd65893

File tree

7 files changed

+154
-149
lines changed

7 files changed

+154
-149
lines changed

src/arch.nim

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
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, osproc, strformat, strutils], constants
9+
import std/[os, osproc, strutils, times], constants
1010

11-
proc setEnvArch*(vendor = "pc") =
12-
for i in [
11+
proc setEnvArch*() =
12+
let env = [
1313
("ARCH", "x86-64"),
14-
("BLDT", execCmdEx(pathCoreRepo / "slibtool/files/config.guess").output.strip()),
15-
("PRETTY_NAME", "glaucus s6 x86-64-v3"),
16-
("TGTT", &"x86_64-{vendor}-linux-musl"),
17-
]:
18-
putEnv(i[0], i[1])
14+
("BUILD", execCmdEx(pathCoreRepo / "slibtool/files/config.guess").output.strip()),
15+
("CTARGET", "x86_64-glaucus-linux-musl"),
16+
("PRETTY_NAME", "glaucus s6 x86-64-v3 " & now().format("YYYYMMdd")),
17+
("TARGET", "x86_64-pc-linux-musl"),
18+
]
19+
20+
for (i, j) in env:
21+
putEnv(i, j)

src/bootstrap.nim

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,87 @@
99
import std/os, constants
1010

1111
proc cleanBootstrap*() =
12-
for i in dirCleanBootstrap:
13-
removeDir(ParDir / i)
12+
const dirs = ["../cross", "../log", "../tmp", "../toolchain"]
13+
14+
for i in dirs:
15+
removeDir(i)
1416

1517
proc prepareBootstrap*() =
16-
for i in dirPrepareBootstrap:
17-
createDir(ParDir / i)
18+
const dirs = ["../cross", "../log", "../pkg", "../src", "../tmp", "../toolchain"]
19+
20+
for i in dirs:
21+
createDir(i)
1822

1923
proc prepareCross*() =
20-
removeDir(ParDir / "tmp")
21-
createDir(ParDir / "tmp")
24+
const dir = "../tmp"
25+
26+
removeDir(dir)
27+
createDir(dir)
2228

2329
proc setEnvBootstrap*() =
24-
for i in envBootstrap:
25-
putEnv(i[0], absolutePath(ParDir) / i[1])
30+
const env = [
31+
("CORD", "../core"),
32+
("CRSD", "../cross"),
33+
("TMPD", "../tmp"),
34+
("TLCD", "../toolchain"),
35+
]
2636

27-
putEnv("PATH", getEnv("TLCD") / "usr/bin" & ':' & getEnv("PATH"))
37+
for (i, j) in env:
38+
putEnv(i, absolutePath(j))
39+
40+
putEnv("PATH", getEnv("TLCD") / "usr/bin" & PathSep & getEnv("PATH"))
2841

2942
proc setEnvCross*() =
30-
for i in envCross:
31-
putEnv(i[0], i[1])
43+
const env = [
44+
("AR", "x86_64-glaucus-linux-musl-gcc-ar"),
45+
("AS", "x86_64-glaucus-linux-musl-as"),
46+
("CC", "x86_64-glaucus-linux-musl-gcc"),
47+
("CPP", "x86_64-glaucus-linux-musl-gcc -E"),
48+
("CROSS_COMPILE", "x86_64-glaucus-linux-musl-"),
49+
("CXX", "x86_64-glaucus-linux-musl-g++"),
50+
("CXXCPP", "x86_64-glaucus-linux-musl-g++ -E"),
51+
("HOSTCC", "gcc"),
52+
("NM", "x86_64-glaucus-linux-musl-gcc-nm"),
53+
("OBJCOPY", "x86_64-glaucus-linux-musl-objcopy"),
54+
("OBJDUMP", "x86_64-glaucus-linux-musl-objdump"),
55+
("RANLIB", "x86_64-glaucus-linux-musl-gcc-ranlib"),
56+
("READELF", "x86_64-glaucus-linux-musl-readelf"),
57+
("SIZE", "x86_64-glaucus-linux-musl-size"),
58+
("STRIP", "x86_64-glaucus-linux-musl-strip"),
59+
]
60+
61+
for (i, j) in env:
62+
putEnv(i, j)
63+
64+
proc setEnvCrossPkgConfig*() =
65+
const env = [
66+
("PKG_CONFIG_LIBDIR", "../cross/usr/lib/pkgconfig"),
67+
("PKG_CONFIG_PATH", "../cross/usr/lib/pkgconfig"),
68+
("PKG_CONFIG_SYSROOT_DIR", "../cross/"),
69+
("PKG_CONFIG_SYSTEM_INCLUDE_PATH", "../cross/usr/include"),
70+
("PKG_CONFIG_SYSTEM_LIBRARY_PATH", "../cross/usr/lib"),
71+
]
3272

33-
for i in envPkgConfig:
34-
putEnv(i[0], getEnv("CRSD") / i[1])
73+
for (i, j) in env:
74+
putEnv(i, absolutePath(j))
3575

3676
proc setEnvNative*() =
37-
for i in envNative:
38-
putEnv(i[0], i[1])
77+
const env = [
78+
("AR", "gcc-ar"),
79+
("AWK", "mawk"),
80+
("CC", "gcc"),
81+
("CORD", pathCoreRepo),
82+
("CPP", "gcc -E"),
83+
("CXX", "g++"),
84+
("CXXCPP", "g++ -E"),
85+
("LEX", "reflex"),
86+
("LIBTOOL", "slibtool"),
87+
("NM", "gcc-nm"),
88+
("PKG_CONFIG", "u-config"),
89+
("RANLIB", "gcc-ranlib"),
90+
("TMPD", pathTmp),
91+
("YACC", "byacc"),
92+
]
3993

40-
putEnv("CORD", pathCoreRepo)
41-
putEnv("TMPD", pathTmp)
94+
for (i, j) in env:
95+
putEnv(i, j)

src/constants.nim

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -7,97 +7,6 @@
77
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
88

99
const
10-
# dir
11-
dirCleanBootstrap* = ["cross", "log", "tmp", "toolchain"]
12-
dirPrepareBootstrap* = ["cross", "log", "pkg", "src", "tmp", "toolchain"]
13-
14-
# env
15-
envBootstrap* =
16-
[("CORD", "core"), ("CRSD", "cross"), ("TMPD", "tmp"), ("TLCD", "toolchain")]
17-
envCross* = [
18-
("AR", "x86_64-glaucus-linux-musl-gcc-ar"),
19-
("AS", "x86_64-glaucus-linux-musl-as"),
20-
("CC", "x86_64-glaucus-linux-musl-gcc"),
21-
("CPP", "x86_64-glaucus-linux-musl-gcc -E"),
22-
("CROSS_COMPILE", "x86_64-glaucus-linux-musl-"),
23-
("CXX", "x86_64-glaucus-linux-musl-g++"),
24-
("CXXCPP", "x86_64-glaucus-linux-musl-g++ -E"),
25-
("HOSTCC", "gcc"),
26-
("NM", "x86_64-glaucus-linux-musl-gcc-nm"),
27-
("OBJCOPY", "x86_64-glaucus-linux-musl-objcopy"),
28-
("OBJDUMP", "x86_64-glaucus-linux-musl-objdump"),
29-
("RANLIB", "x86_64-glaucus-linux-musl-gcc-ranlib"),
30-
("READELF", "x86_64-glaucus-linux-musl-readelf"),
31-
("SIZE", "x86_64-glaucus-linux-musl-size"),
32-
("STRIP", "x86_64-glaucus-linux-musl-strip"),
33-
]
34-
envNative* = [
35-
("AR", "gcc-ar"),
36-
("AWK", "mawk"),
37-
("CC", "gcc"),
38-
("CPP", "gcc -E"),
39-
("CXX", "g++"),
40-
("CXXCPP", "g++ -E"),
41-
("LEX", "reflex"),
42-
("LIBTOOL", "slibtool"),
43-
("NM", "gcc-nm"),
44-
("PKG_CONFIG", "u-config"),
45-
("RANLIB", "gcc-ranlib"),
46-
("YACC", "byacc"),
47-
]
48-
envPkgConfig* = [
49-
("PKG_CONFIG_LIBDIR", "usr/lib/pkgconfig"),
50-
("PKG_CONFIG_PATH", "usr/lib/pkgconfig"),
51-
("PKG_CONFIG_SYSROOT_DIR", "/"),
52-
("PKG_CONFIG_SYSTEM_INCLUDE_PATH", "usr/include"),
53-
("PKG_CONFIG_SYSTEM_LIBRARY_PATH", "usr/lib"),
54-
]
55-
56-
# flags
57-
cflags* =
58-
"-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"
59-
ldflags* =
60-
"-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"
61-
ltoflags* = "-flto=auto -flto-compression-level=3 -fuse-linker-plugin "
62-
makeflags* = "-j 5 -O"
63-
64-
# help
65-
help* =
66-
"""
67-
USAGE:
68-
rad [ COMMAND ]
69-
70-
COMMANDS:
71-
build Build packages
72-
clean Clean cache
73-
contents List package contents
74-
help Display this help message
75-
info Show package information
76-
install Install packages
77-
list List installed packages
78-
orphan List orphaned packages
79-
remove Remove packages
80-
search Search for packages
81-
update Update repositories
82-
upgrade Upgrade packages
83-
version Display rad version"""
84-
helpBootstrap* =
85-
"""
86-
USAGE:
87-
rad bootstrap [ COMMAND ]
88-
89-
COMMANDS:
90-
clean Clean cache
91-
cross Bootstrap cross glaucus (stage 2)
92-
native Bootstrap native glaucus (stage 3)
93-
toolchain Bootstrap toolchain (stage 1)"""
94-
version* =
95-
"""
96-
rad version 0.1.0
97-
98-
Licensed under the Mozilla Public License Version 2.0 (MPL-2.0)
99-
Copyright © 2018-2025 Firas Khana"""
100-
10110
# path
10211
pathPkgCache* = "/var/cache/rad/pkg"
10312
pathSrcCache* = "/var/cache/rad/src"
@@ -111,14 +20,6 @@ Copyright © 2018-2025 Firas Khana"""
11120
# shell
11221
shellRedirect* = ">/dev/null 2>&1"
11322

114-
# tool
115-
tool* = [
116-
"autoconf", "automake", "autopoint", "awk", "bash", "booster", "bzip2", "curl",
117-
"diff", "find", "gcc", "git", "grep", "gzip", "ld.bfd", "lex", "libtool", "limine",
118-
"m4", "make", "meson", "mkfs.erofs", "mkfs.fat", "ninja", "patch", "perl",
119-
"pkg-config", "sed", "tar", "xz", "yacc", "zstd",
120-
]
121-
12223
type Stages* = enum
12324
cross
12425
native

src/flags.nim

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,28 @@
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], constants
9+
import std/os
1010

11-
proc setEnvFlags*() =
12-
for i in [
13-
("CFLAGS", cflags),
14-
("CXXFLAGS", cflags),
15-
("LDFLAGS", &"{ldflags} {cflags}"),
16-
("MAKEFLAGS", makeflags),
17-
]:
18-
putEnv(i[0], i[1])
11+
proc setEnvFlags*(lto = true, parallel = true) =
12+
let
13+
cflags =
14+
if lto:
15+
"-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"
16+
else:
17+
"-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"
18+
ldflags =
19+
if lto:
20+
"-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 " &
21+
cflags
22+
else:
23+
"-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"
24+
makeflags = if parallel: "-j 5 -O" else: "-j 1"
25+
env = [
26+
("CFLAGS", cflags),
27+
("CXXFLAGS", cflags),
28+
("LDFLAGS", ldflags),
29+
("MAKEFLAGS", makeflags),
30+
]
1931

20-
proc setEnvFlagsNoLTO*() =
21-
for i in [
22-
("CFLAGS", replace(cflags, $ltoflags)),
23-
("CXXFLAGS", replace(cflags, $ltoflags)),
24-
("LDFLAGS", ldflags),
25-
("MAKEFLAGS", makeflags),
26-
]:
27-
putEnv(i[0], i[1])
28-
29-
proc setEnvFlagsNoParallel*() =
30-
putEnv("MAKEFLAGS", "-j 1")
32+
for (i, j) in env:
33+
putEnv(i, j)

src/options.nim

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,43 @@
99
import std/[os, parseopt, strutils], arch, bootstrap, packages, constants, tools
1010

1111
proc options*() =
12+
const
13+
help =
14+
"""
15+
USAGE:
16+
rad [ COMMAND ]
17+
18+
COMMANDS:
19+
build Build packages
20+
clean Clean cache
21+
contents List package contents
22+
help Display this help message
23+
info Show package information
24+
install Install packages
25+
list List installed packages
26+
orphan List orphaned packages
27+
remove Remove packages
28+
search Search for packages
29+
update Update repositories
30+
upgrade Upgrade packages
31+
version Display rad version"""
32+
helpBootstrap =
33+
"""
34+
USAGE:
35+
rad bootstrap [ COMMAND ]
36+
37+
COMMANDS:
38+
clean Clean cache
39+
cross Bootstrap cross glaucus (stage 2)
40+
native Bootstrap native glaucus (stage 3)
41+
toolchain Bootstrap toolchain (stage 1)"""
42+
version =
43+
"""
44+
rad version 0.1.0
45+
46+
Licensed under the Mozilla Public License Version 2.0 (MPL-2.0)
47+
Copyright © 2018-2025 Firas Khana"""
48+
1249
if paramCount() < 1:
1350
quit(help, QuitFailure)
1451

@@ -36,7 +73,7 @@ proc options*() =
3673

3774
echo "clean complete"
3875
of "cross":
39-
setEnvArch("glaucus")
76+
setEnvArch()
4077
setEnvBootstrap()
4178
setEnvCross()
4279
prepareCross()
@@ -57,7 +94,7 @@ proc options*() =
5794
echo "native complete"
5895
of "toolchain":
5996
require()
60-
setEnvArch("glaucus")
97+
setEnvArch()
6198
setEnvBootstrap()
6299
cleanBootstrap()
63100
prepareBootstrap()

src/packages.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ proc buildPackages*(
193193
setEnvFlags()
194194

195195
if "no-lto" in $package.opt:
196-
setEnvFlagsNoLTO()
196+
setEnvFlags(lto = false)
197197

198198
if "no-parallel" in $package.opt:
199-
setEnvFlagsNoParallel()
199+
setEnvFlags(parallel = false)
200200
else:
201201
putEnv("MAKEFLAGS", "parallel")
202202

src/tools.nim

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ proc lock*() =
7575
setControlCHook(interrupt)
7676

7777
proc require*() =
78-
for i in tool:
78+
const tools = [
79+
"autoconf", "automake", "autopoint", "awk", "bash", "booster", "bzip2", "curl",
80+
"diff", "find", "gcc", "git", "grep", "gzip", "ld.bfd", "lex", "libtool", "limine",
81+
"m4", "make", "meson", "mkfs.erofs", "mkfs.fat", "ninja", "patch", "perl",
82+
"pkg-config", "sed", "tar", "xz", "yacc", "zstd",
83+
]
84+
85+
for i in tools:
7986
if findExe(i).isEmptyOrWhitespace():
8087
abort(&"""{127:8}{&"\{i\} not found":48}""")
8188

0 commit comments

Comments
 (0)