我的嵌入式开发环境已经用 Bazel 设置好了。 借助 Bazel 6.5.x 和工作区,我能够交叉构建我想要的一切。 由于某些原因,我想迁移到 Bazel 模块。 直接 bazel 依赖项和项目文件等已轻松迁移。 但目前,我受困于我的项目的外部依赖项。
使用 Bazel 工作区我可以做到:
http_archive(
name = "cmsis_device_g0",
url = "https://github.com/STMicroelectronics/cmsis_device_g0/archive/refs/tags/v1.4.4.zip",
strip_prefix = "cmsis-device-g0-1.4.4",
sha256 = "c60d9f8478f356db0461d797d573d82baebe62695acea5944128f242a7a71fc6",
build_file = "//thirdparty/stm32:stm32_cmsis_device.BUILD",
)
http_archive(
name = "stm32g0xx_hal_driver",
url = "https://github.com/STMicroelectronics/stm32g0xx_hal_driver/archive/refs/tags/v1.4.6.zip",
strip_prefix = "stm32g0xx-hal-driver-1.4.6",
sha256 = "1098b8b816047063bed5fb3abfc2e5a15e16d6696a279b59b9a0be5d850d2f09",
build_file = "//thirdparty/stm32:stm32_hal_driver.BUILD",
)
将它们作为依赖项添加到我的项目并构建。
但是对于 Bazel 模块,我似乎找不到正确的方法或解释(或者至少我不明白)来处理非 Bazel 依赖项。
使用 MODULE.bazel,您仍然可以在 MODULE.bazel 文件中执行类似的操作:
http_archive = use_repo_rule(
"@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive",
)
http_archive(
name = "cmsis_device_g0",
url = "https://github.com/STMicroelectronics/cmsis_device_g0/archive/refs/tags/v1.4.4.zip",
strip_prefix = "cmsis-device-g0-1.4.4",
sha256 = "c60d9f8478f356db0461d797d573d82baebe62695acea5944128f242a7a71fc6",
build_file = "//thirdparty/stm32:stm32_cmsis_device.BUILD",
)