4ms / metamodule

MetaModule virtual patch module firmware
Other
9 stars 0 forks source link

MinGW building firmware fails with CMake Ninja generator (works with Cmake Unix Makefiles generator) #78

Open danngreen opened 1 year ago

danngreen commented 1 year ago

In the firmware-cmake branch, on my minimal windows 11 + MSYS + MinGW64 setup, it will build fine if I use cmake to generate Makefiles:

cd firmware
cmake -B build -G"Unix Makefiles"
cmake --build build

# Or, this also works and is faster:
cd build && make -j8

But if I use Ninja like this:

cd firmware
cmake -B build -GNinja
cmake --build build

...then I get some strange errors, which I haven't found a solution to. The errors happen during build steps that were generated from cmake add_custom_command and add_custom_target commands. These run commands in the terminal, and I suspect there's some sort of slash issue, or character escaping, or shell-wrapping issue happening. Example (verbose output shown with cd build && ninja -v -j 1:

cmd.exe /C "cd /D C:\msys64\home\dann\stm32\metamodule\firmware\build && cd C:/msys64/home/dann/stm32/metamodule/firmware && make --no-print-directory -f tests/Makefile -j8 && cd C:/msys64/home/dann/stm32/metamodule/firmware/../shared/patch_convert && make --no-print-directory -f tests/Makefile -j8 && cd C:/msys64/home/dann/stm32/metamodule/firmware/../shared/CoreModules && make --no-print-directory -f tests/Makefile -j8"
Warning: Outputs are connected: panel_jack_id=2 and int_cable=0
[√] Unit tests passed: build
[√] Unit tests passed: build
ninja: build stopped: GetFileAttributesEx(C:/msys64/home/dann/stm32/metamodule/firmware/tests/build/*): The filename, directory name, or volume label syntax is incorrect.

That one is from running the unit test via an external Makefile. I'm noticing use of forward and back slashes, and also the wrapping of the make command within a cmd.exe /C "cd /D C:\(path) ..." wrapper. The commands run fine if I manually run them verbatim, but without this wrapper.

If I skip building the tests, I still get errors when doing the POST_BUILD steps after linking the main_m4.elf:

[221/538] cmd.exe /C "cd . && C:\msys64\home\dann\bin\arm-gnu-toolchain-12.3.rel1-mingw-w64-i686-arm-none-eabi\bin\arm-none-eabi-g++.exe -O2 -g -DNDEBUG -Wl,-Map,C:/msys64/home/dann/stm32/metamodule/firmware/build/mp1corem4/medium/main_m4.map,--cref -Wl,--no-warn-rwx-segments -T C:/msys64/home/dann/stm32/metamodule/firmware/system/linker/stm32mp15xx_m4.ld -LC:/msys64/home/dann/stm32/metamodule/firmware -Wl,--gc-sections -ffreestanding -nostartfiles -nostdlib -flto=auto -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mthumb -mlittle-endian -mfloat-abi=hard @CMakeFiles\main_m4.elf.rsp -o mp1corem4\medium\main_m4.elf  && cmd.exe /C "cd /D C:\msys64\home\dann\stm32\metamodule\firmware\build\mp1corem4\medium && arm-none-eabi-objcopy -O binary -j .rodata C:/msys64/home/dann/stm32/metamodule/firmware/build/mp1corem4/medium/main_m4.elf C:/msys64/home/dann/stm32/metamodule/firmware/build/mp1corem4/medium/m4_rodata.bin && \bin\sh C:/msys64/home/dann/stm32/metamodule/firmware/flashing/bin_to_ld.sh m4_rodata.bin m4_rodata.ld && rm m4_rodata.bin && cd /D C:\msys64\home\dann\stm32\metamodule\firmware\build\mp1corem4\medium && arm-none-eabi-objcopy -O binary -j .isr_vector C:/msys64/home/dann/stm32/metamodule/firmware/build/mp1corem4/medium/main_m4.elf vectors.bin && xxd -i -c 8 vectors.bin firmware_m4_vectors.h && rm vectors.bin && cd /D C:\msys64\home\dann\stm32\metamodule\firmware\build\mp1corem4\medium && arm-none-eabi-objcopy -O binary -j .text -j .startup_copro_fw.Reset_Handler -j .init_array -j .data C:/msys64/home/dann/stm32/metamodule/firmware/build/mp1corem4/medium/main_m4.elf firmware.bin && xxd -i -c 8 firmware.bin firmware_m4.h && rm firmware.bin""
FAILED: mp1corem4/medium/main_m4.elf mp1corem4/medium/m4_rodata.ld mp1corem4/medium/firmware_m4_vectors.h mp1corem4/medium/firmware_m4.h C:/msys64/home/dann/stm32/metamodule/firmware/build/mp1corem4/medium/m4_rodata.ld C:/msys64/home/dann/stm32/metamodule/firmware/build/mp1corem4/medium/firmware_m4_vectors.h C:/msys64/home/dann/stm32/metamodule/firmware/build/mp1corem4/medium/firmware_m4.h
cmd.exe /C "cd . && C:\msys64\home\dann\bin\arm-gnu-toolchain-12.3.rel1-mingw-w64-i686-arm-none-eabi\bin\arm-none-eabi-g++.exe -O2 -g -DNDEBUG -Wl,-Map,C:/msys64/home/dann/stm32/metamodule/firmware/build/mp1corem4/medium/main_m4.map,--cref -Wl,--no-warn-rwx-segments -T C:/msys64/home/dann/stm32/metamodule/firmware/system/linker/stm32mp15xx_m4.ld -LC:/msys64/home/dann/stm32/metamodule/firmware -Wl,--gc-sections -ffreestanding -nostartfiles -nostdlib -flto=auto -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mthumb -mlittle-endian -mfloat-abi=hard @CMakeFiles\main_m4.elf.rsp -o mp1corem4\medium\main_m4.elf  && cmd.exe /C "cd /D C:\msys64\home\dann\stm32\metamodule\firmware\build\mp1corem4\medium && arm-none-eabi-objcopy -O binary -j .rodata C:/msys64/home/dann/stm32/metamodule/firmware/build/mp1corem4/medium/main_m4.elf C:/msys64/home/dann/stm32/metamodule/firmware/build/mp1corem4/medium/m4_rodata.bin && \bin\sh C:/msys64/home/dann/stm32/metamodule/firmware/flashing/bin_to_ld.sh m4_rodata.bin m4_rodata.ld && rm m4_rodata.bin && cd /D C:\msys64\home\dann\stm32\metamodule\firmware\build\mp1corem4\medium && arm-none-eabi-objcopy -O binary -j .isr_vector C:/msys64/home/dann/stm32/metamodule/firmware/build/mp1corem4/medium/main_m4.elf vectors.bin && xxd -i -c 8 vectors.bin firmware_m4_vectors.h && rm vectors.bin && cd /D C:\msys64\home\dann\stm32\metamodule\firmware\build\mp1corem4\medium && arm-none-eabi-objcopy -O binary -j .text -j .startup_copro_fw.Reset_Handler -j .init_array -j .data C:/msys64/home/dann/stm32/metamodule/firmware/build/mp1corem4/medium/main_m4.elf firmware.bin && xxd -i -c 8 firmware.bin firmware_m4.h && rm firmware.bin""

Huge wall of text, but it also has both types of slashes, and starts with the same cmd.exe wrapper, and even has another nested cmd.exe /C "cd /D..."wrapper inside the first one.

The work-around I came up with is to make Unix Makefiles the default build system if MinGW is detected. This is done in the firmware Makefile (which has shortcuts for conveniently running the cmake commands) I'll also add this info to the docs.

mhetrick commented 1 year ago

As a heads up, the latest firmware commit is failing project creation on Windows due to missing quotes. In Makefile I had to add quotes around Unix Makefiles:

# Detect MinGW and use Make
ifdef SYSTEMROOT
GEN := "Unix Makefiles"
else
GEN := Ninja
endif
danngreen commented 1 year ago

Aha, good catch! I think the quotes got lost along the way (and we don't have CI for windows building firmware yet) Do you want to make a PR, or I'm happy to do it?

mhetrick commented 1 year ago

https://github.com/4ms/metamodule/pull/86

I just submitted the pull request. I'm sorry, I didn't realize that it would trigger a CI build just via that.

danngreen commented 1 year ago

Thanks!