Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module manager POC #524

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@
.idea
.DS_Store

build/
src/bundles/js/
src/js/core.js
src/js/std.js
src/version.h
node_modules/
docs/api/
test_dir*/
/build/
/src/bundles/js/
/src/js/core.js
/src/js/std.js
/src/version.h
/node_modules/
/docs/api/
/test_dir*/

#External modules
/benchmark/extras/
/deps/extras/
/examples/extras/
/tests/extras/
/src/bundles/c/extras/
/src/js/extras/
/src/extras/
/extras/
/docs/types/extras/

/src/*.c.frag

#Module files
modules.json
23 changes: 21 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ cmake_minimum_required(VERSION 3.14)

project(tjs LANGUAGES C)

if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/deps/extras")
enable_language(CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD 20)
endif()

include(ExternalProject)
include(GNUInstallDirs)

Expand All @@ -16,6 +23,8 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_C_STANDARD 11)



set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

list(APPEND tjs_cflags -Wall -g)
Expand Down Expand Up @@ -57,6 +66,10 @@ add_subdirectory(deps/sqlite3 EXCLUDE_FROM_ALL)
set(BUILD_WASI "simple" CACHE STRING "WASI implementation")
add_subdirectory(deps/wasm3 EXCLUDE_FROM_ALL)

if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/deps/extras")
add_subdirectory(deps/extras EXCLUDE_FROM_ALL)
endif()

if(BUILD_WITH_MIMALLOC)
option(MI_OVERRIDE "" OFF)
option(MI_BUILD_SHARED "" OFF)
Expand All @@ -68,6 +81,9 @@ endif()

find_package(CURL REQUIRED)

file(GLOB_RECURSE src_extras "src/extras/**/*.c" "src/extras/**/*.cpp")
file(GLOB src_bundles_extras "src/bundles/c/extras/*.c")

