Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Aug 10, 2024
1 parent 1b74730 commit b93af8f
Show file tree
Hide file tree
Showing 15 changed files with 2,206 additions and 2 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Wokwi-CI Build

on: [push, pull_request]

# jobs:
# build:
# strategy:
# fail-fast: false
# matrix:
# target: [esp32, esp32s2, esp32s3, esp32c3, esp32h2, esp32c6, esp32p4]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: espressif/esp-idf-ci-action@v1
# with:
# esp_idf_version: v5.3
# target: ${{ matrix.target }}
# - name: Copy diagram ${{ matrix.target }}
# run: |
# cp .github/workflows/wokwi/diagram-${{ matrix.target }}.json diagram.json
# - uses: wokwi/wokwi-ci-action@v1
# with:
# token: ${{ secrets.WOKWI_CI_TOKEN }}
# timeout: 5000
# expect_text: 'Hello, world from C3!'
8 changes: 8 additions & 0 deletions .github/workflows/wokwi/diagram-esp32.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": 1,
"author": "Juraj Michálek",
"editor": "wokwi",
"parts": [ { "type": "board-esp32-devkit-c-v4", "id": "esp", "top": 0, "left": 0, "attrs": {} } ],
"connections": [ [ "esp:TX", "$serialMonitor:RX", "", [] ], [ "esp:RX", "$serialMonitor:TX", "", [] ] ],
"dependencies": {}
}
16 changes: 16 additions & 0 deletions .github/workflows/wokwi/diagram-esp32c3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": 1,
"author": "Juraj Michálek",
"editor": "wokwi",
"parts": [
{
"type": "board-esp32-c3-devkitm-1",
"id": "esp",
"top": 0,
"left": 0,
"attrs": { "builder": "esp-idf" }
}
],
"connections": [ [ "esp:TX", "$serialMonitor:RX", "", [] ], [ "esp:RX", "$serialMonitor:TX", "", [] ] ],
"dependencies": {}
}
16 changes: 16 additions & 0 deletions .github/workflows/wokwi/diagram-esp32c6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": 1,
"author": "Juraj Michálek",
"editor": "wokwi",
"parts": [
{
"type": "board-esp32-c6-devkitc-1",
"id": "esp",
"top": 0,
"left": 0,
"attrs": { }
}
],
"connections": [ [ "esp:TX", "$serialMonitor:RX", "", [] ], [ "esp:RX", "$serialMonitor:TX", "", [] ] ],
"dependencies": {}
}
16 changes: 16 additions & 0 deletions .github/workflows/wokwi/diagram-esp32h2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": 1,
"author": "Juraj Michálek",
"editor": "wokwi",
"parts": [
{
"type": "board-esp32-h2-devkitm-1",
"id": "esp",
"top": 0,
"left": 0,
"attrs": { "builder": "esp-idf" }
}
],
"connections": [ [ "esp:TX", "$serialMonitor:RX", "", [] ], [ "esp:RX", "$serialMonitor:TX", "", [] ] ],
"dependencies": {}
}
14 changes: 14 additions & 0 deletions .github/workflows/wokwi/diagram-esp32p4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": 1,
"author": "Uri Shaked",
"editor": "wokwi",
"parts": [
{ "type": "board-esp32-p4-preview", "id": "esp", "top": -17.23, "left": -16.04, "attrs": {} }
],
"connections": [
["esp:TX", "$serialMonitor:RX", "", []],
["esp:RX", "$serialMonitor:TX", "", []]
],
"serialMonitor": { "display": "terminal" },
"dependencies": {}
}
8 changes: 8 additions & 0 deletions .github/workflows/wokwi/diagram-esp32s2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": 1,
"author": "Juraj Michálek",
"editor": "wokwi",
"parts": [ { "type": "board-esp32-s2-devkitm-1", "id": "esp", "top": 0, "left": 0, "attrs": {} } ],
"connections": [ [ "esp:TX", "$serialMonitor:RX", "", [] ], [ "esp:RX", "$serialMonitor:TX", "", [] ] ],
"dependencies": {}
}
8 changes: 8 additions & 0 deletions .github/workflows/wokwi/diagram-esp32s3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": 1,
"author": "Juraj Michálek",
"editor": "wokwi",
"parts": [ { "type": "board-esp32-s3-devkitc-1", "id": "esp", "top": 0, "left": 0, "attrs": { "flashSize":"8"} } ],
"connections": [ [ "esp:TX", "$serialMonitor:RX", "", [] ], [ "esp:RX", "$serialMonitor:TX", "", [] ] ],
"dependencies": {}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
build/
build.sh
.vscode/
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(BUILD_PATH ${CMAKE_CURRENT_SOURCE_DIR})
project(c3-sample-idf)
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# esp32-xtensa-c3
Testing C3 lang for esp32 target
# esp32-c3lang

