Add QEMU into the monorepo
This adds QEMU and all its dependencies into the monorepo. Enough features are enabled that
this QEMU should be both usable for running tests for Metropolis as well as running customer VMs in
containers. Thus we can also get rid of the QEMU ambient dependency.
All dependencies have their includes fully rewritten as to be reusable without a huge effort. QEMU itself
relies on `includes` attributes since the patch would otherwise be enormous and it is a binary and thus
any include path madness ends there.
Overall though this is quite nice, the final QEMU build with full optimization is <10MiB and has no further
ambient dependencies. It also has full io_uring support, which works very well with our 5.10 kernel.
TPM support is also included.
This is not used anywhere, replacing the ambient dependency and shipping a container will be in an upcoming
revision.
Test Plan:
Manually tested to run a Ubuntu cloud image with io_uring and virtio. Automated tests will follow as
part of its roles in this repo.
X-Origin-Diff: phab/D712
GitOrigin-RevId: 9c2607d75c875b1d65346e3cdac1a5e08467ea33
diff --git a/third_party/qemu/patches/bazel_support.patch b/third_party/qemu/patches/bazel_support.patch
new file mode 100644
index 0000000..9dea8d0
--- /dev/null
+++ b/third_party/qemu/patches/bazel_support.patch
@@ -0,0 +1,1603 @@
+Copyright 2020 The Monogon Project Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+
+From 88ba396b627c26b9b01c2bc358557964cbb59cf8 Mon Sep 17 00:00:00 2001
+From: Lorenz Brun <lorenz@brun.one>
+Date: Wed, 10 Mar 2021 18:25:11 +0100
+Subject: [PATCH 3/6] Add Bazel support
+
+---
+ BUILD | 1146 +++++++++++++++++++++++++++++++
+ defs.bzl | 52 ++
+ qapi/BUILD | 25 +
+ qapi/defs.bzl | 40 ++
+ scripts/BUILD | 35 +
+ scripts/modules/BUILD | 7 +
+ scripts/qapi/BUILD | 7 +
+ scripts/qapi/defs.bzl | 52 ++
+ scripts/tracetool/BUILD | 11 +
+ scripts/tracetool/backend/BUILD | 7 +
+ scripts/tracetool/defs.bzl | 65 ++
+ scripts/tracetool/format/BUILD | 7 +
+ trace/BUILD | 18 +
+ 13 files changed, 1472 insertions(+)
+ create mode 100644 BUILD
+ create mode 100644 defs.bzl
+ create mode 100644 qapi/BUILD
+ create mode 100644 qapi/defs.bzl
+ create mode 100644 scripts/BUILD
+ create mode 100644 scripts/modules/BUILD
+ create mode 100644 scripts/qapi/BUILD
+ create mode 100644 scripts/qapi/defs.bzl
+ create mode 100644 scripts/tracetool/BUILD
+ create mode 100644 scripts/tracetool/backend/BUILD
+ create mode 100644 scripts/tracetool/defs.bzl
+ create mode 100644 scripts/tracetool/format/BUILD
+ create mode 100644 trace/BUILD
+
+diff --git a/BUILD b/BUILD
+new file mode 100644
+index 0000000000..436f8c5cf3
+--- /dev/null
++++ b/BUILD
+@@ -0,0 +1,1147 @@
++load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
++load("@rules_python//python:defs.bzl", "py_binary")
++load("@dev_source_monogon//build/utils:template_file.bzl", "template_file")
++load(":defs.bzl", "filter_label_suffix")
++load("//:defs.bzl", "cc_qemu_keymaps")
++
++filegroup(
++ name = "trace-files",
++ srcs = glob(["**/trace-events"]) + ["//qapi:trace-events"],
++ visibility = ["//visibility:public"],
++)
++
++filter_label_suffix(
++ name = "qapi_hdrs_gen",
++ srcs = ["//qapi:qapi_generated"],
++ suffix = ".h",
++)
++
++filter_label_suffix(
++ name = "qapi_c",
++ srcs = ["//qapi:qapi_generated"],
++ suffix = ".c",
++)
++
++filter_label_suffix(
++ name = "trace_c",
++ srcs = ["//trace"],
++ exclude = [
++ "trace-linux-user.c",
++ "trace-hw_pci-host.c",
++ ],
++ suffix = ".c",
++)
++
++genrule(
++ name = "block-coroutine-gen",
++ srcs = [
++ "include/block/block.h",
++ "block/coroutines.h",
++ ],
++ outs = ["block-gen.c"],
++ cmd = "./$(location //scripts:block-coroutine-wrapper) \"$@\" $(location include/block/block.h) $(location block/coroutines.h)",
++ tools = ["//scripts:block-coroutine-wrapper"],
++)
++
++filter_label_suffix(
++ name = "trace_hdrs_gen",
++ srcs = ["//trace"],
++ suffix = ".h",
++)
++
++filegroup(
++ name = "gen_hdrs",
++ srcs = [
++ ":libslirp-version.h",
++ ":qapi_hdrs_gen",
++ ":trace_hdrs_gen",
++ "//qapi:extra_hdrs",
++ "//trace:extra_hdrs",
++ ],
++)
++
++filegroup(
++ name = "all_headers",
++ srcs = glob([
++ "accel/**/*.h",
++ "accel/**/*.inc",
++ "audio/**/*.h",
++ "audio/**/*.inc",
++ "authz/**/*.h",
++ "authz/**/*.inc",
++ "backends/**/*.h",
++ "backends/**/*.inc",
++ "block/**/*.h",
++ "block/**/*.inc",
++ "capstone/**/*.h",
++ "capstone/**/*.inc",
++ "chardev/**/*.h",
++ "chardev/**/*.inc",
++ "contrib/**/*.h",
++ "contrib/**/*.inc",
++ "crypto/**/*.h",
++ "crypto/**/*.inc",
++ "default-configs/**/*.h",
++ "default-configs/**/*.inc",
++ "disas/**/*.h",
++ "disas/**/*.inc",
++ "dtc/**/*.h",
++ "dtc/**/*.inc",
++ "dump/**/*.h",
++ "dump/**/*.inc",
++ "fpu/**/*.h",
++ "fpu/**/*.inc",
++ "fsdev/**/*.h",
++ "fsdev/**/*.inc",
++ "gdb-xml/**/*.h",
++ "gdb-xml/**/*.inc",
++ "hw/**/*.h",
++ "hw/**/*.inc",
++ "include/**/*.h",
++ "include/**/*.inc",
++ "io/**/*.h",
++ "io/**/*.inc",
++ "libdecnumber/**/*.h",
++ "libdecnumber/**/*.inc",
++ "linux-headers/**/*.h",
++ "linux-headers/**/*.inc",
++ "linux-user/**/*.h",
++ "linux-user/**/*.inc",
++ "migration/**/*.h",
++ "migration/**/*.inc",
++ "monitor/**/*.h",
++ "monitor/**/*.inc",
++ "nbd/**/*.h",
++ "nbd/**/*.inc",
++ "net/**/*.h",
++ "net/**/*.inc",
++ "plugins/**/*.h",
++ "plugins/**/*.inc",
++ "qapi/**/*.h",
++ "qapi/**/*.inc",
++ "qga/**/*.h",
++ "qga/**/*.inc",
++ "qobject/**/*.h",
++ "qobject/**/*.inc",
++ "qom/**/*.h",
++ "qom/**/*.inc",
++ "replay/**/*.h",
++ "replay/**/*.inc",
++ "scripts/**/*.h",
++ "scripts/**/*.inc",
++ "scsi/**/*.h",
++ "scsi/**/*.inc",
++ "slirp/**/*.h",
++ "slirp/**/*.inc",
++ "softmmu/**/*.h",
++ "softmmu/**/*.inc",
++ "storage-daemon/**/*.h",
++ "storage-daemon/**/*.inc",
++ "subprojects/**/*.h",
++ "subprojects/**/*.inc",
++ "stubs/**/*.h",
++ "stubs/**/*.inc",
++ "target/**/*.h",
++ "target/**/*.inc",
++ "tcg/**/*.h",
++ "tcg/**/*.inc",
++ "tools/**/*.h",
++ "tools/**/*.inc",
++ "trace/**/*.h",
++ "trace/**/*.inc",
++ "ui/**/*.h",
++ "ui/**/*.inc",
++ "util/**/*.h",
++ "util/**/*.inc",
++ ]) + [
++ ":hmp-commands",
++ ":module-block",
++ ":cursor-hdrs",
++ ":keymaps-gen",
++ "qemu-img-cmds.h",
++ "qemu-options.h",
++ "qemu-options-wrapper.h",
++ "qemu-version.h",
++ "replication.h",
++ "x86_64-softmmu-config-devices.h",
++ "x86_64-softmmu-config-target.h",
++ "memory_ldst.c.inc",
++ ],
++)
++
++cc_library(
++ name = "capstone",
++ srcs = [":all_headers"] + [
++ "capstone/cs.c",
++ "capstone/MCInst.c",
++ "capstone/MCInstrDesc.c",
++ "capstone/MCRegisterInfo.c",
++ "capstone/SStream.c",
++ "capstone/utils.c",
++ "capstone/arch/X86/X86Disassembler.c",
++ "capstone/arch/X86/X86DisassemblerDecoder.c",
++ "capstone/arch/X86/X86ATTInstPrinter.c",
++ "capstone/arch/X86/X86IntelInstPrinter.c",
++ "capstone/arch/X86/X86InstPrinterCommon.c",
++ "capstone/arch/X86/X86Mapping.c",
++ "capstone/arch/X86/X86Module.c",
++ ],
++ local_defines = [
++ "_GNU_SOURCE",
++ "_FILE_OFFSET_BITS=64",
++ "_LARGEFILE_SOURCE",
++ ],
++ includes = ["capstone/include"],
++)
++
++template_file(
++ name = "libslirp-version.h",
++ src = "slirp/src/libslirp-version.h.in",
++ substitutions = {
++ "@SLIRP_MAJOR_VERSION@": "0",
++ "@SLIRP_MINOR_VERSION@": "0",
++ "@SLIRP_MICRO_VERSION@": "1",
++ "@SLIRP_VERSION_STRING@": "\"0.0.1\"",
++ },
++)
++
++cc_library(
++ name = "slirp",
++ srcs = [":all_headers"] + [
++ "slirp/src/arp_table.c",
++ "slirp/src/bootp.c",
++ "slirp/src/cksum.c",
++ "slirp/src/dhcpv6.c",
++ "slirp/src/dnssearch.c",
++ "slirp/src/if.c",
++ "slirp/src/ip6_icmp.c",
++ "slirp/src/ip6_input.c",
++ "slirp/src/ip6_output.c",
++ "slirp/src/ip_icmp.c",
++ "slirp/src/ip_input.c",
++ "slirp/src/ip_output.c",
++ "slirp/src/mbuf.c",
++ "slirp/src/misc.c",
++ "slirp/src/ncsi.c",
++ "slirp/src/ndp_table.c",
++ "slirp/src/sbuf.c",
++ "slirp/src/slirp.c",
++ "slirp/src/socket.c",
++ "slirp/src/state.c",
++ "slirp/src/stream.c",
++ "slirp/src/tcp_input.c",
++ "slirp/src/tcp_output.c",
++ "slirp/src/tcp_subr.c",
++ "slirp/src/tcp_timer.c",
++ "slirp/src/tftp.c",
++ "slirp/src/udp.c",
++ "slirp/src/udp6.c",
++ "slirp/src/util.c",
++ "slirp/src/version.c",
++ "slirp/src/vmstate.c",
++ ] + [":libslirp-version.h"],
++ local_defines = [
++ "_GNU_SOURCE",
++ "_FILE_OFFSET_BITS=64",
++ "_LARGEFILE_SOURCE",
++ "G_LOG_DOMAIN=\\\"Slirp\\\"",
++ ],
++ deps = [
++ "@glib//glib",
++ ],
++ includes = ["include", "slirp/src"],
++)
++
++cc_library(
++ name = "fdt",
++ srcs = [":all_headers"] + [
++ "dtc/libfdt/fdt.c",
++ "dtc/libfdt/fdt_ro.c",
++ "dtc/libfdt/fdt_wip.c",
++ "dtc/libfdt/fdt_sw.c",
++ "dtc/libfdt/fdt_rw.c",
++ "dtc/libfdt/fdt_strerror.c",
++ "dtc/libfdt/fdt_empty_tree.c",
++ "dtc/libfdt/fdt_addresses.c",
++ "dtc/libfdt/fdt_overlay.c",
++ "dtc/libfdt/fdt_check.c",
++ ],
++ local_defines = [
++ "_GNU_SOURCE",
++ "_FILE_OFFSET_BITS=64",
++ "_LARGEFILE_SOURCE",
++ ],
++ includes = ["include", "dtc/libfdt", "disas/libvixl"],
++)
++
++cc_library(
++ name = "qemu",
++ srcs = [":all_headers"] + [
++ "accel/accel.c",
++ "audio/audio_legacy.c",
++ "audio/audio.c",
++ "audio/mixeng.c",
++ "audio/noaudio.c",
++ "audio/wavaudio.c",
++ "audio/wavcapture.c",
++ "authz/base.c",
++ "authz/list.c",
++ "authz/listfile.c",
++ "authz/simple.c",
++ "backends/cryptodev-builtin.c",
++ "backends/cryptodev-vhost.c",
++ "backends/cryptodev.c",
++ "backends/hostmem-file.c",
++ "backends/hostmem-memfd.c",
++ "backends/hostmem-ram.c",
++ "backends/hostmem.c",
++ "backends/rng-builtin.c",
++ "backends/rng-egd.c",
++ "backends/rng-random.c",
++ "backends/rng.c",
++ "backends/tpm/tpm_backend.c",
++ "backends/tpm/tpm_emulator.c",
++ "backends/tpm/tpm_passthrough.c",
++ "backends/tpm/tpm_util.c",
++ "block.c",
++ "block/accounting.c",
++ "block/aio_task.c",
++ "block/amend.c",
++ "block/backup-top.c",
++ "block/backup.c",
++ "block/blkdebug.c",
++ "block/blklogwrites.c",
++ "block/blkverify.c",
++ "block/block-backend.c",
++ "block/block-copy.c",
++ "block/commit.c",
++ "block/copy-on-read.c",
++ "block/create.c",
++ "block/crypto.c",
++ "block/dirty-bitmap.c",
++ "block/export/export.c",
++ "block/file-posix.c",
++ "block/filter-compress.c",
++ "block/io_uring.c",
++ "block/io.c",
++ "block/mirror.c",
++ "block/monitor/bitmap-qmp-cmds.c",
++ "block/monitor/block-hmp-cmds.c",
++ "block/nbd.c",
++ "block/null.c",
++ "block/nvme.c",
++ "block/qapi-sysemu.c",
++ "block/qapi.c",
++ "block/qcow2-bitmap.c",
++ "block/qcow2-cache.c",
++ "block/qcow2-cluster.c",
++ "block/qcow2-refcount.c",
++ "block/qcow2-snapshot.c",
++ "block/qcow2-threads.c",
++ "block/qcow2.c",
++ "block/quorum.c",
++ "block/raw-format.c",
++ "block/snapshot.c",
++ "block/stream.c",
++ "block/throttle-groups.c",
++ "block/throttle.c",
++ "block/vhdx-endian.c",
++ "block/vhdx-log.c",
++ "block/vhdx.c",
++ "block/vmdk.c",
++ "block/vpc.c",
++ "block/write-threshold.c",
++ "blockdev-nbd.c",
++ "blockdev.c",
++ "blockjob.c",
++ "chardev/char-fd.c",
++ "chardev/char-fe.c",
++ "chardev/char-file.c",
++ "chardev/char-io.c",
++ "chardev/char-mux.c",
++ "chardev/char-null.c",
++ "chardev/char-parallel.c",
++ "chardev/char-pipe.c",
++ "chardev/char-pty.c",
++ "chardev/char-ringbuf.c",
++ "chardev/char-serial.c",
++ "chardev/char-socket.c",
++ "chardev/char-stdio.c",
++ "chardev/char-udp.c",
++ "chardev/char.c",
++ "chardev/msmouse.c",
++ "chardev/testdev.c",
++ "chardev/wctablet.c",
++ "cpus-common.c",
++ "crypto/aes.c",
++ "crypto/afsplit.c",
++ "crypto/block-luks.c",
++ "crypto/block-qcow.c",
++ "crypto/block.c",
++ "crypto/cipher.c",
++ "crypto/desrfb.c",
++ "crypto/hash-glib.c",
++ "crypto/hash.c",
++ "crypto/hmac-glib.c",
++ "crypto/hmac.c",
++ "crypto/init.c",
++ "crypto/ivgen-essiv.c",
++ "crypto/ivgen-plain.c",
++ "crypto/ivgen-plain64.c",
++ "crypto/ivgen.c",
++ "crypto/pbkdf-stub.c",
++ "crypto/pbkdf.c",
++ "crypto/random-platform.c",
++ "crypto/secret_common.c",
++ "crypto/secret.c",
++ "crypto/tlscreds.c",
++ "crypto/tlscredsanon.c",
++ "crypto/tlscredspsk.c",
++ "crypto/tlscredsx509.c",
++ "crypto/tlssession.c",
++ "crypto/xts.c",
++ "disas/capstone.c",
++ "disas/i386.c",
++ "dump/dump-hmp-cmds.c",
++ "fsdev/qemu-fsdev-dummy.c",
++ "fsdev/qemu-fsdev-opts.c",
++ "fsdev/qemu-fsdev-throttle.c",
++ "hw/acpi/acpi_interface.c",
++ "hw/acpi/aml-build.c",
++ "hw/acpi/bios-linker-loader.c",
++ "hw/acpi/core.c",
++ "hw/acpi/cpu_hotplug.c",
++ "hw/acpi/cpu.c",
++ "hw/acpi/generic_event_device.c",
++ "hw/acpi/hmat.c",
++ "hw/acpi/ich9.c",
++ "hw/acpi/ipmi.c",
++ "hw/acpi/memory_hotplug.c",
++ "hw/acpi/nvdimm.c",
++ "hw/acpi/pci.c",
++ "hw/acpi/pcihp.c",
++ "hw/acpi/piix4.c",
++ "hw/acpi/tco.c",
++ "hw/acpi/tpm.c",
++ "hw/acpi/utils.c",
++ "hw/acpi/vmgenid.c",
++ "hw/audio/ac97.c",
++ "hw/audio/adlib.c",
++ "hw/audio/cs4231a.c",
++ "hw/audio/es1370.c",
++ "hw/audio/fmopl.c",
++ "hw/audio/gus.c",
++ "hw/audio/gusemu_hal.c",
++ "hw/audio/gusemu_mixer.c",
++ "hw/audio/hda-codec.c",
++ "hw/audio/intel-hda.c",
++ "hw/audio/pcspk.c",
++ "hw/audio/sb16.c",
++ "hw/audio/soundhw.c",
++ "hw/block/block.c",
++ "hw/block/cdrom.c",
++ "hw/block/fdc.c",
++ "hw/block/hd-geometry.c",
++ "hw/block/nvme-ns.c",
++ "hw/block/nvme.c",
++ "hw/block/pflash_cfi01.c",
++ "hw/char/debugcon.c",
++ "hw/char/ipoctal232.c",
++ "hw/char/parallel-isa.c",
++ "hw/char/parallel.c",
++ "hw/char/serial-isa.c",
++ "hw/char/serial-pci-multi.c",
++ "hw/char/serial-pci.c",
++ "hw/char/serial.c",
++ "hw/char/virtio-console.c",
++ "hw/core/bus.c",
++ "hw/core/clock-vmstate.c",
++ "hw/core/clock.c",
++ "hw/core/cpu.c",
++ "hw/core/fw-path-provider.c",
++ "hw/core/generic-loader.c",
++ "hw/core/hotplug.c",
++ "hw/core/irq.c",
++ "hw/core/loader.c",
++ "hw/core/machine-hmp-cmds.c",
++ "hw/core/machine.c",
++ "hw/core/nmi.c",
++ "hw/core/null-machine.c",
++ "hw/core/qdev-clock.c",
++ "hw/core/qdev-fw.c",
++ "hw/core/qdev-properties-system.c",
++ "hw/core/qdev-properties.c",
++ "hw/core/qdev.c",
++ "hw/core/reset.c",
++ "hw/core/resettable.c",
++ "hw/core/sysbus.c",
++ "hw/core/vm-change-state-handler.c",
++ "hw/core/vmstate-if.c",
++ "hw/cpu/cluster.c",
++ "hw/cpu/core.c",
++ "hw/display/ati_2d.c",
++ "hw/display/ati_dbg.c",
++ "hw/display/ati.c",
++ "hw/display/bochs-display.c",
++ "hw/display/cirrus_vga_isa.c",
++ "hw/display/cirrus_vga.c",
++ "hw/display/edid-generate.c",
++ "hw/display/edid-region.c",
++ "hw/display/i2c-ddc.c",
++ "hw/display/ramfb-standalone.c",
++ "hw/display/ramfb.c",
++ "hw/display/vga-isa.c",
++ "hw/display/vga-pci.c",
++ "hw/display/virtio-gpu-base.c",
++ "hw/display/virtio-gpu-pci.c",
++ "hw/display/virtio-gpu.c",
++ "hw/display/virtio-vga.c",
++ "hw/display/vmware_vga.c",
++ "hw/dma/i8257.c",
++ "hw/i2c/bitbang_i2c.c",
++ "hw/i2c/core.c",
++ "hw/i2c/pm_smbus.c",
++ "hw/i2c/smbus_eeprom.c",
++ "hw/i2c/smbus_ich9.c",
++ "hw/i2c/smbus_master.c",
++ "hw/i2c/smbus_slave.c",
++ "hw/ide/ahci.c",
++ "hw/ide/atapi.c",
++ "hw/ide/core.c",
++ "hw/ide/ich.c",
++ "hw/ide/ioport.c",
++ "hw/ide/isa.c",
++ "hw/ide/pci.c",
++ "hw/ide/piix.c",
++ "hw/ide/qdev.c",
++ "hw/input/hid.c",
++ "hw/input/pckbd.c",
++ "hw/input/ps2.c",
++ "hw/input/virtio-input-hid.c",
++ "hw/input/virtio-input-host.c",
++ "hw/input/virtio-input.c",
++ "hw/intc/i8259_common.c",
++ "hw/intc/i8259.c",
++ "hw/intc/intc.c",
++ "hw/intc/ioapic_common.c",
++ "hw/ipack/ipack.c",
++ "hw/ipack/tpci200.c",
++ "hw/ipmi/ipmi_bmc_extern.c",
++ "hw/ipmi/ipmi_bmc_sim.c",
++ "hw/ipmi/ipmi_bt.c",
++ "hw/ipmi/ipmi_kcs.c",
++ "hw/ipmi/ipmi.c",
++ "hw/ipmi/isa_ipmi_bt.c",
++ "hw/ipmi/isa_ipmi_kcs.c",
++ "hw/ipmi/pci_ipmi_bt.c",
++ "hw/ipmi/pci_ipmi_kcs.c",
++ "hw/ipmi/smbus_ipmi.c",
++ "hw/isa/apm.c",
++ "hw/isa/isa-bus.c",
++ "hw/isa/piix3.c",
++ "hw/mem/memory-device.c",
++ "hw/mem/nvdimm.c",
++ "hw/mem/pc-dimm.c",
++ "hw/misc/applesmc.c",
++ "hw/misc/debugexit.c",
++ "hw/misc/edu.c",
++ "hw/misc/ivshmem.c",
++ "hw/misc/pc-testdev.c",
++ "hw/misc/pci-testdev.c",
++ "hw/misc/pvpanic.c",
++ "hw/misc/sga.c",
++ "hw/misc/vmcoreinfo.c",
++ "hw/net/can/can_kvaser_pci.c",
++ "hw/net/can/can_mioe3680_pci.c",
++ "hw/net/can/can_pcm3680_pci.c",
++ "hw/net/can/can_sja1000.c",
++ "hw/net/can/ctucan_core.c",
++ "hw/net/can/ctucan_pci.c",
++ "hw/net/e1000.c",
++ "hw/net/e1000e_core.c",
++ "hw/net/e1000e.c",
++ "hw/net/e1000x_common.c",
++ "hw/net/eepro100.c",
++ "hw/net/ne2000-isa.c",
++ "hw/net/ne2000-pci.c",
++ "hw/net/ne2000.c",
++ "hw/net/net_rx_pkt.c",
++ "hw/net/net_tx_pkt.c",
++ "hw/net/pcnet-pci.c",
++ "hw/net/pcnet.c",
++ "hw/net/rocker/rocker_desc.c",
++ "hw/net/rocker/rocker_fp.c",
++ "hw/net/rocker/rocker_of_dpa.c",
++ "hw/net/rocker/rocker_world.c",
++ "hw/net/rocker/rocker.c",
++ "hw/net/rtl8139.c",
++ "hw/net/tulip.c",
++ "hw/net/vhost_net.c",
++ "hw/net/vmxnet3.c",
++ "hw/nvram/eeprom93xx.c",
++ "hw/nvram/fw_cfg-interface.c",
++ "hw/nvram/fw_cfg.c",
++ "hw/pci-bridge/gen_pcie_root_port.c",
++ "hw/pci-bridge/i82801b11.c",
++ "hw/pci-bridge/ioh3420.c",
++ "hw/pci-bridge/pci_bridge_dev.c",
++ "hw/pci-bridge/pci_expander_bridge.c",
++ "hw/pci-bridge/pcie_pci_bridge.c",
++ "hw/pci-bridge/pcie_root_port.c",
++ "hw/pci-bridge/xio3130_downstream.c",
++ "hw/pci-bridge/xio3130_upstream.c",
++ "hw/pci-host/gpex-acpi.c",
++ "hw/pci-host/gpex.c",
++ "hw/pci-host/i440fx.c",
++ "hw/pci-host/pam.c",
++ "hw/pci-host/q35.c",
++ "hw/pci/msi.c",
++ "hw/pci/msix.c",
++ "hw/pci/pci_bridge.c",
++ "hw/pci/pci_host.c",
++ "hw/pci/pci.c",
++ "hw/pci/pcie_aer.c",
++ "hw/pci/pcie_host.c",
++ "hw/pci/pcie_port.c",
++ "hw/pci/pcie.c",
++ "hw/pci/shpc.c",
++ "hw/pci/slotid_cap.c",
++ "hw/pcmcia/pcmcia.c",
++ "hw/scsi/emulation.c",
++ "hw/scsi/esp-pci.c",
++ "hw/scsi/esp.c",
++ "hw/scsi/lsi53c895a.c",
++ "hw/scsi/megasas.c",
++ "hw/scsi/mptconfig.c",
++ "hw/scsi/mptendian.c",
++ "hw/scsi/mptsas.c",
++ "hw/scsi/scsi-bus.c",
++ "hw/scsi/scsi-disk.c",
++ "hw/scsi/scsi-generic.c",
++ "hw/scsi/vmw_pvscsi.c",
++ "hw/sd/core.c",
++ "hw/sd/sd.c",
++ "hw/sd/sdhci-pci.c",
++ "hw/sd/sdhci.c",
++ "hw/sd/sdmmc-internal.c",
++ "hw/smbios/smbios_type_38.c",
++ "hw/smbios/smbios.c",
++ "hw/timer/hpet.c",
++ "hw/timer/i8254_common.c",
++ "hw/timer/i8254.c",
++ "hw/usb/bus.c",
++ "hw/usb/combined-packet.c",
++ "hw/usb/core.c",
++ "hw/usb/desc-msos.c",
++ "hw/usb/desc.c",
++ "hw/usb/dev-audio.c",
++ "hw/usb/dev-hid.c",
++ "hw/usb/dev-hub.c",
++ "hw/usb/dev-mtp.c",
++ "hw/usb/dev-network.c",
++ "hw/usb/dev-serial.c",
++ "hw/usb/dev-smartcard-reader.c",
++ "hw/usb/dev-storage.c",
++ "hw/usb/dev-uas.c",
++ "hw/usb/dev-wacom.c",
++ "hw/usb/hcd-ehci-pci.c",
++ "hw/usb/hcd-ehci.c",
++ "hw/usb/hcd-ohci-pci.c",
++ "hw/usb/hcd-ohci.c",
++ "hw/usb/hcd-uhci.c",
++ "hw/usb/hcd-xhci-nec.c",
++ "hw/usb/hcd-xhci-pci.c",
++ "hw/usb/hcd-xhci-sysbus.c",
++ "hw/usb/hcd-xhci.c",
++ "hw/usb/host-stub.c",
++ "hw/usb/imx-usb-phy.c",
++ "hw/usb/libhw.c",
++ "hw/usb/u2f-passthru.c",
++ "hw/usb/u2f.c",
++ "hw/virtio/virtio-bus.c",
++ "hw/virtio/virtio-mmio.c",
++ "hw/virtio/virtio-pci.c",
++ "hw/watchdog/watchdog.c",
++ "hw/watchdog/wdt_i6300esb.c",
++ "hw/watchdog/wdt_ib700.c",
++ "io/channel-buffer.c",
++ "io/channel-command.c",
++ "io/channel-file.c",
++ "io/channel-socket.c",
++ "io/channel-tls.c",
++ "io/channel-util.c",
++ "io/channel-watch.c",
++ "io/channel-websock.c",
++ "io/channel.c",
++ "io/dns-resolver.c",
++ "io/net-listener.c",
++ "io/task.c",
++ "iothread.c",
++ "job-qmp.c",
++ "job.c",
++ "migration/block-dirty-bitmap.c",
++ "migration/channel.c",
++ "migration/colo-failover.c",
++ "migration/colo.c",
++ "migration/exec.c",
++ "migration/fd.c",
++ "migration/global_state.c",
++ "migration/migration.c",
++ "migration/multifd-zlib.c",
++ "migration/multifd.c",
++ "migration/page_cache.c",
++ "migration/postcopy-ram.c",
++ "migration/qemu-file-channel.c",
++ "migration/qemu-file.c",
++ "migration/savevm.c",
++ "migration/socket.c",
++ "migration/tls.c",
++ "migration/vmstate-types.c",
++ "migration/vmstate.c",
++ "migration/xbzrle.c",
++ "migration/qjson.c",
++ "monitor/hmp-cmds.c",
++ "monitor/hmp.c",
++ "monitor/monitor.c",
++ "monitor/qmp-cmds-control.c",
++ "monitor/qmp-cmds.c",
++ "monitor/qmp.c",
++ "nbd/client.c",
++ "nbd/common.c",
++ "nbd/server.c",
++ "net/announce.c",
++ "net/can/can_core.c",
++ "net/can/can_host.c",
++ "net/can/can_socketcan.c",
++ "net/checksum.c",
++ "net/colo-compare.c",
++ "net/colo.c",
++ "net/dump.c",
++ "net/eth.c",
++ "net/filter-buffer.c",
++ "net/filter-mirror.c",
++ "net/filter-rewriter.c",
++ "net/filter.c",
++ "net/hub.c",
++ "net/l2tpv3.c",
++ "net/net.c",
++ "net/queue.c",
++ "net/slirp.c",
++ "net/socket.c",
++ "net/tap-linux.c",
++ "net/tap.c",
++ "net/util.c",
++ "net/vhost-user-stub.c",
++ "net/vhost-vdpa.c",
++ "os-posix.c",
++ "qemu-io-cmds.c",
++ "qobject/block-qdict.c",
++ "qobject/json-lexer.c",
++ "qobject/json-parser.c",
++ "qobject/json-streamer.c",
++ "qobject/qbool.c",
++ "qobject/qdict.c",
++ "qobject/qjson.c",
++ "qobject/qlist.c",
++ "qobject/qlit.c",
++ "qobject/qnull.c",
++ "qobject/qnum.c",
++ "qobject/qobject.c",
++ "qobject/qstring.c",
++ "qom/container.c",
++ "qom/object_interfaces.c",
++ "qom/object.c",
++ "qom/qom-hmp-cmds.c",
++ "qom/qom-qmp-cmds.c",
++ "qom/qom-qobject.c",
++ "replay/stubs-system.c",
++ "scsi/pr-manager-helper.c",
++ "scsi/pr-manager.c",
++ "scsi/utils.c",
++ "softmmu/bootdevice.c",
++ "softmmu/device_tree.c",
++ "softmmu/dma-helpers.c",
++ "softmmu/qdev-monitor.c",
++ "softmmu/qemu-seccomp.c",
++ "softmmu/tpm.c",
++ "stubs/gdbstub.c",
++ "stubs/icount.c",
++ "stubs/replay-tools.c",
++ "stubs/replay.c",
++ "stubs/semihost.c",
++ "stubs/target-get-monitor-def.c",
++ "stubs/win32-kbd-hook.c",
++ "stubs/xen-hw-stub.c",
++ "contrib/libvhost-user/libvhost-user-glib.c",
++ "contrib/libvhost-user/libvhost-user.c",
++ "ui/console.c",
++ "ui/cursor.c",
++ "ui/input-barrier.c",
++ "ui/input-keymap.c",
++ "ui/input-legacy.c",
++ "ui/input-linux.c",
++ "ui/input.c",
++ "ui/kbd-state.c",
++ "ui/keymaps.c",
++ "ui/qemu-pixman.c",
++ "ui/spice-module.c",
++ "ui/vnc-stubs.c",
++ "util/aio-posix.c",
++ "util/aio-wait.c",
++ "util/aiocb.c",
++ "util/async.c",
++ "util/base64.c",
++ "util/bitmap.c",
++ "util/bitops.c",
++ "util/block-helpers.c",
++ "util/buffer.c",
++ "util/bufferiszero.c",
++ "util/cacheinfo.c",
++ "util/compatfd.c",
++ "util/coroutine-ucontext.c",
++ "util/crc32c.c",
++ "util/cutils.c",
++ "util/drm.c",
++ "util/envlist.c",
++ "util/error.c",
++ "util/event_notifier-posix.c",
++ "util/fdmon-epoll.c",
++ "util/fdmon-io_uring.c",
++ "util/fdmon-poll.c",
++ "util/fifo8.c",
++ "util/filemonitor-inotify.c",
++ "util/getauxval.c",
++ "util/guest-random.c",
++ "util/hbitmap.c",
++ "util/hexdump.c",
++ "util/host-utils.c",
++ "util/id.c",
++ "util/iov.c",
++ "util/iova-tree.c",
++ "util/keyval.c",
++ "util/lockcnt.c",
++ "util/log.c",
++ "util/main-loop.c",
++ "util/memfd.c",
++ "util/mmap-alloc.c",
++ "util/module.c",
++ "util/notify.c",
++ "util/nvdimm-utils.c",
++ "util/osdep.c",
++ "util/oslib-posix.c",
++ "util/pagesize.c",
++ "util/path.c",
++ "util/qdist.c",
++ "util/qemu-co-shared-resource.c",
++ "util/qemu-config.c",
++ "util/qemu-coroutine-io.c",
++ "util/qemu-coroutine-lock.c",
++ "util/qemu-coroutine-sleep.c",
++ "util/qemu-error.c",
++ "util/qemu-openpty.c",
++ "util/qemu-option.c",
++ "util/qemu-print.c",
++ "util/qemu-progress.c",
++ "util/qemu-sockets.c",
++ "util/qemu-thread-posix.c",
++ "util/qemu-timer-common.c",
++ "util/qemu-timer.c",
++ "util/qht.c",
++ "util/qsp.c",
++ "util/range.c",
++ "util/rcu.c",
++ "util/readline.c",
++ "util/stats64.c",
++ "util/sys_membarrier.c",
++ "util/systemd.c",
++ "util/thread-pool.c",
++ "util/throttle.c",
++ "util/timed-average.c",
++ "util/unicode.c",
++ "util/uri.c",
++ "util/uuid.c",
++ "util/vfio-helpers.c",
++ "util/vhost-user-server.c",
++ "util/qemu-coroutine.c",
++ ] + [
++ "//qapi:opts-visitor.c",
++ "//qapi:qapi-clone-visitor.c",
++ "//qapi:qapi-dealloc-visitor.c",
++ "//qapi:qapi-util.c",
++ "//qapi:qapi-visit-core.c",
++ "//qapi:qmp-dispatch.c",
++ "//qapi:qmp-event.c",
++ "//qapi:qmp-registry.c",
++ "//qapi:qobject-input-visitor.c",
++ "//qapi:qobject-output-visitor.c",
++ "//qapi:string-input-visitor.c",
++ "//qapi:string-output-visitor.c",
++ "//trace:control.c",
++ "//trace:qmp.c",
++ ] + [
++ ":gen_hdrs",
++ ":block-coroutine-gen",
++ ],
++ # QEMU relies on hacky two's complement representation interpretation of bitshifts
++ copts = ["-fwrapv"],
++ local_defines = [
++ "_GNU_SOURCE",
++ "_FILE_OFFSET_BITS=64",
++ "_LARGEFILE_SOURCE",
++ ],
++ deps = [
++ ":capstone",
++ ":fdt",
++ ":slirp",
++ "@glib//glib",
++ "@pixman//:pixman",
++ "@seccomp",
++ "@uring//:uring",
++ "@zlib//:zlib",
++ ],
++ includes = ["include", "capstone/include/capstone"],
++ alwayslink = True, # QEMU uses __attribute__((constructor)) functions
++)
++
++cc_binary(
++ name = "qemu-x86_64-softmmu",
++ srcs = [":all_headers"] + [
++ "//trace:control-target.c",
++ "accel/dummy-cpus.c",
++ "accel/kvm/kvm-all.c",
++ "accel/kvm/kvm-cpus.c",
++ "accel/qtest/qtest.c",
++ "accel/stubs/hax-stub.c",
++ "accel/stubs/tcg-stub.c",
++ "accel/stubs/xen-stub.c",
++ "cpu.c",
++ "disas.c",
++ "dump/dump.c",
++ "dump/win_dump.c",
++ "exec-vary.c",
++ "gdbstub.c",
++ "hw/block/dataplane/virtio-blk.c",
++ "hw/block/virtio-blk.c",
++ "hw/char/virtio-serial-bus.c",
++ "hw/core/machine-qmp-cmds.c",
++ "hw/core/numa.c",
++ "hw/display/vga.c",
++ "hw/hyperv/hyperv_testdev.c",
++ "hw/hyperv/hyperv.c",
++ "hw/hyperv/vmbus.c",
++ "hw/i386/acpi-build.c",
++ "hw/i386/acpi-common.c",
++ "hw/i386/acpi-microvm.c",
++ "hw/i386/amd_iommu.c",
++ "hw/i386/e820_memory_layout.c",
++ "hw/i386/fw_cfg.c",
++ "hw/i386/generic_event_device_x86.c",
++ "hw/i386/intel_iommu.c",
++ "hw/i386/kvm/apic.c",
++ "hw/i386/kvm/clock.c",
++ "hw/i386/kvm/i8254.c",
++ "hw/i386/kvm/i8259.c",
++ "hw/i386/kvm/ioapic.c",
++ "hw/i386/kvmvapic.c",
++ "hw/i386/microvm.c",
++ "hw/i386/multiboot.c",
++ "hw/i386/pc_piix.c",
++ "hw/i386/pc_q35.c",
++ "hw/i386/pc_sysfw.c",
++ "hw/i386/pc.c",
++ "hw/i386/port92.c",
++ "hw/i386/vmmouse.c",
++ "hw/i386/vmport.c",
++ "hw/i386/x86-iommu.c",
++ "hw/i386/x86.c",
++ "hw/intc/apic_common.c",
++ "hw/intc/apic.c",
++ "hw/intc/ioapic.c",
++ "hw/isa/lpc_ich9.c",
++ "hw/net/virtio-net.c",
++ "hw/rtc/mc146818rtc.c",
++ "hw/scsi/virtio-scsi-dataplane.c",
++ "hw/scsi/virtio-scsi.c",
++ "hw/vfio/common.c",
++ "hw/vfio/display.c",
++ "hw/vfio/igd.c",
++ "hw/vfio/migration.c",
++ "hw/vfio/pci-quirks.c",
++ "hw/vfio/pci.c",
++ "hw/vfio/spapr.c",
++ "hw/virtio/vhost-backend.c",
++ "hw/virtio/vhost-vdpa.c",
++ "hw/virtio/vhost.c",
++ "hw/virtio/virtio-balloon-pci.c",
++ "hw/virtio/virtio-balloon.c",
++ "hw/virtio/virtio-blk-pci.c",
++ "hw/virtio/virtio-crypto-pci.c",
++ "hw/virtio/virtio-crypto.c",
++ "hw/virtio/virtio-input-host-pci.c",
++ "hw/virtio/virtio-input-pci.c",
++ "hw/virtio/virtio-iommu-pci.c",
++ "hw/virtio/virtio-iommu.c",
++ "hw/virtio/virtio-mem-pci.c",
++ "hw/virtio/virtio-mem.c",
++ "hw/virtio/virtio-net-pci.c",
++ "hw/virtio/virtio-pmem-pci.c",
++ "hw/virtio/virtio-pmem.c",
++ "hw/virtio/virtio-rng-pci.c",
++ "hw/virtio/virtio-rng.c",
++ "hw/virtio/virtio-scsi-pci.c",
++ "hw/virtio/virtio-serial-pci.c",
++ "hw/virtio/virtio.c",
++ "migration/dirtyrate.c",
++ "migration/ram.c",
++ "monitor/misc.c",
++ "softmmu/arch_init.c",
++ "softmmu/balloon.c",
++ "softmmu/cpu-throttle.c",
++ "softmmu/cpu-timers.c",
++ "softmmu/cpus.c",
++ "softmmu/ioport.c",
++ "softmmu/main.c",
++ "softmmu/memory_mapping.c",
++ "softmmu/memory.c",
++ "softmmu/physmem.c",
++ "softmmu/qtest.c",
++ "softmmu/vl.c",
++ "target/i386/arch_dump.c",
++ "target/i386/arch_memory_mapping.c",
++ "target/i386/cpu.c",
++ "target/i386/gdbstub.c",
++ "target/i386/helper.c",
++ "target/i386/kvm.c",
++ "target/i386/hyperv.c",
++ "target/i386/machine.c",
++ "target/i386/monitor.c",
++ "target/i386/tcg-stub.c",
++ "target/i386/sev.c",
++ "target/i386/xsave_helper.c",
++ ] + [
++ ":gen_hdrs",
++ ":trace_c",
++ ":qapi_c",
++ ],
++ copts = ["-fwrapv"], # QEMU relies on hacky two's complement representations of bitshifts
++ linkopts = [
++ "-pthread",
++ "-lutil", # Not actually a library but weird GLIBC shenanigans
++ ],
++ data = glob(["pc-bios/**"]),
++ local_defines = [
++ "_GNU_SOURCE",
++ "_FILE_OFFSET_BITS=64",
++ "_LARGEFILE_SOURCE",
++ "NEED_CPU_H",
++ "CONFIG_TARGET=\\\"x86_64-softmmu-config-target.h\\\"",
++ "CONFIG_DEVICES=\\\"x86_64-softmmu-config-devices.h\\\"",
++ ],
++ deps = [
++ ":fdt",
++ ":qemu",
++ ":slirp",
++ "@glib//glib",
++ "@pixman//:pixman",
++ "@zlib//:zlib",
++ ],
++ visibility = ["//visibility:public"],
++ includes = ["target/i386", "tcg/i386", "accel/tcg", "linux-headers"],
++)
++
++genrule(
++ name = "cursor-hdrs",
++ srcs = [
++ "ui/cursor_hidden.xpm",
++ "ui/cursor_left_ptr.xpm",
++ ],
++ outs = [
++ "ui/cursor_hidden.h",
++ "ui/cursor_left_ptr.h",
++ ],
++ cmd = """
++ cp $(location ui/cursor_hidden.xpm) $(location ui/cursor_hidden.h)
++ cp $(location ui/cursor_left_ptr.xpm) $(location ui/cursor_left_ptr.h)
++ """,
++)
++
++genrule(
++ name = "module-block",
++ outs = ["block/module_block.h"],
++ cmd = "./$(location //scripts/modules:module_block) $(location block/module_block.h)",
++ tools = ["//scripts/modules:module_block"],
++)
++
++genrule(
++ name = "hmp-commands",
++ srcs = [
++ "hmp-commands.hx",
++ "hmp-commands-info.hx",
++ "qemu-options.hx",
++ "qemu-img-cmds.hx",
++ ],
++ outs = [
++ "hmp-commands.h",
++ "hmp-commands-info.h",
++ "qemu-options-gen.h",
++ "qemu-img-cmds.h",
++ ],
++ cmd = """
++ ./$(location //scripts:hxtool-sh) -h $(location hmp-commands.hx) > $(location hmp-commands.h)
++ ./$(location //scripts:hxtool-sh) -h $(location hmp-commands-info.hx) > $(location hmp-commands-info.h)
++ ./$(location //scripts:hxtool-sh) -h $(location qemu-options.hx) > $(location qemu-options-gen.h)
++ ./$(location //scripts:hxtool-sh) -h $(location qemu-img-cmds.hx) > $(location qemu-img-cmds.h)
++ """,
++ tools = ["//scripts:hxtool-sh"],
++)
++
++cc_qemu_keymaps(
++ name = "keymaps-gen",
++ src = "ui/keycodemapdb/data/keymaps.csv",
++ maps = {
++ "atset1": ["qcode"],
++ "linux": ["qcode"],
++ "qcode": [
++ "atset1",
++ "atset2",
++ "atset3",
++ "linux",
++ "qnum",
++ "sun",
++ ],
++ "qnum": ["qcode"],
++ "usb": ["qcode"],
++ "win32": ["qcode"],
++ "x11": ["qcode"],
++ "xorgevdev": ["qcode"],
++ "xorgkbd": ["qcode"],
++ "xorgxquartz": ["qcode"],
++ "xorgxwin": ["qcode"],
++ "osx": ["qcode"],
++ },
++)
++
++
++genrule(
++ name = "renamed-keymap-gen",
++ srcs = ["ui/keycodemapdb/tools/keymap-gen"],
++ outs = ["keymap-gen.py"],
++ cmd = "cp $(location ui/keycodemapdb/tools/keymap-gen) $@",
++)
++
++py_binary(
++ name = "keymap-gen",
++ srcs = [":renamed-keymap-gen"],
++ visibility = ["//visibility:public"],
++)
++
++genrule(
++ name = "gdbstub-xml",
++ srcs = ["gdb-xml/i386-64bit.xml"],
++ outs = ["x86_64-softmmu-gdbstub-xml.c"],
++ cmd = "./$(location //scripts:feature_to_c) $(location gdb-xml/i386-64bit.xml) > $@",
++ tools = ["//scripts:feature_to_c"],
++)
++
++# TODO: x86_64-softmmu-config-target.h, x86_64-softmmu-config-devices.h, include/qemu/config-host.h (probably copy)
++# TODO: ui/input-keymap-*.c.inc (generate at top level with //ui/keycodemapdb/tools:keymap-gen)
+diff --git a/defs.bzl b/defs.bzl
+new file mode 100644
+index 0000000000..3a8d50d429
+--- /dev/null
++++ b/defs.bzl
+@@ -0,0 +1,52 @@
++def _impl_filter_label_suffix(ctx):
++ return [DefaultInfo(
++ files = depset([f for f in ctx.files.srcs if f.path.endswith(ctx.attr.suffix) and f.basename not in ctx.attr.exclude]),
++ )]
++
++filter_label_suffix = rule(
++ implementation = _impl_filter_label_suffix,
++ attrs = {
++ "srcs": attr.label_list(
++ mandatory = True,
++ allow_files = True,
++ ),
++ "suffix": attr.string(
++ mandatory = True,
++ ),
++ "exclude": attr.string_list(
++ default = [],
++ ),
++ },
++)
++
++def _impl_cc_qemu_keymaps(ctx):
++ outs = []
++ for _from in ctx.attr.maps:
++ for _to in ctx.attr.maps[_from]:
++ out = ctx.actions.declare_file("ui/input-keymap-{}-to-{}.c.inc".format(_from, _to))
++ ctx.actions.run(
++ inputs = ctx.files.src + ctx.files._keymap_gen,
++ executable = ctx.executable._savestdout,
++ arguments = [out.path, ctx.files._keymap_gen[0].path, "--lang=glib2", "--varname=qemu_input_map_{}_to_{}".format(_from, _to), "code-map", ctx.files.src[0].path, _from, _to],
++ outputs = [out],
++ )
++ outs.append(out)
++ return [DefaultInfo(files = depset(outs))]
++
++cc_qemu_keymaps = rule(
++ implementation = _impl_cc_qemu_keymaps,
++ attrs = {
++ "src": attr.label(allow_single_file = True),
++ "maps": attr.string_list_dict(),
++ "_keymap_gen": attr.label(
++ default = Label("//:keymap-gen"),
++ executable = True,
++ cfg = "exec",
++ ),
++ "_savestdout": attr.label(
++ default = Label("@dev_source_monogon//build/savestdout"),
++ executable = True,
++ cfg = "exec",
++ ),
++ },
++)
+diff --git a/qapi/BUILD b/qapi/BUILD
+new file mode 100644
+index 0000000000..71ff5a7445
+--- /dev/null
++++ b/qapi/BUILD
+@@ -0,0 +1,25 @@
++load("//scripts/qapi:defs.bzl", "cc_qapi")
++
++cc_qapi(
++ name = "qapi_generated",
++ srcs = glob(["*.json"]),
++ main = "qapi-schema.json",
++ visibility = ["//visibility:public"],
++)
++
++exports_files(glob([
++ "*.c",
++ "*.h",
++]) + ["trace-events"])
++
++filegroup(
++ name = "extra_hdrs",
++ srcs = glob(["**/*.h"]),
++ visibility = ["//visibility:public"],
++)
++
++filegroup(
++ name = "schema",
++ srcs = glob(["*.json"]),
++ visibility = ["//visibility:public"],
++)
+diff --git a/qapi/defs.bzl b/qapi/defs.bzl
+new file mode 100644
+index 0000000000..2d1f38fdfa
+--- /dev/null
++++ b/qapi/defs.bzl
+@@ -0,0 +1,40 @@
++load("@rules_cc//cc:defs.bzl", "cc_library")
++
++# The actual rule which does the filtering.
++def _do_filter_impl(ctx):
++ return [DefaultInfo(
++ files = depset([f for f in ctx.files.srcs if f.path.endswith(ctx.attr.suffix)]),
++ )]
++
++_do_filter = rule(
++ implementation = _do_filter_impl,
++ attrs = {
++ "srcs": attr.label_list(
++ mandatory = True,
++ allow_files = True,
++ ),
++ "suffix": attr.string(
++ mandatory = True,
++ ),
++ },
++)
++
++def filtered_cc_library(name, srcs, hdrs, **kwargs):
++ _do_filter(
++ name = "%s_hdrs" % name,
++ visibility = ["//visibility:private"],
++ srcs = hdrs,
++ suffix = ".h",
++ )
++ _do_filter(
++ name = "%s_srcs" % name,
++ visibility = ["//visibility:private"],
++ srcs = srcs,
++ suffix = ".c",
++ )
++ cc_library(
++ name = name,
++ srcs = [":%s_srcs" % name],
++ hdrs = [":%s_hdrs" % name],
++ **kwargs
++ )
+diff --git a/scripts/BUILD b/scripts/BUILD
+new file mode 100644
+index 0000000000..0b4fc8a248
+--- /dev/null
++++ b/scripts/BUILD
+@@ -0,0 +1,35 @@
++load("@rules_python//python:defs.bzl", "py_binary")
++
++py_binary(
++ name = "qapi-gen",
++ srcs = ["qapi-gen.py"],
++ visibility = ["//visibility:public"],
++ deps = ["//scripts/qapi"],
++)
++
++py_binary(
++ # We cannot use tracetool as name as a directory with the same name exists
++ name = "tracetool-cli",
++ srcs = ["tracetool.py"],
++ main = "tracetool.py",
++ visibility = ["//visibility:public"],
++ deps = ["//scripts/tracetool"],
++)
++
++py_binary(
++ name = "block-coroutine-wrapper",
++ srcs = ["block-coroutine-wrapper.py"],
++ visibility = ["//visibility:public"],
++)
++
++sh_binary(
++ name = "hxtool-sh",
++ srcs = ["hxtool"],
++ visibility = ["//visibility:public"],
++)
++
++sh_binary(
++ name = "feature_to_c",
++ srcs = ["feature_to_c.sh"],
++ visibility = ["//:__subpackages__"],
++)
+diff --git a/scripts/modules/BUILD b/scripts/modules/BUILD
+new file mode 100644
+index 0000000000..99a5ab2243
+--- /dev/null
++++ b/scripts/modules/BUILD
+@@ -0,0 +1,7 @@
++load("@rules_python//python:defs.bzl", "py_binary")
++
++py_binary(
++ name = "module_block",
++ srcs = ["module_block.py"],
++ visibility = ["//:__subpackages__"]
++)
+diff --git a/scripts/qapi/BUILD b/scripts/qapi/BUILD
+new file mode 100644
+index 0000000000..a7e8da9368
+--- /dev/null
++++ b/scripts/qapi/BUILD
+@@ -0,0 +1,7 @@
++load("@rules_python//python:defs.bzl", "py_library")
++
++py_library(
++ name = "qapi",
++ srcs = glob(["*.py"]),
++ visibility = ["//visibility:public"],
++)
+diff --git a/scripts/qapi/defs.bzl b/scripts/qapi/defs.bzl
+new file mode 100644
+index 0000000000..807f4b37d5
+--- /dev/null
++++ b/scripts/qapi/defs.bzl
+@@ -0,0 +1,52 @@
++def _impl_qapi_cc(ctx):
++ out = []
++ out_types = ["types", "visit", "events", "commands"]
++ system_modules = ["builtin-types", "builtin-visit", "introspect", "init-commands", "emit-events", "types-error", "visit-error"]
++ for t in out_types:
++ out.append(ctx.actions.declare_file("qapi-{}.c".format(t)))
++ out.append(ctx.actions.declare_file("qapi-{}.h".format(t)))
++ for t in system_modules:
++ out.append(ctx.actions.declare_file("qapi-{}.c".format(t)))
++ out.append(ctx.actions.declare_file("qapi-{}.h".format(t)))
++
++ input_dir = ""
++ main_file = ctx.files.main[0]
++ for src in ctx.files.srcs:
++ if src.path == main_file.path:
++ continue
++ extension = src.extension
++ basename = src.basename[:-len(extension) - 1]
++ if input_dir == "":
++ input_dir = src.dirname
++ elif input_dir != src.dirname:
++ fail("all cc_qapi sources need to be in the same folder")
++
++ for t in out_types:
++ out.append(ctx.actions.declare_file("qapi-{}-{}.c".format(t, basename)))
++ out.append(ctx.actions.declare_file("qapi-{}-{}.h".format(t, basename)))
++
++ ctx.actions.run(
++ inputs = ctx.files.srcs + ctx.files.main,
++ executable = ctx.executable._qapi_gen,
++ arguments = ["-o", out[0].dirname, "-b", main_file.path],
++ outputs = out,
++ )
++ return [DefaultInfo(files = depset(out))]
++
++cc_qapi = rule(
++ implementation = _impl_qapi_cc,
++ attrs = {
++ "srcs": attr.label_list(
++ mandatory = True,
++ allow_files = True,
++ ),
++ "main": attr.label(
++ allow_single_file = True,
++ ),
++ "_qapi_gen": attr.label(
++ default = Label("//scripts:qapi-gen"),
++ executable = True,
++ cfg = "exec",
++ ),
++ },
++)
+diff --git a/scripts/tracetool/BUILD b/scripts/tracetool/BUILD
+new file mode 100644
+index 0000000000..93ccf94480
+--- /dev/null
++++ b/scripts/tracetool/BUILD
+@@ -0,0 +1,11 @@
++load("@rules_python//python:defs.bzl", "py_library")
++
++py_library(
++ name = "tracetool",
++ srcs = glob(["*.py"]),
++ visibility = ["//visibility:public"],
++ deps = [
++ "//scripts/tracetool/backend",
++ "//scripts/tracetool/format",
++ ],
++)
+diff --git a/scripts/tracetool/backend/BUILD b/scripts/tracetool/backend/BUILD
+new file mode 100644
+index 0000000000..6cc626682c
+--- /dev/null
++++ b/scripts/tracetool/backend/BUILD
+@@ -0,0 +1,7 @@
++load("@rules_python//python:defs.bzl", "py_library")
++
++py_library(
++ name = "backend",
++ srcs = glob(["*.py"]),
++ visibility = ["//visibility:public"],
++)
+diff --git a/scripts/tracetool/defs.bzl b/scripts/tracetool/defs.bzl
+new file mode 100644
+index 0000000000..70ce080a62
+--- /dev/null
++++ b/scripts/tracetool/defs.bzl
+@@ -0,0 +1,65 @@
++def _impl_cc_qemu_trace(ctx):
++ outs = []
++ for src in ctx.files.srcs:
++ name = src.path.replace("external/qemu/", "").replace("/trace-events", "").replace("/", "_")
++ if name == "trace-events":
++ name = "root"
++ trace_h = ctx.actions.declare_file("trace-{}.h".format(name))
++ trace_c = ctx.actions.declare_file("trace-{}.c".format(name))
++ outs.append(trace_c)
++ outs.append(trace_h)
++
++ ctx.actions.run(
++ inputs = [src] + ctx.files._tracetool,
++ executable = ctx.executable._savestdout,
++ arguments = [trace_h.path, ctx.files._tracetool[0].path, "--backend", ctx.attr.backend, "--group", name, "--format=h", src.path],
++ outputs = [trace_h],
++ )
++ ctx.actions.run(
++ inputs = [src] + ctx.files._tracetool,
++ executable = ctx.executable._savestdout,
++ arguments = [trace_c.path, ctx.files._tracetool[0].path, "--backend", ctx.attr.backend, "--group", name, "--format=c", src.path],
++ outputs = [trace_c],
++ )
++ return [DefaultInfo(files = depset(outs))]
++
++cc_qemu_trace = rule(
++ implementation = _impl_cc_qemu_trace,
++ attrs = {
++ "srcs": attr.label_list(
++ mandatory = True,
++ allow_files = True,
++ ),
++ "backend": attr.string(
++ default = "log",
++ ),
++ "_tracetool": attr.label(
++ default = Label("//scripts:tracetool-cli"),
++ executable = True,
++ cfg = "exec",
++ ),
++ "_savestdout": attr.label(
++ default = Label("@dev_source_monogon//build/savestdout"),
++ executable = True,
++ cfg = "exec",
++ ),
++ },
++)
++
++def _impl_cc_qemu_trace_single(ctx):
++ trace_h = ctx.actions.declare_file("trace-{}.h".format(ctx.attr.name))
++ trace_c = ctx.actions.declare_file("trace-{}.c".format(ctx.attr.name))
++
++ ctx.actions.run(
++ inputs = ctx.files.src,
++ executable = ctx.executable._tracetool,
++ arguments = ["--backend", ctx.attr.backend, "--group", ctx.attr.name, "--format=h", ctx.files.src[0].path, trace_h.path],
++ outputs = [trace_h],
++ )
++ ctx.actions.run(
++ inputs = ctx.files.src,
++ executable = ctx.executable._tracetool,
++ arguments = ["--backend", ctx.attr.backend, "--group", ctx.attr.name, "--format=c", ctx.files.src[0].path, trace_c.path],
++ outputs = [trace_c],
++ )
++ return [DefaultInfo(files = depset([trace_c, trace_h]))]
+diff --git a/scripts/tracetool/format/BUILD b/scripts/tracetool/format/BUILD
+new file mode 100644
+index 0000000000..1b2dc209e1
+--- /dev/null
++++ b/scripts/tracetool/format/BUILD
+@@ -0,0 +1,7 @@
++load("@rules_python//python:defs.bzl", "py_library")
++
++py_library(
++ name = "format",
++ srcs = glob(["*.py"]),
++ visibility = ["//visibility:public"],
++)
+diff --git a/trace/BUILD b/trace/BUILD
+new file mode 100644
+index 0000000000..2f2e71d81a
+--- /dev/null
++++ b/trace/BUILD
+@@ -0,0 +1,18 @@
++load("//scripts/tracetool:defs.bzl", "cc_qemu_trace")
++
++cc_qemu_trace(
++ name = "trace",
++ srcs = ["//:trace-files"],
++ visibility = ["//visibility:public"],
++)
++
++exports_files(glob([
++ "*.c",
++ "*.h",
++]))
++
++filegroup(
++ name = "extra_hdrs",
++ srcs = glob(["**/*.h"]),
++ visibility = ["//visibility:public"],
++)
+--
+2.25.1
+