Skip to content

Commit 482e658

Browse files
committed
chore: wip
1 parent 8b3f5fa commit 482e658

File tree

3 files changed

+87
-8
lines changed

3 files changed

+87
-8
lines changed

packages/launchpad/bin/cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3373,7 +3373,8 @@ cli
33733373
// Output the script content for shell evaluation
33743374
const scriptContent = fs.readFileSync(buildEnvScript, 'utf-8')
33753375
console.log(scriptContent)
3376-
} else {
3376+
}
3377+
else {
33773378
// Execute the script directly
33783379
const { execSync } = await import('node:child_process')
33793380
execSync(`source "${buildEnvScript}"`, { stdio: 'inherit', shell: '/bin/sh' })

packages/launchpad/src/install-core.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import process from 'node:process'
77
import { install_bun } from './bun'
88
import { getCachedPackagePath, savePackageToCache } from './cache'
99
import { config } from './config'
10-
import { createShims, createVersionCompatibilitySymlinks, createVersionSymlinks, validatePackageInstallation, createBuildEnvironmentScript } from './install-helpers'
10+
import { createBuildEnvironmentScript, createPkgConfigSymlinks, createShims, createVersionCompatibilitySymlinks, createVersionSymlinks, validatePackageInstallation } from './install-helpers'
1111
import { cleanupSpinner, logUniqueMessage } from './logging'
1212
import { getLatestVersion, parsePackageSpec, resolvePackageName, resolveVersion } from './package-resolution'
1313
import { installMeilisearch } from './special-installers'
@@ -864,6 +864,9 @@ export async function downloadPackage(
864864
// Create missing library symlinks for dynamic linking
865865
await createLibrarySymlinks(packageDir, domain)
866866

867+
// Create pkg-config symlinks for common naming mismatches
868+
await createPkgConfigSymlinks(packageDir, domain)
869+
867870
// Create version symlinks like pkgx does
868871
await createVersionSymlinks(installPath, domain, version)
869872

packages/launchpad/src/install-helpers.ts

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable no-console */
22
import fs from 'node:fs'
33
import path from 'node:path'
4+
import process from 'node:process'
45
import { config } from './config'
56

67
/**
@@ -637,9 +638,10 @@ fi
637638
// Set up library paths
638639
if (libraryPaths.length > 0) {
639640
const libraryPathString = libraryPaths.join(':')
641+
const isDarwin = process.platform === 'darwin'
640642
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 LD_LIBRARY_PATH="${libraryPathString}${isDarwin ? ':$LD_LIBRARY_PATH' : ''}"
644+
export DYLD_LIBRARY_PATH="${libraryPathString}${isDarwin ? ':$DYLD_LIBRARY_PATH' : ''}"
643645
export DYLD_FALLBACK_LIBRARY_PATH="${libraryPathString}:/usr/local/lib:/lib:/usr/lib"
644646
645647
`
@@ -648,24 +650,54 @@ export DYLD_FALLBACK_LIBRARY_PATH="${libraryPathString}:/usr/local/lib:/lib:/usr
648650
// Set up pkg-config paths
649651
if (pkgConfigPaths.length > 0) {
650652
const pkgConfigPathString = pkgConfigPaths.join(':')
653+
const existingPkgConfig = process.env.PKG_CONFIG_PATH || ''
654+
const pkgConfigPath = existingPkgConfig ? `${pkgConfigPathString}:${existingPkgConfig}` : pkgConfigPathString
651655
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 : ''}"
656+
export PKG_CONFIG_PATH="${pkgConfigPath}"
653657
654658
`
655659
}
656660

657661
// Set up include and library paths for compilation
658662
if (includePaths.length > 0 || libraryPaths.length > 0) {
663+
const existingCppflags = process.env.CPPFLAGS || ''
664+
const existingLdflags = process.env.LDFLAGS || ''
665+
const cppflags = existingCppflags ? `-I${includePaths.join(' -I')} ${existingCppflags}` : `-I${includePaths.join(' -I')}`
666+
const ldflags = existingLdflags ? `-L${libraryPaths.join(' -L')} ${existingLdflags}` : `-L${libraryPaths.join(' -L')}`
659667
scriptContent += `# Set up include paths for compilation
660-
export CPPFLAGS="-I${includePaths.join(' -I')}${process.env.CPPFLAGS ? ' ' + process.env.CPPFLAGS : ''}"
668+
export CPPFLAGS="${cppflags}"
661669
662670
# Set up library paths for linking
663-
export LDFLAGS="-L${libraryPaths.join(' -L')}${process.env.LDFLAGS ? ' ' + process.env.LDFLAGS : ''}"
671+
export LDFLAGS="${ldflags}"
664672
665673
`
666674
}
667675

668-
scriptContent += `# Print environment info
676+
scriptContent += `# Create pkg-config symlinks for common naming mismatches
677+
# This handles cases where build scripts expect different package names
678+
for pkg_dir in "$PKG_CONFIG_PATH"; do
679+
IFS=':' read -ra PKG_DIRS <<< "$pkg_dir"
680+
for dir in "\${PKG_DIRS[@]}"; do
681+
if [ -d "$dir" ]; then
682+
# libpng16 -> libpng
683+
if [ -f "$dir/libpng16.pc" ] && [ ! -f "$dir/libpng.pc" ]; then
684+
ln -sf libpng16.pc "$dir/libpng.pc"
685+
fi
686+
687+
# libturbojpeg -> libjpeg
688+
if [ -f "$dir/libturbojpeg.pc" ] && [ ! -f "$dir/libjpeg.pc" ]; then
689+
ln -sf libturbojpeg.pc "$dir/libjpeg.pc"
690+
fi
691+
692+
# openssl -> libssl
693+
if [ -f "$dir/openssl.pc" ] && [ ! -f "$dir/libssl.pc" ]; then
694+
ln -sf openssl.pc "$dir/libssl.pc"
695+
fi
696+
fi
697+
done
698+
done
699+
700+
# Print environment info
669701
echo "Launchpad build environment activated:"
670702
echo " PATH: $PATH"
671703
echo " LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
@@ -681,3 +713,46 @@ echo " LDFLAGS: $LDFLAGS"
681713
console.warn(`Created build environment script: ${scriptPath}`)
682714
}
683715
}
716+
717+
/**
718+
* Create pkg-config symlinks for common naming mismatches
719+
* This handles cases where build scripts expect different package names than what's installed
720+
*/
721+
export async function createPkgConfigSymlinks(packageDir: string, domain: string): Promise<void> {
722+
const pkgConfigDir = path.join(packageDir, 'lib', 'pkgconfig')
723+
if (!fs.existsSync(pkgConfigDir))
724+
return
725+
726+
const pkgConfigSymlinks: Record<string, Array<{ target: string, link: string }>> = {
727+
'libpng.org': [
728+
{ target: 'libpng16.pc', link: 'libpng.pc' },
729+
],
730+
'libjpeg-turbo.org': [
731+
{ target: 'libturbojpeg.pc', link: 'libjpeg.pc' },
732+
],
733+
'openssl.org': [
734+
{ target: 'openssl.pc', link: 'libssl.pc' },
735+
],
736+
}
737+
738+
const symlinks = pkgConfigSymlinks[domain] || []
739+
740+
for (const { target, link } of symlinks) {
741+
const targetPath = path.join(pkgConfigDir, target)
742+
const linkPath = path.join(pkgConfigDir, link)
743+
744+
if (fs.existsSync(targetPath) && !fs.existsSync(linkPath)) {
745+
try {
746+
await fs.promises.symlink(target, linkPath)
747+
if (config.verbose) {
748+
console.warn(`Created pkg-config symlink: ${link} -> ${target}`)
749+
}
750+
}
751+
catch (error) {
752+
if (config.verbose) {
753+
console.warn(`Failed to create pkg-config symlink ${link} -> ${target}:`, error)
754+
}
755+
}
756+
}
757+
}
758+
}

0 commit comments

Comments
 (0)