Testing [C3 language](http://www.c3-lang.org/) in esp32 target.

## Requirments
- [esp-idf](https://github.com/espressif/esp-idf)
- [c3c](https://github.com/c3lang/c3c) forked to [espressif/llvm](https://github.com/espressif/llvm-project) backend

## Preview

```bash
# C3 with espressif/llvm 18.1.2
c3c --version
C3 Compiler Version: 0.6.2 (prerelease)
Installed directory: /home/kassane/.local/bin/
LLVM version: 18.1.2
LLVM default target: x86_64-linux-musl
```
![image](https://github.com/user-attachments/assets/b7160ec9-fdb0-4e1a-aa9b-8c365f56d053)
58 changes: 58 additions & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
set(DEPS pthread driver)

idf_component_register(SRCS "placeholder.c"
INCLUDE_DIRS "."
PRIV_REQUIRES "${DEPS}"
)

# Based on zig-esp-idf-sample project

if(CONFIG_IDF_TARGET_ARCH_RISCV)
set(C3_TARGET "elf-riscv32") # generic
# if(CONFIG_IDF_TARGET_ESP32C6 OR CONFIG_IDF_TARGET_ESP32C5 OR CONFIG_IDF_TARGET_ESP32H2)
# set(TARGET_CPU_MODEL "generic_rv32+m+a+c")
# elseif(CONFIG_IDF_TARGET_ESP32P4)
# string(REGEX REPLACE "-none" "-eabihf" C3_TARGET ${C3_TARGET})
# set(TARGET_CPU_MODEL "generic_rv32+m+a+c+f")
# else()
# set(TARGET_CPU_MODEL "generic_rv32+m+c")
# endif()
elseif(CONFIG_IDF_TARGET_ARCH_XTENSA)
set(C3_TARGET "elf-xtensa") # generic
# if(CONFIG_IDF_TARGET_ESP32)
# set(TARGET_CPU_MODEL "esp32")
# elseif(CONFIG_IDF_TARGET_ESP32S2)
# set(TARGET_CPU_MODEL "esp32s2")
# else(CONFIG_IDF_TARGET_ESP32S3)
# set(TARGET_CPU_MODEL "esp32s3")
# endif()
else()
message(FATAL_ERROR "Unsupported target ${CONFIG_IDF_TARGET}")
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(C3_BUILD_TYPE "-g0")
else()
set(C3_BUILD_TYPE "-Oz")
endif()

add_custom_target(c3_build
COMMAND ${CMAKE_COMMAND} -E env
"INCLUDE_DIRS=${include_dirs}"
c3c
--no-entry
--use-stdlib=no
--link-libc=no
static-lib
-o libc3
app.c3
--output-dir ${CMAKE_BINARY_DIR}/lib
${C3_BUILD_TYPE}
--target ${C3_TARGET}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
BYPRODUCTS ${CMAKE_BINARY_DIR}/lib/libc3.a
VERBATIM)

add_prebuilt_library(c3 ${CMAKE_BINARY_DIR}/lib/libc3.a)
add_dependencies(c3 c3_build)
target_link_libraries(${COMPONENT_LIB} PRIVATE ${CMAKE_BINARY_DIR}/lib/libc3.a)
7 changes: 7 additions & 0 deletions main/app.c3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

extern fn int printf(char* format, ...);

fn void app_main() @export("app_main")
{
printf("Hello World C3 language!\n");
}
1 change: 1 addition & 0 deletions main/placeholder.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// empty file
Loading

0 comments on commit b93af8f

Please sign in to comment.