2022-09-23 13:19:43 -07:00
|
|
|
# MAIN: https://kuroko-lang.github.io/
|
|
|
|
# REPO: https://github.com/kuroko-lang/kuroko
|
|
|
|
# TODO: add /zip/ support by default and include dist modules.
|
|
|
|
|
|
|
|
FROM localhost/notwa-util AS downloader
|
2022-10-01 04:37:53 -07:00
|
|
|
ARG KUROKO_COMMIT=7d57acd49a430d697998b90f1a112b2c1fd31e59
|
|
|
|
ARG KUROKO_SHA256=29ab4ca692f5adf1507d9730888c80c312965d4daa33c7a8cae9d0d480cbb71a
|
2022-09-23 13:19:43 -07:00
|
|
|
|
|
|
|
RUN --mount=type=cache,id=common,target=/media/common,sharing=locked \
|
|
|
|
--mount=type=tmpfs,target=/tmp : \
|
2022-10-02 03:19:50 -07:00
|
|
|
&& acquire from=github repo=kuroko-lang/kuroko dest=/kuroko \
|
|
|
|
commit="$KUROKO_COMMIT" checksum="$KUROKO_SHA256" \
|
2022-09-23 13:19:43 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
FROM localhost/cosmo AS builder
|
|
|
|
COPY --from=downloader /kuroko /kuroko
|
|
|
|
WORKDIR /kuroko
|
|
|
|
|
2022-10-01 11:02:27 -07:00
|
|
|
COPY --chmod=0755 --from=localhost/notwa-util /nu/shed /usr/bin/
|
2022-09-23 13:19:43 -07:00
|
|
|
RUN : \
|
2022-09-26 00:53:25 -07:00
|
|
|
&& cp -r . ../kuroko.orig \
|
|
|
|
\
|
2022-10-01 10:36:12 -07:00
|
|
|
&& shed src/os.c \
|
|
|
|
's@.*char \*\* environ.*@#ifndef COSMOPOLITAN_LIBC_RUNTIME_RUNTIME_H_\n&\n#endif@' \
|
2022-09-25 22:29:06 -07:00
|
|
|
\
|
2022-10-01 10:36:12 -07:00
|
|
|
&& shed src/vm.c \
|
|
|
|
'/FUNC_SIG(list,append)/d' \
|
|
|
|
'/void _callSetName/i\\extern FUNC_SIG(list,append);' \
|
2022-09-25 22:29:06 -07:00
|
|
|
\
|
2022-10-01 10:36:12 -07:00
|
|
|
&& shed src/vm.c \
|
|
|
|
'/static.*cache/c\\static KrkClassCacheEntry * cache = 0;' \
|
|
|
|
$'/define CACHE_SIZE/,/nextCount/{N;w /temp\nd}' \
|
|
|
|
$'/void krk_initVM/{r /temp\nN}' \
|
|
|
|
$'/Reset current thread/i\\\tcache = calloc(CACHE_SIZE, sizeof(KrkClassCacheEntry));' \
|
|
|
|
$'/krk_freeMemoryDebugger();/a\\\tcache = (free(cache), NULL);' \
|
2022-09-25 22:29:06 -07:00
|
|
|
\
|
2022-10-01 10:36:12 -07:00
|
|
|
&& shed src/threads.c '/define gettid/d' \
|
|
|
|
&& shed src/vm.c '/"initial-exec"/d' \
|
2022-09-25 22:29:06 -07:00
|
|
|
\
|
2022-10-01 10:36:12 -07:00
|
|
|
&& shed src/vm.c \
|
|
|
|
$'/Ensure we don\'t have a macro/i\\\
|
2022-09-23 13:19:43 -07:00
|
|
|
\#ifdef KRK_DISABLE_DYNAMIC\\\n\
|
|
|
|
KrkValue krk_module_onload_math(void);\\\n\
|
|
|
|
KrkValue krk_module_onload_random(void);\\\n\
|
|
|
|
KrkValue krk_module_onload_socket(void);\\\n\
|
|
|
|
KrkValue krk_module_onload_timeit(void);\\\n\
|
|
|
|
KrkValue krk_module_onload_wcwidth(void);\\\n\
|
|
|
|
\#endif\\\n\
|
2022-10-01 10:36:12 -07:00
|
|
|
\\\n\
|
2022-09-23 13:19:43 -07:00
|
|
|
\#define BUILTIN_MODULE(name, init) { \\\\\\\n\
|
|
|
|
\tKrkInstance * module = (KrkInstance*)AS_OBJECT(init()); \\\\\\\n\
|
|
|
|
\tkrk_attachNamedObject(&vm.modules, name, (KrkObj*)module); \\\\\\\n\
|
|
|
|
\tkrk_attachNamedObject(&module->fields, "__name__", (KrkObj*)S(name)); \\\\\\\n\
|
|
|
|
\tkrk_attachNamedValue(&module->fields, "__file__", NONE_VAL()); \\\\\\\n\
|
2022-10-01 10:36:12 -07:00
|
|
|
} \\' \
|
|
|
|
$'/krk_module_init_dis/a\\\
|
2022-09-23 13:19:43 -07:00
|
|
|
\#endif\\\n\
|
|
|
|
\#ifdef KRK_DISABLE_DYNAMIC\\\n\
|
|
|
|
\t\tBUILTIN_MODULE("math", krk_module_onload_math)\\\n\
|
|
|
|
\t\tBUILTIN_MODULE("random", krk_module_onload_random)\\\n\
|
|
|
|
\t\tBUILTIN_MODULE("socket", krk_module_onload_socket)\\\n\
|
|
|
|
\t\tBUILTIN_MODULE("timeit", krk_module_onload_timeit)\\\n\
|
|
|
|
\t\tBUILTIN_MODULE("wcwidth", krk_module_onload_wcwidth)\n\
|
2022-10-01 10:36:12 -07:00
|
|
|
' \
|
2022-09-25 22:29:06 -07:00
|
|
|
\
|
2022-10-01 10:36:12 -07:00
|
|
|
&& shed src/modules/module_socket.c \
|
|
|
|
'/netdb\.h/a\#include <netinet/in.h>' \
|
|
|
|
$'/switch (afval)/{\ni\\\
|
2022-09-23 13:19:43 -07:00
|
|
|
\tif (afval == AF_INET) return "AF_INET";\\\n\
|
|
|
|
\tif (afval == AF_INET6) return "AF_INET6";\\\n\
|
|
|
|
\tif (afval == AF_UNIX) return "AF_UNIX";\\\n\
|
|
|
|
\tsnprintf(tmp,30,"%d",afval);\\\n\
|
|
|
|
\treturn tmp;\n\
|
|
|
|
}\n\
|
2022-10-01 10:36:12 -07:00
|
|
|
/switch (afval)/,/}/d' \
|
2022-09-25 22:29:06 -07:00
|
|
|
\
|
2022-10-01 10:36:12 -07:00
|
|
|
&& shed src/kuroko.c \
|
|
|
|
$'/strlen(buf)-1/{\n\
|
2022-09-23 13:19:43 -07:00
|
|
|
s/if .*/if (buf[buflen-1] == \'\\\\n\') {/\n\
|
|
|
|
i\\\
|
|
|
|
\t\t\t\tsize_t buflen = strlen(buf);\n\
|
|
|
|
a\\\
|
|
|
|
\t\t\t\t\t\\if (buflen >= 2 && buf[buflen-2] == \'\\\\r\') buf[buflen-2] = \'\\\\n\', buf[buflen-1] = \'\\\\0\';\\\n\
|
|
|
|
\t\t\t\t} else {\n\
|
2022-10-01 10:36:12 -07:00
|
|
|
}' \
|
2022-09-25 22:29:06 -07:00
|
|
|
\
|
2022-10-01 10:36:12 -07:00
|
|
|
&& shed Makefile \
|
|
|
|
$'/ifdef KRK_DISABLE_THREADS/i\\\
|
2022-09-25 22:29:06 -07:00
|
|
|
ifdef KRK_DISABLE_DYNAMIC\\\n\
|
|
|
|
BIN_OBJS += src/modules/module_math.o src/modules/module_random.o src/modules/module_socket.o src/modules/module_timeit.o src/modules/module_wcwidth.o\\\n\
|
|
|
|
CFLAGS += -DKRK_DISABLE_DYNAMIC -DSTATIC_ONLY\\\n\
|
|
|
|
endif\\\n\
|
2022-10-01 10:36:12 -07:00
|
|
|
' \
|
|
|
|
$'/CFLAGS += -DKRK_DISABLE_THREADS/a\\\
|
2022-09-25 22:29:06 -07:00
|
|
|
else\\\n\
|
2022-09-26 00:53:25 -07:00
|
|
|
CFLAGS += -DKRK_MEDIOCRE_TLS\
|
2022-10-01 10:36:12 -07:00
|
|
|
' \
|
2022-09-25 22:29:06 -07:00
|
|
|
\
|
2022-09-23 13:19:43 -07:00
|
|
|
&& { diff -NrU3 /kuroko.orig/ /kuroko/ > /kuroko.patch; [ $? -le 1 ]; }
|
|
|
|
# diff exit status is normally 0 or 1, anything greater is an error.
|
|
|
|
|
|
|
|
RUN : \
|
|
|
|
# this isn't included in the patch because it's super specific to cosmopolitan. \
|
2022-10-01 10:36:12 -07:00
|
|
|
&& shed src/kuroko.c 's/int main/dontinline int _main/' \
|
2022-09-26 00:53:25 -07:00
|
|
|
&& printf %s >>src/kuroko.c $'\n\
|
2022-09-23 13:19:43 -07:00
|
|
|
STATIC_YOINK("__die");\n\
|
2022-09-25 22:29:06 -07:00
|
|
|
void ShowCrashReports(void);\n\
|
2022-09-23 13:19:43 -07:00
|
|
|
int LoadZipArgs(int *, char ***);\n\
|
|
|
|
int main(int argc, char * argv[]) {\n\
|
|
|
|
\tShowCrashReports();\n\
|
|
|
|
\tLoadZipArgs(&argc, &argv);\n\
|
|
|
|
\treturn _main(argc, argv);\n\
|
|
|
|
}\n\
|
2022-09-26 00:53:25 -07:00
|
|
|
'
|
2022-09-23 13:19:43 -07:00
|
|
|
|
2022-09-25 22:29:06 -07:00
|
|
|
RUN tar zxf /cosmopolitan/dist/headers.tar.gz -C /cosmopolitan
|
2022-10-01 11:02:27 -07:00
|
|
|
COPY --chmod=0755 --from=localhost/notwa-util /nu/cosmocc /usr/bin/
|
2022-09-23 13:19:43 -07:00
|
|
|
RUN : \
|
2022-09-25 22:29:06 -07:00
|
|
|
&& CC=cosmocc CFLAGS="-Os -g" AR=ar.com ARFLAGS=rcsD \
|
|
|
|
make.com kuroko modules/codecs/sbencs.krk modules/codecs/dbdata.krk \
|
|
|
|
-j2 KRK_DISABLE_RLINE=1 KRK_DISABLE_DYNAMIC=1 \
|
|
|
|
&& cp kuroko kuroko.com.dbg \
|
|
|
|
&& objcopy -S -O binary kuroko.com.dbg kuroko.com \
|
2022-09-23 13:19:43 -07:00
|
|
|
;
|
2022-09-25 22:29:06 -07:00
|
|
|
RUN make.com test
|
2022-09-23 13:19:43 -07:00
|
|
|
|
|
|
|
FROM scratch AS runner
|
2022-10-01 11:02:27 -07:00
|
|
|
COPY --chmod=0755 --from=localhost/notwa-util /nu/busybox /bin/busybox
|
2022-09-23 13:19:43 -07:00
|
|
|
COPY --chmod=0755 --from=builder /cosmopolitan/bin/ape /bin/ape
|
2022-09-26 19:43:00 -07:00
|
|
|
COPY --chmod=0755 --from=builder /kuroko/kuroko.com /kuroko/kuroko.com.dbg /bin/
|
2022-09-23 13:19:43 -07:00
|
|
|
COPY --from=builder /kuroko.patch /var/local/kuroko.patch
|
|
|
|
ENTRYPOINT ["/bin/ape", "/bin/kuroko.com"]
|