From 32c2a49bf09721e3d40cd3058dd9d27ce1884a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C3=ABl=20Kooi?= <3961583-RA-Kooi@users.noreply.gitlab.com> Date: Wed, 4 Dec 2019 20:49:08 +0100 Subject: [PATCH] Support pure clang-cl builds on not Windows A.k.a. I just tested it on Linux. --- waflib/Tools/winres.py | 18 ++++++++++-- waflib/extras/clang_cl.py | 62 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 5 deletions(-) diff --git a/waflib/Tools/winres.py b/waflib/Tools/winres.py index 9be1ed66..80b1f5b1 100644 --- a/waflib/Tools/winres.py +++ b/waflib/Tools/winres.py @@ -4,7 +4,7 @@ "Process *.rc* files for C/C++: X{.rc -> [.res|.rc.o]}" -import re +import re, sys from waflib import Task from waflib.TaskGen import extension from waflib.Tools import c_preproc @@ -68,7 +68,21 @@ def configure(conf): v = conf.env if not v.WINRC: if v.CC_NAME == 'msvc': - conf.find_program('RC', var='WINRC', path_list=v.PATH) + if sys.platform == 'win32': + conf.find_program('RC', var='WINRC', path_list=v.PATH) + else: + llvm_env_path = conf.environ.get('LLVM_PATH') + llvm_path = None + if llvm_env_path: + llvm_path = llvm_env_path + elif 'LLVM_PATH' in v: + llvm_path = v['LLVM_PATH'] + + paths = v.PATH + if llvm_path: + paths = [llvm_path] + v.PATH + conf.find_program('llvm-rc', var='WINRC', path_list=paths) + v.WINRC_TGT_F = '/fo' v.WINRC_SRC_F = '' else: diff --git a/waflib/extras/clang_cl.py b/waflib/extras/clang_cl.py index cfbbdbd6..7634e5b5 100644 --- a/waflib/extras/clang_cl.py +++ b/waflib/extras/clang_cl.py @@ -24,7 +24,7 @@ Or: import sys, os -from waflib import Utils +from waflib import Utils, Errors, Logs from waflib.Configure import conf def options(opt): @@ -71,11 +71,67 @@ def find_clang_cl(conf): v.CC = v.CXX = cc v.CC_NAME_SECONDARY = v.CXX_NAME_SECONDARY = 'clang' + if sys.platform != 'win32': + v.MSVC_COMPILER = 'msvc' + v.MSVC_VERSION = 19 + + if not v.LINK_CXX: + conf.find_program( \ + 'lld-link', \ + path_list=paths, \ + errmsg='lld-link was not found (linker)', \ + var='LINK_CXX') + + if not v.LINK_CC: + v.LINK_CC = v.LINK_CXX + +@conf +def find_llvm_tools(conf): + """ + Find the librarian, manifest tool, and resource compiler. + """ + + v = conf.env + + v.CC_NAME = v.CXX_NAME = 'msvc' + + llvm_env_path = conf.environ.get('LLVM_PATH') + llvm_path = None + if llvm_env_path: + llvm_path = llvm_env_path + elif 'LLVM_PATH' in v: + llvm_path = v['LLVM_PATH'] + + paths = v.PATH + if llvm_path: + paths = [llvm_path] + v.PATH + + if not v.AR: + stliblink = conf.find_program('llvm-lib', path_list=paths, var='AR') + if not stliblink: + conf.fatal('Unable to find required program "llvm-lib"') + + v.ARFLAGS = ['/nologo'] + + # We assume clang_cl to only be used with relatively new MSVC installations. + v.MSVC_MANIFEST = True + conf.find_program('llvm-mt', path_list=paths, var='MT') + v.MTFLAGS = ['/nologo'] + + try: + conf.load('winres') + except Errors.ConfigurationError: + Logs.warn('Resource compiler not found. Compiling resource file is disabled') + def configure(conf): from waflib.Tools.msvc import autodetect, find_msvc, msvc_common_flags - conf.autodetect(True) - conf.find_msvc() + if sys.platform == 'win32': + conf.autodetect(True) + conf.find_msvc() + else: + conf.find_llvm_tools() + conf.find_clang_cl() conf.msvc_common_flags() conf.cc_load_tools()