third_party/edk2: use toolchain-bundle for edk2 build
This moves the build into a custom rule instead of a genrule.
This also adds the AARCH64 build and renames the files to be more
generic
Change-Id: If6e3cecaf4011e2e39f13b1d40bcc7060cee3afb
Reviewed-on: https://review.monogon.dev/c/monogon/+/4154
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
Tested-by: Jenkins CI
diff --git a/build/bazel/third_party.MODULE.bazel b/build/bazel/third_party.MODULE.bazel
index 76d7c69..2c22364 100644
--- a/build/bazel/third_party.MODULE.bazel
+++ b/build/bazel/third_party.MODULE.bazel
@@ -11,6 +11,8 @@
patches = [
"//third_party/edk2/patches:disable-werror.patch",
"//third_party/edk2/patches:remove-brotli-build.patch",
+ "//third_party/edk2/patches:fix-uuid-flag.patch",
+ "//third_party/edk2/patches:fix-build.patch",
],
ref = "fbe0805b2091393406952e84724188f8c1941837", # stable202502
repo = "edk2",
diff --git a/cloud/agent/e2e/BUILD.bazel b/cloud/agent/e2e/BUILD.bazel
index ce068f8..e6cf594 100644
--- a/cloud/agent/e2e/BUILD.bazel
+++ b/cloud/agent/e2e/BUILD.bazel
@@ -7,14 +7,14 @@
"//build/toolchain/toolchain-bundle:qemu-kvm",
"//cloud/agent/takeover:initramfs",
"//metropolis/installer/test/testos:testos_image",
- "//third_party/edk2:OVMF_CODE.fd",
- "//third_party/edk2:OVMF_VARS.fd",
+ "//third_party/edk2:CODE.fd",
+ "//third_party/edk2:VARS.fd",
"//third_party/linux",
],
x_defs = {
"xImagePath": "$(rlocationpath //metropolis/installer/test/testos:testos_image )",
- "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:OVMF_VARS.fd )",
- "xOvmfCodePath": "$(rlocationpath //third_party/edk2:OVMF_CODE.fd )",
+ "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:VARS.fd )",
+ "xOvmfCodePath": "$(rlocationpath //third_party/edk2:CODE.fd )",
"xKernelPath": "$(rlocationpath //third_party/linux )",
"xInitramfsOrigPath": "$(rlocationpath //cloud/agent/takeover:initramfs )",
"xQEMUPath": "$(rlocationpath //build/toolchain/toolchain-bundle:qemu-kvm )",
diff --git a/cloud/agent/takeover/e2e/BUILD.bazel b/cloud/agent/takeover/e2e/BUILD.bazel
index 2016a9d..dc05d9e 100644
--- a/cloud/agent/takeover/e2e/BUILD.bazel
+++ b/cloud/agent/takeover/e2e/BUILD.bazel
@@ -6,15 +6,15 @@
data = [
# We use the layer instead of the binary to not add a transition target
"//cloud/agent/takeover",
- "//third_party/edk2:OVMF_CODE.fd",
- "//third_party/edk2:OVMF_VARS.fd",
+ "//third_party/edk2:CODE.fd",
+ "//third_party/edk2:VARS.fd",
"@debian_11_cloudimage//file",
"//build/toolchain/toolchain-bundle:qemu-kvm",
],
x_defs = {
"xCloudImagePath": "$(rlocationpath @debian_11_cloudimage//file )",
- "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:OVMF_VARS.fd )",
- "xOvmfCodePath": "$(rlocationpath //third_party/edk2:OVMF_CODE.fd )",
+ "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:VARS.fd )",
+ "xOvmfCodePath": "$(rlocationpath //third_party/edk2:CODE.fd )",
"xTakeoverPath": "$(rlocationpath //cloud/agent/takeover )",
"xQEMUPath": "$(rlocationpath //build/toolchain/toolchain-bundle:qemu-kvm )",
},
diff --git a/metropolis/cli/takeover/e2e/BUILD.bazel b/metropolis/cli/takeover/e2e/BUILD.bazel
index 4098904..d01812e 100644
--- a/metropolis/cli/takeover/e2e/BUILD.bazel
+++ b/metropolis/cli/takeover/e2e/BUILD.bazel
@@ -8,14 +8,14 @@
"//metropolis/cli/metroctl:metroctl_lite",
"//metropolis/cli/takeover",
"//metropolis/installer/test/testos:testos_image",
- "//third_party/edk2:OVMF_CODE.fd",
- "//third_party/edk2:OVMF_VARS.fd",
+ "//third_party/edk2:CODE.fd",
+ "//third_party/edk2:VARS.fd",
"@debian_11_cloudimage//file",
],
x_defs = {
"xImagePath": "$(rlocationpath //metropolis/installer/test/testos:testos_image )",
- "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:OVMF_VARS.fd )",
- "xOvmfCodePath": "$(rlocationpath //third_party/edk2:OVMF_CODE.fd )",
+ "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:VARS.fd )",
+ "xOvmfCodePath": "$(rlocationpath //third_party/edk2:CODE.fd )",
"xCloudImagePath": "$(rlocationpath @debian_11_cloudimage//file )",
"xTakeoverPath": "$(rlocationpath //metropolis/cli/takeover )",
"xMetroctlPath": "$(rlocationpath //metropolis/cli/metroctl:metroctl_lite )",
diff --git a/metropolis/installer/test/BUILD.bazel b/metropolis/installer/test/BUILD.bazel
index 8aab4b4..8c6bc8d 100644
--- a/metropolis/installer/test/BUILD.bazel
+++ b/metropolis/installer/test/BUILD.bazel
@@ -9,14 +9,14 @@
":kernel",
"//build/toolchain/toolchain-bundle:qemu-kvm",
"//metropolis/installer/test/testos:testos_image",
- "//third_party/edk2:OVMF_CODE.fd",
- "//third_party/edk2:OVMF_VARS.fd",
+ "//third_party/edk2:CODE.fd",
+ "//third_party/edk2:VARS.fd",
],
importpath = "source.monogon.dev/metropolis/installer/test",
visibility = ["//visibility:private"],
x_defs = {
- "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:OVMF_VARS.fd )",
- "xOvmfCodePath": "$(rlocationpath //third_party/edk2:OVMF_CODE.fd )",
+ "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:VARS.fd )",
+ "xOvmfCodePath": "$(rlocationpath //third_party/edk2:CODE.fd )",
"xInstallerPath": "$(rlocationpath :kernel )",
"xImagePath": "$(rlocationpath //metropolis/installer/test/testos:testos_image )",
"xQEMUPath": "$(rlocationpath //build/toolchain/toolchain-bundle:qemu-kvm )",
diff --git a/metropolis/node/core/update/e2e/BUILD.bazel b/metropolis/node/core/update/e2e/BUILD.bazel
index cd4bef9..0bc7652 100644
--- a/metropolis/node/core/update/e2e/BUILD.bazel
+++ b/metropolis/node/core/update/e2e/BUILD.bazel
@@ -5,8 +5,8 @@
srcs = ["e2e_test.go"],
data = [
# For emulation
- "//third_party/edk2:OVMF_CODE.fd",
- "//third_party/edk2:OVMF_VARS.fd",
+ "//third_party/edk2:CODE.fd",
+ "//third_party/edk2:VARS.fd",
# For the initial image creation
"//metropolis/node/core/update/e2e/testos:testos_image_x",
"//metropolis/node/abloader",
@@ -19,8 +19,8 @@
"xImageXPath": "$(rlocationpath //metropolis/node/core/update/e2e/testos:testos_image_x )",
"xImageYPath": "$(rlocationpath //metropolis/node/core/update/e2e/testos:testos_image_y )",
"xImageZPath": "$(rlocationpath //metropolis/node/core/update/e2e/testos:testos_image_z )",
- "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:OVMF_VARS.fd )",
- "xOvmfCodePath": "$(rlocationpath //third_party/edk2:OVMF_CODE.fd )",
+ "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:VARS.fd )",
+ "xOvmfCodePath": "$(rlocationpath //third_party/edk2:CODE.fd )",
"xAbloaderPath": "$(rlocationpath //metropolis/node/abloader )",
"xQEMUPath": "$(rlocationpath //build/toolchain/toolchain-bundle:qemu-kvm )",
},
diff --git a/metropolis/test/launch/BUILD.bazel b/metropolis/test/launch/BUILD.bazel
index c03da7d..b2530c5 100644
--- a/metropolis/test/launch/BUILD.bazel
+++ b/metropolis/test/launch/BUILD.bazel
@@ -20,8 +20,8 @@
"//metropolis/test/swtpm/certtool",
"//metropolis/test/swtpm/swtpm_cert",
"//osbase/test/ktest:linux-testing",
- "//third_party/edk2:OVMF_CODE.fd",
- "//third_party/edk2:OVMF_VARS.fd",
+ "//third_party/edk2:CODE.fd",
+ "//third_party/edk2:VARS.fd",
"@swtpm",
"@swtpm//:swtpm_localca",
"@swtpm//:swtpm_setup",
@@ -35,8 +35,8 @@
"xSwtpmCertPath": "$(rlocationpath //metropolis/test/swtpm/swtpm_cert )",
"xCerttoolPath": "$(rlocationpath //metropolis/test/swtpm/certtool )",
"xMetroctlPath": "$(rlocationpath //metropolis/cli/metroctl:metroctl_lite )",
- "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:OVMF_VARS.fd )",
- "xOvmfCodePath": "$(rlocationpath //third_party/edk2:OVMF_CODE.fd )",
+ "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:VARS.fd )",
+ "xOvmfCodePath": "$(rlocationpath //third_party/edk2:CODE.fd )",
"xKernelPath": "$(rlocationpath //osbase/test/ktest:linux-testing )",
"xInitramfsPath": "$(rlocationpath //metropolis/test/nanoswitch:initramfs )",
"xNodeImagePath": "$(rlocationpath //metropolis/node:oci_image_uncompressed )",
diff --git a/metropolis/test/launch/cluster.go b/metropolis/test/launch/cluster.go
index d2bbb4b..af15564 100644
--- a/metropolis/test/launch/cluster.go
+++ b/metropolis/test/launch/cluster.go
@@ -322,7 +322,7 @@
}
tpmSocketPath := filepath.Join(r.sd, "tpm-socket")
- fwVarPath := filepath.Join(r.ld, "OVMF_VARS.fd")
+ fwVarPath := filepath.Join(r.ld, "VARS.fd")
storagePath := filepath.Join(r.ld, "image.img")
qemuArgs := []string{
"-machine", "q35",
diff --git a/osbase/bringup/test/BUILD.bazel b/osbase/bringup/test/BUILD.bazel
index f63b0d6..307220c 100644
--- a/osbase/bringup/test/BUILD.bazel
+++ b/osbase/bringup/test/BUILD.bazel
@@ -16,14 +16,14 @@
":kernel_panic",
":kernel_succeeded",
"//build/toolchain/toolchain-bundle:qemu-kvm",
- "//third_party/edk2:OVMF_CODE.fd",
- "//third_party/edk2:OVMF_VARS.fd",
+ "//third_party/edk2:CODE.fd",
+ "//third_party/edk2:VARS.fd",
],
importpath = "source.monogon.dev/metropolis/installer/test",
visibility = ["//visibility:private"],
x_defs = {
- "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:OVMF_VARS.fd )",
- "xOvmfCodePath": "$(rlocationpath //third_party/edk2:OVMF_CODE.fd )",
+ "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:VARS.fd )",
+ "xOvmfCodePath": "$(rlocationpath //third_party/edk2:CODE.fd )",
"xSucceedKernelPath": "$(rlocationpath :kernel_succeeded )",
"xPanicKernelPath": "$(rlocationpath :kernel_panic )",
"xErrorKernelPath": "$(rlocationpath :kernel_error )",
diff --git a/third_party/edk2/BUILD.bazel b/third_party/edk2/BUILD.bazel
index 8809591..8e5ef36 100644
--- a/third_party/edk2/BUILD.bazel
+++ b/third_party/edk2/BUILD.bazel
@@ -1,17 +1,50 @@
-alias(
+load("@bazel_skylib//rules:select_file.bzl", "select_file")
+load("//build/utils:target_info.bzl", "target_info")
+load("//third_party/edk2:def.bzl", "edk2")
+
+edk2(
name = "firmware",
- actual = "@edk2//:firmware",
+ src = "@edk2//:all",
visibility = ["//visibility:public"],
)
-alias(
- name = "OVMF_CODE.fd",
- actual = "@edk2//:OVMF_CODE.fd",
+select_file(
+ name = "CODE.fd",
+ srcs = ":firmware",
+ subpath = "CODE.fd",
visibility = ["//visibility:public"],
)
-alias(
- name = "OVMF_VARS.fd",
- actual = "@edk2//:OVMF_VARS.fd",
+select_file(
+ name = "VARS.fd",
+ srcs = ":firmware",
+ subpath = "VARS.fd",
visibility = ["//visibility:public"],
)
+
+target_info(
+ name = "target_arch",
+ value = select({
+ "@platforms//cpu:x86_64": "X64",
+ "@platforms//cpu:aarch64": "AARCH64",
+ "@platforms//cpu:riscv64": "RISCV64",
+ }),
+ visibility = ["//visibility:private"],
+)
+
+target_info(
+ name = "compilation_mode",
+ value = select({
+ ":is_compilation_mode_dbg": "DEBUG",
+ "//conditions:default": "RELEASE",
+ }),
+ visibility = ["//visibility:private"],
+)
+
+config_setting(
+ name = "is_compilation_mode_dbg",
+ values = {
+ "compilation_mode": "dbg",
+ },
+ visibility = ["//visibility:private"],
+)
diff --git a/third_party/edk2/def.bzl b/third_party/edk2/def.bzl
new file mode 100644
index 0000000..62a0fbe
--- /dev/null
+++ b/third_party/edk2/def.bzl
@@ -0,0 +1,141 @@
+# Copyright The Monogon Project Authors.
+# SPDX-License-Identifier: Apache-2.0
+
+load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cpp_toolchain", "use_cc_toolchain")
+load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
+load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
+load("//build/utils:detect_root.bzl", "detect_root", "detect_roots")
+load("//build/utils:foreign_build.bzl", "generate_foreign_build_env", "merge_env")
+load("//build/utils:target_info.bzl", "TargetInfo")
+load("//osbase/build:def.bzl", "ignore_unused_configuration")
+
+TOOLCHAINS = [
+ "//build/toolchain/toolchain-bundle:make_toolchain",
+ "//build/toolchain/toolchain-bundle:nasm_toolchain",
+ "//build/toolchain/toolchain-bundle:iasl_toolchain",
+ "//build/toolchain/toolchain-bundle:strace_toolchain",
+]
+
+def _edk2_impl(ctx):
+ _, libuuid_gen = detect_roots(ctx.attr._libuuid[CcInfo].compilation_context.direct_public_headers)
+ extra_env = {
+ "HOSTLDFLAGS": " -L ".join(
+ [
+ "", # First element empty, for force a the join prefix
+ detect_root(ctx.attr._libuuid.files.to_list()).rsplit("/", 1)[0],
+ ],
+ ),
+ "HOSTCFLAGS": " -I ".join(
+ [
+ "", # First element empty, for force a the join prefix
+ libuuid_gen,
+ ],
+ ),
+ "CROSS_LIB_UUID_INC": libuuid_gen.rsplit("/", 1)[0],
+ "CROSS_LIB_UUID": detect_root(ctx.attr._libuuid.files.to_list()).rsplit("/", 1)[0],
+ }
+
+ inputs = depset(
+ ctx.files.src +
+ ctx.files._libuuid +
+ ctx.attr._libuuid[CcInfo].compilation_context.direct_public_headers,
+ )
+
+ # Setup the environment for the foreign build.
+ toolchain_env, toolchain_inputs, toolchain_cmd = generate_foreign_build_env(
+ ctx = ctx,
+ target_toolchain = find_cpp_toolchain(ctx),
+ exec_toolchain = ctx.attr._exec_toolchain[cc_common.CcToolchainInfo],
+ toolchain_bundle_tools = TOOLCHAINS,
+ )
+
+ target_arch = ctx.attr._target_arch[TargetInfo].value
+ target_path = None
+ export_script = None
+ if target_arch == "X64":
+ target_path = "OvmfPkg/OvmfPkgX64.dsc"
+ export_script = """
+ cp {src}/Build/OvmfX64/{release_type}_"$TOOLCHAIN"/FV/OVMF_CODE.fd {code}
+ cp {src}/Build/OvmfX64/{release_type}_"$TOOLCHAIN"/FV/OVMF_VARS.fd {vars}
+ """
+ elif target_arch == "AARCH64":
+ target_path = "ArmVirtPkg/ArmVirtQemu.dsc"
+ export_script = """
+ dd of="{code}" if=/dev/zero bs=1M count=64
+ dd of="{code}" if={src}/Build/ArmVirtQemu-AARCH64/{release_type}_"$TOOLCHAIN"/FV/QEMU_EFI.fd conv=notrunc
+ dd of="{vars}" if=/dev/zero bs=1M count=64
+ dd of="{vars}" if={src}/Build/ArmVirtQemu-AARCH64/{release_type}_"$TOOLCHAIN"/FV/QEMU_VARS.fd conv=notrunc
+ """
+ else:
+ fail("Unsupported target architecture: %s" % target_arch)
+
+ code = ctx.actions.declare_file("CODE.fd")
+ vars = ctx.actions.declare_file("VARS.fd")
+ ctx.actions.run_shell(
+ outputs = [code, vars],
+ inputs = depset(transitive = [inputs, toolchain_inputs]),
+ env = merge_env(toolchain_env, extra_env),
+ progress_message = "Building EDK2 firmware",
+ mnemonic = "BuildEDK2Firmware",
+ command = toolchain_cmd + ("""
+ TOOLCHAIN=CLANGDWARF
+ export CLANG_BIN="$CC_PATH/"
+
+ (
+ cd {src}
+ . edksetup.sh
+ make \
+ BUILD_OPTFLAGS="$HOSTCFLAGS" EXTRA_LDFLAGS="$HOSTLDFLAGS" \
+ -C BaseTools/Source/C
+
+ build -DTPM2_ENABLE -DSECURE_BOOT_ENABLE \
+ -t $TOOLCHAIN -a {target_arch} -b {release_type} \
+ -p $PWD/{target_path}
+ ) > /dev/null
+ """ + export_script).format(
+ src = detect_root(ctx.attr.src.files.to_list()),
+ code = code.path,
+ vars = vars.path,
+ target_arch = target_arch,
+ target_path = target_path,
+ release_type = ctx.attr._compilation_mode[TargetInfo].value,
+ ),
+ use_default_shell_env = True,
+ )
+
+ return [
+ DefaultInfo(
+ files = depset([code, vars]),
+ runfiles = ctx.runfiles(files = [code, vars]),
+ ),
+ ]
+
+edk2 = rule(
+ doc = """
+ Build EDK2 hermetically.
+ """,
+ implementation = _edk2_impl,
+ cfg = ignore_unused_configuration,
+ attrs = {
+ "src": attr.label(
+ doc = """
+ Filegroup containing EDK2 sources.
+ """,
+ ),
+ "_libuuid": attr.label(
+ default = "@libuuid//:uuid",
+ ),
+ "_exec_toolchain": attr.label(
+ default = "@rules_cc//cc:current_cc_toolchain",
+ cfg = "exec",
+ ),
+ "_target_arch": attr.label(
+ default = "//third_party/edk2:target_arch",
+ ),
+ "_compilation_mode": attr.label(
+ default = "//third_party/edk2:compilation_mode",
+ ),
+ },
+ fragments = ["cpp"],
+ toolchains = TOOLCHAINS + use_cc_toolchain(),
+)
diff --git a/third_party/edk2/edk2.bzl b/third_party/edk2/edk2.bzl
index 43effe5..24ebf0f 100644
--- a/third_party/edk2/edk2.bzl
+++ b/third_party/edk2/edk2.bzl
@@ -7,28 +7,5 @@
"CryptoPkg/Library/OpensslLib/openssl/fuzz/corpora/**",
],
),
-)
-
-genrule(
- name = "firmware",
- srcs = [":all"],
- outs = [
- "OVMF_CODE.fd",
- "OVMF_VARS.fd",
- ],
- cmd = """
- (
- # The edk2 build does not like Bazel's default genrule environment.
- set +u
-
- cd {path}
- . edksetup.sh
- make -C BaseTools/Source/C
- build -DTPM2_ENABLE -DSECURE_BOOT_ENABLE -t GCC5 -a X64 -b RELEASE -p $$PWD/OvmfPkg/OvmfPkgX64.dsc
- ) > /dev/null
-
- cp {path}/Build/OvmfX64/RELEASE_GCC5/FV/OVMF_CODE.fd $(RULEDIR)
- cp {path}/Build/OvmfX64/RELEASE_GCC5/FV/OVMF_VARS.fd $(RULEDIR)
- """.format(path = package_relative_label(":all").workspace_root),
visibility = ["//visibility:public"],
)
diff --git a/third_party/edk2/patches/fix-build.patch b/third_party/edk2/patches/fix-build.patch
new file mode 100644
index 0000000..3f9ebd9
--- /dev/null
+++ b/third_party/edk2/patches/fix-build.patch
@@ -0,0 +1,62 @@
+EDK2 doens't respect HOSTCFLAGS and HOSTLDFLAGS which we need to pass the sysroot
+and target flags to the compiler and linker.
+
+diff --git a/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile b/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
+--- a/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
++++ b/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
+@@ -131,16 +131,17 @@
+ COPT=-O
+ ANTLR=${BIN_DIR}/antlr
+ DLG=${BIN_DIR}/dlg
+ CFLAGS= $(COPT) -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN -DZZLEXBUFSIZE=65536 -std=gnu11
++CFLAGS += $(HOSTCFLAGS)
+ CPPFLAGS=
+ OBJ_EXT=o
+ OUT_OBJ = -o
+ OBJ = dlg_p.o dlg_a.o main.o err.o set.o support.o output.o \
+ relabel.o automata.o
+
+ $(BIN_DIR)/dlg : $(OBJ) $(SRC)
+- $(CC) $(CFLAGS) -o $(BIN_DIR)/dlg $(OBJ)
++ $(CC) $(HOSTLDFLAGS) -o $(BIN_DIR)/dlg $(OBJ)
+
+ SRC = dlg_p.c dlg_a.c main.c err.c $(SET)/set.c support.c output.c \
+ relabel.c automata.c
+
+diff --git a/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile b/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
+--- a/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
++++ b/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
+@@ -176,8 +176,9 @@
+ DLG=${BIN_DIR}/dlg
+ OBJ_EXT=o
+ OUT_OBJ = -o
+ CFLAGS= $(COPT) -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN $(COTHER) -DZZLEXBUFSIZE=65536 -std=gnu11
++CFLAGS += $(HOSTCFLAGS)
+ CPPFLAGS=
+ #
+ # SGI Users, use this CFLAGS
+ #
+@@ -185,9 +186,9 @@
+ OBJ=antlr.o scan.o err.o bits.o build.o fset2.o fset.o gen.o \
+ globals.o hash.o lex.o main.o misc.o set.o pred.o egman.o mrhoist.o fcache.o
+
+ $(BIN_DIR)/antlr : $(OBJ) $(SRC)
+- $(CC) $(CFLAGS) -o $(BIN_DIR)/antlr $(OBJ)
++ $(CC) $(HOSTLDFLAGS) -o $(BIN_DIR)/antlr $(OBJ)
+
+ # what files does PCCTS generate (both ANTLR and DLG)
+ PCCTS_GEN=antlr.c scan.c err.c tokens.h mode.h parser.dlg stdpccts.h remap.h
+
+diff --git a/BaseTools/Source/C/GNUmakefile b/BaseTools/Source/C/GNUmakefile
+--- a/BaseTools/Source/C/GNUmakefile
++++ b/BaseTools/Source/C/GNUmakefile
+@@ -50,9 +50,8 @@
+
+ LIBRARIES = Common
+ VFRAUTOGEN = VfrCompile/VfrLexer.h
+ APPLICATIONS = \
+- BrotliCompress \
+ VfrCompile \
+ EfiRom \
+ GenFfs \
+ GenFv \
diff --git a/third_party/edk2/patches/fix-uuid-flag.patch b/third_party/edk2/patches/fix-uuid-flag.patch
new file mode 100644
index 0000000..5051623
--- /dev/null
+++ b/third_party/edk2/patches/fix-uuid-flag.patch
@@ -0,0 +1,13 @@
+diff --git a/BaseTools/Source/C/GenFv/GNUmakefile b/BaseTools/Source/C/GenFv/GNUmakefile
+--- a/BaseTools/Source/C/GenFv/GNUmakefile
++++ b/BaseTools/Source/C/GenFv/GNUmakefile
+@@ -21,8 +21,8 @@
+ ifndef CROSS_LIB_UUID
+ LIBS += -luuid
+ else
+ LIBS += -L$(CROSS_LIB_UUID)
+- BUILD_CFLAGS += -D__CROSS_LIB_UUID__ -I $(CROSS_LIB_UUID_INC)
++ CFLAGS += -D__CROSS_LIB_UUID__ -I $(CROSS_LIB_UUID_INC)
+ endif
+ endif
+