pico-sdk/bazel/README.md

117 lines
4.2 KiB
Markdown
Raw Normal View History

Introduce initial Bazel build (#1705) * Build boot_stage2 with Bazel Introduces the initial foundations of a Bazel build, including a toolchain, critical generated headers, platform patterns, and enough BUILD files to build boot_stage2. * Bazel libraries to support picotool * Move SDK defines to toolchain * Switch to `archive_override` in MODULE.bazel Uses archive_override where applicable to allow transitive bzlmod deps to propagate. * Multiplatform objcopy selection in Bazel build Makes an objcopy alias that redirects to the objcopy tool for the current exec platform, which allows boot_stage2 to build on Linux, macOS, and Windows. * Generate Bazel build files Adds initial set of generated Bazel build files. Note that these do not yet build, as dependency cycles are present. * Fix dependency cycles in Bazel build Fixes many dependency cycles, some were unintentionally created by the build file generator, others are true dependency cycles that require manual workarounds. * Silence warning in pico_stdio Bazel build Silences a stray warning in the Bazel build. * Fix wildcard Bazel build This makes `bazel build //...` succeed, and also prevents the fetching of toolchains that aren't compatible with the current execution environment (i.e. Windows computers will no longer try to download macOS toolchains). * Get the SDK working Finishes out the remainder of the work required to successfully compile a working blinky example. * Fix UART stdio dependencies in Bazel build Fixes some dependencies around pico_stdlib so that pico_stdlib links properly and UART stdio works. * Add linux support to Bazel build * Get Bazel deps from registry Adds external an external registry for resolving Bazel module dependencies. * Fix host configuration for picotool Provides the appropriate defines for host builds to support the picotool build. * Remove -ffreestanding from Bazel toolchain The -ffreestanding toolchain flag is quite strict, so remove it from the Bazel toolchain. * Remove unused .bzl file * Reduce Bazel compiler flags Cuts out most of the Bazel toolchain flags and only specifies the bare-minimum set of flags. Also, adds wrapper linker flags for functions the SDK wraps. * Get USB serial working Adds initial TinyUSB support and enough integration to get USB serial working. * Remove "Generated build file" Removes comments that indicates BUILD.bazel files are generated. This was used during initial bringup to indicate hand-crafted vs automatically generated BUILD.bazel files. * Do not build USB libraries unless configured Prevents USB libraries from being built unless the build is properly configured to use them. * Switch to rules_cc toolchains Moves toolchain configuration to use the new rules in rules_cc. * Minor cleanup in parse_version.py Cleans up trailing whitespace and runs the black formatter on parse_version.py. * Simplify constraint dimensions in Bazel build Consolidates the class/chip constraint settings to be a single constraint_setting with a config_setting that represents the rp2 class. * Update pin of rules_cc in Bazel build Includes a necessary fix for the target_compatible_with expression in the cc_toolchain to work as intended. * Move toolchains from pico.bzl to BUILD.bazel Moves toolchain definitions from pico.bzl to BUILD.bazel to make them easier to find and read. * Run buildifier on Bazel build files Fix trivial formatting issues by running buildifier on all BUILD.bazel files. * Make objcopy rule Makes a simple objcopy rule to remove direct references to the ARM toolchains. * Fix link flags in Bazel build Critical flags were not being applied to link steps. This applies -mcpu and -mthumb to the link steps to make the produced binaries work again. * Mention missing host build support * Fix various Bazel library rules * pico_bit_ops was incomplete. * pico_double and pico_float were trying to link in the "none" implementation. * Extend Bazel build documentation Improves documentation and comments across the Bazel build. * Clean up auxilary tools in Bazel build Switches genrules to use skylib rules to simplify things. Reworks version header generation to use the Bazel module version rather than parsing CMake. * Update boot_stage2 Bazel build file Moves `includes` to be enumerated on the correct library. * Add WORKSPACE version fallback WORKSPACE Bazel projects don't support querying module version, so add a fallback of '0.0.1-WORKSPACE' so the build can succeed. * Fix malloc handling in Bazel build * Fix Bazel dependency cycle in pico_malloc * Prevent malloc from being linked into boot_stage2 Prevents Bazel from ever trying to link malloc into the boot_stage2 binary. * Remove custom bootloader platform A dedicated boot_stage2 platform introduces a lot of complexity that needs to be more thought-through.
2024-06-04 16:50:32 -07:00
# Bazel build
## Using the Pico SDK in a Bazel project.
### Add pico-sdk as a dependency
First, in your `MODULE.bazel` file, add a dependency on the Pico SDK:
```python
bazel_dep(
name = "pico-sdk",
version = "1.6.0-rc1",
)
```
Second, in the same file you'll need to add an explicit dependency on
`rules_cc`, as it's a special-cased Bazel module:
```python
# Note: rules_cc is special-cased repository; a dependency on rules_cc in a
# module will not ensure that the root Bazel module has that same version of
# rules_cc. For that reason, this primarily acts as a FYI. You'll still need
# to explicitly list this dependency in your own project's MODULE.bazel file.
Expand bazel build to include configuration options and broader support. (#1731) * Add host Bazel build Updates target_compatible_with across the repo to ensure that wildcard builds for both host and rp2040 succeed. * Get unit tests building * Add Python script to identify build system differences Uses the build system tags to make it easier to identify differences between the CMake and Bazel builds. * Temporarily disable pico divider test * Support PICO_BARE_METAL in Bazel * Support PICO_NO_GC_SECTIONS in Bazel * Support boot2 configuration in Bazel Adds support for PICO_DEFAULT_BOOT_STAGE2 and PICO_DEFAULT_BOOT_STAGE2_FILE in the Bazel build. * Allowlist some CMake-only options * Support CXX configuration options in Bazel * Move multiple_choice_flag.bzl * Support all pico boards * Support linking multiple stdio implementations Changes the Bazel build so stdio implementations are no longer mutually exclusive. * Add PICO_BOOT_STAGE2_LINK_IMAGE * Support PICO_CMSIS_PATH in Bazel * Support PICO_USE_DEFAULT_MAX_PAGE_SIZE in Bazel * Silence PICO_CMSIS_VENDOR and PICO_CMSIS_DEVICE differences * Support PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS in Bazel * Properly support version defines * Support embedding binary info in Bazel * Embed build type in binary * Support different linker scripts in Bazel build * Finish out missing PICO_BUILD_DEFINE in Bazel build * Support PICO_NO_TARGET_NAME * Reorganize initial configuration options in Bazel Cleans up and reorganizes some of the initial configuration options added to the Bazel build so everything is consistent. * Add builds for pioasm and elf2uf2 * Use Python rules from rules_python * Actually link in output formats in pioasm tool * Make tools have public visibility * Add UF2 Bazel aspect * Add TODOs for pioasm/uf2 helpers * Fix compile flag typo * Update Bazel SDK configuration strings to match recent CMake changes * Fix pico_divider test * Clean up straggling TODOs * Clarify pico_stdio_test compatibility * Initial Bazel Pico W support * Add new files from develop * Clean up compatibility expressions in Bazel build * Clean up rp2 constraint handling in Bazel * More Bazel docs cleanup * Format Bazel build files * Consolidate transitions in the Pico SDK * Make every _allowlist_function_transition explicit * More docs cleanup * Add a few missing defines * Improve PICO_CONFIG_HEADER correctness in Bazel * Minor docs clarifications
2024-06-13 07:50:04 -07:00
bazel_dep(name = "rules_cc", version = "0.0.9")
Introduce initial Bazel build (#1705) * Build boot_stage2 with Bazel Introduces the initial foundations of a Bazel build, including a toolchain, critical generated headers, platform patterns, and enough BUILD files to build boot_stage2. * Bazel libraries to support picotool * Move SDK defines to toolchain * Switch to `archive_override` in MODULE.bazel Uses archive_override where applicable to allow transitive bzlmod deps to propagate. * Multiplatform objcopy selection in Bazel build Makes an objcopy alias that redirects to the objcopy tool for the current exec platform, which allows boot_stage2 to build on Linux, macOS, and Windows. * Generate Bazel build files Adds initial set of generated Bazel build files. Note that these do not yet build, as dependency cycles are present. * Fix dependency cycles in Bazel build Fixes many dependency cycles, some were unintentionally created by the build file generator, others are true dependency cycles that require manual workarounds. * Silence warning in pico_stdio Bazel build Silences a stray warning in the Bazel build. * Fix wildcard Bazel build This makes `bazel build //...` succeed, and also prevents the fetching of toolchains that aren't compatible with the current execution environment (i.e. Windows computers will no longer try to download macOS toolchains). * Get the SDK working Finishes out the remainder of the work required to successfully compile a working blinky example. * Fix UART stdio dependencies in Bazel build Fixes some dependencies around pico_stdlib so that pico_stdlib links properly and UART stdio works. * Add linux support to Bazel build * Get Bazel deps from registry Adds external an external registry for resolving Bazel module dependencies. * Fix host configuration for picotool Provides the appropriate defines for host builds to support the picotool build. * Remove -ffreestanding from Bazel toolchain The -ffreestanding toolchain flag is quite strict, so remove it from the Bazel toolchain. * Remove unused .bzl file * Reduce Bazel compiler flags Cuts out most of the Bazel toolchain flags and only specifies the bare-minimum set of flags. Also, adds wrapper linker flags for functions the SDK wraps. * Get USB serial working Adds initial TinyUSB support and enough integration to get USB serial working. * Remove "Generated build file" Removes comments that indicates BUILD.bazel files are generated. This was used during initial bringup to indicate hand-crafted vs automatically generated BUILD.bazel files. * Do not build USB libraries unless configured Prevents USB libraries from being built unless the build is properly configured to use them. * Switch to rules_cc toolchains Moves toolchain configuration to use the new rules in rules_cc. * Minor cleanup in parse_version.py Cleans up trailing whitespace and runs the black formatter on parse_version.py. * Simplify constraint dimensions in Bazel build Consolidates the class/chip constraint settings to be a single constraint_setting with a config_setting that represents the rp2 class. * Update pin of rules_cc in Bazel build Includes a necessary fix for the target_compatible_with expression in the cc_toolchain to work as intended. * Move toolchains from pico.bzl to BUILD.bazel Moves toolchain definitions from pico.bzl to BUILD.bazel to make them easier to find and read. * Run buildifier on Bazel build files Fix trivial formatting issues by running buildifier on all BUILD.bazel files. * Make objcopy rule Makes a simple objcopy rule to remove direct references to the ARM toolchains. * Fix link flags in Bazel build Critical flags were not being applied to link steps. This applies -mcpu and -mthumb to the link steps to make the produced binaries work again. * Mention missing host build support * Fix various Bazel library rules * pico_bit_ops was incomplete. * pico_double and pico_float were trying to link in the "none" implementation. * Extend Bazel build documentation Improves documentation and comments across the Bazel build. * Clean up auxilary tools in Bazel build Switches genrules to use skylib rules to simplify things. Reworks version header generation to use the Bazel module version rather than parsing CMake. * Update boot_stage2 Bazel build file Moves `includes` to be enumerated on the correct library. * Add WORKSPACE version fallback WORKSPACE Bazel projects don't support querying module version, so add a fallback of '0.0.1-WORKSPACE' so the build can succeed. * Fix malloc handling in Bazel build * Fix Bazel dependency cycle in pico_malloc * Prevent malloc from being linked into boot_stage2 Prevents Bazel from ever trying to link malloc into the boot_stage2 binary. * Remove custom bootloader platform A dedicated boot_stage2 platform introduces a lot of complexity that needs to be more thought-through.
2024-06-04 16:50:32 -07:00
# rules_cc v0.0.10 is not yet cut, so manually pull in the desired version.
# This does not apply to dependent projects, so it needs to be copied to your
# project's MODULE.bazel too.
archive_override(
module_name = "rules_cc",
urls = "https://github.com/bazelbuild/rules_cc/archive/1acf5213b6170f1f0133e273cb85ede0e732048f.zip",
strip_prefix = "rules_cc-1acf5213b6170f1f0133e273cb85ede0e732048f",
integrity = "sha256-NddP6xi6LzsIHT8bMSVJ2NtoURbN+l3xpjvmIgB6aSg=",
)
```
### Register toolchains
These toolchains tell Bazel how to compile for ARM cores. Add the following
to the `MODULE.bazel` for your project:
```python
register_toolchains(
"@pico-sdk//bazel/toolchain:arm_gcc_linux-x86_64",
"@pico-sdk//bazel/toolchain:arm_gcc_win-x86_64",
"@pico-sdk//bazel/toolchain:arm_gcc_mac-x86_64",
"@pico-sdk//bazel/toolchain:arm_gcc_mac-aarch64",
)
```
### Enable required .bazelrc flags
To use the toolchains provided by the Pico SDK, you'll need to enable a few
new features. In your project's `.bazelrc`, add the following
```
# Required for new toolchain resolution API.
build --incompatible_enable_cc_toolchain_resolution
build --@rules_cc//cc/toolchains:experimental_enable_rule_based_toolchains
```
### Ready to build!
You're now ready to start building Pico Projects in Bazel! When building,
don't forget to specify `--platforms` so Bazel knows you're targeting the
Raspberry Pi Pico:
```console
$ bazelisk build --platforms=@pico-sdk//bazel/platform:rp2040 //...
```
Expand bazel build to include configuration options and broader support. (#1731) * Add host Bazel build Updates target_compatible_with across the repo to ensure that wildcard builds for both host and rp2040 succeed. * Get unit tests building * Add Python script to identify build system differences Uses the build system tags to make it easier to identify differences between the CMake and Bazel builds. * Temporarily disable pico divider test * Support PICO_BARE_METAL in Bazel * Support PICO_NO_GC_SECTIONS in Bazel * Support boot2 configuration in Bazel Adds support for PICO_DEFAULT_BOOT_STAGE2 and PICO_DEFAULT_BOOT_STAGE2_FILE in the Bazel build. * Allowlist some CMake-only options * Support CXX configuration options in Bazel * Move multiple_choice_flag.bzl * Support all pico boards * Support linking multiple stdio implementations Changes the Bazel build so stdio implementations are no longer mutually exclusive. * Add PICO_BOOT_STAGE2_LINK_IMAGE * Support PICO_CMSIS_PATH in Bazel * Support PICO_USE_DEFAULT_MAX_PAGE_SIZE in Bazel * Silence PICO_CMSIS_VENDOR and PICO_CMSIS_DEVICE differences * Support PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS in Bazel * Properly support version defines * Support embedding binary info in Bazel * Embed build type in binary * Support different linker scripts in Bazel build * Finish out missing PICO_BUILD_DEFINE in Bazel build * Support PICO_NO_TARGET_NAME * Reorganize initial configuration options in Bazel Cleans up and reorganizes some of the initial configuration options added to the Bazel build so everything is consistent. * Add builds for pioasm and elf2uf2 * Use Python rules from rules_python * Actually link in output formats in pioasm tool * Make tools have public visibility * Add UF2 Bazel aspect * Add TODOs for pioasm/uf2 helpers * Fix compile flag typo * Update Bazel SDK configuration strings to match recent CMake changes * Fix pico_divider test * Clean up straggling TODOs * Clarify pico_stdio_test compatibility * Initial Bazel Pico W support * Add new files from develop * Clean up compatibility expressions in Bazel build * Clean up rp2 constraint handling in Bazel * More Bazel docs cleanup * Format Bazel build files * Consolidate transitions in the Pico SDK * Make every _allowlist_function_transition explicit * More docs cleanup * Add a few missing defines * Improve PICO_CONFIG_HEADER correctness in Bazel * Minor docs clarifications
2024-06-13 07:50:04 -07:00
## SDK configuration
An exhaustive list of build system configuration options is available in
`//bazel/config:BUILD.bazel`.
Introduce initial Bazel build (#1705) * Build boot_stage2 with Bazel Introduces the initial foundations of a Bazel build, including a toolchain, critical generated headers, platform patterns, and enough BUILD files to build boot_stage2. * Bazel libraries to support picotool * Move SDK defines to toolchain * Switch to `archive_override` in MODULE.bazel Uses archive_override where applicable to allow transitive bzlmod deps to propagate. * Multiplatform objcopy selection in Bazel build Makes an objcopy alias that redirects to the objcopy tool for the current exec platform, which allows boot_stage2 to build on Linux, macOS, and Windows. * Generate Bazel build files Adds initial set of generated Bazel build files. Note that these do not yet build, as dependency cycles are present. * Fix dependency cycles in Bazel build Fixes many dependency cycles, some were unintentionally created by the build file generator, others are true dependency cycles that require manual workarounds. * Silence warning in pico_stdio Bazel build Silences a stray warning in the Bazel build. * Fix wildcard Bazel build This makes `bazel build //...` succeed, and also prevents the fetching of toolchains that aren't compatible with the current execution environment (i.e. Windows computers will no longer try to download macOS toolchains). * Get the SDK working Finishes out the remainder of the work required to successfully compile a working blinky example. * Fix UART stdio dependencies in Bazel build Fixes some dependencies around pico_stdlib so that pico_stdlib links properly and UART stdio works. * Add linux support to Bazel build * Get Bazel deps from registry Adds external an external registry for resolving Bazel module dependencies. * Fix host configuration for picotool Provides the appropriate defines for host builds to support the picotool build. * Remove -ffreestanding from Bazel toolchain The -ffreestanding toolchain flag is quite strict, so remove it from the Bazel toolchain. * Remove unused .bzl file * Reduce Bazel compiler flags Cuts out most of the Bazel toolchain flags and only specifies the bare-minimum set of flags. Also, adds wrapper linker flags for functions the SDK wraps. * Get USB serial working Adds initial TinyUSB support and enough integration to get USB serial working. * Remove "Generated build file" Removes comments that indicates BUILD.bazel files are generated. This was used during initial bringup to indicate hand-crafted vs automatically generated BUILD.bazel files. * Do not build USB libraries unless configured Prevents USB libraries from being built unless the build is properly configured to use them. * Switch to rules_cc toolchains Moves toolchain configuration to use the new rules in rules_cc. * Minor cleanup in parse_version.py Cleans up trailing whitespace and runs the black formatter on parse_version.py. * Simplify constraint dimensions in Bazel build Consolidates the class/chip constraint settings to be a single constraint_setting with a config_setting that represents the rp2 class. * Update pin of rules_cc in Bazel build Includes a necessary fix for the target_compatible_with expression in the cc_toolchain to work as intended. * Move toolchains from pico.bzl to BUILD.bazel Moves toolchain definitions from pico.bzl to BUILD.bazel to make them easier to find and read. * Run buildifier on Bazel build files Fix trivial formatting issues by running buildifier on all BUILD.bazel files. * Make objcopy rule Makes a simple objcopy rule to remove direct references to the ARM toolchains. * Fix link flags in Bazel build Critical flags were not being applied to link steps. This applies -mcpu and -mthumb to the link steps to make the produced binaries work again. * Mention missing host build support * Fix various Bazel library rules * pico_bit_ops was incomplete. * pico_double and pico_float were trying to link in the "none" implementation. * Extend Bazel build documentation Improves documentation and comments across the Bazel build. * Clean up auxilary tools in Bazel build Switches genrules to use skylib rules to simplify things. Reworks version header generation to use the Bazel module version rather than parsing CMake. * Update boot_stage2 Bazel build file Moves `includes` to be enumerated on the correct library. * Add WORKSPACE version fallback WORKSPACE Bazel projects don't support querying module version, so add a fallback of '0.0.1-WORKSPACE' so the build can succeed. * Fix malloc handling in Bazel build * Fix Bazel dependency cycle in pico_malloc * Prevent malloc from being linked into boot_stage2 Prevents Bazel from ever trying to link malloc into the boot_stage2 binary. * Remove custom bootloader platform A dedicated boot_stage2 platform introduces a lot of complexity that needs to be more thought-through.
2024-06-04 16:50:32 -07:00
### Selecting a different board
Expand bazel build to include configuration options and broader support. (#1731) * Add host Bazel build Updates target_compatible_with across the repo to ensure that wildcard builds for both host and rp2040 succeed. * Get unit tests building * Add Python script to identify build system differences Uses the build system tags to make it easier to identify differences between the CMake and Bazel builds. * Temporarily disable pico divider test * Support PICO_BARE_METAL in Bazel * Support PICO_NO_GC_SECTIONS in Bazel * Support boot2 configuration in Bazel Adds support for PICO_DEFAULT_BOOT_STAGE2 and PICO_DEFAULT_BOOT_STAGE2_FILE in the Bazel build. * Allowlist some CMake-only options * Support CXX configuration options in Bazel * Move multiple_choice_flag.bzl * Support all pico boards * Support linking multiple stdio implementations Changes the Bazel build so stdio implementations are no longer mutually exclusive. * Add PICO_BOOT_STAGE2_LINK_IMAGE * Support PICO_CMSIS_PATH in Bazel * Support PICO_USE_DEFAULT_MAX_PAGE_SIZE in Bazel * Silence PICO_CMSIS_VENDOR and PICO_CMSIS_DEVICE differences * Support PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS in Bazel * Properly support version defines * Support embedding binary info in Bazel * Embed build type in binary * Support different linker scripts in Bazel build * Finish out missing PICO_BUILD_DEFINE in Bazel build * Support PICO_NO_TARGET_NAME * Reorganize initial configuration options in Bazel Cleans up and reorganizes some of the initial configuration options added to the Bazel build so everything is consistent. * Add builds for pioasm and elf2uf2 * Use Python rules from rules_python * Actually link in output formats in pioasm tool * Make tools have public visibility * Add UF2 Bazel aspect * Add TODOs for pioasm/uf2 helpers * Fix compile flag typo * Update Bazel SDK configuration strings to match recent CMake changes * Fix pico_divider test * Clean up straggling TODOs * Clarify pico_stdio_test compatibility * Initial Bazel Pico W support * Add new files from develop * Clean up compatibility expressions in Bazel build * Clean up rp2 constraint handling in Bazel * More Bazel docs cleanup * Format Bazel build files * Consolidate transitions in the Pico SDK * Make every _allowlist_function_transition explicit * More docs cleanup * Add a few missing defines * Improve PICO_CONFIG_HEADER correctness in Bazel * Minor docs clarifications
2024-06-13 07:50:04 -07:00
A different board can be selected specifying `--@pico-sdk//bazel/config:PICO_BOARD`:
```console
$ bazelisk build --platforms=//bazel/platform:rp2040 --@pico-sdk//bazel/config:PICO_BOARD=pico_w //...
```
If you have a bespoke board definition, you can configure the Pico SDK to use it
by pointing `--@pico-sdk//bazel/config:PICO_CONFIG_HEADER` to a `cc_library`
that defines `PICO_BOARD` and either a `PICO_CONFIG_HEADER` define or a
`pico/config_autogen.h` header. Make sure any required `includes`, `hdrs`, and
`deps` are also provided.
## Generating UF2 firmware images
Creation of UF2 images can be done as explicit build steps on a per-binary
rule basis, or through an aspect. Running a wildcard build with the
`pico_uf2_aspect` enabled is the easiest way to create a UF2 for every ELF
firmware image.
```console
$ bazel build --platforms=@pico-sdk//bazel/platform:rp2040 \
--aspects @pico-sdk//tools:uf2_aspect.bzl%pico_uf2_aspect \
--output_groups=+pico_uf2_files \
//...
Introduce initial Bazel build (#1705) * Build boot_stage2 with Bazel Introduces the initial foundations of a Bazel build, including a toolchain, critical generated headers, platform patterns, and enough BUILD files to build boot_stage2. * Bazel libraries to support picotool * Move SDK defines to toolchain * Switch to `archive_override` in MODULE.bazel Uses archive_override where applicable to allow transitive bzlmod deps to propagate. * Multiplatform objcopy selection in Bazel build Makes an objcopy alias that redirects to the objcopy tool for the current exec platform, which allows boot_stage2 to build on Linux, macOS, and Windows. * Generate Bazel build files Adds initial set of generated Bazel build files. Note that these do not yet build, as dependency cycles are present. * Fix dependency cycles in Bazel build Fixes many dependency cycles, some were unintentionally created by the build file generator, others are true dependency cycles that require manual workarounds. * Silence warning in pico_stdio Bazel build Silences a stray warning in the Bazel build. * Fix wildcard Bazel build This makes `bazel build //...` succeed, and also prevents the fetching of toolchains that aren't compatible with the current execution environment (i.e. Windows computers will no longer try to download macOS toolchains). * Get the SDK working Finishes out the remainder of the work required to successfully compile a working blinky example. * Fix UART stdio dependencies in Bazel build Fixes some dependencies around pico_stdlib so that pico_stdlib links properly and UART stdio works. * Add linux support to Bazel build * Get Bazel deps from registry Adds external an external registry for resolving Bazel module dependencies. * Fix host configuration for picotool Provides the appropriate defines for host builds to support the picotool build. * Remove -ffreestanding from Bazel toolchain The -ffreestanding toolchain flag is quite strict, so remove it from the Bazel toolchain. * Remove unused .bzl file * Reduce Bazel compiler flags Cuts out most of the Bazel toolchain flags and only specifies the bare-minimum set of flags. Also, adds wrapper linker flags for functions the SDK wraps. * Get USB serial working Adds initial TinyUSB support and enough integration to get USB serial working. * Remove "Generated build file" Removes comments that indicates BUILD.bazel files are generated. This was used during initial bringup to indicate hand-crafted vs automatically generated BUILD.bazel files. * Do not build USB libraries unless configured Prevents USB libraries from being built unless the build is properly configured to use them. * Switch to rules_cc toolchains Moves toolchain configuration to use the new rules in rules_cc. * Minor cleanup in parse_version.py Cleans up trailing whitespace and runs the black formatter on parse_version.py. * Simplify constraint dimensions in Bazel build Consolidates the class/chip constraint settings to be a single constraint_setting with a config_setting that represents the rp2 class. * Update pin of rules_cc in Bazel build Includes a necessary fix for the target_compatible_with expression in the cc_toolchain to work as intended. * Move toolchains from pico.bzl to BUILD.bazel Moves toolchain definitions from pico.bzl to BUILD.bazel to make them easier to find and read. * Run buildifier on Bazel build files Fix trivial formatting issues by running buildifier on all BUILD.bazel files. * Make objcopy rule Makes a simple objcopy rule to remove direct references to the ARM toolchains. * Fix link flags in Bazel build Critical flags were not being applied to link steps. This applies -mcpu and -mthumb to the link steps to make the produced binaries work again. * Mention missing host build support * Fix various Bazel library rules * pico_bit_ops was incomplete. * pico_double and pico_float were trying to link in the "none" implementation. * Extend Bazel build documentation Improves documentation and comments across the Bazel build. * Clean up auxilary tools in Bazel build Switches genrules to use skylib rules to simplify things. Reworks version header generation to use the Bazel module version rather than parsing CMake. * Update boot_stage2 Bazel build file Moves `includes` to be enumerated on the correct library. * Add WORKSPACE version fallback WORKSPACE Bazel projects don't support querying module version, so add a fallback of '0.0.1-WORKSPACE' so the build can succeed. * Fix malloc handling in Bazel build * Fix Bazel dependency cycle in pico_malloc * Prevent malloc from being linked into boot_stage2 Prevents Bazel from ever trying to link malloc into the boot_stage2 binary. * Remove custom bootloader platform A dedicated boot_stage2 platform introduces a lot of complexity that needs to be more thought-through.
2024-06-04 16:50:32 -07:00
```
## Building the Pico SDK itself
### First time setup
You'll need Bazel (v7.0.0 or higher) or Bazelisk (a self-updating Bazel
launcher) to build the Pico SDK.
We strongly recommend you set up
[Bazelisk](https://bazel.build/install/bazelisk).
### Building
To build all of the Pico SDK, run the following command:
```console
$ bazelisk build --platforms=//bazel/platform:rp2040 //...
```
## Known issues and limitations
Expand bazel build to include configuration options and broader support. (#1731) * Add host Bazel build Updates target_compatible_with across the repo to ensure that wildcard builds for both host and rp2040 succeed. * Get unit tests building * Add Python script to identify build system differences Uses the build system tags to make it easier to identify differences between the CMake and Bazel builds. * Temporarily disable pico divider test * Support PICO_BARE_METAL in Bazel * Support PICO_NO_GC_SECTIONS in Bazel * Support boot2 configuration in Bazel Adds support for PICO_DEFAULT_BOOT_STAGE2 and PICO_DEFAULT_BOOT_STAGE2_FILE in the Bazel build. * Allowlist some CMake-only options * Support CXX configuration options in Bazel * Move multiple_choice_flag.bzl * Support all pico boards * Support linking multiple stdio implementations Changes the Bazel build so stdio implementations are no longer mutually exclusive. * Add PICO_BOOT_STAGE2_LINK_IMAGE * Support PICO_CMSIS_PATH in Bazel * Support PICO_USE_DEFAULT_MAX_PAGE_SIZE in Bazel * Silence PICO_CMSIS_VENDOR and PICO_CMSIS_DEVICE differences * Support PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS in Bazel * Properly support version defines * Support embedding binary info in Bazel * Embed build type in binary * Support different linker scripts in Bazel build * Finish out missing PICO_BUILD_DEFINE in Bazel build * Support PICO_NO_TARGET_NAME * Reorganize initial configuration options in Bazel Cleans up and reorganizes some of the initial configuration options added to the Bazel build so everything is consistent. * Add builds for pioasm and elf2uf2 * Use Python rules from rules_python * Actually link in output formats in pioasm tool * Make tools have public visibility * Add UF2 Bazel aspect * Add TODOs for pioasm/uf2 helpers * Fix compile flag typo * Update Bazel SDK configuration strings to match recent CMake changes * Fix pico_divider test * Clean up straggling TODOs * Clarify pico_stdio_test compatibility * Initial Bazel Pico W support * Add new files from develop * Clean up compatibility expressions in Bazel build * Clean up rp2 constraint handling in Bazel * More Bazel docs cleanup * Format Bazel build files * Consolidate transitions in the Pico SDK * Make every _allowlist_function_transition explicit * More docs cleanup * Add a few missing defines * Improve PICO_CONFIG_HEADER correctness in Bazel * Minor docs clarifications
2024-06-13 07:50:04 -07:00
The Bazel build for the Pico SDK is relatively new, but most features and
configuration options available in the CMake build are also available in Bazel.
You are welcome and encouraged to file issues for any problems and limitations
you encounter along the way.
Currently, the following features are not supported:
* "None" variants of pico_double, pico_float, and pico_printf are not yet
supported.
* The pioasm parser cannot be built from source via Bazel.