Skip to content

Commit

Permalink
Merge branch 'bugfix/enable_simple_http_server_on_linux' into 'master'
Browse files Browse the repository at this point in the history
fix(examples): simple http_server example build for Linux target

See merge request espressif/esp-idf!36277
  • Loading branch information
mahavirj committed Jan 13, 2025
2 parents 52b558d + 25fe9e5 commit 5238519
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 87 deletions.
11 changes: 2 additions & 9 deletions components/esp_http_server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
set(priv_req mbedtls)
set(priv_inc_dir "src/util")
set(priv_req mbedtls lwip esp_timer)
set(priv_inc_dir "src/util" "src/port/esp32")
set(requires http_parser esp_event)
if(NOT ${IDF_TARGET} STREQUAL "linux")
list(APPEND priv_req lwip esp_timer)
list(APPEND priv_inc_dir "src/port/esp32")
else()
list(APPEND priv_inc_dir "src/port/linux")
list(APPEND priv_req pthread)
endif()

idf_component_register(SRCS "src/httpd_main.c"
"src/httpd_parse.c"
Expand Down
55 changes: 0 additions & 55 deletions components/esp_http_server/src/port/linux/osal.h

This file was deleted.

2 changes: 1 addition & 1 deletion components/freertos/esp_additions/idf_additions.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

/* Allocate memory for the task's stack using the provided memory caps
* */
pxStack = heap_caps_malloc( usStackDepth, ( uint32_t ) uxMemoryCaps );
pxStack = heap_caps_malloc( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ), ( uint32_t ) uxMemoryCaps );

if( ( pxTaskBuffer == NULL ) || ( pxStack == NULL ) )
{
Expand Down
47 changes: 29 additions & 18 deletions examples/protocols/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ examples/protocols/esp_http_client:
- if: INCLUDE_DEFAULT == 1 or IDF_TARGET == "linux"
disable_test:
- if: IDF_TARGET not in ["esp32", "linux"]
depends_filepatterns:
- components/esp_http_client/**/*
depends_components+:
- esp_http_client

examples/protocols/esp_local_ctrl:
<<: *default_dependencies
Expand All @@ -36,8 +36,9 @@ examples/protocols/esp_local_ctrl:
- if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"]
reason: only test on these targets
depends_filepatterns:
- components/protocomm/**/*
- tools/esp_prov/**/*
depends_components+:
- protocomm

examples/protocols/http_request:
<<: *default_dependencies
Expand All @@ -50,8 +51,8 @@ examples/protocols/http_server:
disable_test:
- if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"]
reason: only test on these targets
depends_filepatterns:
- components/esp_http_server/**/*
depends_components+:
- esp_http_server

examples/protocols/http_server/captive_portal:
<<: *default_dependencies
Expand All @@ -61,25 +62,35 @@ examples/protocols/http_server/captive_portal:
disable_test:
- if: IDF_TARGET != "esp32"
reason: only test on esp32
depends_filepatterns:
- components/esp_http_server/**/*
depends_components+:
- esp_http_server

examples/protocols/http_server/restful_server:
<<: *default_dependencies
disable:
- if: IDF_TARGET in ["esp32h2"]
temporary: true
reason: not supported yet
depends_filepatterns:
- components/esp_http_server/**/*
depends_components+:
- esp_http_server

examples/protocols/http_server/simple:
<<: *default_dependencies
enable:
- if: INCLUDE_DEFAULT == 1 or IDF_TARGET == "linux"
disable_test:
- if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"]
reason: only test on these targets
depends_components+:
- esp_http_server

examples/protocols/http_server/ws_echo_server:
<<: *default_dependencies
disable_test:
- if: IDF_TARGET != "esp32"
reason: only test on esp32
depends_filepatterns:
- components/esp_http_server/**/*
depends_components+:
- esp_http_server

examples/protocols/https_mbedtls:
<<: *default_dependencies
Expand All @@ -104,25 +115,25 @@ examples/protocols/https_server/simple:
disable_test:
- if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"]
reason: only test on these targets
depends_filepatterns:
- components/esp_https_server/**/*
- components/esp_tls/**/*
depends_components+:
- esp_https_server
- esp-tls

examples/protocols/https_server/wss_server:
<<: *default_dependencies
disable_test:
- if: IDF_TARGET != "esp32"
reason: only test on esp32
depends_filepatterns:
- components/esp_https_server/**/*
depends_components+:
- esp_https_server

examples/protocols/https_x509_bundle:
<<: *default_dependencies
disable_test:
- if: IDF_TARGET != "esp32"
reason: only test on esp32
depends_filepatterns:
- components/esp_tls/**/*
depends_components+:
- esp-tls

examples/protocols/icmp_echo:
<<: *default_dependencies
Expand Down
4 changes: 2 additions & 2 deletions examples/protocols/http_server/simple/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | Linux |
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- | ----- |

# Simple HTTPD Server Example

Expand Down
5 changes: 4 additions & 1 deletion examples/protocols/http_server/simple/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
set(requires esp-tls nvs_flash esp_netif esp_http_server esp_wifi esp_eth)
set(requires esp-tls nvs_flash esp_netif esp_http_server)
idf_build_get_property(target IDF_TARGET)

if(${target} STREQUAL "linux")
list(APPEND requires esp_stubs protocol_examples_common)
else()
list(APPEND requires esp_wifi esp_eth)
endif()

idf_component_register(SRCS "main.c"
INCLUDE_DIRS "."
PRIV_REQUIRES ${requires})
2 changes: 1 addition & 1 deletion examples/protocols/http_server/simple/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ static esp_err_t sse_handler(httpd_req_t *req)
gettimeofday(&tv, NULL); // Get the current time
int64_t time_since_boot = tv.tv_sec; // Time since boot in seconds
esp_err_t err;
int len = snprintf(sse_data, sizeof(sse_data), "data: Time since boot: %lld seconds\n\n", time_since_boot);
int len = snprintf(sse_data, sizeof(sse_data), "data: Time since boot: %" PRIi64 " seconds\n\n", time_since_boot);
if ((err = httpd_resp_send_chunk(req, sse_data, len)) != ESP_OK) {
ESP_LOGE(TAG, "Failed to send sse data (returned %02X)", err);
break;
Expand Down

0 comments on commit 5238519

Please sign in to comment.