@@ -19,7 +19,9 @@ type Package = object
1919 ver, url, sum, bld, run* , opt = " nil"
2020
2121type Stages * = enum
22- cross, native, toolchain
22+ cross
23+ native
24+ toolchain
2325
2426proc cleanCache * () =
2527 removeDir (radTmp)
@@ -37,7 +39,7 @@ proc parseInfo*(nom: string): Package =
3739 if line.isEmptyOrWhitespace () or line.startsWith ('#' ):
3840 continue
3941
40- if line.contains (" = \" " ) or line.contains (" = \" " ) or '=' notin line:
42+ if line.contains (" = \" " ) or line.contains (" = \" " ) or '=' notin line:
4143 abort (& """ { " nom" :8 } { " whitespace found" :48 } """ )
4244
4345 let pair = line.split ('=' , 1 )
@@ -77,10 +79,13 @@ idx nom ver cmd now
7779proc genContents (dir, contents: string ) =
7880 var entries: seq [string ]
7981
80- for entry in walkDirRec (dir, yieldFilter = {pcFile .. pcLinkToDir}, relative = true , skipSpecial = true ):
82+ for entry in walkDirRec (
83+ dir, yieldFilter = {pcFile .. pcLinkToDir}, relative = true , skipSpecial = true
84+ ):
8185 entries &= (
8286 if getFileInfo (dir / entry, followSymlink = false ).kind == pcDir: entry & '/'
83- else : entry)
87+ else : entry
88+ )
8489
8590 let contents = open (contents, fmWrite)
8691
@@ -131,7 +136,9 @@ proc fetchPackages(packages: openArray[string]) =
131136 createDir (tmp)
132137 discard extractTar (archive, tmp)
133138
134- proc resolveDeps (nom: string , packages: var seq [string ], deps: var Table [string , seq [string ]]) =
139+ proc resolveDeps (
140+ nom: string , packages: var seq [string ], deps: var Table [string , seq [string ]]
141+ ) =
135142 if nom in packages:
136143 return
137144
@@ -185,10 +192,9 @@ proc buildPackages*(packages: openArray[string], bootstrap = false, stage = nati
185192 for idx, nom in queue:
186193 let package = parseInfo (nom)
187194 let archive =
188- if package.url == " nil" :
189- pkgCache / nom / nom & " .tar.zst"
190- else :
191- pkgCache / nom / nom & '-' & package.ver & " .tar.zst"
195+ pkgCache / nom / nom &
196+ (if package.url == " nil" : " .tar.zst"
197+ else : '-' & package.ver & " .tar.zst" )
192198
193199 printContent (idx, nom, package.ver, " build" )
194200
@@ -197,10 +203,9 @@ proc buildPackages*(packages: openArray[string], bootstrap = false, stage = nati
197203 if fileExists (archive):
198204 continue
199205
200- putEnv (" dir" , pkgCache / nom / " dir" )
201- createDir (getEnv (" dir" ))
206+ createDir (pkgCache / nom / " dir" )
202207
203- const env = [
208+ const envExes = [
204209 (" AR" , " gcc-ar" ),
205210 (" AWK" , " mawk" ),
206211 (" CC" , " gcc" ),
@@ -212,48 +217,68 @@ proc buildPackages*(packages: openArray[string], bootstrap = false, stage = nati
212217 (" NM" , " gcc-nm" ),
213218 (" PKG_CONFIG" , " u-config" ),
214219 (" RANLIB" , " gcc-ranlib" ),
215- (" YACC" , " byacc" )]
220+ (" YACC" , " byacc" ),
221+ ]
216222
217- for (i, j) in env :
223+ for (i, j) in envExes :
218224 putEnv (i, j)
219225
220- if dirExists (radTmp / nom):
221- setCurrentDir (radTmp / nom)
222- if dirExists (radTmp / nom / nom & '-' & package.ver):
223- setCurrentDir (radTmp / nom / nom & '-' & package.ver)
226+ let cflags =
227+ " -pipe -O2 -fgraphite-identity -floop-nest-optimize" & (
228+ if " no-lto" notin package.opt:
229+ " -flto=auto -flto-compression-level=3 -fuse-linker-plugin "
230+ else :
231+ " "
232+ ) &
233+ " -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"
224234
225235 let env = [
226236 (" ARCH" , " x86-64" ),
227- (" GLAUCUS_BUILD" , execCmdEx (coreRepo / " slibtool/files/config.guess" ).output.strip ()),
228- (" GLAUCUS_HOST" , " x86_64-glaucus-linux-musl" ),
229- (" GLAUCUS_TARGET" , " x86_64-pc-linux-musl" ),
230- (" PRETTY_NAME" , " glaucus s6 x86-64-v3 " & now ().format (" YYYYMMdd" ))]
237+ (" CFLAGS" , cflags),
238+ (" CXXFLAGS" , cflags),
239+ (
240+ " LDFLAGS" ,
241+ " -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" &
242+ (
243+ if " no-lto" notin package.opt:
244+ " " & cflags
245+ else :
246+ " "
247+ ),
248+ ),
249+ (" MAKEFLAGS" , if " no-parallel" notin package.opt: " -j 5 -O" else : " -j 1" ),
250+ (" PRETTY_NAME" , " glaucus s6 x86-64-v3 " & now ().format (" YYYYMMdd" )),
251+ ]
231252
232253 for (i, j) in env:
233254 putEnv (i, j)
234255
235- let cflags =
236- if " no-lto " notin package.opt:
237- " -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 "
238- else :
239- " -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 "
256+ let crossShell =
257+ & """
258+ build= { execCmdEx (coreRepo / " slibtool/files/config.guess " ).output. strip () }
259+ host=x86_64-glaucus-linux-musl
260+ target=x86_64-pc-linux-musl
240261
241- let envFlags = [
242- (" CFLAGS" , cflags),
243- (" CXXFLAGS" , cflags),
244- (" LDFLAGS" ,
245- if " no-lto" notin package.opt:
246- " -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 " &
247- cflags
248- else :
249- " -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" ),
250- (" MAKEFLAGS" , if " no-parallel" notin package.opt: " -j 5 -O" else : " -j 1" )]
262+ cross={ absolutePath (" ../../glaucus/cross" )}
263+ toolchain={ absolutePath (" ../../glaucus/toolchain" )} """
251264
252- for (i, j) in envFlags:
253- putEnv (i, j)
265+ if dirExists (radTmp / nom):
266+ setCurrentDir (radTmp / nom)
267+ if dirExists (radTmp / nom / nom & '-' & package.ver):
268+ setCurrentDir (radTmp / nom / nom & '-' & package.ver)
254269
255270 let shell = execCmdEx (
256271 & """ sh -efu -c '
272+ { (if bootstrap: crossShell else : " :" )}
273+
274+ core={ coreRepo}
275+ tmp={ radTmp}
276+
277+ dir={ pkgCache / nom / " dir" }
278+
279+ nom={ nom}
280+ ver={ package.ver}
281+
257282 . { coreRepo / nom / (if stage == native: " build" else : " build" & '-' & $ stage)}
258283
259284 for i in prepare configure build; do
@@ -262,9 +287,12 @@ proc buildPackages*(packages: openArray[string], bootstrap = false, stage = nati
262287 fi
263288 done
264289
265- package' """ )
290+ package' """
291+ )
266292
267- writeFile (radLog / nom & (if stage == native: " " else : '.' & $ stage), shell.output.strip ())
293+ writeFile (
294+ radLog / nom & (if stage == native: " " else : '.' & $ stage), shell.output.strip ()
295+ )
268296
269297 if shell.exitCode != QuitSuccess :
270298 abort (& " { shell.exitCode:<8 } { nom:24 } { package.ver:24 } " )
0 commit comments