@@ -36,10 +36,11 @@ import {
3636 undefinedIfEmpty ,
3737 getOptOutPreference ,
3838 isAmazonLinux2 ,
39+ fs ,
3940 getClientId ,
4041 extensionVersion ,
4142} from 'aws-core-vscode/shared'
42- import { processUtils } from 'aws-core-vscode/shared'
43+ import { processUtils , isSageMaker } from 'aws-core-vscode/shared'
4344import { activate } from './chat/activation'
4445import { AmazonQResourcePaths } from './lspInstaller'
4546import { ConfigSection , isValidConfigSection , pushConfigUpdate , toAmazonQLSPLogLevel } from './config'
@@ -53,11 +54,24 @@ import { InlineChatTutorialAnnotation } from '../app/inline/tutorials/inlineChat
5354const localize = nls . loadMessageBundle ( )
5455const logger = getLogger ( 'amazonqLsp.lspClient' )
5556
56- export const glibcLinker : string = process . env . VSCODE_SERVER_CUSTOM_GLIBC_LINKER || ''
57- export const glibcPath : string = process . env . VSCODE_SERVER_CUSTOM_GLIBC_PATH || ''
57+ export async function hasGlibcPatch ( ) : Promise < boolean > {
58+ // Skip GLIBC patching for SageMaker environments
59+ if ( isSageMaker ( ) ) {
60+ getLogger ( 'amazonqLsp' ) . info ( 'SageMaker environment detected in hasGlibcPatch, skipping GLIBC patching' )
61+ return false // Return false to ensure SageMaker doesn't try to use GLIBC patching
62+ }
63+
64+ // Check for environment variables first (for CDM)
65+ const glibcLinker = process . env . VSCODE_SERVER_CUSTOM_GLIBC_LINKER || ''
66+ const glibcPath = process . env . VSCODE_SERVER_CUSTOM_GLIBC_PATH || ''
5867
59- export function hasGlibcPatch ( ) : boolean {
60- return glibcLinker . length > 0 && glibcPath . length > 0
68+ if ( glibcLinker . length > 0 && glibcPath . length > 0 ) {
69+ getLogger ( 'amazonqLsp' ) . info ( 'GLIBC patching environment variables detected' )
70+ return true
71+ }
72+
73+ // Fall back to file check for other environments
74+ return await fs . exists ( '/opt/vsc-sysroot/lib64/ld-linux-x86-64.so.2' )
6175}
6276
6377export async function startLanguageServer (
@@ -82,9 +96,31 @@ export async function startLanguageServer(
8296 const traceServerEnabled = Settings . instance . isSet ( `${ clientId } .trace.server` )
8397 let executable : string [ ] = [ ]
8498 // apply the GLIBC 2.28 path to node js runtime binary
85- if ( isAmazonLinux2 ( ) && hasGlibcPatch ( ) ) {
86- executable = [ glibcLinker , '--library-path' , glibcPath , resourcePaths . node ]
87- getLogger ( 'amazonqLsp' ) . info ( `Patched node runtime with GLIBC to ${ executable } ` )
99+ if ( isSageMaker ( ) ) {
100+ // SageMaker doesn't need GLIBC patching
101+ getLogger ( 'amazonqLsp' ) . info ( 'SageMaker environment detected, skipping GLIBC patching' )
102+ executable = [ resourcePaths . node ]
103+ } else if ( isAmazonLinux2 ( ) && ( await hasGlibcPatch ( ) ) ) {
104+ // Use environment variables if available (for CDM)
105+ if ( process . env . VSCODE_SERVER_CUSTOM_GLIBC_LINKER && process . env . VSCODE_SERVER_CUSTOM_GLIBC_PATH ) {
106+ executable = [
107+ process . env . VSCODE_SERVER_CUSTOM_GLIBC_LINKER ,
108+ '--library-path' ,
109+ process . env . VSCODE_SERVER_CUSTOM_GLIBC_PATH ,
110+ resourcePaths . node ,
111+ ]
112+ getLogger ( 'amazonqLsp' ) . info ( `Patched node runtime with GLIBC using env vars to ${ executable } ` )
113+ }
114+ // Fall back to hardcoded path
115+ else {
116+ executable = [
117+ '/opt/vsc-sysroot/lib64/ld-linux-x86-64.so.2' ,
118+ '--library-path' ,
119+ '/opt/vsc-sysroot/lib64' ,
120+ resourcePaths . node ,
121+ ]
122+ getLogger ( 'amazonqLsp' ) . info ( `Patched node runtime with GLIBC using hardcoded path to ${ executable } ` )
123+ }
88124 } else {
89125 executable = [ resourcePaths . node ]
90126 }
0 commit comments