summaryrefslogtreecommitdiffhomepage
path: root/CMakeLists.txt
AgeCommit message (Collapse)Author
2024-06-18lib: introduce zlib libraryThibaut VARÈNE
Introduce a new "zlib" library which provides simplified bindings for zlib inflate/deflate operations. Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
2024-05-02ubus: fix uc_ubus_have_uloop for eloop+uloop combinationFelix Fietkau
When uloop has been integrated with eloop (in hostapd/wpa_supplicant), uloop_cancelling will return false, since uloop_run is not being called. This leads to ubus.defer() calling uloop_run in a context where it can prevent the other event loop from running. Fix this by detecting event loop integration via uloop_fd_set_cb being set Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-04-24build: fix symbol and library detectionJo-Philipp Wich
Do not unset CMAKE_REQUIRED_* variables in order to allow various feature tests to work properly with nonstandard locations. Fixes: #186 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-04-24lib: introduce socket libraryJo-Philipp Wich
Introduce a new socket module which provides bindings for the BSD sockets API to ucode scripts. Example usage: import * as socket from 'socket'; let sk = socket.create(socket.AF_INET, socket.SOCK_STREAM); sk.connect("192.168.1.1", 80); sk.send("GET / HTTP/1.0\r\n\r\n"); print(sk.recv(4096)); sk.close(); Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-11-03uloop: support new interval and signal APIsJo-Philipp Wich
Add bindings for the new uloop interval and signal handling APIs and extend the CMake logic to properly detect the presence of these facilities. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-11-02build: avoid redefining _FORTIFY_SOURCEJo-Philipp Wich
Check if `-D_FORTIFY_SOURCE` was already passed via the CFLAGS environment variable and only add the flag if not already present. Fixes: ea046bd ("build: enable source fortification by default") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-11-01build: enable source fortification by defaultJo-Philipp Wich
Also switch debug builds to -Og instead of -O0 in order to make -D_FORTIFY_SOURCE=2 effective for debug builds. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-10lib: introduce log libraryJo-Philipp Wich
Introduce a new `log` library which provides bindings for syslog and, if available, the OpenWrt libubox ulog functions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-10build: auto-enable module depending on present librariesJo-Philipp Wich
Decide based upon the found libraries whether to enable certain, OpenWrt specific modules by default. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-10build: convert CMakeLists.txt into lowercaseJo-Philipp Wich
Convert cmake directives into lowercase notation for better readability. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-08-09lib: introduce debug libraryJo-Philipp Wich
Introduce a new debug library which provides introspection facilities for debugging ucode scripts. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-08-09treewide: consolidate platform specific code in platform.cJo-Philipp Wich
Get rid of most __APPLE__ guards by introducing a central platform.c unit providing drop-in replacements for missing APIs. Also move system signal definitions into the new platform file to be able to share them with the upcoming debug library. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-03-17ucode: also link libresolv if ns_initparse() is not foundJo-Philipp Wich
Recent glibc versions require linking libresolv to obtain ns_initparse(). Fixes: #144 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-01-31rtnl: add support for registering an uloop based listenerFelix Fietkau
Similar to nl80211 uloop listener Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-01-19nl80211: add support for registering an uloop based listenerFelix Fietkau
Can be used to capture nl80211 messages in an event driven program Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-01-06build: make rtnl/nl80211 depend on linux instead of !APPLEFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2022-09-09ubus: add toplevel constants for ubus status codesJo-Philipp Wich
Add constants for ubus status codes to the toplevel module scope in order to avoid the need for magic values in the code. Suggested-by: Felix Fietkau <nbd@nbd.name> Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-31build: remove legacy json-c checkJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-31build: add polyfills for older libjson-c versionsJo-Philipp Wich
The libjson-c versions commonly shipped by Debian and Ubuntu lack unsigned 64bit integer support and a number of extended API functions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-23build: fix symlink install targetJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-22build: only stage ucc symlink if compile support is enabledJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-21main: turn ucode into multicall executableJo-Philipp Wich
Turn the ucode executable into a multicall binary and select default flags based on the name it was invoked with. Introduce two new symlinks "ucc" and "utpl" which start ucode in compile and template mode respectively. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-15build: consolidate CMakeLists.txt and cover OS X deviationsJo-Philipp Wich
- Add OS X specific linker flags - Default disable Linux specific modules on OS X - Simplify json-c discovery - Fix uloop_timeout_remaining64() detection Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-02lib: introduce uloop bindingJo-Philipp Wich
The uloop module allows controlling the uloop event loop and supports adding timeouts, processes and file descriptors. Example: #!ucode -RS let fs = require("fs"); let uloop = require("uloop"); let fd1 = fs.popen("echo 1; sleep 1; echo 2; sleep 1; echo 3", "r"); let fd2 = fs.popen("echo 4; sleep 1; echo 5; sleep 1; echo 6", "r"); function fd_read_callback(flags) { if (flags & uloop.ULOOP_READ) { let line = this.handle().read("line"); printf("Line from fd <%s/%d>: <%s>\n", this, this.fileno(), trim(line)); } } uloop.init(); uloop.timer(1500, function() { printf("Timeout after 1500ms\n"); }); uloop.handle(fd1, fd_read_callback, uloop.ULOOP_READ); uloop.handle(fd2, fd_read_callback, uloop.ULOOP_READ); uloop.process("date", [ "+%s" ], { LC_ALL: "C" }, function(exitcode) { printf("Date command exited with code %d\n", exitcode); }); uloop.run(); Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-01-18syntax: drop legacy syntax supportJo-Philipp Wich
Drop support for the `local` keyword and `delete` function calls. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-01-18build: support building without compile capabilitiesJo-Philipp Wich
Introduce a new default enable CMake option "COMPILE_SUPPORT" which allows to disable source code compilation in the ucode interpreter. Such an interpreter will only be able to load precompiled ucode files. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-01-18types: add initial infrastructure for function serializationJo-Philipp Wich
- Introduce a new "program" entity which holds the list of functions created during compilation - Instead of storing pointers to the in-memory function representation in the constant list, store the index of the function within the program's function list - When loading functions from the constant list, retrieve the function by index from the program entity Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-01-04treewide: rework numeric value handlingJo-Philipp Wich
- Parse integer literals as unsigned numeric values in order to be able to represent the entire unsigned 64bit value range - Stop parsing minus-prefixed integer literals as negative numbers but treat them as separate minus operator followed by a positive integer instead - Only store unsigned numeric constants in bytecode - Rework numeric comparison logic to be able to handle full 64bit unsigned integers - If possible, yield unsigned 64 bit results for additions - Simplify numeric value conversion API - Compile code with -fwrapv for defined signed overflow semantics Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-10-31lib: introduce struct libraryJo-Philipp Wich
Introduce a new "struct" library which is a port of the Python 3.10 struct module with a reduced set of API functions. It supports the same format patterns and conversions while providing the following methods: struct = require('struct'); buf = struct.pack("fmt", args...); values = struct.unpack("fmt", buf); struct_inst = struct.new("fmt"); buf = struct_inst.pack(args...); values = struct_inst.unpack(buf); Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-10-22lib: introduce resolver libraryJo-Philipp Wich
This adds a simple, UDP-only DNS resolver library mimicking the operation of the extended busybox nslookup applet. Simply querying a domain name will perform A + AAAA resolving by default: # ucode -mresolv -Rs 'printf("%.J\n", resolv.query("example.com"))' { "example.com": { "A": [ "93.184.216.34" ], "AAAA": [ "2606:2800:220:1:248:1893:25c8:1946" ] } } Passing IP addresses will automatically perform PTR requests: # ucode -mresolv -Rs 'printf("%.J\n", resolv.query("8.8.8.8"))' { "8.8.8.8.in-addr.arpa": { "PTR": [ "dns.google" ] } } # ucode -mresolv -Rs 'printf("%.J\n", resolv.query("2001:4860:4860::8888"))' { "8.8.8.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.6.8.4.0.6.8.4.1.0.0.2.ip6.arpa": { "PTR": [ "dns.google" ] } } Additional options for query type and nameserver selection can be passed via a second optional options dictionary: # ucode -mresolv -Rs 'printf("%.J\n", resolv.query([ "openwrt.org", "example.org", "doesnotexist.tld" ], { type: [ "A", "AAAA", "MX" ], nameserver: [ "1.1.1.1", "8.8.4.4" ], timeout: 5000, retries: 2, edns_maxsize: 4096 }))' { "openwrt.org": { "A": [ "139.59.209.225" ], "MX": [ [ 10, "util-01.infra.openwrt.org" ] ], "AAAA": [ "2a03:b0c0:3:d0::1af1:1" ] }, "example.org": { "A": [ "93.184.216.34" ], "AAAA": [ "2606:2800:220:1:248:1893:25c8:1946" ], "MX": [ [ 0, "." ] ] }, "doesnotexist.tld": { "rcode": "NXDOMAIN" } } Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-09-21lib: introduce Linux 802.11 netlink bindingJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-09-15lib: introduce Linux route netlink bindingJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11treewide: harmonize function namingJo-Philipp Wich
- Ensure that most functions follow the subject_verb naming schema - Move type related function from value.c to types.c - Rename value.c to vallist.c Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11examples: add libucode usage examplesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11treewide: move header files into dedicated directoryJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11build: install header filesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11build: split into libucode and ucode cliJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-25main: simplify REQUIRE_SEARCH_PATH initializationJo-Philipp Wich
Do not require parsing in C, pre-split string in cmake and pass it as command separated string array down to CPP, so that it can be interpolated directly into a char *path[] array. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-19build: let require search patch default to CMAKE_INSTALL_PREFIXJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-18compiler, lexer: add NO_LEGACY define to disable legacy syntax featuresJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-14build: lower minimum required CMake version to v3.13Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-27treewide: ISO C / pedantic complianceJo-Philipp Wich
- Shuffle typedefs to avoid need for non-compliant forward declarations - Fix non-compliant empty struct initializers - Remove use of braced expressions - Remove use of anonymous unions - Avoid `void *` pointer arithmetic - Fix several warnings reported by gcc -pedantic mode and clang 11 compilation Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-27build: output error messages on test failuresJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-25treewide: rework internal data type systemJo-Philipp Wich
Instead of relying on json_object values internally, use custom types to represent the different ucode value types which brings a number of advantages compared to the previous approach: - Due to the use of tagged pointers, small integer, string and bool values can be stored directly in the pointer addresses, vastly reducing required heap memory - Ability to create circular data structures such as `let o; o = { test: o };` - Ability to register custom `tostring()` function through prototypes - Initial mark/sweep GC implementation to tear down circular object graphs on VM deinit The change also paves the way for possible future extensions such as constant variables and meta methods for custom ressource types. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-23tests: add more testsPetr Štetiar
* add cram based tests * test under either valgrind or LLVM sanitizers * add libFuzzer template Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23cmake: do not output binaries into lib directoryPetr Štetiar
It doesn't work properly with out of tree builds etc. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23cmake: enable extra compiler checksPetr Štetiar
Let's enforce additional automatic checks enforced by the compiler in order to catch possible errors during compilation. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23cmake: fix includes and librariesPetr Štetiar
So it can be built out of the tree. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23cmake: make 3.0 minimum versionPetr Štetiar
Probably using 3.0+ features anyway and should silence following warning: CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-02-17treewide: rewrite ucode interpreterJo-Philipp Wich
Replace the former AST walking interpreter implementation with a single pass bytecode compiler and a corresponding virtual machine. The rewrite lays the groundwork for a couple of improvements with will be subsequently implemented: - Ability to precompile ucode sources into binary byte code - Strippable debug information - Reduced runtime memory usage Signed-off-by: Jo-Philipp Wich <jo@mein.io>