all: use shed utility

This commit is contained in:
Connor Olding 2022-10-01 10:36:12 -07:00
parent 39dc4acfca
commit c5d5b03b25
4 changed files with 50 additions and 46 deletions

View file

@ -22,27 +22,29 @@ FROM localhost/cosmo AS builder
COPY --from=downloader /kuroko /kuroko COPY --from=downloader /kuroko /kuroko
WORKDIR /kuroko WORKDIR /kuroko
COPY --chmod=0755 --from=localhost/notwa-util /usr/local/bin/shed /usr/bin/
RUN : \ RUN : \
&& cp -r . ../kuroko.orig \ && cp -r . ../kuroko.orig \
\ \
&& sed -i '/bind(gamma)/{N;N;d;}' src/modules/module_math.c \ && shed src/os.c \
&& sed -i '/MATH_ONE(gamma)/d' src/modules/module_math.c \ 's@.*char \*\* environ.*@#ifndef COSMOPOLITAN_LIBC_RUNTIME_RUNTIME_H_\n&\n#endif@' \
\ \
&& sed -i 's@.*char \*\* environ.*@#ifndef COSMOPOLITAN_LIBC_RUNTIME_RUNTIME_H_\n&\n#endif@' src/os.c \ && shed src/vm.c \
'/FUNC_SIG(list,append)/d' \
'/void _callSetName/i\\extern FUNC_SIG(list,append);' \
\ \
&& sed -i '/FUNC_SIG(list,append)/d' src/vm.c \ && shed src/vm.c \
&& sed -i '/void _callSetName/i\\extern FUNC_SIG(list,append);' 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);' \
\ \
&& sed -i '/static.*cache/c\\static KrkClassCacheEntry * cache = 0;' src/vm.c \ && shed src/threads.c '/define gettid/d' \
&& sed -i $'/define CACHE_SIZE/,/nextCount/{N;w /temp\nd}' src/vm.c \ && shed src/vm.c '/"initial-exec"/d' \
&& sed -i $'/void krk_initVM/{r /temp\nN}' src/vm.c \
&& sed -i $'/Reset current thread/i\\\tcache = calloc(CACHE_SIZE, sizeof(KrkClassCacheEntry));' src/vm.c \
&& sed -i $'/krk_freeMemoryDebugger();/a\\\tcache = (free(cache), NULL);' src/vm.c \
\ \
&& sed -i '/define gettid/d' src/threads.c \ && shed src/vm.c \
&& sed -i '/"initial-exec"/d' src/vm.c \ $'/Ensure we don\'t have a macro/i\\\
\
&& sed -i $'/Ensure we don\'t have a macro/{\ni\\\
\#ifdef KRK_DISABLE_DYNAMIC\\\n\ \#ifdef KRK_DISABLE_DYNAMIC\\\n\
KrkValue krk_module_onload_math(void);\\\n\ KrkValue krk_module_onload_math(void);\\\n\
KrkValue krk_module_onload_random(void);\\\n\ KrkValue krk_module_onload_random(void);\\\n\
@ -50,18 +52,14 @@ KrkValue krk_module_onload_socket(void);\\\n\
KrkValue krk_module_onload_timeit(void);\\\n\ KrkValue krk_module_onload_timeit(void);\\\n\
KrkValue krk_module_onload_wcwidth(void);\\\n\ KrkValue krk_module_onload_wcwidth(void);\\\n\
\#endif\\\n\ \#endif\\\n\
\n\ \\\n\
}' src/vm.c \
&& sed -i $'/Ensure we don\'t have a macro/{\ni\\\
\#define BUILTIN_MODULE(name, init) { \\\\\\\n\ \#define BUILTIN_MODULE(name, init) { \\\\\\\n\
\tKrkInstance * module = (KrkInstance*)AS_OBJECT(init()); \\\\\\\n\ \tKrkInstance * module = (KrkInstance*)AS_OBJECT(init()); \\\\\\\n\
\tkrk_attachNamedObject(&vm.modules, name, (KrkObj*)module); \\\\\\\n\ \tkrk_attachNamedObject(&vm.modules, name, (KrkObj*)module); \\\\\\\n\
\tkrk_attachNamedObject(&module->fields, "__name__", (KrkObj*)S(name)); \\\\\\\n\ \tkrk_attachNamedObject(&module->fields, "__name__", (KrkObj*)S(name)); \\\\\\\n\
\tkrk_attachNamedValue(&module->fields, "__file__", NONE_VAL()); \\\\\\\n\ \tkrk_attachNamedValue(&module->fields, "__file__", NONE_VAL()); \\\\\\\n\
} \\\n\ } \\' \
\n\ $'/krk_module_init_dis/a\\\
}' src/vm.c \
&& sed -i $'/krk_module_init_dis/{\na\\\
\#endif\\\n\ \#endif\\\n\
\#ifdef KRK_DISABLE_DYNAMIC\\\n\ \#ifdef KRK_DISABLE_DYNAMIC\\\n\
\t\tBUILTIN_MODULE("math", krk_module_onload_math)\\\n\ \t\tBUILTIN_MODULE("math", krk_module_onload_math)\\\n\
@ -69,44 +67,47 @@ KrkValue krk_module_onload_wcwidth(void);\\\n\
\t\tBUILTIN_MODULE("socket", krk_module_onload_socket)\\\n\ \t\tBUILTIN_MODULE("socket", krk_module_onload_socket)\\\n\
\t\tBUILTIN_MODULE("timeit", krk_module_onload_timeit)\\\n\ \t\tBUILTIN_MODULE("timeit", krk_module_onload_timeit)\\\n\
\t\tBUILTIN_MODULE("wcwidth", krk_module_onload_wcwidth)\n\ \t\tBUILTIN_MODULE("wcwidth", krk_module_onload_wcwidth)\n\
}' src/vm.c \ ' \
\ \
&& sed -i '/netdb\.h/a\#include <netinet/in.h>' src/modules/module_socket.c \ && shed src/modules/module_socket.c \
&& sed -i $'/switch (afval)/{\ni\\\ '/netdb\.h/a\#include <netinet/in.h>' \
$'/switch (afval)/{\ni\\\
\tif (afval == AF_INET) return "AF_INET";\\\n\ \tif (afval == AF_INET) return "AF_INET";\\\n\
\tif (afval == AF_INET6) return "AF_INET6";\\\n\ \tif (afval == AF_INET6) return "AF_INET6";\\\n\
\tif (afval == AF_UNIX) return "AF_UNIX";\\\n\ \tif (afval == AF_UNIX) return "AF_UNIX";\\\n\
\tsnprintf(tmp,30,"%d",afval);\\\n\ \tsnprintf(tmp,30,"%d",afval);\\\n\
\treturn tmp;\n\ \treturn tmp;\n\
}\n\ }\n\
/switch (afval)/,/}/d' src/modules/module_socket.c \ /switch (afval)/,/}/d' \
\ \
&& sed -i $'/strlen(buf)-1/{\n\ && shed src/kuroko.c \
$'/strlen(buf)-1/{\n\
s/if .*/if (buf[buflen-1] == \'\\\\n\') {/\n\ s/if .*/if (buf[buflen-1] == \'\\\\n\') {/\n\
i\\\ i\\\
\t\t\t\tsize_t buflen = strlen(buf);\n\ \t\t\t\tsize_t buflen = strlen(buf);\n\
a\\\ 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\t\\if (buflen >= 2 && buf[buflen-2] == \'\\\\r\') buf[buflen-2] = \'\\\\n\', buf[buflen-1] = \'\\\\0\';\\\n\
\t\t\t\t} else {\n\ \t\t\t\t} else {\n\
}' src/kuroko.c \ }' \
\ \
&& sed -i $'/ifdef KRK_DISABLE_THREADS/i\\\ && shed Makefile \
$'/ifdef KRK_DISABLE_THREADS/i\\\
ifdef KRK_DISABLE_DYNAMIC\\\n\ 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\ 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\ CFLAGS += -DKRK_DISABLE_DYNAMIC -DSTATIC_ONLY\\\n\
endif\\\n\ endif\\\n\
' Makefile \ ' \
&& sed -i $'/CFLAGS += -DKRK_DISABLE_THREADS/a\\\ $'/CFLAGS += -DKRK_DISABLE_THREADS/a\\\
else\\\n\ else\\\n\
CFLAGS += -DKRK_MEDIOCRE_TLS\ CFLAGS += -DKRK_MEDIOCRE_TLS\
' Makefile \ ' \
\ \
&& { diff -NrU3 /kuroko.orig/ /kuroko/ > /kuroko.patch; [ $? -le 1 ]; } && { diff -NrU3 /kuroko.orig/ /kuroko/ > /kuroko.patch; [ $? -le 1 ]; }
# diff exit status is normally 0 or 1, anything greater is an error. # diff exit status is normally 0 or 1, anything greater is an error.
RUN : \ RUN : \
# this isn't included in the patch because it's super specific to cosmopolitan. \ # this isn't included in the patch because it's super specific to cosmopolitan. \
&& sed -i 's/int main/dontinline int _main/' src/kuroko.c \ && shed src/kuroko.c 's/int main/dontinline int _main/' \
&& printf %s >>src/kuroko.c $'\n\ && printf %s >>src/kuroko.c $'\n\
STATIC_YOINK("__die");\n\ STATIC_YOINK("__die");\n\
void ShowCrashReports(void);\n\ void ShowCrashReports(void);\n\

