diff --git a/examples/demo/welcome.js b/examples/demo/welcome.js new file mode 100644 index 0000000..0636f32 --- /dev/null +++ b/examples/demo/welcome.js @@ -0,0 +1,30 @@ +console.log(`Hello from ${navigator.userAgent}! Did you know:\n`); + +const rows = [ + ['Feature', 'Description'], + ['Async/Await', 'Full coroutine support with minicoro'], + ['HTTP Server', 'Built-in Ant.serve() with TLS support'], + ['Fetch API', 'HTTP client with TLS via tlsuv'], + ['File System', 'Async/sync fs with ant:fs module'], + ['FFI', 'Native library integration'], + ['Web Locks', 'Navigator.locks API'], + ['TypeScript', 'Built-in type stripping via oxc'], + ['Garbage Collection', 'Mark-copy compacting + Boehm-Demers'], + ['', ''], + ['And more...'] +]; + +const widths = [0, 0]; +for (const r of rows) { + if (r[0].length > widths[0]) widths[0] = r[0].length; + if (r[1].length > widths[1]) widths[1] = r[1].length; +} + +const border = '+' + '-'.repeat(widths[0] + 2) + '+' + '-'.repeat(widths[1] + 2) + '+'; +console.log(border); +for (let i = 0; i < rows.length; i++) { + const r = rows[i]; + console.log('| ' + r[0].padEnd(widths[0], ' ') + ' | ' + r[1].padEnd(widths[1], ' ') + ' |'); + if (i === 0) console.log(border); +} +console.log(border); diff --git a/libant/example.sh b/libant/example.sh new file mode 100755 index 0000000..0f9dd9f --- /dev/null +++ b/libant/example.sh @@ -0,0 +1,34 @@ +#!/bin/bash +set -e + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +DIST_DIR="$SCRIPT_DIR/dist" +SOURCE="$SCRIPT_DIR/../examples/embed/embed.c" +OUTPUT="$SCRIPT_DIR/dist/embed" + +if [ ! -f "$DIST_DIR/libant.a" ]; then + echo "Error: libant.a not found in $DIST_DIR" + echo "Run ./build.sh first" + exit 1 +fi + +case "$(uname -s)" in + Darwin) + LIBS="-framework Security -framework CoreFoundation -lpthread" + ;; + Linux) + LIBS="-lpthread -ldl -lm" + ;; + MINGW*|MSYS*|CYGWIN*|Windows_NT) + LIBS="-lws2_32 -lrpcrt4 -lsecur32 -lntdll -lcrypt32 -luserenv" + ;; + *) + LIBS="-lpthread" + ;; +esac + +CC="${CC:-clang}" + +echo "Compiling embed example..." +$CC "$SOURCE" -I"$DIST_DIR" "$DIST_DIR/libant.a" $LIBS -o "$OUTPUT" +echo "Done: $OUTPUT" \ No newline at end of file diff --git a/libant/meson b/libant/meson new file mode 120000 index 0000000..baeab15 --- /dev/null +++ b/libant/meson @@ -0,0 +1 @@ +../meson \ No newline at end of file diff --git a/libant/meson.build b/libant/meson.build index b21b037..8332871 100644 --- a/libant/meson.build +++ b/libant/meson.build @@ -13,7 +13,7 @@ src_root = meson.project_source_root() / '..' vendor_dir = 'vendor' is_static = true -subdir('../meson') +subdir('meson') module_files = run_command('sh', '-c', 'ls ' + src_root / 'src' / 'modules' / '*.c', @@ -48,7 +48,12 @@ endif libant_core = static_library( 'ant_core', lib_sources + [snapshot_h], - include_directories: [include, build_include, strip_include], + include_directories: [ + include, + build_include, + version_include, + strip_include + ], dependencies: ant_deps + [oxc_dep], ) @@ -56,7 +61,12 @@ if use_lto libant_core_lto = static_library( 'ant_core_lto', lib_sources + [snapshot_h], - include_directories: [include, build_include, strip_include], + include_directories: [ + include, + build_include, + version_include, + strip_include + ], dependencies: ant_deps + [oxc_dep], c_args: ['-flto'], ) @@ -82,7 +92,7 @@ pkg.generate( libraries: ['-L${libdir}', '-lant'] + pkg_libs ) -gen_header = custom_target( +custom_target( 'ant_header', input: [config_h], output: 'libant.h', @@ -90,5 +100,6 @@ gen_header = custom_target( 'bash', meson.project_source_root() / 'scripts' / 'header.sh', '@INPUT0@', '@OUTPUT@' ], - build_by_default: true + build_by_default: true, + build_always_stale: true ) diff --git a/libant/scripts/compile.sh b/libant/scripts/compile.sh index 2904f71..1d7f51c 100755 --- a/libant/scripts/compile.sh +++ b/libant/scripts/compile.sh @@ -7,5 +7,9 @@ cd "$SCRIPT_DIR" export PKG_CONFIG_PATH="$DEPS_DIR/lib/pkgconfig:$PKG_CONFIG_PATH" -meson setup build --prefer-static -Dtls_library=mbedtls -Ddeps_prefix_cmake="$DEPS_DIR" "$@" -meson compile -C build +mkdir -p "$BUILD_DIR/vendor/tlsuv" +rm -rf "$BUILD_DIR/vendor/tlsuv/deps" +cp -RL "$BUILD_DIR/deps" "$BUILD_DIR/vendor/tlsuv/deps" + +meson setup build --prefer-static -Dtls_library=mbedtls -Ddeps_prefix_cmake="$BUILD_DIR/vendor/tlsuv/deps" "$@" +meson compile -C build \ No newline at end of file diff --git a/libant/scripts/header.sh b/libant/scripts/header.sh index d4b300d..a593df0 100755 --- a/libant/scripts/header.sh +++ b/libant/scripts/header.sh @@ -16,16 +16,14 @@ VENDOR_DIR="$SCRIPT_DIR/vendor" HEADERS=( "config.h:$CONFIG_H" + "common.h:$INCLUDE_DIR/common.h" "compat.h:$INCLUDE_DIR/compat.h" "ant.h:$INCLUDE_DIR/ant.h" "utils.h:$INCLUDE_DIR/utils.h" - "gc_version.h:$VENDOR_DIR/gc-8.2.10/include/gc_version.h" - "gc_config_macros.h:$VENDOR_DIR/gc-8.2.10/include/gc_config_macros.h" - "gc.h:$VENDOR_DIR/gc-8.2.10/include/gc.h" "minicoro.h:$VENDOR_DIR/minicoro/minicoro.h" - "arena.h:$INCLUDE_DIR/arena.h" "runtime.h:$INCLUDE_DIR/runtime.h" "esm/remote.h:$INCLUDE_DIR/esm/remote.h" + "argtable3.h:$VENDOR_DIR/argtable-v3.3.0.116da6c/src/argtable3.h" ) for f in "$INCLUDE_DIR"/modules/*.h; do @@ -71,6 +69,9 @@ cat > "$OUTPUT" << 'EOF' #ifndef LIBANT_H #define LIBANT_H +/* forward declarations */ +struct arg_file; + EOF for entry in "${HEADERS[@]}"; do @@ -99,7 +100,7 @@ for entry in "${HEADERS[@]}"; do continue fi - if [[ "$line" =~ ^[[:space:]]*#[[:space:]]*include[[:space:]]+\ ]]; then + if [[ "$line" =~ ^[[:space:]]*#[[:space:]]*include[[:space:]]+\<(config|common|argtable3)\.h\> ]]; then continue fi diff --git a/meson/version/meson.build b/meson/version/meson.build index 8cc58dc..2c382f6 100644 --- a/meson/version/meson.build +++ b/meson/version/meson.build @@ -4,7 +4,7 @@ git_hash = git_hash != '' ? git_hash : 'unknown' timestamp_opt = get_option('build_timestamp') timestamp = timestamp_opt != '' ? timestamp_opt : run_command('date', '+%s', check: true).stdout().strip() -ant_version = '0.4.0.' + timestamp + '-g' + git_hash +ant_version = '0.4.1.' + timestamp + '-g' + git_hash cmd_cc = meson.get_compiler('c') target_triple = run_command(cmd_cc.cmd_array(), '-dumpmachine', check: true).stdout().strip() @@ -22,7 +22,7 @@ version_conf.set('ANT_BUILD_TIMESTAMP', timestamp) version_conf.set_quoted('ANT_GIT_HASH', git_hash) version_conf.set_quoted('ANT_TARGET_TRIPLE', target_triple) -configure_file( +config_h = configure_file( output: 'config.h', configuration: version_conf )