Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/examples_build-host-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ jobs:
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build with IDF-${{ matrix.idf_ver }}
shell: bash
run: |
. ${GITHUB_WORKSPACE}/ci/config_env.sh
. ${IDF_PATH}/export.sh
python -m pip install idf-build-apps
python ./ci/build_apps.py examples/mqtt -l -t linux -r 'sdkconfig.ci'
./ci/test_broker/run.sh
timeout 5 ./examples/mqtt/build_linux/esp_mqtt_demo.elf | tee test.log || true
grep 'MQTT_EVENT_DATA' test.log
pkill -f 'broker.elf'

run_on_target:
# Skip running on forks since it won't have access to secrets
Expand Down
12 changes: 12 additions & 0 deletions ci/test_broker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -e

BROKER_PATH=components/mosquitto/examples/broker
SCRIPT_DIR=$(dirname $0)
cp ${SCRIPT_DIR}/sdkconfig.broker ${BROKER_PATH}/sdkconfig.broker
idf.py -B build -DSDKCONFIG=sdkconfig.broker -C ${BROKER_PATH} build

./build/broker.elf &
export MOSQ_PID=$!
echo "Broker started with PID ${MOSQ_PID}"
5 changes: 5 additions & 0 deletions ci/test_broker/sdkconfig.broker
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CONFIG_IDF_TARGET="linux"
CONFIG_EXAMPLE_BROKER_PORT=1234
CONFIG_EXAMPLE_BROKER_RUN_LOCAL_MQTT_CLIENT=n
CONFIG_EXAMPLE_BROKER_WITH_TLS=n
CONFIG_ESP_EVENT_POST_FROM_ISR=n
6 changes: 6 additions & 0 deletions components/mosquitto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
idf_build_get_property(idf_target IDF_TARGET)

set(m_dir mosquitto)
set(m_src_dir ${m_dir}/src)
set(m_incl_dir ${m_dir}/include)
Expand Down Expand Up @@ -94,6 +96,10 @@ target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
# without modifying upstream code
target_link_options(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=mosquitto_unpwd_check")

if(${idf_target} STREQUAL "linux")
target_link_options(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=main")
endif()

# Some mosquitto source unconditionally define `_GNU_SOURCE` which collides with IDF build system
# producing warning: "_GNU_SOURCE" redefined
# This workarounds this issue by undefining the macro for the selected files
Expand Down
7 changes: 7 additions & 0 deletions components/mosquitto/examples/broker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
cmake_minimum_required(VERSION 3.16)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)

if("${IDF_TARGET}" STREQUAL "linux")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't cleaner to move this to component manager yml?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's probably cleaner, but less practical.
Remember the issues Ondrej had with #ifdef-in components/version? Plus it'd add one more expansion.

list(APPEND EXTRA_COMPONENT_DIRS "../../../../common_components/linux_compat")
endif()

idf_build_set_property(MINIMAL_BUILD ON)

project(broker)
2 changes: 1 addition & 1 deletion components/mosquitto/examples/broker/main/example_broker.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "mosq_broker.h"
#include "protocol_examples_common.h"

const static char *TAG = "mqtt_broker";
__attribute__((unused)) const static char *TAG = "mqtt_broker";

/* Basic auth credentials for the example */
#define EXAMPLE_USERNAME "testuser"
Expand Down
3 changes: 3 additions & 0 deletions components/mosquitto/examples/broker/main/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ dependencies:
rules:
- if: idf_version >=6.0
version: ^1.0.0
espressif/sock_utils:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we guard to not add it on Linux target build?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanted to keep this cleaner, but i'll probably make sense in future when component manager becomes more stable and dependency resolution more predictable.
just didn't want to end-up like our Ethernet component: https://github.com/espressif/esp-eth-drivers/blob/master/ethernet_init/idf_component.yml 😄

version: '*'
override_path: '../../../../sock_utils'
2 changes: 2 additions & 0 deletions components/mosquitto/port/broker.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "mosquitto_broker_internal.h"
#include "memory_mosq.h"
#include "mosq_broker.h"
#include <time.h>
#include <sys/time.h>

static struct mosquitto__listener_sock *listensock = NULL;
static int listensock_count = 0;
Expand Down
11 changes: 11 additions & 0 deletions components/mosquitto/port/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "utlist.h"
#include "lib_load.h"
#include "syslog.h"
#include <limits.h>
#include "sdkconfig.h"


Expand Down Expand Up @@ -244,3 +245,13 @@ pid_t fork(void)
abort();
return 0;
}

#ifdef CONFIG_IDF_TARGET_LINUX
extern void app_main(void);

int __wrap_main(int argc, char *argv[])
{
app_main();
return 0;
}
#endif
2 changes: 1 addition & 1 deletion components/mosquitto/port/mosq_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <time.h>
#include "time_mosq.h"

#include "esp_err.h"
#include "esp_timer.h"

void mosquitto_time_init(void)
Expand Down
3 changes: 0 additions & 3 deletions components/mosquitto/port/priv_include/sys/syslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#pragma once


#define EAI_SYSTEM 11 /* system error returned in errno */

#include "esp_log.h"
#define LOG_EMERG (0)
#define LOG_ALERT (1)
Expand All @@ -30,6 +28,5 @@

#define syslog(sev, format, ... ) ESP_LOG_LEVEL_LOCAL(sev-2, "mosquitto", format, ##__VA_ARGS__)

#define gai_strerror(x) "gai_strerror() not supported"
#define openlog(a, b, c)
#define closelog()
5 changes: 4 additions & 1 deletion components/mosquitto/port/signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
* SPDX-FileContributor: 2024 Espressif Systems (Shanghai) CO LTD
*/
#include "signal.h"
#include "sdkconfig.h"

int sigprocmask (int, const sigset_t *, sigset_t *)
#ifndef CONFIG_IDF_TARGET_LINUX
int sigprocmask(int, const sigset_t *, sigset_t *)
{
return 0;
}
#endif
8 changes: 8 additions & 0 deletions components/sock_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
idf_build_get_property(idf_target IDF_TARGET)

if(${idf_target} STREQUAL "linux")
# This component is no-op for linux simulator
idf_component_register()
return()
endif()

idf_component_register(SRCS "src/getnameinfo.c"
"src/ifaddrs.c"
"src/gai_strerror.c"
Expand Down
2 changes: 1 addition & 1 deletion examples/mqtt/sdkconfig.ci
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# CONFIG_ESP_EVENT_POST_FROM_ISR is not set
CONFIG_BROKER_URL="mqtt://${CI_MQTT_BROKER_URI}"
CONFIG_BROKER_URL="mqtt://127.0.0.1:1234"
Loading