View file

@ -75,10 +75,11 @@ RUN : \
WORKDIR perl WORKDIR perl
COPY --chmod=0755 --from=localhost/notwa-util /usr/local/bin/shed /usr/bin/
RUN : \ RUN : \
&& sed -i '/x86_64-linux-musl/d' hints/cosmo.sh \ && shed hints/cosmo.sh '/x86_64-linux-musl/d' \
&& sed -i 's/.*-musl-objcopy/\tobjcopy/g' Makefile.SH \ && shed Makefile.SH 's/.*-musl-objcopy/\tobjcopy/g' \
&& sed -i '/^cosmo\//d' MANIFEST \ && shed MANIFEST '/^cosmo\//d' \
\ \
&& COSMO_MODE="" COSMO_REPO="/cosmopolitan" sh Configure -d -e \ && COSMO_MODE="" COSMO_REPO="/cosmopolitan" sh Configure -d -e \
-Dprefix="/zip" \ -Dprefix="/zip" \

View file

@ -49,15 +49,15 @@ RUN : \
&& cd /cosmopolitan \ && cd /cosmopolitan \
&& tar zxf dist/headers.tar.gz \ && tar zxf dist/headers.tar.gz \
; ;
COPY --chmod=0755 --from=localhost/notwa-util /usr/local/bin/cosmocc /usr/local/bin/quickconf /usr/bin/ COPY --chmod=0755 --from=localhost/notwa-util /usr/local/bin/cosmocc /usr/local/bin/quickconf /usr/local/bin/shed /usr/bin/
COPY --from=downloader /kissat /kissat COPY --from=downloader /kissat /kissat
WORKDIR /kissat WORKDIR /kissat
RUN : \ RUN : \
# the alarm function is located here: \ # the alarm function is located here: \
&& sed -i '/#include <unistd.h>/i\\#include <time.h>' src/application.c \ && shed src/application.c '/#include <unistd.h>/i\\#include <time.h>' \
# completely override CFLAGS: \ # completely override CFLAGS: \
&& sed -i '/passtocompiler -fpic/i\\CFLAGS=" -O2 -g -Wall"' configure \ && shed configure '/passtocompiler -fpic/i\\CFLAGS=" -O2 -g -Wall"' \
# we don't need -static here because it's already part of cosmocc: \ # we don't need -static here because it's already part of cosmocc: \
&& CC=cosmocc ./configure \ && CC=cosmocc ./configure \
; ;
@ -90,11 +90,12 @@ COPY --from=downloader /yices /yices
WORKDIR /yices WORKDIR /yices
RUN : \ RUN : \
# patch up some trivial incompatibilities with cosmopolitan: \ # patch up some trivial incompatibilities with cosmopolitan: \
&& sed -i 's/\bdonothing\b/&_/g' src/context/context.c \ && shed src/context/context.c 's/\bdonothing\b/&_/g' \
&& sed -i 's/\bhextoint\b/&_/g' src/terms/bv_constants.c src/terms/bv64_constants.c \ && shed src/terms/bv_constants.c 's/\bhextoint\b/&_/g' \
&& sed -i '/#include <unistd.h>/i\\#include <time.h>' src/utils/timeout.c \ && shed src/terms/bv64_constants.c 's/\bhextoint\b/&_/g' \
&& shed src/utils/timeout.c '/#include <unistd.h>/i\\#include <time.h>' \
# the static-lib target attempts to build a dynamic library. don't do that. \ # the static-lib target attempts to build a dynamic library. don't do that. \
&& sed -i 's/ $(static_libyices_dynamic)//g' src/Makefile \ && shed src/Makefile 's/ $(static_libyices_dynamic)//g' \
\ \
&& autoconf \ && autoconf \
&& CC=cosmocc \ && CC=cosmocc \

