feat(mosq): Add support for linux build

This commit is contained in:
David Cermak
2025-12-16 07:52:40 +01:00
parent 77abff48e1
commit 583805850d
9 changed files with 35 additions and 6 deletions

View File

@@ -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)
@@ -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

View File

@@ -3,4 +3,11 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
if("${IDF_TARGET}" STREQUAL "linux")
list(APPEND EXTRA_COMPONENT_DIRS "../../../../common_components/linux_compat")
endif()
idf_build_set_property(MINIMAL_BUILD ON)
project(broker)

View File

@@ -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"

View File

@@ -8,3 +8,6 @@ dependencies:
rules:
- if: idf_version >=6.0
version: ^1.0.0
espressif/sock_utils:
version: '*'
override_path: '../../../../sock_utils'

View File

@@ -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;

View File

@@ -14,6 +14,7 @@
#include "utlist.h"
#include "lib_load.h"
#include "syslog.h"
#include <limits.h>
#include "sdkconfig.h"
@@ -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

View File

@@ -8,7 +8,7 @@
#include <time.h>
#include "time_mosq.h"
#include "esp_err.h"
#include "esp_timer.h"
void mosquitto_time_init(void)

View File

@@ -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)
@@ -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()

View File

@@ -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