add_library(tjs STATIC
src/builtins.c
src/curl-utils.c
Expand Down Expand Up @@ -100,6 +116,8 @@ add_library(tjs STATIC
src/bundles/c/core/polyfills.c
src/bundles/c/core/run-main.c
src/bundles/c/core/worker-bootstrap.c
${src_extras}
${src_bundles_extras}
deps/quickjs/cutils.c
)

Expand Down Expand Up @@ -152,7 +170,8 @@ target_compile_options(tjs PRIVATE ${tjs_cflags})
target_compile_definitions(tjs PRIVATE TJS__PLATFORM="${TJS_PLATFORM}")
target_include_directories(tjs PRIVATE ${CURL_INCLUDE_DIRS})
target_include_directories(tjs PUBLIC src)
target_link_libraries(tjs qjs uv_a m3 sqlite3 m pthread ${CURL_LIBRARIES})
target_include_directories(tjs PRIVATE deps)
target_link_libraries(tjs qjs uv_a m3 sqlite3 m pthread ${CURL_LIBRARIES} ${EXTRA_MODULES})

if (BUILD_WITH_MIMALLOC)
target_compile_definitions(tjs PRIVATE TJS__HAS_MIMALLOC)
Expand All @@ -170,4 +189,4 @@ set_target_properties(tjs-cli
add_executable(tjsc EXCLUDE_FROM_ALL
src/qjsc.c
)
target_link_libraries(tjsc qjs m)
target_link_libraries(tjsc qjs m)
23 changes: 18 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ JS_NO_STRIP?=0
TJS=$(BUILD_DIR)/tjs
QJSC=$(BUILD_DIR)/tjsc
STDLIB_MODULES=$(wildcard src/js/stdlib/*.js)
EXTRAS_MODULES=$(wildcard src/js/extras/*.js)
ESBUILD?=npx esbuild
ESBUILD_PARAMS_COMMON=--target=es2022 --platform=neutral --format=esm --main-fields=main,module
ESBUILD_PARAMS_MINIFY=--minify
Expand Down Expand Up @@ -109,18 +110,29 @@ src/bundles/js/stdlib/%.js: src/js/stdlib/*.js src/js/stdlib/ffi/*.js
$(ESBUILD_PARAMS_MINIFY) \
$(ESBUILD_PARAMS_COMMON)

src/bundles/c/stdlib/%.c: $(QJSC) src/bundles/js/stdlib/%.js
src/bundles/c/extras/%.c: $(QJSC) src/bundles/js/extras/%.js
@mkdir -p $(basename $(dir $@))
$(QJSC) -m \
$(QJSC_PARAMS_STIP) \
-o $@ \
-n "tjs:$(basename $(notdir $@))" \
-p tjs__ \
src/bundles/js/stdlib/$(basename $(notdir $@)).js
src/bundles/js/extras/$(basename $(notdir $@)).js

src/bundles/js/extras/%.js: src/js/extras/*.js
$(ESBUILD) src/js/extras/$(notdir $@) \
--bundle \
--outfile=$@ \
--external:buffer \
--external:crypto \
--external:"tjs:*" \
$(ESBUILD_PARAMS_MINIFY) \
$(ESBUILD_PARAMS_COMMON)

stdlib: $(addprefix src/bundles/c/stdlib/, $(patsubst %.js, %.c, $(notdir $(STDLIB_MODULES))))
extras: $(addprefix src/bundles/c/extras/, $(patsubst %.js, %.c, $(notdir $(EXTRAS_MODULES))))

js: core stdlib
js: core stdlib extras

install: $(TJS)
cmake --build $(BUILD_DIR) --target install
Expand All @@ -140,10 +152,11 @@ format:

test:
./$(BUILD_DIR)/tjs test tests/
if [ -d "tests/extras" ]; then ./$(BUILD_DIR)/tjs test tests/extras/; fi

test-advanced:
cd tests/advanced && npm install
./$(BUILD_DIR)/tjs test tests/advanced/

.PRECIOUS: src/bundles/js/core/%.js src/bundles/js/stdlib/%.js
.PHONY: all js debug install clean distclean format test test-advanced core stdlib $(TJS)
.PRECIOUS: src/bundles/js/core/%.js src/bundles/js/stdlib/%.js src/bundles/js/extras/%.js
.PHONY: all js debug install clean distclean format test test-advanced core stdlib extras $(TJS)
36 changes: 20 additions & 16 deletions docs/tsconfig.doc.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
{
"compilerOptions": {
"lib": ["ES2020", "dom"],
"noImplicitAny": true
},
"typedocOptions": {
"name": "txiki.js",
"entryPoints": [ "types/" ],
"entryPointStrategy": "expand",
"out": "api/",
"readme": "intro.md",
"disableSources": true,
"exclude":["types/index.d.ts"]
},
"watchOptions": {
"excludeDirectories": ["api/*"]
}
"compilerOptions": {
"lib": ["ES2020", "dom"],
"target": "ESNext",
"noImplicitAny": true,
"baseUrl": ".",
"typeRoots": ["./node_modules/@types"]
},
"typedocOptions": {
"name": "txiki.js",
"entryPoints": ["types/"],
"entryPointStrategy": "expand",
"out": "api/",
"readme": "intro.md",
"disableSources": true,
"exclude": ["types/index.d.ts"]
},
"watchOptions": {
"excludeDirectories": ["api/*"]
},
"include": ["types/**/*.ts"]
}
19 changes: 10 additions & 9 deletions docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/// <reference path="./txikijs.d.ts" />
/// <reference path="./assert.d.ts" />
/// <reference path="./ffi.d.ts" />
/// <reference path="./getopts.d.ts" />
/// <reference path="./hashing.d.ts" />
/// <reference path="./ipaddr.d.ts" />
/// <reference path="./path.d.ts" />
/// <reference path="./sqlite.d.ts" />
/// <reference path="./uuid.d.ts" />
import "./txikijs.d.ts"
import "./assert.d.ts"
import "./ffi.d.ts"
import "./getopts.d.ts"
import "./hashing.d.ts"
import "./ipaddr.d.ts"
import "./path.d.ts"
import "./sqlite.d.ts"
import "./uuid.d.ts"
import "./extras/index.d.ts"

export {};
Loading