diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 9727a2b3a4..49210130f6 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -111,6 +111,33 @@ jobs: cache-from: type=registry,ref=toxchat/c-toxcore:wasm cache-to: type=inline + docker-esp32: + runs-on: ubuntu-latest + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + with: + driver: docker + - name: Login to DockerHub + if: ${{ github.event_name == 'push' }} + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build toxchat/c-toxcore:sources + uses: docker/build-push-action@v2 + with: + file: other/docker/sources/Dockerfile + tags: toxchat/c-toxcore:sources + - name: Build and push + uses: docker/build-push-action@v2 + with: + file: other/docker/esp32/Dockerfile + push: ${{ github.event_name == 'push' }} + tags: toxchat/c-toxcore:esp32 + cache-from: type=registry,ref=toxchat/c-toxcore:esp32 + cache-to: type=inline + docker-win32: runs-on: ubuntu-latest steps: diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 5df2d65f0e..a6b29d73f0 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -b3fb4157d7fc6cd3455f40020bb6b69e5bab4bbdb6ce66d5bc7095146ba5a49e /usr/local/bin/tox-bootstrapd +4e6c181b03e20cdd0669296fae53a9433e31a7c37beed5430272fbefbf501bbb /usr/local/bin/tox-bootstrapd diff --git a/other/docker/esp32/CMakeLists.txt b/other/docker/esp32/CMakeLists.txt new file mode 100644 index 0000000000..b113a286b2 --- /dev/null +++ b/other/docker/esp32/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(toxcore) diff --git a/other/docker/esp32/Dockerfile b/other/docker/esp32/Dockerfile new file mode 100644 index 0000000000..9b6ad76c34 --- /dev/null +++ b/other/docker/esp32/Dockerfile @@ -0,0 +1,48 @@ +FROM toxchat/c-toxcore:sources AS src +FROM ubuntu:18.04 + +RUN apt-get update && \ + DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \ + bison \ + ccache \ + cmake \ + flex \ + git \ + gperf \ + libncurses-dev \ + ninja-build \ + python \ + python-cryptography \ + python-future \ + python-pip \ + python-pyparsing \ + python-serial \ + python-setuptools \ + wget \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +ENV ESP32_TARBALL=xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0 \ + IDF_PATH="/root/esp/esp-idf" \ + PATH="/root/esp/esp-idf/tools:/root/esp/xtensa-esp32-elf/bin:$PATH" +WORKDIR /root/esp +RUN wget -q https://dl.espressif.com/dl/$ESP32_TARBALL.tar.gz \ + && tar zxf $ESP32_TARBALL.tar.gz \ + && rm -f $ESP32_TARBALL.tar.gz \ + && git clone -b v3.3 --recursive --depth=1 --shallow-submodules https://github.com/espressif/esp-idf + +# Build a hello world first, so the OS and libsodium etc. are compiled. +WORKDIR /root/esp/toxcore +COPY other/docker/esp32/CMakeLists.txt /root/esp/toxcore/ +COPY other/docker/esp32/hello/ /root/esp/toxcore/main/ +RUN idf.py build + +# Then copy over the actual toxcore sources and build those. +COPY --from=src /src/third_party/cmp/ /root/esp/toxcore/main/third_party/cmp/ +COPY --from=src /src/toxencryptsave/defines.h /root/esp/toxcore/main/toxencryptsave/ +COPY --from=src /src/toxcore/ /root/esp/toxcore/main/toxcore/ +COPY other/docker/esp32/toxcore/CMakeLists.txt /root/esp/toxcore/main/ +COPY other/docker/esp32/toxcore/toxcore_main.cc /root/esp/toxcore/main/other/docker/esp32/main/ +RUN idf.py build +RUN ls -lh build/toxcore.bin \ + && shasum build/toxcore.bin diff --git a/other/docker/esp32/hello/CMakeLists.txt b/other/docker/esp32/hello/CMakeLists.txt new file mode 100644 index 0000000000..0a8bbce165 --- /dev/null +++ b/other/docker/esp32/hello/CMakeLists.txt @@ -0,0 +1,4 @@ +set(COMPONENT_SRCS "hello_main.c") +set(COMPONENT_ADD_INCLUDEDIRS "") + +register_component() diff --git a/other/docker/esp32/hello/hello_main.c b/other/docker/esp32/hello/hello_main.c new file mode 100644 index 0000000000..1c961d6cdf --- /dev/null +++ b/other/docker/esp32/hello/hello_main.c @@ -0,0 +1,6 @@ +#include + +void app_main(void) +{ + printf("Hello world!\n"); +} diff --git a/other/docker/esp32/run b/other/docker/esp32/run new file mode 100755 index 0000000000..c611413f3d --- /dev/null +++ b/other/docker/esp32/run @@ -0,0 +1,4 @@ +#!/bin/sh + +docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile . +docker build -t toxchat/c-toxcore:esp32 -f other/docker/esp32/Dockerfile . diff --git a/other/docker/esp32/toxcore/CMakeLists.txt b/other/docker/esp32/toxcore/CMakeLists.txt new file mode 100644 index 0000000000..0b844e5e96 --- /dev/null +++ b/other/docker/esp32/toxcore/CMakeLists.txt @@ -0,0 +1,12 @@ +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-field-initializers") + +file(GLOB toxcore_SRCS "toxcore/*.[ch]" "toxcore/*/*.[ch]") +set(COMPONENT_SRCS + ${toxcore_SRCS} + other/docker/esp32/main/toxcore_main.cc + third_party/cmp/cmp.c + third_party/cmp/cmp.h + toxencryptsave/defines.h) +set(COMPONENT_ADD_INCLUDEDIRS "") + +register_component() diff --git a/other/docker/esp32/toxcore/toxcore_main.cc b/other/docker/esp32/toxcore/toxcore_main.cc new file mode 100644 index 0000000000..0ddec81a22 --- /dev/null +++ b/other/docker/esp32/toxcore/toxcore_main.cc @@ -0,0 +1,14 @@ +#include + +#include "../../../../toxcore/ccompat.h" +#include "../../../../toxcore/tox.h" +#include "../../../../toxcore/tox_events.h" + +extern "C" void app_main(void) +{ + printf("Hello Tox!\n"); + + Tox *tox = tox_new(nullptr, nullptr); + tox_events_free(tox_events_iterate(tox, true, nullptr)); + tox_kill(tox); +} diff --git a/toxcore/mono_time.c b/toxcore/mono_time.c index 176dbf17e5..df64f2246c 100644 --- a/toxcore/mono_time.c +++ b/toxcore/mono_time.c @@ -44,8 +44,10 @@ struct Mono_Time { bool last_clock_update; #endif +#ifndef ESP_PLATFORM /* protect `time` from concurrent access */ pthread_rwlock_t *time_update_lock; +#endif mono_time_current_time_cb *current_time_callback; void *user_data; @@ -128,6 +130,7 @@ Mono_Time *mono_time_new(mono_time_current_time_cb *current_time_callback, void return nullptr; } +#ifndef ESP_PLATFORM mono_time->time_update_lock = (pthread_rwlock_t *)calloc(1, sizeof(pthread_rwlock_t)); if (mono_time->time_update_lock == nullptr) { @@ -140,6 +143,7 @@ Mono_Time *mono_time_new(mono_time_current_time_cb *current_time_callback, void free(mono_time); return nullptr; } +#endif mono_time_set_current_time_callback(mono_time, current_time_callback, user_data); @@ -177,8 +181,10 @@ void mono_time_free(Mono_Time *mono_time) #ifdef OS_WIN32 pthread_mutex_destroy(&mono_time->last_clock_lock); #endif +#ifndef ESP_PLATFORM pthread_rwlock_destroy(mono_time->time_update_lock); free(mono_time->time_update_lock); +#endif free(mono_time); } @@ -196,9 +202,13 @@ void mono_time_update(Mono_Time *mono_time) pthread_mutex_unlock(&mono_time->last_clock_lock); #endif +#ifndef ESP_PLATFORM pthread_rwlock_wrlock(mono_time->time_update_lock); +#endif mono_time->cur_time = cur_time; +#ifndef ESP_PLATFORM pthread_rwlock_unlock(mono_time->time_update_lock); +#endif } uint64_t mono_time_get(const Mono_Time *mono_time) @@ -207,9 +217,13 @@ uint64_t mono_time_get(const Mono_Time *mono_time) // Fuzzing is only single thread for now, no locking needed */ return mono_time->cur_time; #else +#ifndef ESP_PLATFORM pthread_rwlock_rdlock(mono_time->time_update_lock); +#endif const uint64_t cur_time = mono_time->cur_time; +#ifndef ESP_PLATFORM pthread_rwlock_unlock(mono_time->time_update_lock); +#endif return cur_time; #endif } diff --git a/toxcore/network.c b/toxcore/network.c index c6cb60bbc0..10252a9e09 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -370,7 +370,12 @@ IP4 get_ip4_loopback(void) IP6 get_ip6_loopback(void) { IP6 loopback; +#ifdef ESP_PLATFORM + loopback = empty_ip_port.ip.ip.v6; + loopback.uint8[15] = 1; +#else get_ip6(&loopback, &in6addr_loopback); +#endif return loopback; } @@ -1196,6 +1201,7 @@ Networking_Core *new_networking_ex( LOGGER_ERROR(log, "Dual-stack socket failed to enable, won't be able to receive from/send to IPv4 addresses"); } +#ifndef ESP_PLATFORM /* multicast local nodes */ struct ipv6_mreq mreq; memset(&mreq, 0, sizeof(mreq)); @@ -1216,6 +1222,7 @@ Networking_Core *new_networking_ex( } net_kill_strerror(strerror); +#endif } /* A hanging program or a different user might block the standard port.