Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search for LLVM clang-cl compiler #2627

Merged
merged 17 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions src/kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,10 @@ export async function kitIfCompiler(bin: string, pr?: ProgressReporter): Promise
// Check by filename what the compiler might be. This is just heuristic.
const gcc_regex = /^((\w+-)*)gcc(-\d+(\.\d+(\.\d+)?)?)?(\.exe)?$/;
const clang_regex = /^clang(-\d+(\.\d+(\.\d+)?)?)?(\.exe)?$/;
const clang_cl_regex = /^clang\-cl(-\d+(\.\d+(\.\d+)?)?)?(\.exe)?$/;
const gcc_res = gcc_regex.exec(fname);
const clang_res = clang_regex.exec(fname);
const clang_cl_res = clang_cl_regex.exec(fname);
if (gcc_res) {
const version = await getCompilerVersion('GCC', bin, pr);
if (version === null) {
Expand Down Expand Up @@ -368,7 +370,7 @@ export async function kitIfCompiler(bin: string, pr?: ProgressReporter): Promise
}
return gccKit;

} else if (clang_res) {
} else if (clang_res || clang_cl_res) {
const version = await getCompilerVersion('Clang', bin, pr);
if (version === null) {
return null;
Expand All @@ -383,7 +385,7 @@ export async function kitIfCompiler(bin: string, pr?: ProgressReporter): Promise
}

const clangCompilers: { [lang: string]: string } = {};
const clangxx_fname = fname.replace(/^clang/, 'clang++');
const clangxx_fname = clang_cl_res ? fname : fname.replace(/^clang/, 'clang++');
const clangxx_bin1 = path.join(path.dirname(bin), clangxx_fname);
log.debug(localize('detected.clang.compiler', 'Detected Clang compiler: {0}', bin));
if (await fs.exists(clangxx_bin1)) {
Expand All @@ -392,9 +394,9 @@ export async function kitIfCompiler(bin: string, pr?: ProgressReporter): Promise
// Names like clang++-13
clangCompilers.CXX = clangxx_bin1;
} else {
const fname2 = fname.replace(/clang(-\d+(\.\d+(\.\d+)?)?)/, 'clang');
const fname2 = clang_cl_res ? fname.replace(/clang\-cl(-\d+(\.\d+(\.\d+)?)?)/, 'clang-cl') : fname.replace(/clang(-\d+(\.\d+(\.\d+)?)?)/, 'clang');
const bin2 = path.join(path.dirname(bin), fname2);
const clangxx_fname2 = fname2.replace(/clang/, 'clang++');
const clangxx_fname2 = clang_cl_res ? fname : fname2.replace(/clang/, 'clang++');
const clangxx_bin2 = path.join(path.dirname(bin), clangxx_fname2);
// Ensure the version is match
const version2 = await fs.exists(bin2) ? await getCompilerVersion('Clang', bin2, pr) : null;
Expand All @@ -416,7 +418,7 @@ export async function kitIfCompiler(bin: string, pr?: ProgressReporter): Promise
}
}
return {
name: version.detectedName,
name: clang_cl_res ? version.detectedName.replace(/^Clang/, 'Clang\-cl') : version.detectedName,
elahehrashedi marked this conversation as resolved.
Show resolved Hide resolved
compilers: clangCompilers
};
} else {
Expand Down Expand Up @@ -798,17 +800,31 @@ async function scanDirForClangForMSVCKits(dir: string, vsInstalls: VSInstallatio
const vs_arch = (version.target && version.target.triple.includes('i686-pc')) ? 'x86' : 'amd64';

const clangArch = (vs_arch === "amd64") ? "x64\\" : "";
const clangKitName = `Clang ${version.version} ${clang_cli} for MSVC ${vs.installationVersion} (${install_name} - ${vs_arch})`;
if (binPath.startsWith(`${vs.installationPath}\\VC\\Tools\\Llvm\\${clangArch}bin`) && await util.checkFileExists(util.lightNormalizePath(binPath))) {
elahehrashedi marked this conversation as resolved.
Show resolved Hide resolved
clangKits.push({
name: clangKitName,
visualStudio: kitVSName(vs),
visualStudioArchitecture: vs_arch,
compilers: {
C: binPath,
CXX: binPath
}
});
const useClangVersion: boolean = versionLess(version.version, '14.0.0');
const clangKitName: string = (isClangCL ? `Clang-cl` : `Clang`) + (useClangVersion ? ` ${version.version}` : "") + ` ${clang_cli} for ${install_name} - ${vs_arch} (MSVC ${vs.installationVersion})`;
elahehrashedi marked this conversation as resolved.
Show resolved Hide resolved
const clangCXX = isClangCL ? binPath : binPath.replace(/^clang/, 'clang++');
const installationVersion = /^(\d+)+./.exec(vs.installationVersion);
let generatorName: string | undefined;
if (installationVersion) {
generatorName = VsGenerators[installationVersion[1]];
elahehrashedi marked this conversation as resolved.
Show resolved Hide resolved
}
if (binPath.startsWith(`${vs.installationPath}\\VC\\Tools\\Llvm\\${clangArch}bin`)) {
if (generatorName) {
clangKits.push({
name: clangKitName,
visualStudio: kitVSName(vs),
visualStudioArchitecture: vs_arch,
preferredGenerator: {
elahehrashedi marked this conversation as resolved.
Show resolved Hide resolved
name: generatorName,
platform: vs_arch,
toolset: `host=${vs_arch}`
},
compilers: {
C: binPath,
CXX: clangCXX
}
});
}
}
}
return clangKits;
Expand Down
2 changes: 1 addition & 1 deletion src/proc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export function execute(command: string, args?: string[], outputConsumer?: Outpu
});
if (options?.timeout) {
timeoutId = setTimeout(() => {
log.warning(localize('process.timeout', 'The command timed out: {0}', `${command} ${args?.join(' ')}`));
log.warning(localize('process.timeout', 'The command timed out: {0}', `${cmdstr}`));
child?.kill();
resolve({retc: -1, stdout: stdout_acc, stderr: stderr_acc });
}, options.timeout);
Expand Down