BaseTools: Add CLANG support to Edk2ToolsBuild.py

Update Edk2ToolsBuild.py to support using Linux/CLANG and
Windows Mingw/CLANG environments to build C tools within
the BaseTools directory. The environment variable settings
CC=clang and CXX=clang++ must also be set before running
Edk2ToolsBuild.py to enable the use of the clang compiler.
PATH must also be set to include the path to the installed
version of clang and clang++ to use. If CC and CXX are not
set, the the default compiler is used.

When Mingw CLANG environment is being used, CLANG_BIN must
be set to the path to the CLANG tools so the mingw-make.exe
utility can be used to process BaseTools makefiles.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
This commit is contained in:
Michael D Kinney
2025-12-24 12:52:02 -08:00
committed by mergify[bot]
parent 8d0afac1d2
commit 85e2fef2a8
+10 -4
View File
@@ -244,7 +244,7 @@ class Edk2ToolsBuild(BaseAbstractInvocable):
self.WritePathEnvFile(self.OutputDir)
return ret
elif self.tool_chain_tag.lower().startswith("gcc"):
elif self.tool_chain_tag.lower().startswith("gcc") or self.tool_chain_tag.lower().startswith("clang"):
# Note: This HOST_ARCH is in respect to the BUILT base tools, not the host arch where
# this script is BUILDING the base tools.
HostInfo = GetHostInfo()
@@ -272,6 +272,12 @@ class Edk2ToolsBuild(BaseAbstractInvocable):
TargetInfoArch = HostInfo.arch
# Otherwise, the built binary arch will be consistent with the host system
make_command = 'make'
clang_bin = shell_env.get_shell_var("CLANG_BIN")
if clang_bin is not None:
if os.path.exists(os.path.join(clang_bin, "mingw32-make.exe")):
make_command = 'mingw32-make'
# Added logic to support cross compilation scenarios
if TargetInfoArch != HostInfo.arch:
# this is defaulting to the version that comes with Ubuntu 20.04
@@ -301,21 +307,21 @@ class Edk2ToolsBuild(BaseAbstractInvocable):
if ret != 0:
raise Exception(f"Failed to configure the util-linux to build with our gcc {ret}")
ret = RunCmd("make", "", workingdir=unzip_dir)
ret = RunCmd(make_command, "", workingdir=unzip_dir)
if ret != 0:
raise Exception(f"Failed to build the libuuid with our gcc {ret}")
shell_environment.GetEnvironment().set_shell_var("CROSS_LIB_UUID", unzip_dir)
shell_environment.GetEnvironment().set_shell_var("CROSS_LIB_UUID_INC", os.path.join(unzip_dir, "libuuid", "src"))
ret = RunCmd("make", "clean", workingdir=shell_env.get_shell_var("EDK_TOOLS_PATH"))
ret = RunCmd(make_command, "clean", workingdir=shell_env.get_shell_var("EDK_TOOLS_PATH"))
if ret != 0:
raise Exception("Failed to build.")
cpu_count = self.GetCpuThreads()
output_stream = edk2_logging.create_output_stream()
ret = RunCmd("make", f"-C . -j {cpu_count}", workingdir=shell_env.get_shell_var("EDK_TOOLS_PATH"))
ret = RunCmd(make_command, f"-C . -j {cpu_count}", workingdir=shell_env.get_shell_var("EDK_TOOLS_PATH"))
edk2_logging.remove_output_stream(output_stream)
problems = edk2_logging.scan_compiler_output(output_stream)
for level, problem in problems: