bazelembedded/bazel-embedded

Windows build does not include system headers

Closed this issue · 7 comments

When building on Linux, the system headers are included in the build command, for example I can clearly see -isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1 added to the command line

Linux:

  external/bazel_embedded/toolchains/gcc_arm_none_eabi/gcc_wrappers/nix/gcc -MD -MF bazel-out/k8-fastbuild/bin/stm32g4_example/_objs/main.elf/sysmem.d '-frandom-seed=bazel-out/k8-fastbuild/bin/stm32g4_example/_objs/main.elf/sysmem.o' -DUSE_HAL_DRIVER -DSTM32G473xx -iquote . -iquote bazel-out/k8-fastbuild/bin -iquote external/STM32CubeG4 -iquote bazel-out/k8-fastbuild/bin/external/STM32CubeG4 -iquote external/bazel_tools -iquote bazel-out/k8-fastbuild/bin/external/bazel_tools -isystem stm32g4_example/Core/Inc -isystem bazel-out/k8-fastbuild/bin/stm32g4_example/Core/Inc -isystem external/STM32CubeG4/Drivers/STM32G4xx_HAL_Driver/Inc -isystem bazel-out/k8-fastbuild/bin/external/STM32CubeG4/Drivers/STM32G4xx_HAL_Driver/Inc -isystem external/STM32CubeG4/Drivers/CMSIS/Include -isystem bazel-out/k8-fastbuild/bin/external/STM32CubeG4/Drivers/CMSIS/Include -isystem external/STM32CubeG4/Drivers/CMSIS/Device/ST/STM32G4xx/Include -isystem bazel-out/k8-fastbuild/bin/external/STM32CubeG4/Drivers/CMSIS/Device/ST/STM32G4xx/Include -isystem stm32g4_example -isystem bazel-out/k8-fastbuild/bin/stm32g4_example -Wall -Wpedantic '-Werror=date-time' -nostdinc -no-canonical-prefixes -fno-canonical-system-headers -isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/newlib-nano -isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1 -isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1/arm-none-eabi -isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1/backward -isystemexternal/com_gcc_arm_none_eabi_compiler/lib/gcc/arm-none-eabi/9.2.1/include -isystemexternal/com_gcc_arm_none_eabi_compiler/lib/gcc/arm-none-eabi/9.2.1/include-fixed -isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include '-isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi-D__USES_INITFINI__/dev/null-mcpu=arm7tdmi-mfloat-abi=soft-marm-march=armv4t' -isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/newlib-nano -isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1 -isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1/arm-none-eabi -isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1/backward -isystemexternal/com_gcc_arm_none_eabi_compiler/lib/gcc/arm-none-eabi/9.2.1/include -isystemexternal/com_gcc_arm_none_eabi_compiler/lib/gcc/arm-none-eabi/9.2.1/include-fixed -isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include -ffunction-sections -fdata-sections '-march=armv7e-m' '-mfpu=fpv4-sp-d16' '-mfloat-abi=hard' -mlittle-endian -O -ffreestanding -fno-common -fstack-protector-strong -c stm32g4_example/Core/Src/sysmem.c -o bazel-out/k8-fastbuild/bin/stm32g4_example/_objs/main.elf/sysmem.o)

However on Windows none of the system includes are added to the command line, as a result my build fails when including any system headers.

Windows:

external/bazel_embedded/toolchains/gcc_arm_none_eabi/gcc_wrappers/windows/gcc.bat -MD -MF bazel-out/x64_windows-fastbuild/bin/stm32g4_example/_objs/frames/frames.d -frandom-seed=bazel-out/x64_windows-fastbuild/bin/stm32g4_example/_objs/frames/frames.o -iquote . -iquote bazel-out/x64_windows-fastbuild/bin -isystem stm32g4_example -isystem bazel-out/x64_windows-fastbuild/bin/stm32g4_example -Wall -Wpedantic -Werror=date-time -nostdinc -no-canonical-prefixes -fno-canonical-system-headers -isystem external/bazel_embedded_upstream_toolchain -ffunction-sections -fdata-sections -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mlittle-endian -O -ffreestanding -fno-common -fstack-protector-strong -c bazel-out/x64_windows-fastbuild/bin/stm32g4_example/frames.c -o bazel-out/x64_windows-fastbuild/bin/stm32g4_example/_objs/frames/frames.o

Same command line for both cases:

bazel build -s //stm32g4_example:main --platforms=@bazel_embedded//platforms:cortex_m4_fpu

Hmm interesting, I'll take a look. There are some subtle differences in how include paths are handled with gcc in general. Just so that I can reproduce the issue, what specific headers are you have issues with so that I can add a regression test. For some context I've had scenarios where 'math' doesn't work in my header search on linux but 'array' does.

Here are two in particular that I know it cannot find:

#include <stdint.h>
#include <string.h>

Looking a bit closer, it looks like the method to auto-extract the correct header info is failing on Windows. My defs.bzl on Linux expands to:


SYSTEM_INCLUDE_COMMAND_LINE = ["-isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/newlib-nano", "-isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1", "-isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1/arm-none-eabi", "-isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1/backward", "-isystemexternal/com_gcc_arm_none_eabi_compiler/lib/gcc/arm-none-eabi/9.2.1/include", "-isystemexternal/com_gcc_arm_none_eabi_compiler/lib/gcc/arm-none-eabi/9.2.1/include-fixed", "-isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include", "-isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi-D__USES_INITFINI__/dev/null-mcpu=arm7tdmi-mfloat-abi=soft-marm-march=armv4t", "-isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/newlib-nano", "-isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1", "-isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1/arm-none-eabi", "-isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1/backward", "-isystemexternal/com_gcc_arm_none_eabi_compiler/lib/gcc/arm-none-eabi/9.2.1/include", "-isystemexternal/com_gcc_arm_none_eabi_compiler/lib/gcc/arm-none-eabi/9.2.1/include-fixed", "-isystemexternal/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include"]
SYSTEM_INCLUDE_PATHS= ["external/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/newlib-nano", "external/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1", "external/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1/arm-none-eabi", "external/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1/backward", "external/com_gcc_arm_none_eabi_compiler/lib/gcc/arm-none-eabi/9.2.1/include", "external/com_gcc_arm_none_eabi_compiler/lib/gcc/arm-none-eabi/9.2.1/include-fixed", "external/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include", "external/com_gcc_arm_none_eabi_compiler/arm-none-eabi-D__USES_INITFINI__/dev/null-mcpu=arm7tdmi-mfloat-abi=soft-marm-march=armv4t", "external/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/newlib-nano", "external/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1", "external/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1/arm-none-eabi", "external/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include/c++/9.2.1/backward", "external/com_gcc_arm_none_eabi_compiler/lib/gcc/arm-none-eabi/9.2.1/include", "external/com_gcc_arm_none_eabi_compiler/lib/gcc/arm-none-eabi/9.2.1/include-fixed", "external/com_gcc_arm_none_eabi_compiler/arm-none-eabi/include"]

Meanwhile on Windows the two lists are empty:


SYSTEM_INCLUDE_COMMAND_LINE = []
SYSTEM_INCLUDE_PATHS= []

So I've found the bug. It is like you are saying related to header discovery, which seems to work differently on windows. Should be somewhat straightforward to fix. I'll hopefully should have that sorted in the next week or so. As a work around you should be able to use most of the build functionality on WSL.

This should be fixed now. Let me know if you have any issues.

You should be able to change the commit attribute in your WORKSPACE to '14d51da3c1de4c7b8b7ce78e87e4f25d9802bee4' and it should work as expected.

Confirmed working, thanks!