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
2724proc 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
163157proc 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
183176proc 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:
0 commit comments