Skip to content

Commit

Permalink
Merge pull request #12 from couchbaselabs/ESP32
Browse files Browse the repository at this point in the history
ESP32 embedded platform support
  • Loading branch information
snej authored Oct 24, 2023
2 parents 3431c37 + 6388a5a commit 19594f3
Show file tree
Hide file tree
Showing 111 changed files with 5,346 additions and 1,154 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
branches: [ main ]

env:
DEVELOPER_DIR: /Applications/Xcode_15.0.app/Contents/Developer

jobs:
build:
name: Build and test
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
libs/
build_cmake/
sdkconfig.old
25 changes: 16 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ else()
-Werror
-Wall
-Wpedantic
-Wno-assume # Lots of bogus "argument to '__builtin_assume' has side effects"
-Wno-unknown-pragmas
-Wno-unknown-warning-option
)
Expand Down Expand Up @@ -110,31 +111,37 @@ add_library( LibCrouton STATIC
src/Coroutine.cc
src/Error.cc
src/Future.cc
src/Logging.cc
src/Scheduler.cc
src/Select.cc

src/io/AddrInfo.cc
src/io/FileStream.cc
src/io/Filesystem.cc
src/io/HTTPConnection.cc
src/io/HTTPHandler.cc
src/io/HTTPParser.cc
src/io/ISocket.cc
src/io/IStream.cc
src/io/Pipe.cc
src/io/Process.cc
src/io/Stream.cc
src/io/TCPServer.cc
src/io/TCPSocket.cc
src/io/URL.cc
src/io/UVBase.cc
src/io/WebSocket.cc

src/io/mbed/TLSSocket.cc

src/io/uv/AddrInfo.cc
src/io/uv/FileStream.cc
src/io/uv/Filesystem.cc
src/io/uv/Pipe.cc
src/io/uv/Stream.cc
src/io/uv/TCPServer.cc
src/io/uv/TCPSocket.cc

src/io/uv/UVBase.cc

src/support/Backtrace.cc
src/support/Backtrace+Unix.cc
src/support/Backtrace+Windows.cc
src/support/betterassert.cc
src/support/Memoized.cc
src/support/Logging.cc
src/support/MiniFormat.cc
src/support/StringUtils.cc
)

Expand Down
22 changes: 22 additions & 0 deletions ESP32/hello_world/pytest_hello_world.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0

from typing import Callable

import pytest
from pytest_embedded_idf.dut import IdfDut
from pytest_embedded_qemu.dut import QemuDut


@pytest.mark.supported_targets
@pytest.mark.generic
def test_hello_world(dut: IdfDut, log_minimum_free_heap_size: Callable[..., None]) -> None:
dut.expect('Hello world!')
log_minimum_free_heap_size()


@pytest.mark.esp32 # we only support qemu on esp32 for now
@pytest.mark.host_test
@pytest.mark.qemu
def test_hello_world_host(dut: QemuDut) -> None:
dut.expect('Hello world!')
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ xcode_deps: debug release
mkdir -p build_cmake/release/xcodedeps
cp build_cmake/release/vendor/libuv/libuv*.a build_cmake/release/xcodedeps/
cp build_cmake/release/vendor/mbedtls/library/libmbed*.a build_cmake/release/xcodedeps/

esp:
cd tests/ESP32 && idf.py build

esptest:
cd tests/ESP32 && idf.py build flash monitor
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Crouton

Crouton is a C++20 coroutine runtime library that provides some general purpose utilities, as well as cross-platform event loops, I/O and networking based on the [libuv][LIBUV], [mbedTLS][MBEDTLS] and [llhttp][LLHTTP] libraries. (On Apple platforms it can also use the system Network.framework.)
**Crouton** is a C++20 coroutine runtime library that provides some general purpose concurrency utilities, as well as cross-platform event loops, I/O and networking that work the same way on Mac, Linux, Windows and ESP32 microcontrollers.

