diff options
author | Nate DeSimone <nathaniel.l.desimone@intel.com> | 2025-06-06 16:04:29 -0700 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2025-06-07 17:56:04 +0000 |
commit | c0ef2b017855177903d87937ac4cdaec5c7851db (patch) | |
tree | 11193ca2285edd90815d1914d97a53fbbbf7e3f2 /BaseTools/Source/Python | |
parent | 18fdec11b1ab6475d1c3f328953f225547983dd5 (diff) | |
download | edk2-c0ef2b017855177903d87937ac4cdaec5c7851db.zip edk2-c0ef2b017855177903d87937ac4cdaec5c7851db.tar.gz edk2-c0ef2b017855177903d87937ac4cdaec5c7851db.tar.bz2 |
BaseTools: Add support for mingw-w64
Adds support for building the C language BaseTools for Windows using
toolchains based on mingw-w64.
Mingw-w64 is a collection of header files, libraries, and tools that
when combined with a compiler enable development of Windows software.
Mingw-w64 is a fork of the original MinGW (Minimalist GNU for Windows).
Most active development on MinGW has ceased and mingw-w64 is now the
actively maintained successor. Mingw-w64 provides a libc implementation
built on top of Microsoft's UCRT (Universal C Runtime) with all
nessesary compiler bindings needed to support the C++11 feature set.
Modern mingw-w64 development appears to have coalesced around MSYS2,
which produces a distributions of both GCC and LLVM/Clang that use
mingw-w64 to target the Windows OS. This MSYS2 Clang distribution has a
UNIX-like directory layout and includes Windows binaries of GNU Make.
Combined with the open source licensing, MSYS2's Clang distribution is a
highly attractive choice as an alternative Windows SDK for open source
projects such as TianoCore.
If one wishes to use EDK II to build UEFI firmware on the Windows
platform, then the C BaseTools need to be compiled as Windows
applications. This includes the PcdValueInit.exe program, which needs
to be recompiled every time a firmware build is run in order to
regenerate the initial values for structured PCDs. Currently, BaseTools
only supports the Visual C++ toolchain on the Windows platform. The
following new features have been added to enable usage of the toolchains
derived from mingw-w64:
- Fixes to the BaseTools C source code to support the use of a
GCC-style compiler on the Windows OS.
- The GNU Make-style Makefiles for the C BaseTools have been modified
to support Windows. Both GCC + mingw-w64 and Clang + mingw-w64 have
been tested and confirmed to build a working BaseTools.
- BaseTools now supports generating GNU Make-style Makefiles on the
Windows platform for the purpose of building firmware.
- edksetup.bat has been modified to optionally build BaseTools via
mingw-w64. There is no impact to the existing support for Visual C++
and Visual C++ remains the default toolchain.
Usage Instructions:
For the vast majority of users, the only system setup change nessesary
to use a mingw-w64 toolchain is to set the BASETOOLS_MINGW_PATH to the
directory containing the desired mingw-w64 based toolchain.
A new command line argument has been added to edksetup.bat: Mingw-w64
If this command line argument is set, then the script will set the
BASETOOLS_MINGW_BUILD environment variable. The user can also opt to set
this environment variable manually before running edksetup.bat
If BASETOOLS_MINGW_BUILD is defined, then the BASETOOLS_MINGW_PATH
environment variable must point to the directory containing the
mingw-w64 toolchain.
If CLANG_BIN is not defined and %BASETOOLS_MINGW_PATH%\bin\clang.exe
exists, then edksetup.bat will set CLANG_BIN=%BASETOOLS_MINGW_PATH%\bin\
This removes the requirement to configure the CLANG_BIN environment
variable manually in order to run a CLANGPDB or CLANGDWARF build if one
has the MSYS2 Clang distribution installed. If one wishes to use a
different copy of Clang (for example official LLVM binaries) to build
firmware and only use the MSYS2 Clang to build BaseTools, then one can
continue to set the CLANG_BIN environment variable, same as before. I
have tested the MSYS2 Clang distribution against the official LLVM
distribution and can confirm that if the compiler version is the same
the emitted machine code is identical between the two. Interestingly,
the MSYS2 Clang distribution emits the path to the PDB file using "/" as
the path seperator instead of "\". That appears to be the only
difference in output. Therefore, using the MSYS2 Clang distribution to
compile firmware seems a reasonable choice.
If CLANG_HOST_BIN is not defined and BASETOOLS_MINGW_BUILD is defined
and %BASETOOLS_MINGW_PATH%\bin\mingw32-make.exe exists, then
edksetup.bat will add %BASETOOLS_MINGW_PATH%\bin\ to the PATH and set
CLANG_HOST_BIN=mingw32-
This enable usage of the GNU Make included in the mingw-w64 toolchain
to build firmware in addition to BaseTools. if BASETOOLS_MINGW_BUILD is
not defined, edksetup.bat will continue to set CLANG_HOST_BIN=n, which
uses nmake to build firmware. This behavior can be overridden by
manually setting the value of CLANG_HOST_BIN before executing
edksetup.bat if one wishes to use a specific Make utility for the
CLANGPDB/CLANGDWARF toolchains.
References:
- https://www.mingw-w64.org/
- https://www.msys2.org/
Co-authored-by: Sandesh Jain <sandesh.jain@intel.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
Diffstat (limited to 'BaseTools/Source/Python')
-rw-r--r-- | BaseTools/Source/Python/Workspace/DscBuildData.py | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py index 5df184f..894cf2f 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -1,7 +1,7 @@ ## @file
# This file is used to create a database used by build tool
#
-# Copyright (c) 2008 - 2020, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2008 - 2025, Intel Corporation. All rights reserved.<BR>
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -38,7 +38,9 @@ from Common.Misc import SaveFileOnChange from Workspace.BuildClassObject import PlatformBuildClassObject, StructurePcd, PcdClassObject, ModuleBuildClassObject
from collections import OrderedDict, defaultdict
import json
+import os
import shutil
+import sys
def _IsFieldValueAnArray (Value):
Value = Value.strip()
@@ -106,9 +108,9 @@ $(APPFILE): $(APPLICATION) '''
PcdGccMakefile = '''
-MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
+MAKEROOT ?= $(EDK_TOOLS_PATH)%sSource%sC
LIBS = -lCommon
-'''
+'''%(os.sep, os.sep)
variablePattern = re.compile(r'[\t\s]*0[xX][a-fA-F0-9]+$')
SkuIdPattern = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*$')
@@ -231,6 +233,21 @@ class DscBuildData(PlatformBuildClassObject): self._Clear()
self.WorkspaceDir = os.getenv("WORKSPACE") if os.getenv("WORKSPACE") else ""
self.DefaultStores = None
+ MingwBaseToolsBuild = None
+ if sys.platform == 'win32':
+ MingwBaseToolsBuild = os.getenv("BASETOOLS_MINGW_BUILD")
+ if MingwBaseToolsBuild is not None:
+ try:
+ MingwBaseToolsBuild = int(MingwBaseToolsBuild)
+ except:
+ pass
+ try:
+ MingwBaseToolsBuild = bool(MingwBaseToolsBuild)
+ except:
+ pass
+ if not isinstance(MingwBaseToolsBuild, bool):
+ MingwBaseToolsBuild = False
+ self._MingwBaseToolsBuild = MingwBaseToolsBuild
self.SkuIdMgr = SkuClass(self.SkuName, self.SkuIds)
self.UpdatePcdTypeDict()
@property
@@ -2772,7 +2789,7 @@ class DscBuildData(PlatformBuildClassObject): def GetBuildOptionsValueList(self):
CC_FLAGS = LinuxCFLAGS
- if sys.platform == "win32":
+ if sys.platform == "win32" and not self._MingwBaseToolsBuild:
CC_FLAGS = WindowsCFLAGS
BuildOptions = OrderedDict()
for Options in self.BuildOptions:
@@ -2957,12 +2974,13 @@ class DscBuildData(PlatformBuildClassObject): # start generating makefile
MakeApp = PcdMakefileHeader
- if sys.platform == "win32":
+ if sys.platform == "win32" and not self._MingwBaseToolsBuild:
MakeApp = MakeApp + 'APPFILE = %s\\%s.exe\n' % (self.OutputPath, PcdValueInitName) + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s\\%s.obj %s.obj\n' % (self.OutputPath, PcdValueInitName, os.path.join(self.OutputPath, PcdValueCommonName)) + 'INC = '
else:
+ AppSuffix = '.exe' if sys.platform == "win32" else ''
MakeApp = MakeApp + PcdGccMakefile
- MakeApp = MakeApp + 'APPFILE = %s/%s\n' % (self.OutputPath, PcdValueInitName) + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s/%s.o %s.o\n' % (self.OutputPath, PcdValueInitName, os.path.join(self.OutputPath, PcdValueCommonName)) + \
- 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'TOOL_INCLUDE +='
+ MakeApp = MakeApp + 'APPFILE = %s%s%s%s\n' % (self.OutputPath, os.sep, PcdValueInitName, AppSuffix) + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s/%s.o %s.o\n' % (self.OutputPath, PcdValueInitName, os.path.join(self.OutputPath, PcdValueCommonName)) + \
+ 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'TOOL_INCLUDE +='
IncSearchList = []
PlatformInc = OrderedDict()
@@ -3010,11 +3028,12 @@ class DscBuildData(PlatformBuildClassObject): MakeApp += CC_FLAGS
- if sys.platform == "win32":
+ if sys.platform == "win32" and not self._MingwBaseToolsBuild:
MakeApp = MakeApp + PcdMakefileEnd
MakeApp = MakeApp + AppTarget % ("""\tcopy $(APPLICATION) $(APPFILE) /y """)
else:
- MakeApp = MakeApp + AppTarget % ("""\tcp -p $(APPLICATION) $(APPFILE) """)
+ AppSuffix = '.exe' if sys.platform == "win32" else ''
+ MakeApp = MakeApp + AppTarget % ("""\t$(CP) $(APPLICATION)%s $(APPFILE)"""%(AppSuffix))
MakeApp = MakeApp + '\n'
IncludeFileFullPaths = []
for includefile in IncludeFiles:
@@ -3057,12 +3076,21 @@ class DscBuildData(PlatformBuildClassObject): #start building the structure pcd value tool
Messages = ''
- if sys.platform == "win32":
+ if sys.platform == "win32" and not self._MingwBaseToolsBuild:
MakeCommand = 'nmake -f %s' % (MakeFileName)
returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (MakeCommand)
Messages = StdOut
else:
- MakeCommand = 'make -f %s' % (MakeFileName)
+ if sys.platform == "win32" and self._MingwBaseToolsBuild:
+ if shutil.which('mingw32-make.exe') is not None:
+ MakeCommand = 'mingw32-make -f %s' % (MakeFileName)
+ else:
+ if self._Toolchain in ('CLANGPDB', 'CLANGDWARF') and 'CLANG_HOST_BIN' in os.environ:
+ MakeCommand = '%smake -f %s' % (os.environ.get('CLANG_HOST_BIN'), MakeFileName)
+ else:
+ MakeCommand = 'make -f %s' % (MakeFileName)
+ else:
+ MakeCommand = 'make -f %s' % (MakeFileName)
returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (MakeCommand)
Messages = StdErr
|