@@ -81,7 +81,7 @@ await rsync(config.path.yaml.parent(), config.path.build.join("props"))
8181// }), force: true })
8282
8383/// create toolchain if necessary
84- const toolchain_PATH = make_toolchain ( )
84+ const toolchain_PATH = await make_toolchain ( )
8585
8686if ( toolchain_PATH ) {
8787 await gum ( 'toolchain' )
@@ -173,7 +173,7 @@ if (ghout) {
173173}
174174
175175///////////////////////////////////////////////////////////////////
176- function make_toolchain ( ) {
176+ async function make_toolchain ( ) {
177177 if ( yml ?. build ?. skip === 'shims' || yml ?. build ?. skip ?. includes ?.( 'shims' ) ) {
178178 return
179179 }
@@ -185,13 +185,33 @@ function make_toolchain() {
185185 const has_llvm = deps . has ( 'llvm.org' )
186186 const has_binutils = deps . has ( 'gnu.org/binutils' )
187187
188+ // ensure default compiler is installed before creating toolchain symlinks
189+ if ( ! has_gcc && ! has_llvm ) {
190+ const rv = await new Deno . Command ( 'pkgx' , { args : [ '+llvm.org' , '--' , 'true' ] } ) . output ( )
191+ if ( ! rv . success ) throw new Error ( 'failed to install default llvm' )
192+ }
193+
188194 // rm ∵ // https://github.com/pkgxdev/brewkit/issues/303
189195 const d = config . path . home . join ( 'toolchain' ) . rm ( { recursive : true } ) . mkdir ( 'p' )
190196 const prefix = useConfig ( ) . prefix
191197
192- const llvm = ( bin : string ) => prefix . join ( 'llvm.org/v*/bin' , bin )
193- const gcc = ( bin : string ) => prefix . join ( 'gnu.org/gcc/v*/bin' , bin )
194- const binutils = ( bin : string ) => prefix . join ( 'gnu.org/binutils/v*/bin' , bin )
198+ const dep_bin = ( project : string , bin : string ) : Path => {
199+ const dep = config . deps . gas . find ( x => x . pkg . project === project )
200+ if ( dep ) return dep . path . join ( 'bin' , bin )
201+ // fallback: resolve from installed versions
202+ const dir = prefix . join ( project )
203+ if ( dir . isDirectory ( ) ) {
204+ const versions = [ ...Deno . readDirSync ( dir . string ) ]
205+ . filter ( e => e . isDirectory && e . name . startsWith ( 'v' ) )
206+ . sort ( ( a , b ) => a . name . localeCompare ( b . name , undefined , { numeric : true } ) )
207+ if ( versions . length ) return dir . join ( versions . at ( - 1 ) ! . name , 'bin' , bin )
208+ }
209+ throw new Error ( `cannot find ${ project } installation` )
210+ }
211+
212+ const llvm = ( bin : string ) => dep_bin ( 'llvm.org' , bin )
213+ const gcc = ( bin : string ) => dep_bin ( 'gnu.org/gcc' , bin )
214+ const binutils = ( bin : string ) => dep_bin ( 'gnu.org/binutils' , bin )
195215
196216 const symlink = ( names : string [ ] , target : Path ) => {
197217 for ( const name of names ) {
0 commit comments