The cross-platform support is based on the widely-used [libuv][LIBUV], [mbedTLS][MBEDTLS] and [llhttp][LLHTTP] libraries. (On Apple platforms it can also use the system Network.framework. On [ESP32][ESP32], where libuv is not supported, it uses lwip and FreeRTOS APIs instead.)

A **Coroutine** is _a function that can return partway through, and then later be resumed where it left off._ Knuth wrote about them in the 1960s and they remained a curiosity for a long time, but they've since become widely used under the hood of the "async / await" concurrency model used in languages like JavaScript, C#, Rust, Nim, and Swift. Crouton brings this to C++.

Expand Down Expand Up @@ -53,15 +55,15 @@ How is that better than threads? It's safer and easier to reason about. The only

* Core classes & APIs:
* General-purpose `Error` and `Result<T>` types
* Logging, a thin wrapper around [spdlog][SPDLOG]
* Logging uses either a thin wrapper around [spdlog][SPDLOG], or a smaller compatible library I wrote.

* Cross-Platform:
* macOS (builds and passes tests)
* iOS? ("It's still Darwin…")
* Linux (builds and passes test)
* Android? ("It's still Linux…")
* [ESP32][ESP32] embedded CPUs (builds and passes tests. File APIs not available yet.)
* Windows (sometimes builds; not yet tested; help wanted!)
* Would very much like to support some embedded platforms like ESP32 (help wanted!)

## Example

Expand All @@ -86,11 +88,13 @@ cout << endl;
See also [demo_server.cc](tests/demo_server.cc), a simple HTTP and WebSocket server.
An example embedded app is at [tests/ESP32](tests/ESP32/README.md).
## Status: ☠️EXPERIMENTAL☠️
[![Build](https://github.com/couchbaselabs/crouton/actions/workflows/build.yml/badge.svg)](https://github.com/couchbaselabs/crouton/actions/workflows/build.yml)
This is new code, under heavy development! So far, it builds with Clang (Xcode 14) on macOS, GCC 12 on Ubuntu, and Visual Studio 17 2022 on Windows.
This is new code, under heavy development! So far, it builds with Clang (Xcode 15) on macOS, GCC 12 on Ubuntu, Visual Studio 17 2022 on Windows, and ESP-IDF 5.0.
The tests run regularly on macOS, and occasionally on Ubuntu (though not in CI.) Test coverage is very limited.
Expand All @@ -104,12 +108,12 @@ APIs are still in flux. Things get refactored a lot.
### Prerequisites:
- CMake
- Clang 15, Xcode 14, or GCC 12
- Clang 15, Xcode 15, or GCC 12
- zlib (aka libz)
#### on macOS:
- Install Xcode 14 or later, or at least the command-line tools.
- Install Xcode 15 or later, or at least the command-line tools.
- Install CMake; this is most easily done with [HomeBrew](https://brew.sh), by running `brew install cmake`
#### on Ubuntu Linux
Expand All @@ -123,7 +127,7 @@ APIs are still in flux. Things get refactored a lot.
The library is `libCrouton`, in either the `build_cmake/debug/` or `build_cmake/release/` directory.
### Building With Xcode
### Building With Xcode 15+
**Before first building with Xcode**, you must use CMake to build libuv and mbedTLS:
Expand All @@ -136,6 +140,9 @@ Then:
- Select the `Tests` scheme and Run.
- To locate the binaries, choose Product > Show Build Folder In Finder
### Building For ESP32 Embedded Systems
The ESP-IDF component is at `src/io/esp32`; please see the [README](src/io/esp32/README.md) for details. A demo app is at [tests/ESP32](tests/ESP32/README.md).
## License(s)
Expand Down Expand Up @@ -171,3 +178,4 @@ Then:
[BAKER]: https://lewissbaker.github.io/2022/08/27/understanding-the-compiler-transform
[BSL]: src/io/blip/licences/BSL.txt
[BLIP]: src/io/blip/README.md
[ESP32]: https://www.espressif.com
Loading

0 comments on commit 19594f3

Please sign in to comment.