Update build rule application
Prior to this CL, the build rules for zephyr-bazel required a reference
to @zephyr//. This approach worked, but was limiting (we weren't able to
use globs). Instead, this new approach generates a patch on the fly and
applies it to Zephyr such that the BUILD.bazel and .bzl files in this
repo are copied to Zephyr's repo directly. The benefits:
1. The used can choose the name. @zephyr is not required.
2. We can reference files as though they were local.
3. We can check for merge conflicts with Zephyr in CI since we're
generating a patch and applying it directly to Zephyr.
BUG=b/346596832
Change-Id: Ifc024c1dec485f4b7d5140b4c1fb20cffeee68b5
Reviewed-on: https://pigweed-review.googlesource.com/c/zephyr/zephyr-bazel/+/223215
Reviewed-by: Sergio Soares <sergiosoares@google.com>
Commit-Queue: Yuval Peress <peress@google.com>
diff --git a/BUILD.bazel b/BUILD.bazel
index 072a1dd..90d9741 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -12,440 +12,23 @@
# License for the specific language governing permissions and limitations under
# the License.
-load("@bazel_skylib//rules/directory:subdirectory.bzl", "subdirectory")
-load("//:defs.bzl", "zephyr_includes")
+load("@rules_cc//cc:defs.bzl", "cc_library")
package(default_visibility = ["//visibility:public"])
-filegroup(
- name = "dt_bindings",
- srcs = [
- "@zephyr//:include/zephyr/dt-bindings/reset/gd32e10x.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/numaker_m46x_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/stm32wb_l_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/stm32u5_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/intel_socfpga_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/stm32-common.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/gd32-common.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/npcx4_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/gd32f4xx.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/gd32vf103.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/stm32l0_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/stm32wba_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/stm32h5_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/stm32l1_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/stm32h7_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/stm32mp1_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/stm32f2_4_7_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/gd32f3x0.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/stm32f0_1_3_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/stm32c0_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/gd32l23x.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/gd32e50x.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/stm32g4_l4_5_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/numaker_m2l31x_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/gd32a50x.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/ast10x0_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/npcx9_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/stm32g0_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/gd32f403.h",
- "@zephyr//:include/zephyr/dt-bindings/reset/npcx7_reset.h",
- "@zephyr//:include/zephyr/dt-bindings/adc/nrf-adc.h",
- "@zephyr//:include/zephyr/dt-bindings/adc/stm32_adc.h",
- "@zephyr//:include/zephyr/dt-bindings/adc/b91-adc.h",
- "@zephyr//:include/zephyr/dt-bindings/adc/ads114s0x_adc.h",
- "@zephyr//:include/zephyr/dt-bindings/adc/adc.h",
- "@zephyr//:include/zephyr/dt-bindings/adc/smartbond-adc.h",
- "@zephyr//:include/zephyr/dt-bindings/adc/mcux-lpadc.h",
- "@zephyr//:include/zephyr/dt-bindings/adc/stm32f1_adc.h",
- "@zephyr//:include/zephyr/dt-bindings/adc/stm32f4_adc.h",
- "@zephyr//:include/zephyr/dt-bindings/adc/gd32f3x0.h",
- "@zephyr//:include/zephyr/dt-bindings/adc/stm32h7_adc.h",
- "@zephyr//:include/zephyr/dt-bindings/adc/stm32l4_adc.h",
- "@zephyr//:include/zephyr/dt-bindings/adc/stm32u5_adc.h",
- "@zephyr//:include/zephyr/dt-bindings/dt-util.h",
- "@zephyr//:include/zephyr/dt-bindings/inputmux/inputmux_trigger_ports.h",
- "@zephyr//:include/zephyr/dt-bindings/pm/imx_spc.h",
- "@zephyr//:include/zephyr/dt-bindings/interrupt-controller/infineon-xmc4xxx-intc.h",
- "@zephyr//:include/zephyr/dt-bindings/interrupt-controller/esp32s2-xtensa-intmux.h",
- "@zephyr//:include/zephyr/dt-bindings/interrupt-controller/openisa-intmux.h",
- "@zephyr//:include/zephyr/dt-bindings/interrupt-controller/intel-ioapic.h",
- "@zephyr//:include/zephyr/dt-bindings/interrupt-controller/esp-xtensa-intmux.h",
- "@zephyr//:include/zephyr/dt-bindings/interrupt-controller/ti-vim.h",
- "@zephyr//:include/zephyr/dt-bindings/interrupt-controller/renesas-ra-icu.h",
- "@zephyr//:include/zephyr/dt-bindings/interrupt-controller/arm-gic.h",
- "@zephyr//:include/zephyr/dt-bindings/interrupt-controller/esp32s3-xtensa-intmux.h",
- "@zephyr//:include/zephyr/dt-bindings/interrupt-controller/esp-esp32c3-intmux.h",
- "@zephyr//:include/zephyr/dt-bindings/interrupt-controller/ite-intc.h",
- "@zephyr//:include/zephyr/dt-bindings/interrupt-controller/it8xxx2-wuc.h",
- "@zephyr//:include/zephyr/dt-bindings/interrupt-controller/mchp-xec-ecia.h",
- "@zephyr//:include/zephyr/dt-bindings/led/worldsemi_ws2812c.h",
- "@zephyr//:include/zephyr/dt-bindings/led/seagate_legend_b1414.h",
- "@zephyr//:include/zephyr/dt-bindings/led/led.h",
- "@zephyr//:include/zephyr/dt-bindings/input/input-event-codes.h",
- "@zephyr//:include/zephyr/dt-bindings/input/esp32-touch-sensor-input.h",
- "@zephyr//:include/zephyr/dt-bindings/input/keymap.h",
- "@zephyr//:include/zephyr/dt-bindings/misc/nordic-nrf-ficr-nrf54h20.h",
- "@zephyr//:include/zephyr/dt-bindings/dma/gd32_dma.h",
- "@zephyr//:include/zephyr/dt-bindings/dma/infineon-xmc4xxx-dma.h",
- "@zephyr//:include/zephyr/dt-bindings/dma/rpi_pico_dma.h",
- "@zephyr//:include/zephyr/dt-bindings/dma/stm32_dma.h",
- "@zephyr//:include/zephyr/dt-bindings/i2c/i2c.h",
- "@zephyr//:include/zephyr/dt-bindings/i2c/it8xxx2-i2c.h",
- "@zephyr//:include/zephyr/dt-bindings/ipc_service/static_vrings.h",
- "@zephyr//:include/zephyr/dt-bindings/gnss/u_blox_m10.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32g0_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32f3_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32wl_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32wb_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/npcx_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/lpc11u6x_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32h7_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/intel_socfpga_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/gd32e50x-clocks.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/esp32_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/esp32s2_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32l0_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32f427_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/rpi_pico_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/numaker_m46x_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/nxp_s32k344_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/nxp_s32z2_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32g4_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/numaker_m2l31x_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/gd32f403-clocks.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/r7fa4m1xxxxxx-clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32f7_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/gd32l23x-clocks.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/imx_ccm.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/gd32-clocks-common.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32c0_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/ast10x0_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/kinetis_pcc.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/gd32a50x-clocks.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32l4_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/gd32f3x0-clocks.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/imx8ulp_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32_common_clocks.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/esp32c3_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32l1_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/mchp_xec_pcr.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/esp32s3_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32wba_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/kinetis_mcg.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32f4_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/kinetis_scg.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/gd32vf103-clocks.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32u5_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/r8a7795_cpg_mssr.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/renesas-ra-cgc.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32f0_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32f1_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32h5_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/gd32e10x-clocks.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/stm32f410_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/mcux_lpc_syscon_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/nxp_s32k146_clock.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/r8a779f0_cpg_mssr.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/atmel_sam_pmc.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/imx_ccm_rev2.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/gd32f4xx-clocks.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/kinetis_sim.h",
- "@zephyr//:include/zephyr/dt-bindings/clock/renesas_cpg_mssr.h",
- "@zephyr//:include/zephyr/dt-bindings/timer/stm32-timer.h",
- "@zephyr//:include/zephyr/dt-bindings/timer/nuclei-systimer.h",
- "@zephyr//:include/zephyr/dt-bindings/acpi/acpi.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/snps-designware-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/andestech-atcgpio100.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/nuvoton-npcx-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/infineon-xmc4xxx-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/ti-cc13xx-cc26xx-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/nordic-npm6001-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/atmel-sam-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/semtech-sx1509b.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/nordic-npm1300-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/digilent-pmod.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/ite-it8xxx2-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/numicro-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/espressif-esp32-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/st-morpho-header.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/renesas-rzt2m-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/nordic-nrf-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/atmel-sam0-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/microchip-xec-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/nxp-s32-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/nxp-kinetis-gpio.h",
- "@zephyr//:include/zephyr/dt-bindings/lvgl/lvgl.h",
- "@zephyr//:include/zephyr/dt-bindings/ethernet/nxp_enet.h",
- "@zephyr//:include/zephyr/dt-bindings/ethernet/xlnx_gem.h",
- "@zephyr//:include/zephyr/dt-bindings/rdc/imx_rdc.h",
- "@zephyr//:include/zephyr/dt-bindings/lora/sx126x.h",
- "@zephyr//:include/zephyr/dt-bindings/regulator/npm6001.h",
- "@zephyr//:include/zephyr/dt-bindings/regulator/max20335.h",
- "@zephyr//:include/zephyr/dt-bindings/regulator/nxp_vref.h",
- "@zephyr//:include/zephyr/dt-bindings/regulator/npm1300.h",
- "@zephyr//:include/zephyr/dt-bindings/regulator/npm1100.h",
- "@zephyr//:include/zephyr/dt-bindings/regulator/adp5360.h",
- "@zephyr//:include/zephyr/dt-bindings/regulator/axp192.h",
- "@zephyr//:include/zephyr/dt-bindings/regulator/rpi_pico.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/ism330dhcx.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/qdec_nxp_s32.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/lsm6dso.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/lis2dh.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/lis2de12.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/lsm6dsv16x.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/ina237.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/tmag5273.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/lps2xdf.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/lis2ds12.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/bq274xx.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/qdec_stm32.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/npcx_tach.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/lps22hh.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/lis2dux12.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/lis2dw12.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/lis2du12.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/iis2dlpc.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/iis2iclx.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/lsm6dso16is.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/ina230.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/it8xxx2_vcmp.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/stts22h.h",
- "@zephyr//:include/zephyr/dt-bindings/sensor/it8xxx2_tach.h",
- "@zephyr//:include/zephyr/dt-bindings/flash_controller/npcx_fiu_qspi.h",
- "@zephyr//:include/zephyr/dt-bindings/flash_controller/ospi.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/b91-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/ambiq-apollo4-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/mchp-xec-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/ene-kb1200-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/numaker-m46x-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/stm32-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/nrf-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/esp32s2-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/esp32c3-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/esp32-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/ti-k3-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/quicklogic-eos-s3-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/renesas/pinctrl-r8a77961.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/renesas/pinctrl-r8a779f0.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/renesas/pinctrl-ra-common.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/renesas/pinctrl-rcar-common.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/renesas/pinctrl-r8a77951.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/renesas/pinctrl-r7fa4m1xxxxxx.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/cc13xx_cc26xx-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/rpi-pico-rp2040-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/gecko-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/imx8qm-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/emsdp-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/nxp-s32-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/imx8qxp-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/gecko-pinctrl-s1.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/npcx-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/esp32s3-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/ifx_cat1-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/esp32s3-gpio-sigmap.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/it8xxx2-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/pinctrl-zynqmp.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/ti-cc32xx-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/pinctrl-zynq.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/renesas-rzt2m-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/numicro-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/esp32s2-gpio-sigmap.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/smartbond-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/esp32c3-gpio-sigmap.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/esp32-gpio-sigmap.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/esp-pinctrl-common.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/xmc4xxx-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/rv32m1-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/stm32f1-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/sifive-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/stm32f1-afio.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/stm32-pinctrl-common.h",
- "@zephyr//:include/zephyr/dt-bindings/pinctrl/lpc11u6x-pinctrl.h",
- "@zephyr//:include/zephyr/dt-bindings/mipi_dsi/mipi_dsi.h",
- "@zephyr//:include/zephyr/dt-bindings/spi/spi.h",
- "@zephyr//:include/zephyr/dt-bindings/mipi_dbi/mipi_dbi.h",
- "@zephyr//:include/zephyr/dt-bindings/memory-controller/stm32-fmc-nor-psram.h",
- "@zephyr//:include/zephyr/dt-bindings/memory-controller/nxp,flexram.h",
- "@zephyr//:include/zephyr/dt-bindings/memory-controller/stm32-fmc-sdram.h",
- "@zephyr//:include/zephyr/dt-bindings/pwm/stm32_pwm.h",
- "@zephyr//:include/zephyr/dt-bindings/pwm/it8xxx2_pwm.h",
- "@zephyr//:include/zephyr/dt-bindings/pwm/pwm.h",
- "@zephyr//:include/zephyr/dt-bindings/memory-attr/memory-attr.h",
- "@zephyr//:include/zephyr/dt-bindings/memory-attr/memory-attr-riscv.h",
- "@zephyr//:include/zephyr/dt-bindings/memory-attr/memory-attr-arm.h",
- "@zephyr//:include/zephyr/dt-bindings/memory-attr/memory-attr-sw.h",
- "@zephyr//:include/zephyr/dt-bindings/memory-attr/memory-attr-xtensa.h",
- "@zephyr//:include/zephyr/dt-bindings/dai/esai.h",
- "@zephyr//:include/zephyr/dt-bindings/pcie/pcie.h",
- "@zephyr//:include/zephyr/dt-bindings/dac/dacx0508.h",
- "@zephyr//:include/zephyr/dt-bindings/display/ili9xxx.h",
- "@zephyr//:include/zephyr/dt-bindings/display/panel.h",
- "@zephyr//:include/zephyr/dt-bindings/power/atmel_sam_supc.h",
- "@zephyr//:include/zephyr/dt-bindings/power/nxp_rw_pmu.h",
- "@zephyr//:include/zephyr/dt-bindings/usb-c/pd.h",
- "@zephyr//:include/zephyr/dt-bindings/usb-c/nxp_nx20p3483.h",
- "@zephyr//:include/zephyr/dt-bindings/espi/npcx_espi.h",
- "@zephyr//:include/zephyr/dt-bindings/usb/usb.h",
- "@zephyr//:include/zephyr/dt-bindings/usb/audio.h",
- "@zephyr//:include/zephyr/sys/util_internal.h",
- "@zephyr//:include/zephyr/sys/util_internal_util_dec.h",
- "@zephyr//:include/zephyr/sys/util_internal_util_inc.h",
- "@zephyr//:include/zephyr/sys/util_internal_util_x2.h",
- "@zephyr//:include/zephyr/sys/util_internal_is_eq.h",
- "@zephyr//:include/zephyr/sys/util_listify.h",
- "@zephyr//:include/zephyr/sys/util_loops.h",
- "@zephyr//:include/zephyr/sys/util_macro.h",
- ],
-)
-
-zephyr_includes(
- name = "zephyr_include_paths",
- includes = [
- "//include:dir",
- "//dts:dir",
- "//dts/common:dir",
- ],
-)
+exports_files(glob(["**"]))
cc_library(
- name = "zephyr",
- hdrs = [
- "@zephyr//:include/zephyr/device.h",
- "@zephyr//:include/zephyr/devicetree.h",
- "@zephyr//:include/zephyr/fatal.h",
- "@zephyr//:include/zephyr/fatal_types.h",
- "@zephyr//:include/zephyr/init.h",
- "@zephyr//:include/zephyr/irq.h",
- "@zephyr//:include/zephyr/irq_multilevel.h",
- "@zephyr//:include/zephyr/irq_offload.h",
- "@zephyr//:include/zephyr/kernel.h",
- "@zephyr//:include/zephyr/kernel_includes.h",
- "@zephyr//:include/zephyr/kernel_structs.h",
- "@zephyr//:include/zephyr/kernel_version.h",
- "@zephyr//:include/zephyr/spinlock.h",
- "@zephyr//:include/zephyr/syscall.h",
- "@zephyr//:include/zephyr/sys_clock.h",
- "@zephyr//:include/zephyr/sw_isr_table.h",
- "@zephyr//:include/zephyr/toolchain.h",
- "@zephyr//:include/zephyr/types.h",
- "@zephyr//:include/zephyr/app_memory/mem_domain.h",
- "@zephyr//:include/zephyr/arch/arch_inlines.h",
- "@zephyr//:include/zephyr/arch/cpu.h",
- "@zephyr//:include/zephyr/arch/structs.h",
- "@zephyr//:include/zephyr/arch/syscall.h",
- "@zephyr//:include/zephyr/arch/arch_interface.h",
- "@zephyr//:include/zephyr/arch/arm/arch.h",
- "@zephyr//:include/zephyr/arch/arm/arch_inlines.h",
- "@zephyr//:include/zephyr/arch/arm/asm_inline.h",
- "@zephyr//:include/zephyr/arch/arm/asm_inline_gcc.h",
- "@zephyr//:include/zephyr/arch/arm/error.h",
- "@zephyr//:include/zephyr/arch/arm/exception.h",
- "@zephyr//:include/zephyr/arch/arm/gdbstub.h",
- "@zephyr//:include/zephyr/arch/arm/irq.h",
- "@zephyr//:include/zephyr/arch/arm/misc.h",
- "@zephyr//:include/zephyr/arch/arm/nmi.h",
- "@zephyr//:include/zephyr/arch/arm/structs.h",
- "@zephyr//:include/zephyr/arch/arm/syscall.h",
- "@zephyr//:include/zephyr/arch/arm/thread.h",
- "@zephyr//:include/zephyr/arch/common/addr_types.h",
- "@zephyr//:include/zephyr/arch/common/ffs.h",
- "@zephyr//:include/zephyr/arch/common/sys_bitops.h",
- "@zephyr//:include/zephyr/arch/x86/arch.h",
- "@zephyr//:include/zephyr/arch/x86/arch_inlines.h",
- "@zephyr//:include/zephyr/arch/x86/mmustructs.h",
- "@zephyr//:include/zephyr/arch/x86/msr.h",
- "@zephyr//:include/zephyr/arch/x86/thread_stack.h",
- "@zephyr//:include/zephyr/arch/x86/x86_acpi.h",
- "@zephyr//:include/zephyr/arch/x86/ia32/arch.h",
- "@zephyr//:include/zephyr/arch/x86/ia32/gdbstub.h",
- "@zephyr//:include/zephyr/arch/x86/ia32/segmentation.h",
- "@zephyr//:include/zephyr/arch/x86/ia32/syscall.h",
- "@zephyr//:include/zephyr/arch/x86/ia32/sys_io.h",
- "@zephyr//:include/zephyr/arch/x86/ia32/thread.h",
- "@zephyr//:include/zephyr/devicetree/io-channels.h",
- "@zephyr//:include/zephyr/devicetree/clocks.h",
- "@zephyr//:include/zephyr/devicetree/gpio.h",
- "@zephyr//:include/zephyr/devicetree/spi.h",
- "@zephyr//:include/zephyr/devicetree/dma.h",
- "@zephyr//:include/zephyr/devicetree/pwms.h",
- "@zephyr//:include/zephyr/devicetree/fixed-partitions.h",
- "@zephyr//:include/zephyr/devicetree/ordinals.h",
- "@zephyr//:include/zephyr/devicetree/pinctrl.h",
- "@zephyr//:include/zephyr/devicetree/can.h",
- "@zephyr//:include/zephyr/devicetree/reset.h",
- "@zephyr//:include/zephyr/devicetree/mbox.h",
- "@zephyr//:include/zephyr/drivers/watchdog.h",
- "@zephyr//:include/zephyr/drivers/gpio.h",
- "@zephyr//:include/zephyr/drivers/mbox.h",
- "@zephyr//:include/zephyr/drivers/interrupt_controller/sysapic.h",
- "@zephyr//:include/zephyr/drivers/interrupt_controller/loapic.h",
- "@zephyr//:include/zephyr/dt-bindings/gpio/gpio.h",
- "@zephyr//:include/zephyr/kernel/mm.h",
- "@zephyr//:include/zephyr/kernel/obj_core.h",
- "@zephyr//:include/zephyr/kernel/stats.h",
- "@zephyr//:include/zephyr/kernel/thread.h",
- "@zephyr//:include/zephyr/kernel/thread_stack.h",
- "@zephyr//:include/zephyr/kernel/internal/mm.h",
- # "@zephyr//:include/zephyr/kernel/internal/sched_priq.h",
- "@zephyr//:include/zephyr/kernel/internal/smp.h",
- "@zephyr//:include/zephyr/linker/sections.h",
- "@zephyr//:include/zephyr/linker/section_tags.h",
- "@zephyr//:include/zephyr/pm/pm.h",
- "@zephyr//:include/zephyr/pm/state.h",
- "@zephyr//:include/zephyr/sys/__assert.h",
- "@zephyr//:include/zephyr/sys/atomic.h",
- "@zephyr//:include/zephyr/sys/atomic_builtin.h",
- "@zephyr//:include/zephyr/sys/atomic_types.h",
- "@zephyr//:include/zephyr/sys/device_mmio.h",
- "@zephyr//:include/zephyr/sys/dlist.h",
- "@zephyr//:include/zephyr/sys/iterable_sections.h",
- "@zephyr//:include/zephyr/sys/kobject.h",
- "@zephyr//:include/zephyr/sys/list_gen.h",
- "@zephyr//:include/zephyr/sys/mem_manage.h",
- "@zephyr//:include/zephyr/sys/mem_stats.h",
- "@zephyr//:include/zephyr/sys/printk.h",
- "@zephyr//:include/zephyr/sys/rb.h",
- "@zephyr//:include/zephyr/sys/slist.h",
- "@zephyr//:include/zephyr/sys/sflist.h",
- "@zephyr//:include/zephyr/sys/sys_heap.h",
- "@zephyr//:include/zephyr/sys/sys_io.h",
- "@zephyr//:include/zephyr/sys/time_units.h",
- "@zephyr//:include/zephyr/sys/util.h",
- "@zephyr//:include/zephyr/sys/util_internal.h",
- "@zephyr//:include/zephyr/sys/util_listify.h",
- "@zephyr//:include/zephyr/sys/util_loops.h",
- "@zephyr//:include/zephyr/sys/util_macro.h",
- "@zephyr//:include/zephyr/sys/util_internal_is_eq.h",
- "@zephyr//:include/zephyr/sys/util_internal_util_inc.h",
- "@zephyr//:include/zephyr/sys/util_internal_util_dec.h",
- "@zephyr//:include/zephyr/sys/util_internal_util_x2.h",
- "@zephyr//:include/zephyr/sys/internal/kobject_internal.h",
- "@zephyr//:include/zephyr/toolchain/common.h",
- "@zephyr//:include/zephyr/toolchain/gcc.h",
- "@zephyr//:include/zephyr/toolchain/llvm.h",
- "@zephyr//:include/zephyr/tracing/tracing_macros.h",
- "@zephyr//:include/zephyr/tracing/tracing.h",
- "@zephyr//:include/zephyr/tracing/tracking.h",
- "@zephyr//:kernel/include/offsets_short.h",
- ],
- deps = [":zephyr_include_paths"],
-)
-
-cc_library(
- name = "posix",
- hdrs = [
- "@zephyr//:include/zephyr/arch/posix/asm_inline.h",
- "@zephyr//:include/zephyr/arch/posix/posix_trace.h",
- "@zephyr//:include/zephyr/arch/posix/thread.h",
- "@zephyr//:include/zephyr/arch/posix/asm_inline_gcc.h",
- "@zephyr//:include/zephyr/arch/posix/posix_soc_if.h",
- "@zephyr//:include/zephyr/arch/posix/arch_inlines.h",
- "@zephyr//:include/zephyr/arch/posix/arch.h",
- ],
- deps = [":zephyr_include_paths"],
+ name = "zephyr",
+ hdrs = [
+ "//:kernel/include/offsets_short.h",
+ "//include:core",
+ ],
+ includes = [
+ "dts",
+ "dts/common",
+ "include",
+ ],
)
exports_files(["defs.bzl"])
diff --git a/README.md b/README.md
index b887ef7..dddbd08 100644
--- a/README.md
+++ b/README.md
@@ -1,42 +1,10 @@
Zephyr-Bazel
=======================================
-This repository contains the logic required to build Zephyr with Bazel. To get
-started, add the repo to your git submodules or West manifest via
-https://pigweed.googlesource.com/zephyr/zephyr-bazel/. For the purpose of
-this doc, we'll assume you have everything checked out under `third_party/`:
-- `third_party/zephyr/` - contains your checkout of Zephyr upstream.
-- `third_party/zephyr-bazel/` - contains this repo.
+The way this repository works is by overlaying itself on top of Zephyr. To get
+started, first make sure you have Bazel's skylib version 1.7.1 or greater. If
+you don't have it, you can use:
-In your root `WORKSPACE` file, add the following:
-
-```
-# Zephyr
-new_local_repository(
- name = "zephyr",
- path = "third_party/zephyr",
- build_file_content = """
-load("@bazel_skylib//rules/directory:directory.bzl", "directory")
-package(default_visibility = ["//visibility:public"])
-
-exports_files(glob(["**"]))
-
-directory(
- name = "root",
- srcs = glob(["**"], exclude = ["BUILD"])
-)
-"""
-)
-
-# Zephyr-bazel
-local_repository(
- name = "zephyr-bazel",
- path = "third_party/zephyr-bazel",
-)
-```
-
-Note that the above requires skylib 1.7.1 or greater! If you don't have it, you
-can use:
```
http_archive(
name = "bazel_skylib",
@@ -46,26 +14,64 @@
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
],
)
+
+load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
+
+bazel_skylib_workspace()
```
-Next, you'll need to make sure all the Python requirements from Zephyr are also
-loaded. If you haven't already added `pip_parse` to your `WORKSPACE`, that load
-command is included in the following:
+To grab the zephyr-bazel repo, use a git_repository rule in your WORKSPACE,
+such as:
+
+```
+git_repository(
+ name = "zephyr-bazel",
+ remote = "https://pigweed.googlesource.com/zephyr/zephyr-bazel"
+ branch = "main",
+)
+```
+
+Once you have `@zephyr-bazel`, we can load the patch rule to generate the
+Zephyr diff that will augment Zephyr to include the BUILD.zephyr rules.
+
+```
+load("@zephyr-bazel//:setup.bzl", "create_zephyr_patch_file")
+
+create_zephyr_patch_file(
+ name = "zephyr-patch",
+ filename = "patch.diff",
+ # This is optional, use it to see what's going on under the hood
+ debug = True,
+)
+```
+
+We now have a diff file at `@zephyr-patch//:patch.diff`. We're ready to load
+Zephyr.
+
+```
+git_repository(
+ name = "zephyr",
+ remote = "https://github.com/zephyrproject-rtos/zephyr.git",
+ branch = "main",
+ patches = [
+ "@zephyr-patch//:patch.diff",
+ ],
+)
+```
+
+The final step will be to load Zephyr's python dependencies:
```
load("@rules_python//python:pip.bzl", "pip_parse")
-# Load the Zephyr pip requirements
pip_parse(
name = "py_deps",
python_interpreter_target = interpreter,
- requirements_lock = "@@zephyr-bazel//scripts:requirements-base-lock.txt",
+ requirements_lock = "@@zephyr//:scripts/requirements-base.txt",
)
-# Load the generated install command
load("@py_deps//:requirements.bzl", zephyr_install_deps = "install_deps")
-# Run the installer
zephyr_install_deps()
```
@@ -75,26 +81,26 @@
your app.
```
-load("@zephyr-bazel//:defs.bzl", "dts_cc_library")
+load("@zephyr//:defs.bzl", "dts_cc_library")
dts_cc_library(
name = "app_native_sim_dts",
- dts_lib = "@zephyr-bazel//boards/native/native_sim:native_sim",
+ dts_lib = "@zephyr//boards/native/native_sim:native_sim",
)
cc_binary(
...
deps = [
...
- "@zephyr-bazel//:zephyr",
+ "@zephyr//:zephyr",
] + select({
- "@platform//host": [
+ "@platform//cpu:x86_64": [
":app_native_sim_dts",
- "@zephyr-bazel//:posix",
+ "@zephyr//include:posix",
],
}),
copts = select({
- "@platform//host": [
+ "@platform//cpu:x86_64": [
"-DCONFIG_ARCH_POSIX=1",
],
}),
diff --git a/boards/native/native_sim/BUILD.bazel b/boards/native/native_sim/BUILD.bazel
index 922f62e..75b4784 100644
--- a/boards/native/native_sim/BUILD.bazel
+++ b/boards/native/native_sim/BUILD.bazel
@@ -18,15 +18,15 @@
dts_library(
name = "native_sim",
- srcs = ["@zephyr//:boards/native/native_sim/native_sim.dts"],
+ includes = [
+ "../../../dts",
+ "../../../dts/common",
+ "../../../include",
+ ],
+ overlay = "native_sim.dts",
references = [
"//dts/posix:posix",
"//dts/common:skeleton",
- "//:dt_bindings",
- ],
- includes = [
- "//include:dir",
- "//dts:dir",
- "//dts/common:dir",
+ "//include:dt_bindings",
],
)
diff --git a/defs.bzl b/defs.bzl
index d823233..547d915 100644
--- a/defs.bzl
+++ b/defs.bzl
@@ -13,12 +13,10 @@
# the License.
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
-load("@bazel_skylib//rules/directory:providers.bzl", "DirectoryInfo")
load("@rules_cc//cc:action_names.bzl", "C_COMPILE_ACTION_NAME")
def _get_inputs(ctx):
- all_input_files = []
- all_input_files.extend(ctx.files.srcs)
+ all_input_files = [ctx.file.overlay]
for label in ctx.attr.references:
if type(label) == "Target" and label.files.to_list():
all_input_files.extend(label.files.to_list())
@@ -26,8 +24,14 @@
fail("Unsupported target kind in references:", label)
return depset(all_input_files)
+def _package_exec_path(ctx):
+ workspace_name = ctx.label.workspace_name
+ if workspace_name == "":
+ return "."
+ return "external/" + workspace_name + "/" + ctx.label.package
+
def _dts_library_impl(ctx):
- sources = ctx.files.srcs
+ sources = [ctx.file.overlay]
include_paths = ctx.attr.includes
output_header = ctx.actions.declare_file(ctx.label.name + ".dts")
cc_toolchain = find_cpp_toolchain(ctx)
@@ -63,9 +67,12 @@
args.append("-include")
args.append(src.path)
source_count += 1
+
+ root_path = _package_exec_path(ctx)
for path in include_paths:
- print("path[DirectoryInfo].path=", path[DirectoryInfo].path)
- args.append("-I" + path[DirectoryInfo].path)
+ flag = "-I" + root_path + "/" + path
+ print(" flag=%s" % (flag))
+ args.append(flag)
args.extend([
"-I",
"-D__DTS__",
@@ -81,7 +88,7 @@
arguments = args,
executable = cxx_compiler_path,
tools = cc_toolchain.all_files,
- mnemonic = "DtsPreCompile"
+ mnemonic = "DtsPreCompile",
)
return [
DefaultInfo(files = depset([output_header])),
@@ -90,12 +97,12 @@
dts_library = rule(
implementation = _dts_library_impl,
attrs = {
- "srcs": attr.label_list(allow_files = True),
- "references": attr.label_list(allow_files = True),
"deps": attr.label_list(allow_files = False),
- "includes": attr.label_list(allow_files = False),
+ "includes": attr.string_list(),
+ "overlay": attr.label(mandatory = True, allow_single_file = True),
+ "references": attr.label_list(allow_files = True),
"_cc_toolchain": attr.label(
- default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")
+ default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
),
},
toolchains = use_cpp_toolchain(),
@@ -137,7 +144,7 @@
compilation_context = cc_common.create_compilation_context(
includes = depset([output_header.path[:-len(output_header_name)]]),
headers = depset([output_header]),
- )
+ ),
),
]
@@ -147,40 +154,9 @@
"dts_lib": attr.label(allow_files = False),
"_gen_defines": attr.label(
default = "//scripts/dts:gen_defines",
- executable=True,
- cfg = "host",
+ executable = True,
+ cfg = "exec",
),
},
provides = [CcInfo],
)
-
-def _zephyr_includes_impl(ctx):
- cc_toolchain = find_cpp_toolchain(ctx)
- all_files = cc_toolchain.all_files
-
- # Resolve Include Paths
- absolute_include_paths = depset([include[DirectoryInfo].path for include in ctx.attr.includes])
-
- return [
- DefaultInfo(files = depset()),
- CcInfo(
- compilation_context = cc_common.create_compilation_context(
- headers = depset(),
- includes = absolute_include_paths,
- system_includes = absolute_include_paths,
- ),
- ),
- cc_toolchain,
- ]
-
-zephyr_includes = rule(
- implementation = _zephyr_includes_impl,
- attrs = {
- "includes": attr.label_list(allow_files = False),
- "_cc_toolchain": attr.label(
- default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
- ),
- },
- provides = [CcInfo],
- toolchains = use_cpp_toolchain(),
-)
diff --git a/dts/BUILD.bazel b/dts/BUILD.bazel
index 033e525..443fbb6 100644
--- a/dts/BUILD.bazel
+++ b/dts/BUILD.bazel
@@ -12,12 +12,4 @@
# License for the specific language governing permissions and limitations under
# the License.
-load("@bazel_skylib//rules/directory:subdirectory.bzl", "subdirectory")
-
package(default_visibility = ["//visibility:public"])
-
-subdirectory(
- name = "dir",
- parent = "@zephyr//:root",
- path = "dts",
-)
diff --git a/dts/common/BUILD.bazel b/dts/common/BUILD.bazel
index 2a245cf..b9cedc8 100644
--- a/dts/common/BUILD.bazel
+++ b/dts/common/BUILD.bazel
@@ -12,22 +12,13 @@
# License for the specific language governing permissions and limitations under
# the License.
-load("@bazel_skylib//rules/directory:subdirectory.bzl", "subdirectory")
-load("//:defs.bzl", "dts_library")
-
package(default_visibility = ["//visibility:public"])
filegroup(
name = "skeleton",
srcs = [
- "@zephyr//:dts/common/freq.h",
- "@zephyr//:dts/common/mem.h",
- "@zephyr//:dts/common/skeleton.dtsi",
+ "freq.h",
+ "mem.h",
+ "skeleton.dtsi",
],
)
-
-subdirectory(
- name = "dir",
- parent = "//dts:dir",
- path = "common",
-)
\ No newline at end of file
diff --git a/dts/posix/BUILD.bazel b/dts/posix/BUILD.bazel
index 771098b..342c3e0 100644
--- a/dts/posix/BUILD.bazel
+++ b/dts/posix/BUILD.bazel
@@ -12,11 +12,9 @@
# License for the specific language governing permissions and limitations under
# the License.
-load("//:defs.bzl", "dts_library")
-
package(default_visibility = ["//visibility:public"])
filegroup(
name = "posix",
- srcs = ["@zephyr//:dts/posix/posix.dtsi"],
+ srcs = ["posix.dtsi"],
)
diff --git a/examples/hello_dts/BUILD.bazel b/examples/hello_dts/BUILD.bazel
index 52edefa..2807542 100644
--- a/examples/hello_dts/BUILD.bazel
+++ b/examples/hello_dts/BUILD.bazel
@@ -12,7 +12,9 @@
# License for the specific language governing permissions and limitations under
# the License.
-load("@zephyr-bazel//:defs.bzl", "dts_cc_library")
+load("@rules_cc//cc:defs.bzl", "cc_binary")
+load("@zephyr//:defs.bzl", "dts_cc_library")
+
package(default_visibility = ["//visibility:public"])
label_flag(
@@ -22,12 +24,18 @@
dts_cc_library(
name = "app_host_dts",
- dts_lib = "@zephyr-bazel//boards/native/native_sim:native_sim",
+ dts_lib = "@zephyr//boards/native/native_sim:native_sim",
)
cc_binary(
name = "app",
srcs = ["hello_dts.cc"],
+ copts = select({
+ "@platforms//cpu:armv7e-m": [],
+ "@platforms//cpu:x86_64": [
+ "-DCONFIG_ARCH_POSIX=1",
+ ],
+ }),
malloc = select({
"@platforms//cpu:armv7e-m": "@pigweed//pw_malloc",
"@platforms//cpu:x86_64": "@bazel_tools//tools/cpp:malloc",
@@ -37,7 +45,7 @@
"@pigweed//pw_sys_io",
"@pigweed//pw_assert:backend_impl",
"@pigweed//pw_log:backend_impl",
- "@zephyr-bazel//:zephyr",
+ "@zephyr//:zephyr",
] + select({
"@platforms//cpu:armv7e-m": [
"@pigweed//pw_toolchain/arm_gcc:arm_none_eabi_gcc_support",
@@ -45,14 +53,8 @@
"@pigweed//targets/stm32f429i_disc1:pre_init",
],
"@platforms//cpu:x86_64": [
- "@zephyr-bazel//:posix",
+ "@zephyr//include:posix",
":app_host_dts",
],
}),
- copts = select({
- "@platforms//cpu:armv7e-m": [],
- "@platforms//cpu:x86_64": [
- "-DCONFIG_ARCH_POSIX=1",
- ],
- }),
)
diff --git a/examples/hello_dts/WORKSPACE b/examples/hello_dts/WORKSPACE
index 2dd0fd4..03644f6 100644
--- a/examples/hello_dts/WORKSPACE
+++ b/examples/hello_dts/WORKSPACE
@@ -98,28 +98,28 @@
strip_prefix = "pw_toolchain_bazel",
)
-git_repository(
- name = "zephyr", # Give it a distinct name
- remote = "https://github.com/zephyrproject-rtos/zephyr.git",
- branch = "main",
- build_file_content = """
-load("@bazel_skylib//rules/directory:directory.bzl", "directory")
-package(default_visibility = ["//visibility:public"])
-
-exports_files(glob(["**"]))
-
-directory(
- name = "root",
- srcs = glob(["**"], exclude = ["BUILD"])
-)
-""",
-)
-
local_repository(
name = "zephyr-bazel",
path = "../..",
)
+load("@zephyr-bazel//:setup.bzl", "create_zephyr_patch_file")
+
+create_zephyr_patch_file(
+ name = "zephyr-patch",
+ filename = "patch.diff",
+ debug = True,
+)
+
+git_repository(
+ name = "zephyr",
+ remote = "https://github.com/zephyrproject-rtos/zephyr.git",
+ branch = "main",
+ patches = [
+ "@zephyr-patch//:patch.diff",
+ ],
+)
+
# Get ready to grab CIPD dependencies. For this minimal example, the only
# dependencies will be the toolchains and OpenOCD (used for flashing).
load(
diff --git a/generate_diff.py b/generate_diff.py
new file mode 100644
index 0000000..288f920
--- /dev/null
+++ b/generate_diff.py
@@ -0,0 +1,81 @@
+import argparse
+import pathlib
+import io
+import sys
+from typing import List
+
+
+def get_bazel_files(root_dir: pathlib.Path) -> List[pathlib.Path]:
+ """Finds files matching "BUILD.bazel" or "*.bzl" under the given directory.
+
+ Args:
+ root_dir: The root directory to search in.
+
+ Returns:
+ A list of pathlib.Path objects representing the matching files.
+ """
+ return [
+ path
+ for path in root_dir.rglob("*")
+ if path.match("BUILD.bazel") or path.match("*.bzl")
+ ]
+
+def print_file_info(
+ file_path: pathlib.Path,
+ root_dir: pathlib.Path,
+ writer: io.TextIOWrapper,
+):
+ """Prints the relative path, line count, and prefixed content of a file.
+
+ Args:
+ file_path: The path to the file.
+ root_dir: The root directory to calculate the relative path from.
+ writer: Where to write the output
+ """
+ relative_path = file_path.relative_to(root_dir)
+ with open(file_path, "r", encoding="utf-8") as file:
+ content = file.readlines()
+ line_count = len(content)
+ writer.write("\n")
+ writer.write("--- /dev/null\n")
+ writer.write(f"+++ {relative_path}\n")
+ writer.write(f"@@ -0,0 +1,{line_count} @@\n")
+ for line in content:
+ writer.write(f"+{line.rstrip()}\n")
+
+def print_all(root_dir: pathlib.Path, writer: io.TextIOWrapper):
+ """Iterate through all BUILD.bazel and *.bzl files and write them to writer
+
+ Args:
+ root_dir: The root directory to calculate the relative path from.
+ writer: Where to write the output
+ """
+ for file_path in get_bazel_files(root_dir=root_dir):
+ print_file_info(file_path=file_path, root_dir=root_dir, writer=writer)
+
+def main() -> None:
+ """Finds all BUILD.bazel files and *.bzl files and generates a diff"""
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--root-dir",
+ type=pathlib.Path,
+ required=True
+ )
+ parser.add_argument(
+ "-o",
+ dest="output",
+ type=pathlib.Path,
+ )
+ args = parser.parse_args()
+ if args.output:
+ args.output.parent.mkdir(parents=True, exist_ok=True)
+ with open(args.output, mode="w", encoding="utf-8") as o:
+ print_all(root_dir=args.root_dir, writer=o)
+ else:
+ print_all(
+ root_dir=args.root_dir,
+ writer=io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
+ )
+
+if __name__ == "__main__":
+ main()
diff --git a/include/BUILD.bazel b/include/BUILD.bazel
index b894b48..294fcbc 100644
--- a/include/BUILD.bazel
+++ b/include/BUILD.bazel
@@ -12,12 +12,160 @@
# License for the specific language governing permissions and limitations under
# the License.
-load("@bazel_skylib//rules/directory:subdirectory.bzl", "subdirectory")
+load("@rules_cc//cc:defs.bzl", "cc_library")
package(default_visibility = ["//visibility:public"])
-subdirectory(
- name = "dir",
- parent = "@zephyr//:root",
- path = "include",
+filegroup(
+ name = "dt_bindings",
+ srcs = glob(["zephyr/dt-bindings/**"]) + [
+ "zephyr/sys/util_internal.h",
+ "zephyr/sys/util_internal_is_eq.h",
+ "zephyr/sys/util_internal_util_dec.h",
+ "zephyr/sys/util_internal_util_inc.h",
+ "zephyr/sys/util_internal_util_x2.h",
+ "zephyr/sys/util_listify.h",
+ "zephyr/sys/util_loops.h",
+ "zephyr/sys/util_macro.h",
+ ],
+)
+
+filegroup(
+ name = "core",
+ srcs = [
+ "zephyr/device.h",
+ "zephyr/devicetree.h",
+ "zephyr/fatal.h",
+ "zephyr/fatal_types.h",
+ "zephyr/init.h",
+ "zephyr/irq.h",
+ "zephyr/irq_multilevel.h",
+ "zephyr/irq_offload.h",
+ "zephyr/kernel.h",
+ "zephyr/kernel_includes.h",
+ "zephyr/kernel_structs.h",
+ "zephyr/kernel_version.h",
+ "zephyr/spinlock.h",
+ "zephyr/syscall.h",
+ "zephyr/sys_clock.h",
+ "zephyr/sw_isr_table.h",
+ "zephyr/toolchain.h",
+ "zephyr/types.h",
+ "zephyr/app_memory/mem_domain.h",
+ "zephyr/arch/arch_inlines.h",
+ "zephyr/arch/cpu.h",
+ "zephyr/arch/structs.h",
+ "zephyr/arch/syscall.h",
+ "zephyr/arch/arch_interface.h",
+ "zephyr/arch/arm/arch.h",
+ "zephyr/arch/arm/arch_inlines.h",
+ "zephyr/arch/arm/asm_inline.h",
+ "zephyr/arch/arm/asm_inline_gcc.h",
+ "zephyr/arch/arm/error.h",
+ "zephyr/arch/arm/exception.h",
+ "zephyr/arch/arm/gdbstub.h",
+ "zephyr/arch/arm/irq.h",
+ "zephyr/arch/arm/misc.h",
+ "zephyr/arch/arm/nmi.h",
+ "zephyr/arch/arm/structs.h",
+ "zephyr/arch/arm/syscall.h",
+ "zephyr/arch/arm/thread.h",
+ "zephyr/arch/common/addr_types.h",
+ "zephyr/arch/common/ffs.h",
+ "zephyr/arch/common/sys_bitops.h",
+ "zephyr/arch/x86/arch.h",
+ "zephyr/arch/x86/arch_inlines.h",
+ "zephyr/arch/x86/mmustructs.h",
+ "zephyr/arch/x86/msr.h",
+ "zephyr/arch/x86/thread_stack.h",
+ "zephyr/arch/x86/x86_acpi.h",
+ "zephyr/arch/x86/ia32/arch.h",
+ "zephyr/arch/x86/ia32/gdbstub.h",
+ "zephyr/arch/x86/ia32/segmentation.h",
+ "zephyr/arch/x86/ia32/syscall.h",
+ "zephyr/arch/x86/ia32/sys_io.h",
+ "zephyr/arch/x86/ia32/thread.h",
+ "zephyr/devicetree/io-channels.h",
+ "zephyr/devicetree/clocks.h",
+ "zephyr/devicetree/gpio.h",
+ "zephyr/devicetree/spi.h",
+ "zephyr/devicetree/dma.h",
+ "zephyr/devicetree/pwms.h",
+ "zephyr/devicetree/fixed-partitions.h",
+ "zephyr/devicetree/ordinals.h",
+ "zephyr/devicetree/pinctrl.h",
+ "zephyr/devicetree/can.h",
+ "zephyr/devicetree/reset.h",
+ "zephyr/devicetree/mbox.h",
+ "zephyr/drivers/watchdog.h",
+ "zephyr/drivers/gpio.h",
+ "zephyr/drivers/mbox.h",
+ "zephyr/drivers/interrupt_controller/sysapic.h",
+ "zephyr/drivers/interrupt_controller/loapic.h",
+ "zephyr/dt-bindings/gpio/gpio.h",
+ "zephyr/kernel/mm.h",
+ "zephyr/kernel/obj_core.h",
+ "zephyr/kernel/stats.h",
+ "zephyr/kernel/thread.h",
+ "zephyr/kernel/thread_stack.h",
+ "zephyr/kernel/internal/mm.h",
+ # "zephyr/kernel/internal/sched_priq.h",
+ "zephyr/kernel/internal/smp.h",
+ "zephyr/linker/sections.h",
+ "zephyr/linker/section_tags.h",
+ "zephyr/pm/pm.h",
+ "zephyr/pm/state.h",
+ "zephyr/sys/__assert.h",
+ "zephyr/sys/atomic.h",
+ "zephyr/sys/atomic_builtin.h",
+ "zephyr/sys/atomic_types.h",
+ "zephyr/sys/device_mmio.h",
+ "zephyr/sys/dlist.h",
+ "zephyr/sys/iterable_sections.h",
+ "zephyr/sys/kobject.h",
+ "zephyr/sys/list_gen.h",
+ "zephyr/sys/mem_manage.h",
+ "zephyr/sys/mem_stats.h",
+ "zephyr/sys/printk.h",
+ "zephyr/sys/rb.h",
+ "zephyr/sys/slist.h",
+ "zephyr/sys/sflist.h",
+ "zephyr/sys/sys_heap.h",
+ "zephyr/sys/sys_io.h",
+ "zephyr/sys/time_units.h",
+ "zephyr/sys/util.h",
+ "zephyr/sys/util_internal.h",
+ "zephyr/sys/util_listify.h",
+ "zephyr/sys/util_loops.h",
+ "zephyr/sys/util_macro.h",
+ "zephyr/sys/util_internal_is_eq.h",
+ "zephyr/sys/util_internal_util_inc.h",
+ "zephyr/sys/util_internal_util_dec.h",
+ "zephyr/sys/util_internal_util_x2.h",
+ "zephyr/sys/internal/kobject_internal.h",
+ "zephyr/toolchain/common.h",
+ "zephyr/toolchain/gcc.h",
+ "zephyr/toolchain/llvm.h",
+ "zephyr/tracing/tracing_macros.h",
+ "zephyr/tracing/tracing.h",
+ "zephyr/tracing/tracking.h",
+ ],
+)
+
+cc_library(
+ name = "posix",
+ hdrs = [
+ "zephyr/arch/posix/arch.h",
+ "zephyr/arch/posix/arch_inlines.h",
+ "zephyr/arch/posix/asm_inline.h",
+ "zephyr/arch/posix/asm_inline_gcc.h",
+ "zephyr/arch/posix/posix_soc_if.h",
+ "zephyr/arch/posix/posix_trace.h",
+ "zephyr/arch/posix/thread.h",
+ ],
+ includes = [
+ ".",
+ "../dts",
+ "../dts/common",
+ ],
)
diff --git a/scripts/dts/BUILD.bazel b/scripts/dts/BUILD.bazel
index 7863fa3..d509be9 100644
--- a/scripts/dts/BUILD.bazel
+++ b/scripts/dts/BUILD.bazel
@@ -12,12 +12,14 @@
# License for the specific language governing permissions and limitations under
# the License.
+load("@rules_python//python:defs.bzl", "py_binary")
+
package(default_visibility = ["//visibility:public"])
py_binary(
name = "gen_defines",
- srcs = ["@zephyr//:scripts/dts/gen_defines.py"],
+ srcs = ["gen_defines.py"],
deps = [
"//scripts/dts/python-devicetree:devicetree",
- ]
+ ],
)
diff --git a/scripts/dts/python-devicetree/BUILD.bazel b/scripts/dts/python-devicetree/BUILD.bazel
index 74c176f..2bcaa3b 100644
--- a/scripts/dts/python-devicetree/BUILD.bazel
+++ b/scripts/dts/python-devicetree/BUILD.bazel
@@ -13,19 +13,20 @@
# the License.
load("@py_deps//:requirements.bzl", "requirement")
+load("@rules_python//python:defs.bzl", "py_library")
package(default_visibility = ["//visibility:public"])
py_library(
name = "devicetree",
srcs = [
- "@zephyr//:scripts/dts/python-devicetree/src/devicetree/edtlib.py",
- "@zephyr//:scripts/dts/python-devicetree/src/devicetree/grutils.py",
- "@zephyr//:scripts/dts/python-devicetree/src/devicetree/dtlib.py",
- "@zephyr//:scripts/dts/python-devicetree/src/devicetree/_private.py",
- "@zephyr//:scripts/dts/python-devicetree/src/devicetree/__init__.py",
+ "src/devicetree/__init__.py",
+ "src/devicetree/_private.py",
+ "src/devicetree/dtlib.py",
+ "src/devicetree/edtlib.py",
+ "src/devicetree/grutils.py",
],
deps = [
requirement("pyyaml"),
- ]
+ ],
)
diff --git a/setup.bzl b/setup.bzl
new file mode 100644
index 0000000..2ec3cb3
--- /dev/null
+++ b/setup.bzl
@@ -0,0 +1,108 @@
+def _local_patched_repository_impl(rctx):
+ path = rctx.attr.path
+
+ # This path is a bit ugly to get the actual path if it is relative.
+ if path[0] != "/":
+ path = rctx.workspace_root.get_child(path)
+
+ # Copy the repository
+ rctx.execute(["mkdir", str(rctx.path(""))])
+ for child in path.readdir():
+ copy_args = ["cp", "-fr", str(child), str(rctx.path(""))]
+ if rctx.attr.debug:
+ print(copy_args)
+ result = rctx.execute(copy_args)
+ if result.return_code != 0:
+ fail("Failed to copy %s (%s):\n%s" % (rctx.attr.path, result.return_code, result.stderr))
+
+ # Now patch the repository
+ for patch_file in rctx.attr.patches:
+ patch_file_path_string = str(rctx.path(patch_file).realpath)
+ if rctx.attr.debug:
+ print("Applying patch file: %s / %s" % (patch_file, patch_file_path_string))
+ result = rctx.execute([
+ "bash",
+ "-c",
+ "patch -p0 < " + patch_file_path_string,
+ ])
+ if result.return_code != 0:
+ fail("Failed to apply patch: %s\n%s" % (patch_file, result.stderr))
+
+local_patched_repository = repository_rule(
+ implementation = _local_patched_repository_impl,
+ attrs = {
+ "debug": attr.bool(default = False),
+ "patches": attr.label_list(allow_files = True),
+ "path": attr.string(mandatory = True),
+ },
+ local = True,
+)
+
+def _create_zephyr_patch_file_impl(rctx):
+ script_path = Label("//:generate_diff.py")
+ output_file = rctx.attr.filename
+ output_file_path = rctx.path(output_file)
+
+ rctx.file(output_file)
+ rctx.file("BUILD")
+
+ args = [
+ rctx.which("python3"),
+ script_path,
+ "--root-dir",
+ rctx.path(script_path).dirname,
+ "-o",
+ output_file_path,
+ ]
+ if rctx.attr.debug:
+ print(args)
+ result = rctx.execute(args)
+ if result.return_code != 0:
+ fail("Failed to generate zephyr-bazel diff file (%s):\n%s" % (result.return_code, result.stderr))
+
+ if rctx.attr.debug:
+ print("Generated %s" % (output_file_path))
+ return [
+ DefaultInfo(
+ files = depset([output_file_path, rctx.path("BUILD")]),
+ ),
+ ]
+
+create_zephyr_patch_file = repository_rule(
+ implementation = _create_zephyr_patch_file_impl,
+ attrs = {
+ "debug": attr.bool(default = False),
+ "filename": attr.string(
+ default = "patch.diff",
+ mandatory = True,
+ ),
+ },
+ local = True,
+)
+
+###############################################################################
+
+def _print_file_impl(ctx):
+ # Get the input file
+ input_file = ctx.file.file
+
+ # Create a dummy output file
+ output_file = ctx.actions.declare_file(ctx.label.name + ".out")
+
+ # Create a shell action to print the file
+ ctx.actions.run_shell(
+ outputs = [output_file],
+ inputs = [input_file],
+ command = "cat {} > {}".format(input_file.path, output_file.path),
+ )
+
+ # Return DefaultInfo to signal dependencies on the input file
+ return DefaultInfo(files = depset([output_file]))
+
+# Define the rule
+print_file = rule(
+ implementation = _print_file_impl,
+ attrs = {
+ "file": attr.label(allow_single_file = True, mandatory = True),
+ },
+)