Skip to content

Commit e1c4c03

Browse files
committed
Fix Clang lib folder detection on Windows
First, more recent versions of Clang do no longer have trailing info in parentheses, so the detection would fail. Since we're not interested in this information, we just ignore it. Then we should not rely on Clang being installed in the default program folder. Instead we look up where the first clang.exe can be found, and assume that it is located in a bin/ folder in the installation path. From there we construct the library path, which is `lib\clang\<ver>\lib\windows` where `<ver>` is either the full version (older Clang) or only the major version. Note that this is the case for stand-alone LLVM installations as well as Visual Studio supplied ones. Finally, we clean up by improving the error messages, and removing the duplicate clang version detection in `add_asan_opts()`. While we're at it, we also apply a cosmetic improvement to avoid (trailing) whitespace in the compiler name (e.g. shown by `-v`).
1 parent ddfa393 commit e1c4c03

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

win32/build/confutils.js

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,7 +3137,7 @@ function toolset_get_compiler_name(short)
31373137
var command = 'cmd /c ""' + PHP_CL + '" -v"';
31383138
var full = execute(command + '" 2>&1"');
31393139

3140-
return full.split(/\n/)[0].replace(/\s/g, ' ');
3140+
return trim(full.split(/\n/)[0].replace(/\s/g, ' '));
31413141
}
31423142

31433143
WARNING("Unsupported toolset");
@@ -3703,31 +3703,31 @@ function check_binary_tools_sdk()
37033703
function get_clang_lib_dir()
37043704
{
37053705
var ret = null;
3706-
var ver = null;
3706+
var ver = null, major = null;
37073707

3708-
if (COMPILER_NAME_LONG.match(/clang version ([\d\.]+) \((.*)\)/)) {
3708+
if (COMPILER_NAME_LONG.match(/clang version ((\d+)\.[\d\.]+)/)) {
37093709
ver = RegExp.$1;
3710+
major = RegExp.$2;
37103711
} else {
3711-
ERROR("Failed to determine clang lib path");
3712+
ERROR("Failed to determine clang version");
37123713
}
37133714

3714-
if (TARGET_ARCH != 'x86') {
3715-
ret = PROGRAM_FILES + "\\LLVM\\lib\\clang\\" + ver + "\\lib";
3715+
var cmd = "cmd /c where clang.exe";
3716+
var path = trim(execute(cmd).split(/\n/)[0]).replace(/bin\\clang\.exe$/, "");
3717+
if (!FSO.FolderExists(path)) {
3718+
ERROR("Failed to determine clang installation folder");
3719+
}
3720+
3721+
ret = path + "lib\\clang\\" + major + "\\lib\\";
3722+
if (!FSO.FolderExists(ret)) {
3723+
ret = path + "lib\\clang\\" + ver + "\\lib\\";
37163724
if (!FSO.FolderExists(ret)) {
37173725
ret = null;
37183726
}
3719-
} else {
3720-
ret = PROGRAM_FILESx86 + "\\LLVM\\lib\\clang\\" + ver + "\\lib";
3721-
if (!FSO.FolderExists(ret)) {
3722-
ret = PROGRAM_FILES + "\\LLVM\\lib\\clang\\" + ver + "\\lib";
3723-
if (!FSO.FolderExists(ret)) {
3724-
ret = null;
3725-
}
3726-
}
37273727
}
37283728

37293729
if (null == ret) {
3730-
ERROR("Invalid clang lib path encountered");
3730+
ERROR("Failed to determine clang lib folder");
37313731
}
37323732

37333733
return ret;
@@ -3736,13 +3736,7 @@ function get_clang_lib_dir()
37363736
function add_asan_opts(cflags_name, libs_name, ldflags_name)
37373737
{
37383738

3739-
var ver = null;
3740-
3741-
if (COMPILER_NAME_LONG.match(/clang version ([\d\.]+) \((.*)\)/)) {
3742-
ver = RegExp.$1;
3743-
} else {
3744-
ERROR("Failed to determine clang lib path");
3745-
}
3739+
var lib_dir = get_clang_lib_dir();
37463740

37473741
if (!!cflags_name) {
37483742
ADD_FLAG(cflags_name, "-fsanitize=address,undefined");
@@ -3759,7 +3753,7 @@ function add_asan_opts(cflags_name, libs_name, ldflags_name)
37593753
}
37603754

37613755
if (!!ldflags_name) {
3762-
ADD_FLAG(ldflags_name, "/libpath:\"" + get_clang_lib_dir() + "\\windows\"");
3756+
ADD_FLAG(ldflags_name, "/libpath:\"" + lib_dir + "\\windows\"");
37633757
}
37643758
}
37653759

0 commit comments

Comments
 (0)