View file

@ -29,18 +29,19 @@ WORKDIR /cosmopolitan
# tell makefiles to be less noisy, also use /tmp: # tell makefiles to be less noisy, also use /tmp:
ENV V=0 COLUMNS=80 TMPDIR=/tmp ENV V=0 COLUMNS=80 TMPDIR=/tmp
COPY --chmod=0755 --from=localhost/notwa-util /usr/local/bin/shed /usr/bin/
RUN : \ RUN : \
# allow optimized builds to be more portable, so the container is too. \ # allow optimized builds to be more portable, so the container is too. \
&& sed -i 's/-march=native/-march=haswell -mno-pclmul -mtune=generic/' build/config.mk \ && shed build/config.mk 's/-march=native/-march=haswell -mno-pclmul -mtune=generic/' \
# fix execution on alpine (although installing the loader mitigates this) \ # fix execution on alpine (although installing the loader mitigates this) \
&& sed -i 's/skip=" 76" count=" 128"/skip=76 count=128 /' build/bootstrap/*.com \ && sed -i 's/skip=" 76" count=" 128"/skip=76 count=128 /' build/bootstrap/*.com \
&& install -m0755 build/bootstrap/ape.elf /usr/bin/ape \ && install -m0755 build/bootstrap/ape.elf /usr/bin/ape \
# include LoadZipArgs in cosmopolitan.a \ # include LoadZipArgs in cosmopolitan.a \
&& sed -i '/COSMOPOLITAN_OBJECTS =/a\\tTOOL_ARGS\t\t\\' Makefile \ && shed Makefile '/COSMOPOLITAN_OBJECTS =/a\\tTOOL_ARGS\t\t\\' \
# include nsync_cv_signal and nsync_cv_wait_with_deadline in cosmopolitan.a \ # include nsync_cv_signal and nsync_cv_wait_with_deadline in cosmopolitan.a \
&& sed -i '/THIRD_PARTY_NSYNC_MALLOC/i\\tTHIRD_PARTY_NSYNC_MEM\t\t\\' Makefile \ && shed Makefile '/THIRD_PARTY_NSYNC_MALLOC/i\\tTHIRD_PARTY_NSYNC_MEM\t\t\\' \
# awk's pledge isn't working for me for whatever reason \ # awk's pledge isn't working for me for whatever reason \
&& sed -i '/pledge.*{/,/}/d' third_party/awk/main.c \ && shed third_party/awk/main.c '/pledge.*{/,/}/d' \
# create a mapping from flavor to mode (possibly an empty string) \ # create a mapping from flavor to mode (possibly an empty string) \
&& { [ "$COSMO_FLAVOR" != def ] && mode="$COSMO_FLAVOR" || mode=; } \ && { [ "$COSMO_FLAVOR" != def ] && mode="$COSMO_FLAVOR" || mode=; } \
&& printf '%s="%s"\n' >env \ && printf '%s="%s"\n' >env \