Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling building of GCC platform as a standalone shared library with no dependencies on e.g. Boost #2370

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
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
7 changes: 3 additions & 4 deletions build/arm-tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ endif
CFLAGS += --specs=nano.specs

# Check if the compiler version is the minimum required
version_to_number=$(shell v=$1; v=($${v//./ }); echo $$((v[0] * 10000 + v[1] * 100 + v[2])))
get_major_version=$(shell v=$1; v=($${v//./ }); echo $${v[0]})
arm_gcc_version_str:=$(shell $(CC) -dumpversion)
arm_gcc_version:=$(call version_to_number,$(arm_gcc_version_str))
include $(COMMON_BUILD)/gcc-version.mk
arm_gcc_version_str:=$(gcc_version_str)
arm_gcc_version:=$(gcc_version)
expected_version_str:=10.2.1
ifeq ($(shell test $(arm_gcc_version) -lt $(call version_to_number,$(expected_version_str)); echo $$?),0)
$(error "ARM gcc version $(expected_version_str) or later required, but found $(arm_gcc_version_str)")
Expand Down
6 changes: 5 additions & 1 deletion build/gcc-tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ CFLAGS += -Wno-return-type-c-linkage
CPPFLAGS += -Wno-unused-private-field
endif

ifeq ($(BUILD_STANDALONE_LIB),y)
CFLAGS += -fPIC -fpic -rdynamic -fno-plt
LDFLAGS += -fPIC -fpic -rdynamic -fno-plt
endif


include $(COMMON_BUILD)/gcc-version.mk
4 changes: 4 additions & 0 deletions build/gcc-version.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version_to_number=$(shell v=$1; v=($${v//./ }); echo $$((v[0] * 10000 + v[1] * 100 + v[2])))
get_major_version=$(shell v=$1; v=($${v//./ }); echo $${v[0]})
gcc_version_str:=$(shell $(CC) -dumpfullversion)
gcc_version:=$(call version_to_number,$(arm_gcc_version_str))
22 changes: 19 additions & 3 deletions build/module-defaults.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ START_DFU_FLASHER_SERIAL_SPEED=14400
START_YMODEM_FLASHER_SERIAL_SPEED=28800

include $(COMMON_BUILD)/version.mk
include $(COMMON_BUILD)/os.mk
include $(COMMON_BUILD)/gcc-version.mk

QUOTE='

Expand Down Expand Up @@ -61,9 +63,12 @@ CFLAGS += -Wno-error=type-limits
CFLAGS += -fno-strict-aliasing
CFLAGS += -DSPARK=1 -DPARTICLE=1
CFLAGS += -Werror=return-type

CFLAGS += -Wundef

ifeq ($(shell test $(gcc_version) -lt $(call version_to_number,"11.0.0"); echo $$?),0)
CFLAGS += -Wno-error=cast-function-type
endif

ifdef START_DFU_FLASHER_SERIAL_SPEED
CFLAGS += -DSTART_DFU_FLASHER_SERIAL_SPEED=$(START_DFU_FLASHER_SERIAL_SPEED)
endif
Expand All @@ -76,6 +81,10 @@ CONLYFLAGS += -Wno-pointer-sign
LDFLAGS += $(LIBS_EXT)
LDFLAGS += $(patsubst %,-L%,$(LIB_DIRS))

ifeq ($(BUILD_STANDALONE_LIB),y)
CFLAGS += -DPARTICLE_BUILD_STANDALONE_LIB
endif

ifeq ($(PLATFORM_ID),6)
CFLAGS += -DBOOTLOADER_SDK_3_3_0_PARTICLE -DPARTICLE_DCT_COMPATIBILITY
endif
Expand Down Expand Up @@ -115,7 +124,7 @@ LTO_EXT = -lto
CFLAGS += -DPARTICLE_COMPILE_LTO
endif

ifeq ("$(TARGET_TYPE)","a")
ifneq (,$(filter $(TARGET_TYPE),a so))
TARGET_FILE_PREFIX = lib
endif

Expand All @@ -134,4 +143,11 @@ BUILD_PATH ?= $(BUILD_PATH_BASE)/$(MODULE)$(and $(BUILD_PATH_EXT),/$(BUILD_PATH_
BUILD_TARGET_PLATFORM = platform-$(PLATFORM_ID)$(MODULAR_EXT)$(LTO_EXT)
BUILD_PATH_EXT ?= $(BUILD_TARGET_PLATFORM)

EXECUTABLE_EXTENSION=
EXECUTABLE_EXTENSION=
ifeq ($(MAKE_OS),WINDOWS)
SHARED_LIBRARY_EXTENSION ?= .dll
else ifeq ($(MAKE_OS),LINUX)
SHARED_LIBRARY_EXTENSION ?= .so
else ifeq ($(MAKE_OS),OSX)
SHARED_LIBRARY_EXTENSION ?= .dylib
endif
9 changes: 9 additions & 0 deletions build/module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ hex: $(TARGET_BASE).hex
lst: $(TARGET_BASE).lst
exe: $(TARGET_BASE)$(EXECUTABLE_EXTENSION)
@echo Built x-compile executable at $(TARGET_BASE)$(EXECUTABLE_EXTENSION)
so: $(TARGET_BASE)$(SHARED_LIBRARY_EXTENSION)
@echo Built shared library at $(TARGET_BASE)$(SHARED_LIBRARY_EXTENSION)
none:
;

Expand Down Expand Up @@ -239,6 +241,13 @@ $(TARGET_BASE)$(EXECUTABLE_EXTENSION) : $(ALLOBJ) $(LIB_DEPS) $(LINKER_DEPS)
$(VERBOSE)$(CCACHE) $(CPP) $(CFLAGS) $(ALLOBJ) --output $@ $(LDFLAGS)
$(call echo,)

$(TARGET_BASE)$(SHARED_LIBRARY_EXTENSION) : $(ALLOBJ) $(LIB_DEPS) $(LINKER_DEPS)
$(call echo,'Building target: $@')
$(call echo,'Invoking: GCC C++ Linker')
$(VERBOSE)$(MKDIR) $(dir $@)
$(VERBOSE)$(CCACHE) $(CPP) $(CFLAGS) -shared $(ALLOBJ) --output $@ $(LDFLAGS)
$(call echo,)


# Tool invocations
$(TARGET_BASE).a : $(ALLOBJ)
Expand Down
6 changes: 5 additions & 1 deletion hal/src/gcc/include.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ ifneq (,$(findstring hal,$(MAKE_DEPENDENCIES)))

LDFLAGS += -lc


# Building as a standalone static library with default
# template implementations and no dependency on boost or
# other external libraries
ifneq ($(BUILD_STANDALONE_LIB),y)
# additional libraries required by gcc build
ifdef SYSTEMROOT
LIBS += boost_system-mgw48-mt-1_57 ws2_32 wsock32
Expand All @@ -23,6 +26,7 @@ endif
LIBS += boost_program_options boost_random boost_thread

LIB_DIRS += $(BOOST_ROOT)/stage/lib
endif # $(BUILD_STANDALONE_LIB),y

# gcc HAL is different for test driver and test subject
ifeq "$(SPARK_TEST_DRIVER)" "1"
Expand Down
7 changes: 7 additions & 0 deletions hal/src/gcc/sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ CPPFLAGS += -DBOOST_ASIO_SEPARATE_COMPILATION

# use the boost libraries
$(info "BOOST $(BOOST_ROOT)")
ifneq ("$(BOOST_ROOT)","")
INCLUDE_DIRS += $(BOOST_ROOT)
INCLUDE_DIRS += $(BOOST_ROOT)/libs/asio/include
endif

HAL_SRC_TEMPLATE_PATH = $(TARGET_HAL_PATH)/src/template
HAL_SRC_GCC_PATH = $(TARGET_HAL_PATH)/src/gcc
Expand All @@ -29,11 +31,16 @@ remove_cpp = $(addsuffix .cpp,$(addprefix $(templatedir)/,$(overrides)))
# remove files from template that have the same basename as an overridden file
# e.g. if template contains core_hal.c, and gcc contains core_hal.cpp, the gcc module
# will override
ifneq ($(BUILD_STANDALONE_LIB),y)
# Not using gcc-specific sources if building as a standalone static library
# with template implementations and no dependency on boost or
# other external libraries
CSRC := $(filter-out $(remove_c),$(CSRC))
CPPSRC := $(filter-out $(remove_cpp),$(CPPSRC))

CSRC += $(call target_files,$(overridedir)/,*.c)
CPPSRC += $(call target_files,$(overridedir)/,*.cpp)
endif # ($(BUILD_STANDALONE_LIB),y)

CPPSRC += $(call target_files,$(HAL_MODULE_PATH)/network/util/,*.cpp)

Expand Down
222 changes: 222 additions & 0 deletions hal/src/template/concurrent_hal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
/*
* Copyright (c) 2021 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#include "concurrent_hal.h"

os_result_t os_thread_create(os_thread_t* thread, const char* name, os_thread_prio_t priority, os_thread_fn_t fun, void* thread_param, size_t stack_size)
{
return 0;
}

os_thread_t os_thread_current(void* reserved)
{
return nullptr;
}

bool os_thread_is_current(os_thread_t thread)
{
return false;
}

os_result_t os_thread_yield(void)
{
return 0;
}

bool os_thread_current_within_stack()
{
return true;
}

os_result_t os_thread_join(os_thread_t thread)
{
return 0;
}

os_result_t os_thread_exit(os_thread_t thread)
{
return 0;
}

os_result_t os_thread_cleanup(os_thread_t thread)
{
return 0;
}

os_result_t os_thread_delay_until(system_tick_t *previousWakeTime, system_tick_t timeIncrement)
{
return 0;
}

os_thread_notify_t os_thread_wait(system_tick_t ms, void* reserved)
{
return 0;
}

int os_thread_notify(os_thread_t thread, void* reserved)
{
return 0;
}

int os_queue_create(os_queue_t* queue, size_t item_size, size_t item_count, void*)
{
return 0;
}

int os_queue_put(os_queue_t queue, const void* item, system_tick_t delay, void*)
{
return 0;
}

int os_queue_take(os_queue_t queue, void* item, system_tick_t delay, void*)
{
return 0;
}

int os_queue_peek(os_queue_t queue, void* item, system_tick_t delay, void*)
{
return 0;
}

int os_queue_destroy(os_queue_t queue, void*)
{
return 0;
}

int os_mutex_create(os_mutex_t* mutex)
{
return 0;
}

int os_mutex_destroy(os_mutex_t mutex)
{
return 0;
}

int os_mutex_lock(os_mutex_t mutex)
{
return 0;
}

int os_mutex_trylock(os_mutex_t mutex)
{
return 0;
}

int os_mutex_unlock(os_mutex_t mutex)
{
return 0;
}

int os_mutex_recursive_create(os_mutex_recursive_t* mutex)
{
return 0;
}

int os_mutex_recursive_destroy(os_mutex_recursive_t mutex)
{
return 0;
}

int os_mutex_recursive_lock(os_mutex_recursive_t mutex)
{
return 0;
}

int os_mutex_recursive_trylock(os_mutex_recursive_t mutex)
{
return 0;
}

int os_mutex_recursive_unlock(os_mutex_recursive_t mutex)
{
return 0;
}

void os_thread_scheduling(bool enabled, void* reserved)
{
}

os_scheduler_state_t os_scheduler_get_state(void* reserved)
{
return OS_SCHEDULER_STATE_NOT_STARTED;
}

int os_semaphore_create(os_semaphore_t* semaphore, unsigned max, unsigned initial)
{
return 0;
}

int os_semaphore_destroy(os_semaphore_t semaphore)
{
return 0;
}

int os_semaphore_take(os_semaphore_t semaphore, system_tick_t timeout, bool reserved)
{
return 0;
}

int os_semaphore_give(os_semaphore_t semaphore, bool reserved)
{
return 0;
}

/**
* Create a new timer. Returns 0 on success.
*/
int os_timer_create(os_timer_t* timer, unsigned period, void (*callback)(os_timer_t timer), void* const timer_id, bool one_shot, void* reserved)
{
return 0;
}

int os_timer_get_id(os_timer_t timer, void** timer_id)
{
return 0;
}

int os_timer_set_id(os_timer_t timer, void* timer_id)
{
return 0;
}

int os_timer_change(os_timer_t timer, os_timer_change_t change, bool fromISR, unsigned period, unsigned block, void* reserved)
{
return 0;
}

int os_timer_destroy(os_timer_t timer, void* reserved)
{
return 0;
}

int os_timer_is_active(os_timer_t timer, void* reserved)
{
return 0;
}

void __flash_acquire() {
}

void __flash_release() {
}

void periph_lock() {
}

void periph_unlock() {
}
Loading