@@ -118,7 +118,80 @@ export async function createShims(packageDir: string, installPath: string, domai
118
118
return libraryPaths
119
119
}
120
120
121
+ // Helper function to build pkg-config paths for all installed packages
122
+ function buildPkgConfigPaths ( installPath : string ) : string [ ] {
123
+ const pkgConfigPaths : string [ ] = [ ]
124
+
125
+ try {
126
+ const domains = fs . readdirSync ( installPath , { withFileTypes : true } )
127
+ . filter ( dirent => dirent . isDirectory ( )
128
+ && ! [ 'bin' , 'sbin' , 'lib' , 'lib64' , 'share' , 'include' , 'etc' , 'pkgs' , '.tmp' , '.cache' ] . includes ( dirent . name ) )
129
+
130
+ for ( const domainEntry of domains ) {
131
+ const domainPath = path . join ( installPath , domainEntry . name )
132
+ if ( fs . existsSync ( domainPath ) ) {
133
+ const versions = fs . readdirSync ( domainPath , { withFileTypes : true } )
134
+ . filter ( dirent => dirent . isDirectory ( ) && dirent . name . startsWith ( 'v' ) )
135
+
136
+ for ( const versionEntry of versions ) {
137
+ const versionPath = path . join ( domainPath , versionEntry . name )
138
+ const pkgConfigDirs = [
139
+ path . join ( versionPath , 'lib' , 'pkgconfig' ) ,
140
+ path . join ( versionPath , 'lib64' , 'pkgconfig' ) ,
141
+ ]
142
+
143
+ for ( const pkgConfigDir of pkgConfigDirs ) {
144
+ if ( fs . existsSync ( pkgConfigDir ) && ! pkgConfigPaths . includes ( pkgConfigDir ) ) {
145
+ pkgConfigPaths . push ( pkgConfigDir )
146
+ }
147
+ }
148
+ }
149
+ }
150
+ }
151
+ }
152
+ catch {
153
+ // Ignore errors reading directories
154
+ }
155
+
156
+ return pkgConfigPaths
157
+ }
158
+
159
+ // Helper function to build include paths for all installed packages
160
+ function buildIncludePaths ( installPath : string ) : string [ ] {
161
+ const includePaths : string [ ] = [ ]
162
+
163
+ try {
164
+ const domains = fs . readdirSync ( installPath , { withFileTypes : true } )
165
+ . filter ( dirent => dirent . isDirectory ( )
166
+ && ! [ 'bin' , 'sbin' , 'lib' , 'lib64' , 'share' , 'include' , 'etc' , 'pkgs' , '.tmp' , '.cache' ] . includes ( dirent . name ) )
167
+
168
+ for ( const domainEntry of domains ) {
169
+ const domainPath = path . join ( installPath , domainEntry . name )
170
+ if ( fs . existsSync ( domainPath ) ) {
171
+ const versions = fs . readdirSync ( domainPath , { withFileTypes : true } )
172
+ . filter ( dirent => dirent . isDirectory ( ) && dirent . name . startsWith ( 'v' ) )
173
+
174
+ for ( const versionEntry of versions ) {
175
+ const versionPath = path . join ( domainPath , versionEntry . name )
176
+ const includeDir = path . join ( versionPath , 'include' )
177
+
178
+ if ( fs . existsSync ( includeDir ) && ! includePaths . includes ( includeDir ) ) {
179
+ includePaths . push ( includeDir )
180
+ }
181
+ }
182
+ }
183
+ }
184
+ }
185
+ catch {
186
+ // Ignore errors reading directories
187
+ }
188
+
189
+ return includePaths
190
+ }
191
+
121
192
const libraryPaths = buildLibraryPaths ( packageDir , installPath )
193
+ const pkgConfigPaths = buildPkgConfigPaths ( installPath )
194
+ const includePaths = buildIncludePaths ( installPath )
122
195
123
196
for ( const { sourceDir, shimDir : targetShimDir } of binaryDirs ) {
124
197
if ( ! fs . existsSync ( sourceDir ) ) {
@@ -139,9 +212,10 @@ export async function createShims(packageDir: string, installPath: string, domai
139
212
let shimContent = `#!/bin/sh
140
213
# Launchpad shim for ${ binary } (${ domain } v${ version } )
141
214
142
- # Set up library paths for dynamic linking
215
+ # Set up comprehensive build environment for launchpad-installed packages
143
216
`
144
217
218
+ // Set up library paths for dynamic linking
145
219
if ( libraryPaths . length > 0 ) {
146
220
const libraryPathString = libraryPaths . join ( ':' )
147
221
shimContent += `# macOS dynamic library paths
@@ -164,6 +238,39 @@ else
164
238
export LD_LIBRARY_PATH="${ libraryPathString } "
165
239
fi
166
240
241
+ `
242
+ }
243
+
244
+ // Set up pkg-config paths for build tools
245
+ if ( pkgConfigPaths . length > 0 ) {
246
+ const pkgConfigPathString = pkgConfigPaths . join ( ':' )
247
+ shimContent += `# Set up pkg-config to find launchpad-installed libraries
248
+ if [ -n "$PKG_CONFIG_PATH" ]; then
249
+ export PKG_CONFIG_PATH="${ pkgConfigPathString } :$PKG_CONFIG_PATH"
250
+ else
251
+ export PKG_CONFIG_PATH="${ pkgConfigPathString } "
252
+ fi
253
+
254
+ `
255
+ }
256
+
257
+ // Set up include paths for compilation
258
+ if ( includePaths . length > 0 ) {
259
+ const includePathString = includePaths . join ( ' ' )
260
+ shimContent += `# Set up include paths for compilation
261
+ if [ -n "$CPPFLAGS" ]; then
262
+ export CPPFLAGS="-I${ includePathString } $CPPFLAGS"
263
+ else
264
+ export CPPFLAGS="-I${ includePathString } "
265
+ fi
266
+
267
+ # Set up library paths for linking
268
+ if [ -n "$LDFLAGS" ]; then
269
+ export LDFLAGS="-L${ libraryPaths . join ( ' -L' ) } $LDFLAGS"
270
+ else
271
+ export LDFLAGS="-L${ libraryPaths . join ( ' -L' ) } "
272
+ fi
273
+
167
274
`
168
275
}
169
276
@@ -444,3 +551,133 @@ export async function validatePackageInstallation(packageDir: string, domain: st
444
551
return true // Assume valid if we can't check
445
552
}
446
553
}
554
+
555
+ /**
556
+ * Create a comprehensive environment setup script for build tools
557
+ * This script can be sourced to set up all launchpad-installed packages for building
558
+ */
559
+ export async function createBuildEnvironmentScript ( installPath : string ) : Promise < void > {
560
+ const scriptPath = path . join ( installPath , 'build-env.sh' )
561
+
562
+ // Build all the paths
563
+ const libraryPaths : string [ ] = [ ]
564
+ const pkgConfigPaths : string [ ] = [ ]
565
+ const includePaths : string [ ] = [ ]
566
+ const binPaths : string [ ] = [ ]
567
+
568
+ try {
569
+ const domains = fs . readdirSync ( installPath , { withFileTypes : true } )
570
+ . filter ( dirent => dirent . isDirectory ( )
571
+ && ! [ 'bin' , 'sbin' , 'lib' , 'lib64' , 'share' , 'include' , 'etc' , 'pkgs' , '.tmp' , '.cache' ] . includes ( dirent . name ) )
572
+
573
+ for ( const domainEntry of domains ) {
574
+ const domainPath = path . join ( installPath , domainEntry . name )
575
+ if ( fs . existsSync ( domainPath ) ) {
576
+ const versions = fs . readdirSync ( domainPath , { withFileTypes : true } )
577
+ . filter ( dirent => dirent . isDirectory ( ) && dirent . name . startsWith ( 'v' ) )
578
+
579
+ for ( const versionEntry of versions ) {
580
+ const versionPath = path . join ( domainPath , versionEntry . name )
581
+
582
+ // Add library paths
583
+ const libDirs = [
584
+ path . join ( versionPath , 'lib' ) ,
585
+ path . join ( versionPath , 'lib64' ) ,
586
+ ]
587
+ for ( const libDir of libDirs ) {
588
+ if ( fs . existsSync ( libDir ) && ! libraryPaths . includes ( libDir ) ) {
589
+ libraryPaths . push ( libDir )
590
+ }
591
+ }
592
+
593
+ // Add pkg-config paths
594
+ const pkgConfigDirs = [
595
+ path . join ( versionPath , 'lib' , 'pkgconfig' ) ,
596
+ path . join ( versionPath , 'lib64' , 'pkgconfig' ) ,
597
+ ]
598
+ for ( const pkgConfigDir of pkgConfigDirs ) {
599
+ if ( fs . existsSync ( pkgConfigDir ) && ! pkgConfigPaths . includes ( pkgConfigDir ) ) {
600
+ pkgConfigPaths . push ( pkgConfigDir )
601
+ }
602
+ }
603
+
604
+ // Add include paths
605
+ const includeDir = path . join ( versionPath , 'include' )
606
+ if ( fs . existsSync ( includeDir ) && ! includePaths . includes ( includeDir ) ) {
607
+ includePaths . push ( includeDir )
608
+ }
609
+
610
+ // Add bin paths
611
+ const binDir = path . join ( versionPath , 'bin' )
612
+ if ( fs . existsSync ( binDir ) && ! binPaths . includes ( binDir ) ) {
613
+ binPaths . push ( binDir )
614
+ }
615
+ }
616
+ }
617
+ }
618
+ }
619
+ catch {
620
+ // Ignore errors reading directories
621
+ }
622
+
623
+ // Create the environment setup script
624
+ let scriptContent = `#!/bin/sh
625
+ # Launchpad Build Environment Setup Script
626
+ # Source this script to set up environment for building with launchpad-installed packages
627
+
628
+ # Set up PATH to include launchpad binaries
629
+ if [ -n "$PATH" ]; then
630
+ export PATH="${ binPaths . join ( ':' ) } :$PATH"
631
+ else
632
+ export PATH="${ binPaths . join ( ':' ) } "
633
+ fi
634
+
635
+ `
636
+
637
+ // Set up library paths
638
+ if ( libraryPaths . length > 0 ) {
639
+ const libraryPathString = libraryPaths . join ( ':' )
640
+ scriptContent += `# Set up library paths for dynamic linking
641
+ export LD_LIBRARY_PATH="${ libraryPathString } ${ process . platform === 'darwin' ? ':$LD_LIBRARY_PATH' : '' } "
642
+ export DYLD_LIBRARY_PATH="${ libraryPathString } ${ process . platform === 'darwin' ? ':$DYLD_LIBRARY_PATH' : '' } "
643
+ export DYLD_FALLBACK_LIBRARY_PATH="${ libraryPathString } :/usr/local/lib:/lib:/usr/lib"
644
+
645
+ `
646
+ }
647
+
648
+ // Set up pkg-config paths
649
+ if ( pkgConfigPaths . length > 0 ) {
650
+ const pkgConfigPathString = pkgConfigPaths . join ( ':' )
651
+ scriptContent += `# Set up pkg-config to find launchpad-installed libraries
652
+ export PKG_CONFIG_PATH="${ pkgConfigPathString } ${ process . env . PKG_CONFIG_PATH ? ':' + process . env . PKG_CONFIG_PATH : '' } "
653
+
654
+ `
655
+ }
656
+
657
+ // Set up include and library paths for compilation
658
+ if ( includePaths . length > 0 || libraryPaths . length > 0 ) {
659
+ scriptContent += `# Set up include paths for compilation
660
+ export CPPFLAGS="-I${ includePaths . join ( ' -I' ) } ${ process . env . CPPFLAGS ? ' ' + process . env . CPPFLAGS : '' } "
661
+
662
+ # Set up library paths for linking
663
+ export LDFLAGS="-L${ libraryPaths . join ( ' -L' ) } ${ process . env . LDFLAGS ? ' ' + process . env . LDFLAGS : '' } "
664
+
665
+ `
666
+ }
667
+
668
+ scriptContent += `# Print environment info
669
+ echo "Launchpad build environment activated:"
670
+ echo " PATH: $PATH"
671
+ echo " LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
672
+ echo " PKG_CONFIG_PATH: $PKG_CONFIG_PATH"
673
+ echo " CPPFLAGS: $CPPFLAGS"
674
+ echo " LDFLAGS: $LDFLAGS"
675
+ `
676
+
677
+ await fs . promises . writeFile ( scriptPath , scriptContent )
678
+ await fs . promises . chmod ( scriptPath , 0o755 )
679
+
680
+ if ( config . verbose ) {
681
+ console . warn ( `Created build environment script: ${ scriptPath } ` )
682
+ }
683
+ }
0 commit comments