Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install devscripts build-essential lintian libjson-c-dev debhelper-compat debhelper cmake
sudo apt install devscripts build-essential lintian libjson-c-dev debhelper-compat debhelper cmake libffi-dev

- name: Build package
run: |
Expand Down
55 changes: 55 additions & 0 deletions .opencode/skills/ucode/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
name: ucode
description: Build, test, and execute ucode programs using cmake, the ucode compiler, and the custom test suite
metadata:
audience: developers
workflow: development
---

## What I do

I handle the common workflows for working with the ucode scripting language project: building from source, running tests, and executing ucode with libraries.

## Build

Configure the build (run this first if CMake files changed):
```bash
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
```

Compile:
```bash
make -C build
```

## Test

Run the entire test suite:
```bash
./tests/custom/run_tests.uc
```

Run tests in a specific directory (note the trailing wildcard pattern):
```bash
./tests/custom/run_tests.uc tests/custom/17_lib_ffi/*
```

## Execute

Run a ucode snippet with a loaded library:
```bash
./build/ucode -L build -l ffi -e 'print(ffi.C.dlsym("size_t"))'
```

Key flags:
- `-L <path>` — prepend path to library search directory
- `-l <name>` — preload a library (e.g. `ffi`, `json`, `uci`)
- `-e '<expr>'` — execute an expression inline

## When to use me

Use this skill when the user wants to:
- Build or rebuild the ucode project
- Run the test suite (all or specific subdirectories)
- Execute ucode code snippets with or without loading custom libraries
- Debug ucode issues by running code interactively
31 changes: 31 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ project(ucode C)

add_library(uc_defines INTERFACE)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckCSourceCompiles)
Expand Down Expand Up @@ -76,6 +78,7 @@ find_library(libubus NAMES ubus)
find_library(libblobmsg_json NAMES blobmsg_json)
find_package(ZLIB)
find_library(libmd NAMES libmd.a md)
find_library(libffi NAMES ffi)

if(LINUX)
find_library(libnl_tiny NAMES nl-tiny)
Expand Down Expand Up @@ -105,10 +108,15 @@ if(libmd)
set(DEFAULT_DIGEST_SUPPORT ON)
endif()

if(libffi)
set(DEFAULT_FFI_SUPPORT ON)
endif()

option(DEBUG_SUPPORT "Debug plugin support" ON)
option(FS_SUPPORT "Filesystem plugin support" ON)
option(IO_SUPPORT "IO plugin support" ON)
option(MATH_SUPPORT "Math plugin support" ON)
option(FFI_SUPPORT "FFI module support" ${DEFAULT_FFI_SUPPORT})
option(UBUS_SUPPORT "Ubus plugin support" ${DEFAULT_UBUS_SUPPORT})
option(UCI_SUPPORT "UCI plugin support" ${DEFAULT_UCI_SUPPORT})
option(RTNL_SUPPORT "Route Netlink plugin support" ${DEFAULT_NL_SUPPORT})
Expand Down Expand Up @@ -407,6 +415,29 @@ if(DIGEST_SUPPORT)
target_link_libraries(digest_lib ${libmd})
endif()

if(FFI_SUPPORT)
pkg_check_modules(LIBFFI REQUIRED libffi)
include_directories(${LIBFFI_INCLUDE_DIRS})
set(LIBRARIES ${LIBRARIES} ffi_lib)
add_library(ffi_lib MODULE lib/ffi/uc_cparse.c lib/ffi/uc_ctype.c lib/ffi/uc_cconv.c lib/ffi/uc_cdata.c lib/ffi/ffi.c)
set_target_properties(ffi_lib PROPERTIES OUTPUT_NAME ffi PREFIX "")

set(CMAKE_REQUIRED_INCLUDES ${LIBFFI_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${LIBFFI_LIBRARIES})

check_c_source_compiles("
#include <ffi.h>
int main() { return FFI_BAD_ARGTYPE; }
" HAVE_FFI_BAD_ARGTYPE)

if(HAVE_FFI_BAD_ARGTYPE)
target_compile_definitions(ffi_lib PRIVATE HAVE_FFI_BAD_ARGTYPE)
endif()

target_link_options(ffi_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS})
target_link_libraries(ffi_lib ${LIBFFI_LINK_LIBRARIES})
endif()

if(UNIT_TESTING)
enable_testing()
add_compile_definitions( UNIT_TESTING )
Expand Down
Loading
Loading