{"id":26500332,"url":"https://github.com/simonhorlick/bazel_esp32","last_synced_at":"2025-03-20T15:29:44.371Z","repository":{"id":49568868,"uuid":"376751852","full_name":"simonhorlick/bazel_esp32","owner":"simonhorlick","description":"A bazel toolchain and example for building Arduino applications for the esp32 microcontroller.","archived":false,"fork":false,"pushed_at":"2022-11-23T04:03:08.000Z","size":62,"stargazers_count":11,"open_issues_count":3,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-03-11T18:33:17.920Z","etag":null,"topics":["arduino","bazel","esp32"],"latest_commit_sha":null,"homepage":"","language":"Starlark","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonhorlick.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-14T08:17:16.000Z","updated_at":"2023-01-02T06:22:27.000Z","dependencies_parsed_at":"2022-09-09T01:23:11.721Z","dependency_job_id":null,"html_url":"https://github.com/simonhorlick/bazel_esp32","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonhorlick%2Fbazel_esp32","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonhorlick%2Fbazel_esp32/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonhorlick%2Fbazel_esp32/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonhorlick%2Fbazel_esp32/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonhorlick","download_url":"https://codeload.github.com/simonhorlick/bazel_esp32/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244639642,"owners_count":20485908,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","bazel","esp32"],"created_at":"2025-03-20T15:29:43.781Z","updated_at":"2025-03-20T15:29:44.362Z","avatar_url":"https://github.com/simonhorlick.png","language":"Starlark","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bazel_esp32\n\nThis repo contains a custom c++ toolchain setup for the [bazel](https://bazel.build) build system. It allows you to use the standard `cc_library` and `cc_binary` to build esp32-compatible binaries.\n\nNote that these rules are currently only supported on amd64 linux systems. Pull requests are welcome to add support for other systems.\n\n## Usage\n\nIn your `WORKSPACE` file load the toolchain dependencies:\n\n```\nload(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"git_repository\")\n\ngit_repository(\n    name = \"bazel_esp32\",\n    branch = \"main\",\n    remote = \"https://github.com/simonhorlick/bazel_esp32.git\",\n)\n\nload(\"@bazel_esp32//:deps.bzl\", \"bazel_esp32_dependencies\")\n\nbazel_esp32_dependencies()\n```\n\nAdd the toolchain configuration to your `.bazelrc` in the root of your repository:\n\n```\nbuild:esp32 --crosstool_top=@bazel_esp32//toolchain:esp32\nbuild:esp32 --cpu=xtensa\nbuild:esp32 --host_crosstool_top=@bazel_tools//tools/cpp:toolchain\n```\n\nIn this example, `hello.cc` contains the standard Arduino `setup` and `loop` functions. To build a binary that we can run we must add the Arduino `main.cc` into the `cc_binary` srcs which in turn calls out to `setup` and `loop`.\n\n```\ncc_binary(\n    name = \"hello\",\n    srcs = [\"@arduino_esp32//:cores/esp32/main.cpp\"],  # main entry point.\n    deps = [\n        \":hello_lib\",\n        \"@arduino_esp32//:core_c_lib\",\n        \"@arduino_esp32//:core_lib\",\n    ],\n)\n\ncc_library(\n    name = \"hello_lib\",\n    srcs = [\"hello.cc\"],\n    deps = [\n        # note that Arduino libraries must be specified as normal c++ dependencies.\n        \"@arduino_esp32//:SPI\",\n    ],\n)\n```\n\nTo build ensure you are using the `esp32` configuration, like so:\n```bash\n$ bazel build --config=esp32 //:hello\nINFO: Analyzed target //:hello (0 packages loaded, 0 targets configured).\nINFO: Found 1 target...\nTarget //:hello up-to-date:\n  bazel-bin/hello\nINFO: Elapsed time: 0.610s, Critical Path: 0.01s\nINFO: 1 process: 1 internal.\nINFO: Build completed successfully, 1 total action\n\n$ file bazel-bin/hello\nbazel-bin/hello: ELF 32-bit LSB executable, Tensilica Xtensa, version 1 (SYSV), statically linked, not stripped\n```\n\n## Examples\n\nTo flash a device:\n```bash\nbazel build --config=esp32 //:gen_partitions\nbazel build --config=esp32 //:gen_image\nesptool.py --chip esp32 -p /dev/cu.usbserial-0001 --baud 460800 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0xe000 /home/simon/.arduino15/packages/esp32/hardware/esp32/2.0.0-alpha1/tools/partitions/boot_app0.bin 0x1000 /home/simon/.arduino15/packages/esp32/hardware/esp32/2.0.0-alpha1/tools/sdk/esp32/bin/bootloader_qio_80m.bin 0x10000 bazel-bin/hello.bin 0x8000 bazel-bin/hello.partitions.bin\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonhorlick%2Fbazel_esp32","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonhorlick%2Fbazel_esp32","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonhorlick%2Fbazel_esp32/lists"}