diff --git a/.gitignore b/.gitignore index 6e99d4207..2aca38c70 100644 --- a/.gitignore +++ b/.gitignore @@ -36,8 +36,8 @@ core ### wasm -libsrc/_wasm/crt0.c -libsrc/_wasm/libc.c +# libsrc/_wasm/crt0.c +# libsrc/_wasm/libc.c *.wasm /wcc diff --git a/Makefile b/Makefile index 188e4e9a1..e8e20dd0a 100644 --- a/Makefile +++ b/Makefile @@ -298,10 +298,7 @@ ASSETS_DIR:=public .PHONY: assets assets: $(ASSETS_DIR)/wccfiles.zip -$(WCC_DIR)/www/lib_list.json: $(LIBSRC_DIR)/_wasm/crt0.c $(LIBSRC_DIR)/_wasm/libc.c - npx ts-node tool/update_lib_list.ts --base=./libsrc $^ - -$(ASSETS_DIR)/wccfiles.zip: $(WCC_DIR)/www/lib_list.json cc.wasm +$(ASSETS_DIR)/wccfiles.zip: $(WCC_DIR)/www/lib_list.json cc.wasm $(WCC_LIB_DIR)/wcrt0.a $(WCC_LIB_DIR)/wlibc.a @mkdir -p $(ASSETS_DIR) npx ts-node tool/pack_libs.js $(WCC_DIR)/www/lib_list.json $@ diff --git a/src/wcc/www/lib_list.json b/src/wcc/www/lib_list.json index 18ade83e6..7dd4fe66c 100644 --- a/src/wcc/www/lib_list.json +++ b/src/wcc/www/lib_list.json @@ -32,166 +32,8 @@ "wasi.h": "./libsrc/_wasm/wasi.h" }, "lib": { - "_file.h": "./libsrc/stdio/_file.h", - "_fileman.h": "./libsrc/stdio/_fileman.h", - "_malloc.h": "./libsrc/stdlib/_malloc.h", - "_ieee.h": "./libsrc/math/_ieee.h", - "crt0.c": [ - "./libsrc/_wasm/crt0/_start.c" - ], - "libc.c": [ - "./libsrc/math/_normalize_radian.c", - "./libsrc/math/acos.c", - "./libsrc/math/acosh.c", - "./libsrc/math/asin.c", - "./libsrc/math/asinh.c", - "./libsrc/math/atan.c", - "./libsrc/math/atan2.c", - "./libsrc/math/atanh.c", - "./libsrc/math/ceil.c", - "./libsrc/math/copysign.c", - "./libsrc/math/cos.c", - "./libsrc/math/cosh.c", - "./libsrc/math/exp.c", - "./libsrc/math/fabs.c", - "./libsrc/math/floor.c", - "./libsrc/math/fmod.c", - "./libsrc/math/frexp.c", - "./libsrc/math/isfinite.c", - "./libsrc/math/isinf.c", - "./libsrc/math/isnan.c", - "./libsrc/math/log.c", - "./libsrc/math/log10.c", - "./libsrc/math/modf.c", - "./libsrc/math/pow.c", - "./libsrc/math/round.c", - "./libsrc/math/sin.c", - "./libsrc/math/sinh.c", - "./libsrc/math/sqrt.c", - "./libsrc/math/tan.c", - "./libsrc/math/tanh.c", - "./libsrc/misc/basename.c", - "./libsrc/misc/dirname.c", - "./libsrc/misc/errno.c", - "./libsrc/misc/isalnum.c", - "./libsrc/misc/isalpha.c", - "./libsrc/misc/isdigit.c", - "./libsrc/misc/islower.c", - "./libsrc/misc/isspace.c", - "./libsrc/misc/isupper.c", - "./libsrc/misc/isxdigit.c", - "./libsrc/misc/longjmp.c", - "./libsrc/misc/setjmp.c", - "./libsrc/misc/tolower.c", - "./libsrc/misc/toupper.c", - "./libsrc/stdio/_fclose.c", - "./libsrc/stdio/_fflush.c", - "./libsrc/stdio/_finit.c", - "./libsrc/stdio/_fread.c", - "./libsrc/stdio/_fseek.c", - "./libsrc/stdio/_fwrite.c", - "./libsrc/stdio/assert.c", - "./libsrc/stdio/fclose.c", - "./libsrc/stdio/fdopen.c", - "./libsrc/stdio/feof.c", - "./libsrc/stdio/fflush.c", - "./libsrc/stdio/fgetc.c", - "./libsrc/stdio/fgets.c", - "./libsrc/stdio/fileno.c", - "./libsrc/stdio/fmemopen.c", - "./libsrc/stdio/fopen.c", - "./libsrc/stdio/fprintf.c", - "./libsrc/stdio/fputc.c", - "./libsrc/stdio/fputs.c", - "./libsrc/stdio/fread.c", - "./libsrc/stdio/fseek.c", - "./libsrc/stdio/ftell.c", - "./libsrc/stdio/fwrite.c", - "./libsrc/stdio/getline.c", - "./libsrc/stdio/open_memstream.c", - "./libsrc/stdio/perror.c", - "./libsrc/stdio/printf.c", - "./libsrc/stdio/putchar.c", - "./libsrc/stdio/puts.c", - "./libsrc/stdio/remove.c", - "./libsrc/stdio/snprintf.c", - "./libsrc/stdio/sprintf.c", - "./libsrc/stdio/stdin.c", - "./libsrc/stdio/tmpfile.c", - "./libsrc/stdio/vfprintf.c", - "./libsrc/stdio/vprintf.c", - "./libsrc/stdio/vsnprintf.c", - "./libsrc/stdio/vsprintf.c", - "./libsrc/stdlib/atexit.c", - "./libsrc/stdlib/atof.c", - "./libsrc/stdlib/atoi.c", - "./libsrc/stdlib/atol.c", - "./libsrc/stdlib/atoll.c", - "./libsrc/stdlib/calloc.c", - "./libsrc/stdlib/drand48.c", - "./libsrc/stdlib/erand48.c", - "./libsrc/stdlib/exit.c", - "./libsrc/stdlib/getrandom.c", - "./libsrc/stdlib/lrand48.c", - "./libsrc/stdlib/malloc.c", - "./libsrc/stdlib/mkstemp.c", - "./libsrc/stdlib/mkstemps.c", - "./libsrc/stdlib/nrand48.c", - "./libsrc/stdlib/qsort.c", - "./libsrc/stdlib/rand.c", - "./libsrc/stdlib/realloc.c", - "./libsrc/stdlib/srand.c", - "./libsrc/stdlib/strtod.c", - "./libsrc/stdlib/strtol.c", - "./libsrc/stdlib/strtold.c", - "./libsrc/stdlib/strtoll.c", - "./libsrc/stdlib/strtoul.c", - "./libsrc/stdlib/strtoull.c", - "./libsrc/string/memccpy.c", - "./libsrc/string/memchr.c", - "./libsrc/string/memcmp.c", - "./libsrc/string/memcpy.c", - "./libsrc/string/memmove.c", - "./libsrc/string/memset.c", - "./libsrc/string/stpcpy.c", - "./libsrc/string/stpncpy.c", - "./libsrc/string/strcasecmp.c", - "./libsrc/string/strcat.c", - "./libsrc/string/strchr.c", - "./libsrc/string/strcmp.c", - "./libsrc/string/strcoll.c", - "./libsrc/string/strcpy.c", - "./libsrc/string/strcspn.c", - "./libsrc/string/strdup.c", - "./libsrc/string/strerror.c", - "./libsrc/string/strerror_r.c", - "./libsrc/string/strlen.c", - "./libsrc/string/strncasecmp.c", - "./libsrc/string/strncat.c", - "./libsrc/string/strncmp.c", - "./libsrc/string/strncpy.c", - "./libsrc/string/strndup.c", - "./libsrc/string/strnlen.c", - "./libsrc/string/strpbrk.c", - "./libsrc/string/strrchr.c", - "./libsrc/string/strspn.c", - "./libsrc/string/strstr.c", - "./libsrc/string/strtok.c", - "./libsrc/string/strtok_r.c", - "./libsrc/_wasm/unistd/brk.c", - "./libsrc/_wasm/unistd/clock_gettime.c", - "./libsrc/_wasm/unistd/close.c", - "./libsrc/_wasm/unistd/fstat.c", - "./libsrc/_wasm/unistd/getcwd.c", - "./libsrc/_wasm/unistd/lseek.c", - "./libsrc/_wasm/unistd/lstat.c", - "./libsrc/_wasm/unistd/open.c", - "./libsrc/_wasm/unistd/read.c", - "./libsrc/_wasm/unistd/stat.c", - "./libsrc/_wasm/unistd/time.c", - "./libsrc/_wasm/unistd/unlink.c", - "./libsrc/_wasm/unistd/write.c" - ] + "wcrt0.a": "./lib/wcrt0.a", + "wlibc.a": "./lib/wlibc.a" } } } diff --git a/tool/pack_libs.js b/tool/pack_libs.js index 460416355..5ce933846 100644 --- a/tool/pack_libs.js +++ b/tool/pack_libs.js @@ -5,7 +5,7 @@ const fsPromise = require('fs').promises const {zip} = require('fflate') function isBinFile(fileName) { - return fileName.match(/\.(wasm)$/) != null + return fileName.match(/\.(wasm|a)$/) != null } function replaceRelativeInclude(content) { diff --git a/tool/run-gen2wcc.sh b/tool/run-gen2wcc.sh index e6c8ace02..b9c506ad0 100755 --- a/tool/run-gen2wcc.sh +++ b/tool/run-gen2wcc.sh @@ -14,6 +14,5 @@ fi --dir=. \ --dir=/tmp \ "--mapdir=/usr/include::$PRJROOT/include" \ - "--mapdir=/usr/lib::$PRJROOT/libsrc/_wasm" \ - "--mapdir=/usr/local/include::$PRJROOT/libsrc" \ + "--mapdir=/usr/lib::$PRJROOT/lib" \ "$WCCWASM" -- "$@" diff --git a/tool/update_lib_list.ts b/tool/update_lib_list.ts deleted file mode 100644 index e660c935a..000000000 --- a/tool/update_lib_list.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { assert } from 'console' -import fsPromise from 'node:fs/promises' -import path from 'path' - -const JSON_FN = 'src/wcc/www/lib_list.json' - -async function readIncludeFiles(fn: string): Promise> { - const content = await fsPromise.readFile(fn, 'utf8') - const files = content.split('\n') - .map(line => { - const m = line.match(/^#include\s+<(.+)>$/) - return m ? m[1] : null - }) - .filter(src => src != null) as Array - return files -} - -function updateJsonLibContent(fileList: Record, fn: string, fileEntries: Array): void { - assert(fileList && fileList['usr'] && fileList['usr']['lib']) - fileList['usr']['lib'][fn] = fileEntries -} - -async function updateJson(contentMap: Map>): Promise { - const content = await fsPromise.readFile(JSON_FN, 'utf8') - const json = JSON.parse(content) as object - - contentMap.forEach((fileEntries, fn) => updateJsonLibContent(json, fn, fileEntries)) - - const updated = JSON.stringify(json, null, 2) - await fsPromise.writeFile(JSON_FN, `${updated}\n`) -} - -async function main(): Promise { - let baseDir: string | undefined - - const program = require('commander') - program - .option('--base ', 'Specify base directory', (value: string) => baseDir = value) - .description('Update lib_list.json') - .usage('[options] ') - .parse(process.argv) - - const files = program.args - if (files.length <= 0) { - program.help() - process.exit(1) - } - - const contentMap = new Map>() - for (const fn of files) { - let files = await readIncludeFiles(fn) - if (baseDir != null) { - files = files.map(fn => `${baseDir}/${fn}`) - } - contentMap.set(path.basename(fn), files) - } - updateJson(contentMap) -} - -main()