Skip to content

Commit f8288c3

Browse files
committed
fix: Windows cross-compile library path resolution
- Set LIB environment variable for lld-link - Use IlcAdditionalLinkArgs for linker flags - Include crt, um, and ucrt library paths - Return env from getWindowsCrossCompileArgs - Bump version to 0.1.57
1 parent 20e9fc8 commit f8288c3

3 files changed

Lines changed: 46 additions & 18 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-dotnet-deploy",
33
"displayName": "Dotnet 部署工具",
44
"description": "通过 SSH 将 .NET 应用程序部署到 Ubuntu/Linux 服务器",
5-
"version": "0.1.56",
5+
"version": "0.1.57",
66
"publisher": "local",
77
"repository": {
88
"type": "git",

src/crossCompile/xwinSetup.ts

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export async function downloadWindowsSdk(
135135
export async function getWindowsCrossCompileArgs(runtime: string): Promise<{
136136
success: boolean;
137137
args: string[];
138+
env: Record<string, string>;
138139
error?: string;
139140
}> {
140141
const sdkPath = getXwinSdkPath();
@@ -143,12 +144,15 @@ export async function getWindowsCrossCompileArgs(runtime: string): Promise<{
143144

144145
// 检查 SDK 是否存在
145146
const crtPath = path.join(splatPath, 'crt');
146-
const sdkLibPath = path.join(splatPath, 'sdk', 'lib', 'ucrt', arch);
147+
const crtLibPath = path.join(splatPath, 'crt', 'lib', arch);
148+
const sdkUmPath = path.join(splatPath, 'sdk', 'lib', 'um', arch);
149+
const sdkUcrtPath = path.join(splatPath, 'sdk', 'lib', 'ucrt', arch);
147150

148151
if (!fs.existsSync(crtPath)) {
149152
return {
150153
success: false,
151154
args: [],
155+
env: {},
152156
error: 'Windows SDK not found. Please download it first.',
153157
};
154158
}
@@ -159,35 +163,57 @@ export async function getWindowsCrossCompileArgs(runtime: string): Promise<{
159163
return {
160164
success: false,
161165
args: [],
166+
env: {},
162167
error: 'lld-link is not installed. Please install LLD: brew install lld',
163168
};
164169
}
165170

171+
// 获取 lld-link 路径
172+
const lldPath = await getLldLinkPath();
173+
166174
// 构建 MSBuild 参数
167175
const args: string[] = [
168176
'-p:DisableUnsupportedError=true',
169-
'-p:CppLinker=lld-link',
170177
'-p:AcceptVSBuildToolsLicense=true',
171178
// 禁用 SourceLink 以避免 lld-link 路径解析问题
172179
'-p:EnableSourceLink=false',
173180
'-p:EnableSourceControlManagerQueries=false',
174181
];
175182

176-
// 添加链接器参数 (通过 LinkerArg)
177-
// 这些参数会被传递给 lld-link
178-
const linkerArgs = [
179-
`/vctoolsdir:${path.join(splatPath, 'crt')}`,
180-
`/winsdkdir:${path.join(splatPath, 'sdk')}`,
181-
`/LIBPATH:${path.join(splatPath, 'crt', 'lib', arch)}/`,
182-
`/LIBPATH:${path.join(splatPath, 'sdk', 'lib', 'um', arch)}/`,
183-
];
184-
185-
// 将链接器参数添加到 MSBuild
186-
for (const arg of linkerArgs) {
187-
args.push(`-p:LinkerArg="${arg}"`);
183+
// 设置 C++ 链接器
184+
if (lldPath) {
185+
args.push(`-p:CppLinker=${lldPath}`);
186+
} else {
187+
args.push('-p:CppLinker=lld-link');
188188
}
189189

190-
return { success: true, args };
190+
// 构建链接器参数 - 使用 /LIBPATH 指定库搜索路径
191+
const libPaths = [
192+
crtLibPath,
193+
sdkUmPath,
194+
sdkUcrtPath,
195+
].filter(p => fs.existsSync(p));
196+
197+
// 通过 IlcAdditionalLinkArgs 传递链接器参数
198+
const linkerArgs = libPaths.map(p => `/LIBPATH:"${p}"`).join(' ');
199+
args.push(`-p:IlcAdditionalLinkArgs=${linkerArgs}`);
200+
201+
// 构建 LIB 环境变量 - lld-link 需要这个来查找库
202+
const libEnvPaths = libPaths.join(path.delimiter);
203+
204+
// 添加 lld-link 到 PATH
205+
const brewPrefix = process.arch === 'arm64' ? '/opt/homebrew' : '/usr/local';
206+
const lldBinPath = path.join(brewPrefix, 'opt', 'lld', 'bin');
207+
const pathEnv = fs.existsSync(lldBinPath)
208+
? `${lldBinPath}:${process.env['PATH'] || ''}`
209+
: process.env['PATH'] || '';
210+
211+
const env: Record<string, string> = {
212+
'LIB': libEnvPaths,
213+
'PATH': pathEnv,
214+
};
215+
216+
return { success: true, args, env };
191217
}
192218

193219
/**

src/publisher.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,10 @@ async function prepareCrossCompileArgs(
226226

227227
const result = await getWindowsCrossCompileArgs(runtime);
228228
if (result.success) {
229-
const env = getWindowsCrossCompileEnv();
230-
return { success: true, args: result.args, env };
229+
// 合并环境变量
230+
const baseEnv = getWindowsCrossCompileEnv();
231+
const combinedEnv = { ...baseEnv, ...result.env };
232+
return { success: true, args: result.args, env: combinedEnv };
231233
} else {
232234
return { success: false, args: [], error: result.error };
233235
}

0 commit comments

Comments
 (0)