From 6f745eee2a2fd7f83a401343b41e1723cd1fd1cf Mon Sep 17 00:00:00 2001 From: theMackabu Date: Sun, 15 Feb 2026 15:23:38 -0800 Subject: [PATCH] improve core sources to snapshot generation --- libant/meson.build | 55 +++++++++----------------------------- libant/scripts/header.sh | 27 ++++++++++++------- meson.build | 7 +---- meson/deps/meson.build | 1 + meson/snapshot/meson.build | 5 ++++ meson/sources.py | 11 +++++--- sources.json | 4 +++ 7 files changed, 47 insertions(+), 63 deletions(-) diff --git a/libant/meson.build b/libant/meson.build index e5758a9..3faa7ed 100644 --- a/libant/meson.build +++ b/libant/meson.build @@ -8,49 +8,24 @@ project('libant', 'c', default_options: [ 'warning_level=2' ], subproject_dir: 'vendor') -use_lto = get_option('lto') +python = find_program('python3') +is_static = true +use_lto = get_option('lto') src_root = meson.project_source_root() / '..' -vendor_dir = 'vendor' -is_static = true +include = include_directories('../include') subdir('meson') -module_files = run_command('sh', '-c', - 'ls ' + src_root / 'src' / 'modules' / '*.c', +lib_sources = files(run_command( + python, files('meson/sources.py'), src_root / 'sources.json', 'library', src_root, check: true -).stdout().strip().split() - -lib_sources = files( - '../src/roots.c', - '../src/utils.c', - '../src/utf8.c', - '../src/escape.c', - '../src/reactor.c', - '../src/sugar.c', - '../src/ant.c', - '../src/errors.c', - '../src/stack.c', - '../src/gc.c', - '../src/repl.c', - '../src/runtime.c', - '../src/snapshot.c', - '../src/esm/remote.c', -) + files(module_files) - -include = include_directories('../include') -build_include = include_directories('.') -strip_include = include_directories('../src/strip') +).stdout().strip().split()) libant_core = static_library( 'ant_core', lib_sources + [snapshot_h], - include_directories: [ - include, - build_include, - version_include, - strip_include - ], + include_directories: include, dependencies: ant_deps + [oxc_dep], ) @@ -58,12 +33,7 @@ if use_lto libant_core_lto = static_library( 'ant_core_lto', lib_sources + [snapshot_h], - include_directories: [ - include, - build_include, - version_include, - strip_include - ], + include_directories: include, dependencies: ant_deps + [oxc_dep], c_args: ['-flto'], ) @@ -83,19 +53,18 @@ endif pkg.generate( name: 'libant', - description: 'Ant JavaScript Engine - Embeddable JS runtime', - version: version_conf.get('ANT_VERSION'), + version: ant_version, + description: 'javascript for 🐜\'s', extra_cflags: ['-I${includedir}/ant'], libraries: ['-L${libdir}', '-lant'] + pkg_libs ) custom_target( 'ant_header', - input: [config_h], output: 'libant.h', command: [ 'bash', meson.project_source_root() / 'scripts' / 'header.sh', - '@INPUT0@', '@OUTPUT@' + '@OUTPUT@', ant_version, timestamp, git_hash, target_triple, ], build_by_default: true, build_always_stale: true diff --git a/libant/scripts/header.sh b/libant/scripts/header.sh index 93fb0bc..0ebed41 100755 --- a/libant/scripts/header.sh +++ b/libant/scripts/header.sh @@ -1,21 +1,22 @@ #!/bin/bash set -e - . "$(dirname "$0")/common.sh" -CONFIG_H="$1" -OUTPUT="$2" +OUTPUT="$1" +ANT_VERSION="$2" +ANT_BUILD_TIMESTAMP="$3" +ANT_GIT_HASH="$4" +ANT_TARGET_TRIPLE="$5" INCLUDE_DIR="$ROOT_DIR/include" -if [ -z "$CONFIG_H" ] || [ -z "$OUTPUT" ]; then - echo "Usage: $0 " +if [ -z "$OUTPUT" ] || [ -z "$ANT_VERSION" ]; then + echo "Usage: $0 " exit 1 fi VENDOR_DIR="$SCRIPT_DIR/vendor" HEADERS=( - "config.h:$CONFIG_H" "common.h:$INCLUDE_DIR/common.h" "types.h:$INCLUDE_DIR/types.h" "gc.h:$INCLUDE_DIR/gc.h" @@ -41,7 +42,7 @@ for f in "$INCLUDE_DIR"/modules/*.h; do HEADERS+=("$name:$f") done -cat > "$OUTPUT" << 'EOF' +cat > "$OUTPUT" << EOF /* * Ant JavaScript Engine * https://github.com/themackabu/ant @@ -82,6 +83,12 @@ cat > "$OUTPUT" << 'EOF' /* forward declarations */ struct arg_file; +/* === metadata === */ +#define ANT_VERSION "$ANT_VERSION" +#define ANT_BUILD_TIMESTAMP $ANT_BUILD_TIMESTAMP +#define ANT_GIT_HASH "$ANT_GIT_HASH" +#define ANT_TARGET_TRIPLE "$ANT_TARGET_TRIPLE" + EOF for entry in "${HEADERS[@]}"; do @@ -100,7 +107,7 @@ for entry in "${HEADERS[@]}"; do continue fi - if [[ "$line" =~ ^[[:space:]]*#[[:space:]]*include[[:space:]]+\"(config\.h|common\.h|gc.\h|types\.h|compat\.h|ant\.h|utils\.h|arena\.h|runtime\.h|internal\.h)\" ]]; then + if [[ "$line" =~ ^[[:space:]]*#[[:space:]]*include[[:space:]]+\"(metadata\.h|common\.h|gc.\h|types\.h|compat\.h|ant\.h|utils\.h|arena\.h|runtime\.h|internal\.h)\" ]]; then continue fi if [[ "$line" =~ ^[[:space:]]*#[[:space:]]*include[[:space:]]+\"esm/ ]]; then @@ -110,7 +117,7 @@ for entry in "${HEADERS[@]}"; do continue fi - if [[ "$line" =~ ^[[:space:]]*#[[:space:]]*include[[:space:]]+\<(config|common|uv|types|utarray|uthash|minicoro)\.h\> ]]; then + if [[ "$line" =~ ^[[:space:]]*#[[:space:]]*include[[:space:]]+\<(metadata|common|uv|types|utarray|uthash|minicoro)\.h\> ]]; then continue fi @@ -122,4 +129,4 @@ done echo "#endif /* LIBANT_H */" >> "$OUTPUT" -echo "Generated $OUTPUT" +echo "Generated $OUTPUT" \ No newline at end of file diff --git a/meson.build b/meson.build index c655390..2f33afe 100644 --- a/meson.build +++ b/meson.build @@ -15,18 +15,13 @@ is_static = get_option('static_link') src_root = meson.project_source_root() include = include_directories('include') -core_files = files(run_command( - python, files('meson/sources.py'), files('sources.json'), 'core', - check: true -).stdout().strip().split()) +subdir('meson') lib_sources = files(run_command( python, files('meson/sources.py'), files('sources.json'), 'engine', check: true ).stdout().strip().split()) -subdir('meson') - libant = static_library( 'ant', lib_sources + [snapshot_h], diff --git a/meson/deps/meson.build b/meson/deps/meson.build index cbcfe6c..56fba1c 100644 --- a/meson/deps/meson.build +++ b/meson/deps/meson.build @@ -64,6 +64,7 @@ tlsuv_compile_args = [ '-Wno-sometimes-uninitialized', '-Wno-cast-function-type-mismatch', '-Wno-missing-field-initializers', + '-I' + src_root / 'vendor' / 'libuv-v1.52.0' / 'include', ] if cmake_prefix != '' diff --git a/meson/snapshot/meson.build b/meson/snapshot/meson.build index 3444fa5..86ff705 100644 --- a/meson/snapshot/meson.build +++ b/meson/snapshot/meson.build @@ -1,5 +1,10 @@ node = find_program('node', required: true) +core_files = files(run_command( + python, files('../sources.py'), src_root / 'sources.json', 'core', src_root, + check: true +).stdout().strip().split()) + snapshot_h = custom_target( 'snapshot', input: core_files, diff --git a/meson/sources.py b/meson/sources.py index e807ffe..35ce95b 100644 --- a/meson/sources.py +++ b/meson/sources.py @@ -1,11 +1,14 @@ -import sys, glob, json +import sys, os, glob, json data = json.load(open(sys.argv[1])) group = data[sys.argv[2]] +base = sys.argv[3] if len(sys.argv) > 3 else '' matched = set() for p in group['patterns']: - matched.update(glob.glob(p, recursive=True)) + full = os.path.join(base, p) if base else p + matched.update(glob.glob(full, recursive=True)) -matched -= set(group.get('exclude', [])) -print('\n'.join(sorted(matched))) \ No newline at end of file +excluded = set(os.path.join(base, e) if base else e for e in group.get('exclude', [])) +matched -= excluded +print('\n'.join(sorted(matched))) diff --git a/sources.json b/sources.json index 1ca4f60..5759272 100644 --- a/sources.json +++ b/sources.json @@ -3,6 +3,10 @@ "patterns": ["src/*.c", "src/esm/*.c", "src/cli/*.c", "src/modules/*.c"], "exclude": ["src/main.c"] }, + "library": { + "patterns": ["src/*.c", "src/esm/*.c", "src/modules/*.c"], + "exclude": ["src/main.c"] + }, "core": { "patterns": ["src/core/**/*.ts"], "exclude": [] -- 2.51.2