mirror of
https://github.com/fluencelabs/redis
synced 2025-04-25 18:42:13 +00:00
update sdk and wasi
This commit is contained in:
parent
ec58d4c34a
commit
654e398f76
7
.gitignore
vendored
7
.gitignore
vendored
@ -78,11 +78,12 @@ cmake-build-debug
|
|||||||
# mpeltonen/sbt-idea plugin
|
# mpeltonen/sbt-idea plugin
|
||||||
.idea_modules/
|
.idea_modules/
|
||||||
|
|
||||||
# JIRA plugin
|
|
||||||
atlassian-ide-plugin.xml
|
|
||||||
|
|
||||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
com_crashlytics_export_strings.xml
|
com_crashlytics_export_strings.xml
|
||||||
crashlytics.properties
|
crashlytics.properties
|
||||||
crashlytics-build.properties
|
crashlytics-build.properties
|
||||||
fabric.properties
|
fabric.properties
|
||||||
|
|
||||||
|
# Wasm files
|
||||||
|
*.wasm
|
||||||
|
*.wat
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
FROM ubuntu:19.04
|
FROM ubuntu:18.04
|
||||||
|
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
&& apt-get install -y ca-certificates \
|
&& apt-get install -y ca-certificates \
|
||||||
curl \
|
curl \
|
||||||
git \
|
git \
|
||||||
make \
|
make
|
||||||
libtinfo5
|
|
||||||
|
|
||||||
RUN curl -L https://github.com/CraneStation/wasi-sdk/releases/download/wasi-sdk-6/wasi-sdk-6.0-linux.tar.gz | tar xz --strip-components=1 -C /
|
RUN curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-10/wasi-sdk-10.0-linux.tar.gz | tar xz --strip-components=1 -C /
|
||||||
|
|
||||||
VOLUME /code
|
VOLUME /code
|
||||||
WORKDIR /code
|
WORKDIR /code
|
||||||
|
@ -3,5 +3,6 @@ services:
|
|||||||
redis:
|
redis:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
|
container_name: redis_builder
|
||||||
volumes:
|
volumes:
|
||||||
- .:/code
|
- .:/code
|
||||||
|
@ -1,24 +1,87 @@
|
|||||||
TARGET = redis
|
TARGET = redis
|
||||||
CC = /opt/wasi-sdk/bin/clang
|
CC = /bin/clang
|
||||||
SYSROOT = /opt/wasi-sdk/share/wasi-sysroot
|
SYSROOT = /share/wasi-sysroot
|
||||||
TARGET_TRIPLE = wasm32-unknown-wasi
|
TARGET_TRIPLE = wasm32-wasi
|
||||||
CFLAGS = -nostartfiles -fvisibility=hidden
|
CFLAGS = -nostartfiles -fvisibility=hidden
|
||||||
LDFLAGS = -Wl,--no-entry,--demangle,--allow-undefined
|
LDFLAGS = -Wl,--no-entry,--demangle,--allow-undefined
|
||||||
EXPORT_FUNCS = --export=allocate,--export=deallocate,--export=invoke,--export=load,--export=store,--export=redis_allocate,--export=redis_deallocate,--export=redis_invoke,--export=redis_load,--export=redis_store
|
|
||||||
WRAPPER_SRC = wrapper.c
|
WRAPPER_SRC = wrapper.c
|
||||||
LUA = /code/deps/lua/src
|
LUA = /code/deps/lua/src
|
||||||
REDIS_SERVER = adlist.c quicklist.c debug.c dict.c server.c sds.c zmalloc.c lzf_c.c lzf_d.c pqsort.c zipmap.c sha1.c ziplist.c release.c networking.c util.c object.c db.c t_string.c t_list.c t_set.c t_zset.c t_hash.c multi.c sort.c intset.c crc16.c endianconv.c slowlog.c scripting.c rand.c crc64.c bitops.c notify.c hyperloglog.c latency.c sparkline.c geo.c evict.c expire.c geohash.c geohash_helper.c defrag.c siphash.c rax.c t_stream.c listpack.c lolwut.c lolwut5.c ../deps/lua/src/*.c
|
SDK = sdk/syscalls_stubs.c
|
||||||
SDK = sdk/logger.c
|
|
||||||
|
EXPORT_FUNCS = \
|
||||||
|
--export=allocate,$\
|
||||||
|
--export=deallocate,$\
|
||||||
|
--export=invoke,$\
|
||||||
|
--export=load,$\
|
||||||
|
--export=store,$\
|
||||||
|
--export=redis_allocate,$\
|
||||||
|
--export=redis_deallocate,$\
|
||||||
|
--export=redis_invoke,$\
|
||||||
|
--export=redis_load,$\
|
||||||
|
--export=redis_store
|
||||||
|
|
||||||
|
REDIS_SERVER_SRC = \
|
||||||
|
adlist.c\
|
||||||
|
quicklist.c\
|
||||||
|
debug.c\
|
||||||
|
dict.c\
|
||||||
|
server.c\
|
||||||
|
sds.c\
|
||||||
|
zmalloc.c\
|
||||||
|
lzf_c.c\
|
||||||
|
lzf_d.c\
|
||||||
|
pqsort.c\
|
||||||
|
zipmap.c\
|
||||||
|
sha1.c\
|
||||||
|
ziplist.c\
|
||||||
|
release.c\
|
||||||
|
networking.c\
|
||||||
|
util.c\
|
||||||
|
object.c\
|
||||||
|
db.c\
|
||||||
|
t_string.c\
|
||||||
|
t_list.c\
|
||||||
|
t_set.c\
|
||||||
|
t_zset.c\
|
||||||
|
t_hash.c\
|
||||||
|
multi.c\
|
||||||
|
sort.c\
|
||||||
|
intset.c\
|
||||||
|
crc16.c\
|
||||||
|
endianconv.c\
|
||||||
|
slowlog.c\
|
||||||
|
scripting.c\
|
||||||
|
rand.c\
|
||||||
|
crc64.c\
|
||||||
|
bitops.c\
|
||||||
|
notify.c\
|
||||||
|
hyperloglog.c\
|
||||||
|
latency.c\
|
||||||
|
sparkline.c\
|
||||||
|
geo.c\
|
||||||
|
evict.c\
|
||||||
|
expire.c\
|
||||||
|
geohash.c\
|
||||||
|
geohash_helper.c\
|
||||||
|
defrag.c\
|
||||||
|
siphash.c\
|
||||||
|
rax.c\
|
||||||
|
t_stream.c\
|
||||||
|
listpack.c\
|
||||||
|
lolwut.c\
|
||||||
|
lolwut5.c\
|
||||||
|
../deps/lua/src/*.c
|
||||||
|
|
||||||
.PHONY: default all clean
|
.PHONY: default all clean
|
||||||
|
|
||||||
default: $(TARGET)
|
default: $(TARGET)
|
||||||
all: default
|
all: default
|
||||||
|
|
||||||
$(TARGET): $(SDK) $(REDIS_SERVER) $(WRAPPER_SRC)
|
$(TARGET): $(SDK) $(REDIS_SERVER_SRC) $(WRAPPER_SRC)
|
||||||
|
./mkreleasehdr.sh
|
||||||
$(CC) -O3 --sysroot=$(SYSROOT) --target=$(TARGET_TRIPLE) -I$(LUA) $(CFLAGS) $(LDFLAGS) -Wl,$(EXPORT_FUNCS) $^ -o $@.wasm
|
$(CC) -O3 --sysroot=$(SYSROOT) --target=$(TARGET_TRIPLE) -I$(LUA) $(CFLAGS) $(LDFLAGS) -Wl,$(EXPORT_FUNCS) $^ -o $@.wasm
|
||||||
|
|
||||||
.PRECIOUS: $(TARGET)
|
.PRECIOUS: $(TARGET)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -f $(TARGET).wasm
|
-rm -f $(TARGET).wasm $(TARGET).wat
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
#include "allocator.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#define UNUSED(x) (void)(x)
|
|
||||||
|
|
||||||
void *allocate(size_t size) {
|
|
||||||
return malloc(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void deallocate(void *ptr, size_t size) {
|
|
||||||
UNUSED(size);
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
#ifndef C_SDK_ALLOCATOR_H
|
|
||||||
#define C_SDK_ALLOCATOR_H
|
|
||||||
|
|
||||||
#include <stddef.h> // for size_t
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allocates a memory region of given size.
|
|
||||||
*
|
|
||||||
* Used by Wasm VM for byte array passing. Should be exported from module.
|
|
||||||
*
|
|
||||||
* @param size a size of needed memory region.
|
|
||||||
* @return a pointer to allocated memory region.
|
|
||||||
*/
|
|
||||||
void *allocate(size_t size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Frees a memory region.
|
|
||||||
*
|
|
||||||
* Used by Wasm VM for freeing previous memory allocated by `allocate` function.
|
|
||||||
* Should be exported from module.
|
|
||||||
*
|
|
||||||
* @param ptr the pointer to the previously allocated memory region.
|
|
||||||
* @param size the size of the previously allocated memory region.
|
|
||||||
*/
|
|
||||||
void deallocate(void *ptr, size_t size);
|
|
||||||
|
|
||||||
#endif //C_SDK_ALLOCATOR_H
|
|
@ -1,15 +0,0 @@
|
|||||||
#include "logger.h"
|
|
||||||
|
|
||||||
#define __LOGGER_IMPORT(name) \
|
|
||||||
__attribute__((__import_module__("logger"), __import_name__(#name)))
|
|
||||||
|
|
||||||
void __write(char ch) __LOGGER_IMPORT(write);
|
|
||||||
void __flush() __LOGGER_IMPORT(flush);
|
|
||||||
|
|
||||||
void wasm_log(const char *str, int len) {
|
|
||||||
for(int byteId = 0; byteId < len; ++byteId) {
|
|
||||||
__write(str[byteId]);
|
|
||||||
}
|
|
||||||
|
|
||||||
__flush();
|
|
||||||
}
|
|
@ -1,11 +1,15 @@
|
|||||||
#ifndef C_SDK_LOGGER_H
|
#ifndef FLUENCE_C_SDK_LOGGER_H
|
||||||
#define C_SDK_LOGGER_H
|
#define FLUENCE_C_SDK_LOGGER_H
|
||||||
|
|
||||||
|
#define __LOGGER_IMPORT(name) \
|
||||||
|
__attribute__((__import_module__("logger"), __import_name__(#name)))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes provided string to Wasm VM logger.
|
* Writes provided utf8 string to Wasm VM logger.
|
||||||
*
|
*
|
||||||
* @param log_message a message that should be logged.
|
* @param str a pointer to the string that should be logged.
|
||||||
|
* @param len a size of the string that should be logged.
|
||||||
*/
|
*/
|
||||||
void wasm_log(const char *str, int len);
|
void log_utf8_string(const char *str, int len) __LOGGER_IMPORT(log_utf8_string);
|
||||||
|
|
||||||
#endif //C_SDK_LOGGER_H
|
#endif // FLUENCE_C_SDK_LOGGER_H
|
||||||
|
23
src/sdk/syscalls_stubs.c
Normal file
23
src/sdk/syscalls_stubs.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/// Some syscalls could be as the result of importing files like stdio.h that in its turn imports standart I/O
|
||||||
|
/// descriptors like stdin/stderr/stdout. Each of them is a structure contains some callbacks (e.g.
|
||||||
|
/// https://github.com/CraneStation/wasi-libc/blob/9bb4cc5c411af8453cbef69c137a4c2337714d89/libc-top-half/musl/src/stdio/stdin.c#L11)
|
||||||
|
/// These stubs could provide default implementations for syscalls. And please include this file, if you are sure
|
||||||
|
/// that these syscalls couldn't be used directly.
|
||||||
|
|
||||||
|
size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int __stdio_close(FILE *f) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
off_t __stdio_seek(FILE *_f, off_t _offset, int _value) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t __stdout_write(FILE *f, const unsigned char *buf, size_t len) {
|
||||||
|
return 1;
|
||||||
|
}
|
@ -411,7 +411,7 @@ void serverLogRaw(int level, const char *msg) {
|
|||||||
if (!log_to_stdout) fclose(fp);
|
if (!log_to_stdout) fclose(fp);
|
||||||
if (server.syslog_enabled) syslog(syslogLevelMap[level], "%s", msg);
|
if (server.syslog_enabled) syslog(syslogLevelMap[level], "%s", msg);
|
||||||
#else
|
#else
|
||||||
wasm_log(msg, strlen(msg));
|
log_utf8_string(msg, strlen(msg));
|
||||||
|
|
||||||
// increment time
|
// increment time
|
||||||
ustime();
|
ustime();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user