Skip to content

Commit

Permalink
Fix C builds (#8795)
Browse files Browse the repository at this point in the history
Missing stdbool.h for 'bool' in features .h, at least one user is arduinoWebSockets
Adds minimal headers sanity-check script to verify that C builds work as expected

Also noticed and removed default argument from crc32() in internal .h that may be used in .c
(not sure how extern C & default worked simultaniously, but at least in our .cpp Gcc somehow figured out it is a no overload solution)
  • Loading branch information
mcspr committed Jan 11, 2023
1 parent 7e2da8b commit 840ef78
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 9 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/build-ide.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ permissions:
jobs:

# Examples are built in parallel to avoid CI total job time limitation
sanity-check:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
with:
submodules: false
- uses: actions/cache@v3
with:
path: ./tools/dist
key: ${{ runner.os }}-${{ hashFiles('package/package_esp8266com_index.template.json', 'tests/common.sh', 'tests/build.sh') }}
- name: Toolchain sanity checks
run: |
bash ./tests/sanity_check.sh
build-linux:
name: Linux - LwIP ${{ matrix.lwip }} (${{ matrix.chunk }})
Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ bool EspClass::checkFlashCRC() {
uint32_t firstPart = (uintptr_t)&__crc_len - 0x40200000; // How many bytes to check before the 1st CRC val

// Start the checksum
uint32_t crc = crc32((const void*)0x40200000, firstPart, 0xffffffff);
uint32_t crc = crc32((const void*)0x40200000, firstPart);
// Pretend the 2 words of crc/len are zero to be idempotent
crc = crc32(z, 8, crc);
// Finish the CRC calculation over the rest of flash
Expand Down
8 changes: 4 additions & 4 deletions cores/esp8266/core_esp8266_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
*/


#ifndef CORE_ESP8266_FEATURES_H
#define CORE_ESP8266_FEATURES_H


#define CORE_HAS_LIBB64
#define CORE_HAS_BASE64_CLASS
#define CORE_HAS_CXA_GUARD
Expand All @@ -33,9 +31,10 @@
#define WIFI_HAS_EVENT_CALLBACK
#define WIFI_IS_OFF_AT_BOOT

#include <stdlib.h> // malloc()
#include <stdbool.h> // bool
#include <stddef.h> // size_t
#include <stdint.h>
#include <stdlib.h> // malloc()

#ifndef __STRINGIFY
#define __STRINGIFY(a) #a
Expand Down Expand Up @@ -118,6 +117,7 @@ int esp_get_cpu_freq_mhz()
#else
inline int esp_get_cpu_freq_mhz()
{
uint8_t system_get_cpu_freq(void);
return system_get_cpu_freq();
}
#endif
Expand All @@ -129,7 +129,7 @@ void enablePhaseLockedWaveform(void);

// Determine when the sketch runs on ESP8285
#if !defined(CORE_MOCK)
bool __attribute__((const, nothrow)) esp_is_8285();
bool esp_is_8285() __attribute__((const, nothrow));
#else
inline bool esp_is_8285()
{
Expand Down
8 changes: 5 additions & 3 deletions cores/esp8266/coredecls.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ void esp_delay(unsigned long ms);
void esp_schedule();
void esp_yield();
void tune_timeshift64 (uint64_t now_us);
bool sntp_set_timezone_in_seconds(int32_t timezone);

void disable_extra4k_at_link_time (void) __attribute__((noinline));
void enable_wifi_enterprise_patch(void) __attribute__((noinline));
bool sntp_set_timezone_in_seconds(int32_t timezone);
void __disableWiFiAtBootTime (void) __attribute__((noinline));
void __real_system_restart_local() __attribute__((noreturn));

uint32_t sqrt32 (uint32_t n);
uint32_t crc32 (const void* data, size_t length, uint32_t crc = 0xffffffff);
uint32_t sqrt32(uint32_t n);

#ifdef __cplusplus
}

uint32_t crc32(const void* data, size_t length, uint32_t crc = 0xffffffff);

#include <functional>

using BoolCB = std::function<void(bool)>;
Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/crc32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "pgmspace.h"

// moved from core_esp8266_eboot_command.cpp
uint32_t crc32 (const void* data, size_t length, uint32_t crc /*= 0xffffffff*/)
uint32_t crc32 (const void* data, size_t length, uint32_t crc)
{
const uint8_t* ldata = (const uint8_t*)data;
while (length--)
Expand Down
44 changes: 44 additions & 0 deletions tests/sanity_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

root=$(git rev-parse --show-toplevel)
source "$root/tests/common.sh"

pushd "$root"/tools
python3 get.py -q

popd
pushd "$cache_dir"

gcc="$root/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc"\
" -I$root/cores/esp8266"\
" -I$root/tools/sdk/include"\
" -I$root/variants/generic"\
" -I$root/tools/sdk/libc/xtensa-lx106-elf"

$gcc --verbose

set -v -x

cat << EOF > arduino.c
#include <Arduino.h>
EOF

$gcc -c arduino.c

cat << EOF > coredecls.c
#include <coredecls.h>
EOF

$gcc -c coredecls.c

cat << EOF > features.c
#include <core_esp8266_features.h>
EOF

$gcc -c features.c

cat << EOF > sdk.c
#include <version.h>
EOF

$gcc -c sdk.c

0 comments on commit 840ef78

Please sign in to comment.